Detector/src/DetectorAccess.cpp

Go to the documentation of this file.
00001 //-----------------------
00002 // This Class's Header --
00003 //-----------------------
00004 #include "Detector/DetectorAccess.h"
00005 
00006 //-----------------
00007 // C/C++ Headers --
00008 //-----------------
00009 #include <algorithm> // for fill_n
00010 #include <sstream>  // for stringstream
00011 
00012 //-------------------------------
00013 // Collaborating Class Headers --
00014 //-------------------------------
00015 #include "MsgLogger/MsgLogger.h"
00016 // to work with detector data include corresponding 
00017 #include "PSEvt/EventId.h"
00018 #include "PSEvt/Source.h"
00019 #include "PSCalib/CalibParsStore.h"
00020 #include "PSCalib/CalibFileFinder.h"
00021 
00022 //-------------------
00023 namespace Detector {
00024 
00025   typedef DetectorAccess::data_t data_t;
00026   typedef DetectorAccess::image_t image_t;
00027   typedef DetectorAccess::common_mode_t common_mode_t;
00028 
00029 //----------------
00030 // Constructors --
00031 //----------------
00032   DetectorAccess::DetectorAccess (const PSEvt::Source& source, boost::shared_ptr<PSEnv::Env> shp_env, const unsigned& pbits)
00033   : m_calibpars(0)
00034   , m_geometry(0)
00035   , m_cmode(0)
00036   , m_source(source)
00037   , m_runnum(-1)
00038   , m_runnum_geo(-1)
00039   , m_runnum_cmode(-1)
00040   , m_mode(0)
00041   , m_pbits(pbits)
00042   , m_vdef(0)
00043   , m_nda_prod(0)
00044   , m_env(*shp_env)
00045 {
00046   std::stringstream ss; ss << source;
00047   m_str_src = ss.str();
00048   m_dettype = ImgAlgos::detectorTypeForSource(m_source);
00049   m_cgroup  = ImgAlgos::calibGroupForDetType(m_dettype); // for ex: "PNCCD::CalibV1";
00050   m_calibdir = shp_env->calibDir(); // std::string();
00051 
00052   if(m_pbits) {
00053       std::stringstream ss;
00054       ss << "in ctor:" // "SOURCE: " << m_source
00055          << "\nData source  : " << m_str_src
00056          << "\nCalib group  : " << m_cgroup 
00057          << "\nCalib dir    : " << m_calibdir 
00058          << "\nPrint bits   : " << m_pbits
00059          << '\n';
00060       MsgLog(_name_(), info, ss.str());
00061   }
00062 }
00063 
00064 //--------------
00065 // Destructor --
00066 //--------------
00067 DetectorAccess::~DetectorAccess ()
00068 {
00069   if(m_geometry)  delete m_geometry;
00070   if(m_cmode)     delete m_cmode;
00071   if(m_calibpars) delete m_calibpars;
00072 }
00073 
00074 //-------------------
00075 
00076 void
00077 DetectorAccess::initCalibStore(PSEvt::Event& evt, PSEnv::Env& env)
00078 {
00079   //const int& runnum = ImgAlgos::getRunNumber(evt);
00080   //const std::string& calibdir = env.calibDir();
00081   initCalibStore(env.calibDir(), ImgAlgos::getRunNumber(evt));
00082 }
00083 
00084 //-------------------
00085 
00086 void
00087 DetectorAccess::initCalibStore(const std::string& calibdir, const int& runnum)
00088 {
00089   m_calibdir = calibdir;
00090   initCalibStore(runnum);
00091 }
00092 
00093 //-------------------
00094 
00095 void
00096 DetectorAccess::initCalibStore(const int& runnum)
00097 {
00098   if(m_calibpars) {
00099     if(runnum == m_runnum) return;
00100     delete m_calibpars;
00101     m_calibpars = 0;
00102   }
00103   m_runnum = runnum;
00104 
00105   if(m_pbits) {
00106       std::stringstream ss;
00107       ss << "initCalibStore(...):"
00108        //<< "\nInstrument  : " << env.instrument()
00109          << "\nCalib dir   : " << m_calibdir 
00110          << "\nCalib group : " << m_cgroup 
00111          << "\nData source : " << m_str_src
00112          << "\nRun number  : " << m_runnum 
00113          << "\nPrint bits  : " << m_pbits 
00114          << '\n';
00115       
00116       MsgLog(_name_(), info, ss.str());
00117   }
00118 
00119   m_calibpars = PSCalib::CalibParsStore::Create(m_calibdir, m_cgroup, m_str_src, m_runnum, m_pbits);
00120 }
00121 
00122 //-------------------
00123 
00124 void 
00125 DetectorAccess::initGeometry(PSEvt::Event& evt, PSEnv::Env& env)
00126 {
00127   //const int& runnum = ImgAlgos::getRunNumber(evt);
00128   //const std::string& calibdir = env.calibDir();
00129   initGeometry(env.calibDir(), ImgAlgos::getRunNumber(evt));
00130 }
00131 
00132 //-------------------
00133 
00134 void 
00135 DetectorAccess::initGeometry(const std::string& calibdir, const int& runnum)
00136 {
00137   m_calibdir = calibdir;
00138   initGeometry(runnum);
00139 }
00140 
00141 //-------------------
00142 
00143 void 
00144 DetectorAccess::initGeometry(const int& runnum)
00145 {
00146   if(m_geometry) {
00147     if(runnum == m_runnum_geo) return;
00148     delete m_geometry;
00149     m_geometry = 0;
00150   }
00151   m_runnum_geo = runnum;
00152 
00153   unsigned pbits_cff = (m_pbits & 2) ? 0xffff : 0;
00154   PSCalib::CalibFileFinder calibfinder(m_calibdir, m_cgroup, pbits_cff);
00155   std::string fname = calibfinder.findCalibFile(m_str_src, "geometry", runnum);
00156 
00157   if(m_pbits) {
00158       std::stringstream ss;
00159       ss << "initGeometry(...):"
00160        //<< "\nInstrument     : " << env.instrument()
00161          << "\nCalib dir      : " << m_calibdir 
00162          << "\nCalib group    : " << m_cgroup 
00163          << "\nCalib file     : " << fname 
00164          << "\nData source    : " << m_str_src
00165          << "\nRun requested  : " << runnum 
00166          << "\nRun for loaded : " << m_runnum_geo 
00167          << "\nPrint bits     : " << m_pbits 
00168          << '\n';
00169       
00170       MsgLog(_name_(), info, ss.str());
00171   }
00172 
00173   if(fname.empty()) return;    
00174 
00175   unsigned pbits_ga = (m_pbits & 4) ? 0xffff : 0;
00176   m_geometry = new PSCalib::GeometryAccess(fname, pbits_ga);
00177 }
00178 
00179 //-------------------
00180 
00181 void 
00182 DetectorAccess::initNDArrProducer()
00183 {
00184   if(!m_nda_prod) m_nda_prod = NDArrProducerStore::Create(m_source, m_mode, m_pbits, m_vdef); // universal access through the factory store
00185 }
00186 
00187 //-------------------
00188 
00189 //void 
00190 //DetectorAccess::initCommonMode(PSEvt::Event& evt, PSEnv::Env& env)
00191 //{
00192 //  initCommonMode(env.calibDir(), ImgAlgos::getRunNumber(evt));
00193 //}
00194 
00195 //-------------------
00196 
00197 //void 
00198 //DetectorAccess::initCommonMode(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00199 //{
00200 //  initCommonMode(shp_env->calibDir(), ImgAlgos::getRunNumber(*shp_evt));
00201 //}
00202 
00203 //-------------------
00204 
00205 void 
00206 DetectorAccess::initCommonMode(const std::string& calibdir, const int& runnum)
00207 {
00208   m_calibdir = calibdir;
00209   initCommonMode(runnum);
00210 }
00211 
00212 //-------------------
00213 
00214 void 
00215 DetectorAccess::initCommonMode(const int& runnum)
00216 {
00217   if(m_cmode) {
00218     if(runnum == m_runnum_cmode) return;
00219     delete m_cmode;
00220     m_cmode = 0;
00221   }
00222 
00223   m_runnum_cmode = runnum;
00224 
00225   const DetectorAccess::common_mode_t*  cmod_pars = this->p_common_mode (runnum); 
00226   const DetectorAccess::pixel_status_t* status    = this->p_pixel_status(runnum);
00227   const size_t size = this->size(runnum);
00228 
00229   if(m_pbits) {
00230       std::stringstream ss;
00231       ss << "initCommonMode(...):"
00232        //<< "\nInstrument  : " << shp_env->instrument()
00233          << "\nData source : " << m_source
00234          << "\nRun cmode   : " << m_runnum 
00235          << "\nRun number  : " << m_runnum_cmode 
00236          << "\nPrint bits  : " << m_pbits 
00237          << '\n';
00238       
00239       MsgLog(_name_(), info, ss.str());
00240   }
00241 
00242   m_cmode = new ImgAlgos::CommonModeCorrection(m_source, cmod_pars, size, status, m_pbits);
00243 }
00244 
00245 //-------------------
00246 
00247 void 
00248 DetectorAccess::setCModPars(const int& runnum, ndarray<const common_mode_t, 1> nda)
00249 {
00250   initCommonMode(runnum);
00251 
00252   //std::cout << "XXX: DetectorAccess::setCModPars test: " << nda << '\n'; 
00253   //m_nda_cmod_pars = nda.copy();
00254   //const DetectorAccess::common_mode_t* p_pars = nda_pars.data();
00255   //m_cmode -> setCModPars(m_nda_cmod_pars.data());
00256   m_cmode -> setCModPars(nda.data());
00257 
00258   if(m_pbits) { 
00259     std::stringstream ss; ss << "setCModPars(...): " << nda;
00260     MsgLog(_name_(), info, ss.str());
00261   }
00262 }
00263 
00264 //-------------------
00265 //-------------------
00266 //-------------------
00267 //-------------------
00268 //-------------------
00269 
00270 const size_t DetectorAccess::ndim(const int& runnum)
00271 {
00272   initCalibStore(runnum);
00273   return m_calibpars->ndim();
00274 }
00275 
00276 //-------------------
00277 
00278 const size_t DetectorAccess::ndim(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00279 {
00280   m_calibdir = shp_env->calibDir();
00281   return ndim(ImgAlgos::getRunNumber(*shp_evt));
00282 }
00283 
00284 //-------------------
00285 //-------------------
00286 
00287 const size_t DetectorAccess::size(const int& runnum)
00288 {
00289   initCalibStore(runnum);
00290   return m_calibpars->size();
00291 }
00292 
00293 //-------------------
00294 
00295 const size_t DetectorAccess::size(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00296 {
00297   m_calibdir = shp_env->calibDir();
00298   return size(ImgAlgos::getRunNumber(*shp_evt));
00299 }
00300 
00301 //-------------------
00302 //-------------------
00303 
00304 ndarray<const DetectorAccess::shape_t, 1>
00305 DetectorAccess::shape(const int& runnum)
00306 {
00307   initCalibStore(runnum);
00308   return make_ndarray(m_calibpars->shape(), m_calibpars->ndim());
00309 }
00310 
00311 //-------------------
00312 
00313 ndarray<const DetectorAccess::shape_t, 1>
00314 DetectorAccess::shape(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00315 {
00316   m_calibdir = shp_env->calibDir();
00317   return shape(ImgAlgos::getRunNumber(*shp_evt));
00318 }
00319 
00320 //-------------------
00321 //-------------------
00322 //-------------------
00323 //-------------------
00324 
00325 const DetectorAccess::pedestals_t*
00326 DetectorAccess::p_pedestals(const int& runnum)
00327 {
00328   initCalibStore(runnum);
00329   return m_calibpars->pedestals(); // constants loaded before call to size()
00330 }
00331 
00332 //-------------------
00333 
00334 const DetectorAccess::pedestals_t*
00335 DetectorAccess::p_pedestals(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00336 {
00337   m_calibdir = shp_env->calibDir();
00338   return p_pedestals(ImgAlgos::getRunNumber(*shp_evt));
00339 }
00340 
00341 //-------------------
00342 
00343 ndarray<const DetectorAccess::pedestals_t, 1> 
00344 DetectorAccess::pedestals(const int& runnum)
00345 {
00346   initCalibStore(runnum);
00347   const DetectorAccess::pedestals_t* p = m_calibpars->pedestals(); // constants loaded before call to size()
00348   return make_ndarray(p, m_calibpars->size());
00349 }
00350 
00351 //-------------------
00352 
00353 ndarray<const DetectorAccess::pedestals_t, 1> 
00354 DetectorAccess::pedestals(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00355 {
00356   m_calibdir = shp_env->calibDir();
00357   return pedestals(ImgAlgos::getRunNumber(*shp_evt));
00358 }
00359 
00360 //-------------------
00361 //-------------------
00362 //-------------------
00363 //-------------------
00364 
00365 const DetectorAccess::pixel_rms_t*
00366 DetectorAccess::p_pixel_rms(const int& runnum)
00367 {
00368   initCalibStore(runnum);
00369   return m_calibpars->pixel_rms();
00370 }
00371 
00372 //-------------------
00373 
00374 const DetectorAccess::pixel_rms_t*
00375 DetectorAccess::p_pixel_rms(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00376 {
00377   m_calibdir = shp_env->calibDir();
00378   return p_pixel_rms(ImgAlgos::getRunNumber(*shp_evt));
00379 }
00380 
00381 //-------------------
00382 
00383 ndarray<const DetectorAccess::pixel_rms_t, 1> 
00384 DetectorAccess::pixel_rms(const int& runnum)
00385 {
00386   initCalibStore(runnum);
00387   const DetectorAccess::pixel_rms_t* p = m_calibpars->pixel_rms();
00388   return make_ndarray(p, m_calibpars->size());
00389 }
00390 
00391 //-------------------
00392 
00393 ndarray<const DetectorAccess::pixel_rms_t, 1> 
00394 DetectorAccess::pixel_rms(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00395 {
00396   m_calibdir = shp_env->calibDir();
00397   return pixel_rms(ImgAlgos::getRunNumber(*shp_evt));
00398 }
00399 
00400 //-------------------
00401 //-------------------
00402 //-------------------
00403 //-------------------
00404 
00405 const DetectorAccess::pixel_gain_t*
00406 DetectorAccess::p_pixel_gain(const int& runnum)
00407 {
00408   initCalibStore(runnum);
00409   return m_calibpars->pixel_gain();
00410 }
00411 
00412 //-------------------
00413 
00414 const DetectorAccess::pixel_gain_t*
00415 DetectorAccess::p_pixel_gain(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00416 {
00417   m_calibdir = shp_env->calibDir();
00418   return p_pixel_gain(ImgAlgos::getRunNumber(*shp_evt));
00419 }
00420 
00421 //-------------------
00422 
00423 ndarray<const DetectorAccess::pixel_gain_t, 1> 
00424 DetectorAccess::pixel_gain(const int& runnum)
00425 {
00426   initCalibStore(runnum);
00427   const DetectorAccess::pixel_gain_t* p = m_calibpars->pixel_gain();
00428   return make_ndarray(p, m_calibpars->size());
00429 }
00430 
00431 //-------------------
00432 
00433 ndarray<const DetectorAccess::pixel_gain_t, 1> 
00434 DetectorAccess::pixel_gain(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00435 {
00436   m_calibdir = shp_env->calibDir();
00437   return pixel_gain(ImgAlgos::getRunNumber(*shp_evt));
00438 }
00439 
00440 //-------------------
00441 //-------------------
00442 //-------------------
00443 //-------------------
00444 
00445 const DetectorAccess::pixel_mask_t*
00446 DetectorAccess::p_pixel_mask(const int& runnum)
00447 {
00448   initCalibStore(runnum);
00449   return m_calibpars->pixel_mask();
00450 }
00451 
00452 //-------------------
00453 
00454 const DetectorAccess::pixel_mask_t*
00455 DetectorAccess::p_pixel_mask(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00456 {
00457   m_calibdir =shp_env->calibDir();
00458   return p_pixel_mask(ImgAlgos::getRunNumber(*shp_evt));
00459 }
00460 
00461 //-------------------
00462 
00463 ndarray<const DetectorAccess::pixel_mask_t, 1> 
00464 DetectorAccess::pixel_mask(const int& runnum)
00465 {
00466   initCalibStore(runnum);
00467   const DetectorAccess::pixel_mask_t* p = m_calibpars->pixel_mask();
00468   return make_ndarray(p, m_calibpars->size());
00469 }
00470 
00471 //-------------------
00472 
00473 ndarray<const DetectorAccess::pixel_mask_t, 1> 
00474 DetectorAccess::pixel_mask(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00475 {
00476   m_calibdir = shp_env->calibDir();
00477   return pixel_mask(ImgAlgos::getRunNumber(*shp_evt));
00478 }
00479 
00480 //-------------------
00481 //-------------------
00482 //-------------------
00483 //-------------------
00484 
00485 const DetectorAccess::pixel_bkgd_t*
00486 DetectorAccess::p_pixel_bkgd(const int& runnum)
00487 {
00488   initCalibStore(runnum);
00489   return m_calibpars->pixel_bkgd();
00490 }
00491 
00492 //-------------------
00493 
00494 const DetectorAccess::pixel_bkgd_t*
00495 DetectorAccess::p_pixel_bkgd(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00496 {
00497   m_calibdir = shp_env->calibDir();
00498   return p_pixel_bkgd(ImgAlgos::getRunNumber(*shp_evt));
00499 }
00500 
00501 //-------------------
00502 
00503 ndarray<const DetectorAccess::pixel_bkgd_t, 1> 
00504 DetectorAccess::pixel_bkgd(const int& runnum)
00505 {
00506   initCalibStore(runnum);
00507   const DetectorAccess::pixel_bkgd_t* p = m_calibpars->pixel_bkgd();
00508   return make_ndarray(p, m_calibpars->size());
00509 }
00510 
00511 //-------------------
00512 
00513 ndarray<const DetectorAccess::pixel_bkgd_t, 1> 
00514 DetectorAccess::pixel_bkgd(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00515 {
00516   m_calibdir = shp_env->calibDir();
00517   return pixel_bkgd(ImgAlgos::getRunNumber(*shp_evt));
00518 }
00519 
00520 //-------------------
00521 //-------------------
00522 //-------------------
00523 //-------------------
00524 
00525 const DetectorAccess::pixel_status_t*
00526 DetectorAccess::p_pixel_status(const int& runnum)
00527 {
00528   initCalibStore(runnum);
00529   return m_calibpars->pixel_status();
00530 }
00531 
00532 //-------------------
00533 
00534 const DetectorAccess::pixel_status_t*
00535 DetectorAccess::p_pixel_status(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00536 {
00537   m_calibdir = shp_env->calibDir();
00538   return p_pixel_status(ImgAlgos::getRunNumber(*shp_evt));
00539 }
00540 
00541 //-------------------
00542 
00543 ndarray<const DetectorAccess::pixel_status_t, 1> 
00544 DetectorAccess::pixel_status(const int& runnum)
00545 {
00546   initCalibStore(runnum);
00547   const DetectorAccess::pixel_status_t* p = m_calibpars->pixel_status();
00548   return make_ndarray(p, m_calibpars->size());
00549 }
00550 
00551 //-------------------
00552 
00553 ndarray<const DetectorAccess::pixel_status_t, 1> 
00554 DetectorAccess::pixel_status(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00555 {
00556   m_calibdir = shp_env->calibDir();
00557   return pixel_status(ImgAlgos::getRunNumber(*shp_evt));
00558 }
00559 
00560 //-------------------
00561 //-------------------
00562 //-------------------
00563 //-------------------
00564 
00565 const DetectorAccess::common_mode_t*
00566 DetectorAccess::p_common_mode(const int& runnum)
00567 {
00568   initCalibStore(runnum);
00569   return m_calibpars->common_mode();
00570 }
00571 
00572 //-------------------
00573 
00574 const DetectorAccess::common_mode_t*
00575 DetectorAccess::p_common_mode(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00576 {
00577   m_calibdir = shp_env->calibDir();
00578   return p_common_mode(ImgAlgos::getRunNumber(*shp_evt));
00579 }
00580 
00581 //-------------------
00582 
00583 ndarray<const DetectorAccess::common_mode_t, 1> 
00584 DetectorAccess::common_mode(const int& runnum)
00585 {
00586   initCalibStore(runnum);
00587   //std::cout << "TEST cm[0]: " << m_calibpars->common_mode()[0] << "\n";
00588   //std::cout << "TEST cm[3]: " << m_calibpars->common_mode()[3] << "\n";
00589   //std::cout << "TEST  size: " << m_calibpars->size(PSCalib::COMMON_MODE) << "\n";
00590   const DetectorAccess::common_mode_t* p = m_calibpars->common_mode();
00591   return make_ndarray(p, m_calibpars->size(PSCalib::COMMON_MODE));
00592 }
00593 
00594 //-------------------
00595 
00596 ndarray<const DetectorAccess::common_mode_t, 1> 
00597 DetectorAccess::common_mode(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00598 {
00599   m_calibdir = shp_env->calibDir();
00600   return common_mode(ImgAlgos::getRunNumber(*shp_evt));
00601 }
00602 
00603 //-------------------
00604 //-------------------
00605 //-------------------
00606 //-------------------
00607 
00608 const int
00609 DetectorAccess::status(const int& runnum, const int& calibtype) // PSCalib::COMMON_MODE
00610 {
00611   initCalibStore(runnum);
00612   return m_calibpars->status((const PSCalib::CALIB_TYPE)calibtype);
00613 }
00614 
00615 //-------------------
00616 
00617 const int
00618 DetectorAccess::status(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, const int& calibtype) // PSCalib::COMMON_MODE
00619 {
00620   m_calibdir = shp_env->calibDir();
00621   return status(ImgAlgos::getRunNumber(*shp_evt), calibtype);
00622 }
00623 
00624 //-------------------
00625 //-------------------
00626 //-------------------
00627 //-------------------
00628 
00629 ndarray<const int16_t, 1> DetectorAccess::data_int16_1(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00630 {
00631   initNDArrProducer();
00632   if(m_nda_prod == NULL) return ndarray<const int16_t, 1>();
00633   return m_nda_prod->data_nda_int16_1(*shp_evt, *shp_env);
00634 }
00635 
00636 //-------------------
00637 
00638 ndarray<const int16_t, 2> DetectorAccess::data_int16_2(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00639 {
00640   initNDArrProducer();
00641   if(m_nda_prod == NULL) return ndarray<const int16_t, 2>();
00642   return m_nda_prod->data_nda_int16_2(*shp_evt, *shp_env);
00643 }
00644 
00645 //-------------------
00646 
00647 ndarray<const int16_t, 3> DetectorAccess::data_int16_3(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00648 {
00649   initNDArrProducer();
00650   if(m_nda_prod == NULL) return ndarray<const int16_t, 3>();
00651   return m_nda_prod->data_nda_int16_3(*shp_evt, *shp_env);
00652 }
00653 
00654 //-------------------
00655 
00656 ndarray<const int16_t, 4> DetectorAccess::data_int16_4(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00657 {
00658   initNDArrProducer();
00659   if(m_nda_prod == NULL) return ndarray<const int16_t, 4>();
00660   return m_nda_prod->data_nda_int16_4(*shp_evt, *shp_env);
00661 }
00662 
00663 //-------------------
00664 
00665 ndarray<const uint16_t, 2> DetectorAccess::data_uint16_2(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00666 {
00667   initNDArrProducer();
00668   if(m_nda_prod == NULL) return ndarray<const uint16_t, 2>();
00669   return m_nda_prod->data_nda_uint16_2(*shp_evt, *shp_env);
00670 }
00671 
00672 //-------------------
00673 
00674 ndarray<const uint16_t, 3> DetectorAccess::data_uint16_3(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00675 {
00676   initNDArrProducer();
00677   if(m_nda_prod == NULL) return ndarray<const uint16_t, 3>();
00678   return m_nda_prod->data_nda_uint16_3(*shp_evt, *shp_env);
00679 }
00680 
00681 //-------------------
00682 
00683 ndarray<const uint8_t, 2> DetectorAccess::data_uint8_2(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00684 {
00685   initNDArrProducer();
00686   if(m_nda_prod == NULL) return ndarray<const uint8_t, 2>();
00687   return m_nda_prod->data_nda_uint8_2(*shp_evt, *shp_env);
00688 }
00689 
00690 //-------------------
00691 //-------------------
00692 //-------------------
00693 //-------------------
00694 
00695 ndarray<const double, 1> DetectorAccess::pixel_coords_x(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00696 {
00697   m_calibdir = shp_env->calibDir();
00698   return pixel_coords_x(ImgAlgos::getRunNumber(*shp_evt));
00699 }
00700 
00701 //-------------------
00702 
00703 ndarray<const double, 1> DetectorAccess::pixel_coords_x(const int& runnum)
00704 {
00705   initGeometry(runnum);
00706 
00707   const double* pX; 
00708   const double* pY; 
00709   const double* pZ; 
00710   unsigned size;
00711 
00712   if(m_geometry==0) return ndarray<const double, 1>();
00713   m_geometry -> get_pixel_coords(pX, pY, pZ, size);
00714   return make_ndarray(pX, size);
00715 }
00716 
00717 //-------------------
00718 
00719 ndarray<const double, 1> DetectorAccess::pixel_coords_y(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00720 {
00721   m_calibdir = shp_env->calibDir();
00722   return pixel_coords_y(ImgAlgos::getRunNumber(*shp_evt));
00723 }
00724 
00725 //-------------------
00726 
00727 ndarray<const double, 1> DetectorAccess::pixel_coords_y(const int& runnum)
00728 {
00729   initGeometry(runnum);
00730 
00731   const double* pX; 
00732   const double* pY; 
00733   const double* pZ; 
00734   unsigned size;
00735 
00736   if(m_geometry==0) return ndarray<const double, 1>();
00737   m_geometry -> get_pixel_coords(pX, pY, pZ, size);
00738   return make_ndarray(pY, size);
00739 }
00740 
00741 //-------------------
00742 
00743 ndarray<const double, 1> DetectorAccess::pixel_coords_z(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00744 {
00745   m_calibdir = shp_env->calibDir();
00746   return pixel_coords_z(ImgAlgos::getRunNumber(*shp_evt));
00747 }
00748 
00749 //-------------------
00750 
00751 ndarray<const double, 1> DetectorAccess::pixel_coords_z(const int& runnum)
00752 {
00753   initGeometry(runnum);
00754 
00755   const double* pX; 
00756   const double* pY; 
00757   const double* pZ; 
00758   unsigned size;
00759 
00760   if(m_geometry==0) return ndarray<const double, 1>();
00761   m_geometry -> get_pixel_coords(pX, pY, pZ, size);
00762   return make_ndarray(pZ, size);
00763 }
00764 
00765 //-------------------
00766 
00767 ndarray<const double, 1> DetectorAccess::pixel_areas(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00768 {
00769   m_calibdir = shp_env->calibDir();
00770   return pixel_areas(ImgAlgos::getRunNumber(*shp_evt));
00771 }
00772 
00773 //-------------------
00774 
00775 ndarray<const double, 1> DetectorAccess::pixel_areas(const int& runnum)
00776 {
00777   initGeometry(runnum);
00778 
00779   const double* A;
00780   unsigned   size;
00781 
00782   if(m_geometry==0) return ndarray<const double, 1>();
00783   m_geometry -> get_pixel_areas(A,size);
00784   return make_ndarray(A, size);
00785 }
00786 
00787 //-------------------
00788 
00789 // mbits=0377; // 1-edges; 2-wide central cols; 4-non-bond; 8-non-bond neighbours
00790 ndarray<const int, 1> DetectorAccess::pixel_mask_geo(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, const unsigned& mbits)
00791 {
00792   m_calibdir = shp_env->calibDir();
00793   return pixel_mask_geo(ImgAlgos::getRunNumber(*shp_evt), mbits);
00794 }
00795 
00796 //-------------------
00797 
00798 // mbits=0377; // 1-edges; 2-wide central cols; 4-non-bond; 8-non-bond neighbours
00799 ndarray<const int, 1> DetectorAccess::pixel_mask_geo(const int& runnum, const unsigned& mbits)
00800 {
00801   initGeometry(runnum);
00802 
00803   const int* mask;
00804   unsigned   size;
00805 
00806   if(m_geometry==0) return ndarray<const int, 1>();
00807   m_geometry -> get_pixel_mask(mask, size, std::string(), 0, mbits);
00808   return make_ndarray(mask, size);
00809 }
00810 
00811 //-------------------
00812 
00813 ndarray<const unsigned, 1> DetectorAccess::pixel_indexes_x(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00814 {
00815   m_calibdir = shp_env->calibDir();
00816   return pixel_indexes_x(ImgAlgos::getRunNumber(*shp_evt));
00817 }
00818 
00819 //-------------------
00820 
00821 ndarray<const unsigned, 1> DetectorAccess::pixel_indexes_x(const int& runnum)
00822 {
00823   initGeometry(runnum);
00824 
00825   const unsigned* iX;
00826   const unsigned* iY; 
00827   unsigned size;
00828 
00829   //      const std::string ioname = "QUAD:V1";                                                            
00830   //      const unsigned ioindex = 1;                                                                      
00831   //      const double pix_scale_size_um = 109.92;                                                         
00832   //      const int xy0_off_pix[] = {200,200};
00833   //      geometry.get_pixel_coord_indexes(iX, iY, isize, ioname, ioindex, pix_scale_size_um, xy0_off_pix, do_tilt);
00834 
00835   if(m_geometry==0) return ndarray<const unsigned, 1>();
00836   m_geometry -> get_pixel_coord_indexes(iX, iY, size); 
00837   return make_ndarray(iX, size);
00838 }
00839 
00840 //-------------------
00841 
00842 ndarray<const unsigned, 1> DetectorAccess::pixel_indexes_y(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00843 {
00844   m_calibdir = shp_env->calibDir();
00845   return pixel_indexes_y(ImgAlgos::getRunNumber(*shp_evt));
00846 }
00847 
00848 //-------------------
00849 
00850 ndarray<const unsigned, 1> DetectorAccess::pixel_indexes_y(const int& runnum)
00851 {
00852   initGeometry(runnum);
00853 
00854   const unsigned* iX;
00855   const unsigned* iY; 
00856   unsigned size;
00857 
00858   if(m_geometry==0) return ndarray<const unsigned, 1>();
00859   m_geometry -> get_pixel_coord_indexes(iX, iY, size); 
00860   return make_ndarray(iY, size);
00861 }
00862 
00863 //-------------------
00864 
00865 double DetectorAccess::pixel_scale_size(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00866 {
00867   m_calibdir = shp_env->calibDir();
00868   return pixel_scale_size(ImgAlgos::getRunNumber(*shp_evt));
00869 }
00870 
00871 //-------------------
00872 
00873 double DetectorAccess::pixel_scale_size(const int& runnum)
00874 {
00875   initGeometry(runnum);
00876 
00877   if(m_geometry==0) return 1;
00878   return m_geometry -> get_pixel_scale_size ();
00879 }
00880 
00881 //-------------------
00882 
00883 ndarray<const image_t, 2>
00884 DetectorAccess::get_image(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, ndarray<const image_t, 1> nda)
00885 {
00886   m_calibdir = shp_env->calibDir();
00887   return get_image(ImgAlgos::getRunNumber(*shp_evt), nda);
00888 }
00889 
00890 //-------------------
00891 
00892 ndarray<const image_t, 2>
00893 DetectorAccess::get_image(const int& runnum, ndarray<const image_t, 1> nda)
00894 {
00895   initGeometry(runnum);
00896 
00897   const unsigned* iX;
00898   const unsigned* iY; 
00899   unsigned isize;
00900 
00901   if(m_geometry==0) return ndarray<const image_t, 2>();
00902   m_geometry -> get_pixel_coord_indexes(iX, iY, isize);
00903 
00904   //std::cout << "DetectorAccess::get_image isize = " << isize << '\n';
00905   //std::cout << "iX : "; for(int i=0; i<10; i++) std::cout << ' ' << iX[i]; std::cout << '\n';
00906   //std::cout << "iY : "; for(int i=0; i<10; i++) std::cout << ' ' << iY[i]; std::cout << '\n';
00907   //std::cout << "nda: "; for(int i=0; i<10; i++) std::cout << ' ' << nda[i]; std::cout << '\n';
00908 
00909   return PSCalib::GeometryAccess::img_from_pixel_arrays(iX, iY, nda.data(), isize); 
00910 }
00911 
00912 //-------------------
00913 //-------------------
00914 //-------------------
00915 //-------------------
00916 
00917 void DetectorAccess::print()
00918 {
00919   initNDArrProducer();
00920   return m_nda_prod->print();
00921 }
00922 
00923 //-------------------
00924 
00925 void DetectorAccess::print_config(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env)
00926 {
00927   initNDArrProducer();
00928   return m_nda_prod->print_config(*shp_evt, *shp_env);
00929 }
00930 
00931 //-------------------
00932 
00933 std::string DetectorAccess::str_inst(boost::shared_ptr<PSEnv::Env> shp_env)
00934 {  
00935   return shp_env->instrument().c_str();
00936 }
00937 
00938 //-------------------
00939 
00940 /*
00941   template <typename T>
00942   void DetectorAccess::apply_common_mode(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, T* nda)
00943     {
00944       initCommonMode(shp_evt, shp_env);
00945       m_cmode -> do_common_mode<T>(nda);
00946     }
00947 
00948 template void DetectorAccess::apply_common_mode<double>  (boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, double* nda);
00949 template void DetectorAccess::apply_common_mode<float>   (boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, float* nda);
00950 template void DetectorAccess::apply_common_mode<int>     (boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, int* nda);
00951 template void DetectorAccess::apply_common_mode<int16_t> (boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, int16_t* nda);
00952 template void DetectorAccess::apply_common_mode<uint16_t>(boost::shared_ptr<PSEvt::Event> shp_evt, boost::shared_ptr<PSEnv::Env> shp_env, uint16_t* nda);
00953 */
00954 
00955 //-------------------
00956 
00957 
00958 //-------------------
00959 } // namespace Detector
00960 //-------------------
00961 
00962 
00963 
00964 
00965 

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7