PSCalib/include/CalibParsStore.h

Go to the documentation of this file.
00001 #ifndef PSCALIB_CALIBPARSSTORE_H
00002 #define PSCALIB_CALIBPARSSTORE_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: CalibParsStore.h 12199 2016-07-01 01:04:24Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // $Revision: 12199 $
00009 //------------------------------------------------------------------------
00010 
00011 //-----------------
00012 // C/C++ Headers --
00013 //-----------------
00014 #include <iostream>
00015 #include <string>
00016 #include <vector>
00017 //#include <map>
00018 //#include <fstream>  // open, close etc.
00019 
00020 //-------------------------------
00021 // Collaborating Class Headers --
00022 //-------------------------------
00023 #include "ndarray/ndarray.h"
00024 #include "pdsdata/xtc/Src.hh"
00025 #include "MsgLogger/MsgLogger.h"
00026 #include "ImgAlgos/GlobalMethods.h" // ::toString( const Pds::Src& src )
00027 #include "PSCalib/CalibPars.h"
00028 
00029 //#include "PSCalib/CSPad2x2CalibIntensity.h"
00030 //#include "PSCalib/CSPadCalibIntensity.h"
00031 //#include "PSCalib/PnccdCalibPars.h"
00032 //#include "PSCalib/PrincetonCalibPars.h"
00033 
00034 
00035 #include "PSCalib/GenericCalibPars.h"
00036 
00037 #include "pdscalibdata/CsPadBaseV2.h"     // shape_base(), Ndim, Rows, Cols, Size, etc.
00038 #include "pdscalibdata/CsPad2x2BaseV2.h"
00039 #include "pdscalibdata/PnccdBaseV1.h"
00040 #include "pdscalibdata/PrincetonBaseV1.h"
00041 #include "pdscalibdata/AndorBaseV1.h"
00042 #include "pdscalibdata/Andor3dBaseV1.h"
00043 #include "pdscalibdata/Epix100aBaseV1.h"
00044 #include "pdscalibdata/VarShapeCameraBaseV1.h"
00045 //#include "pdscalibdata/Opal1000BaseV1.h"
00046 //#include "pdscalibdata/Opal4000BaseV1.h"
00047 
00048 
00049 //-----------------------------
00050 
00051 namespace PSCalib {
00052 
00053 /**
00054  *  @defgroup PSCalib PSCalib package
00055  *  @brief Package PSCalib provides access to the calibration parameters of all detectors
00056  */
00057 
00058 /// @addtogroup PSCalib PSCalib
00059 
00060 /**
00061  *  @ingroup PSCalib
00062  *
00063  *  @brief class CalibParsStore has a static factory method Create for CalibPars
00064  *
00065  *  This software was developed for the LCLS project. If you use all or 
00066  *  part of it, please give an appropriate acknowledgment.
00067  *
00068  *  @version $Id: CalibParsStore.h 12199 2016-07-01 01:04:24Z dubrovin@SLAC.STANFORD.EDU $
00069  *
00070  *  @author Mikhail S. Dubrovin
00071  *
00072  *  @see CalibPars
00073  *
00074  *  @anchor interface
00075  *  @par<interface> Interface Description
00076  * 
00077  *  @li  Includes
00078  *  @code
00079  *  #include "psana/Module.h" // for evt, env, get,  etc.
00080  *  #include "PSCalib/CalibPars.h"
00081  *  #include "PSCalib/CalibParsStore.h"
00082  *  @endcode
00083  *
00084  *  @li Instatiation
00085  *  \n
00086  *  Here we assume that code is working inside psana module where evt and env variables are defined through input parameters of call-back methods. 
00087  *  Code below instateates calibpars object using factory static method PSCalib::CalibParsStore::Create:
00088  *  @code
00089  *  std::string calib_dir = env.calibDir(); // or "/reg/d/psdm/<INS>/<experiment>/calib"
00090  *  std::string  group = std::string(); // or something like "PNCCD::CalibV1";
00091  *  const std::string source = "Camp.0:pnCCD.1";
00092  *  const std::string key = ""; // key for raw data
00093  *  Pds::Src src; env.get(source, key, &src);
00094  *  PSCalib::CalibPars* calibpars = PSCalib::CalibParsStore::Create(calib_dir, group, src, PSCalib::getRunNumber(evt));
00095  *  @endcode
00096  *
00097  *  @li Access methods
00098  *  @code
00099  *  calibpars->printCalibPars();
00100  *  const PSCalib::CalibPars::pedestals_t*    peds_data = calibpars->pedestals();
00101  *  const PSCalib::CalibPars::pixel_gain_t*   gain_data = calibpars->pixel_gain();
00102  *  const PSCalib::CalibPars::pixel_mask_t*   mask_data = calibpars->pixel_mask();
00103  *  const PSCalib::CalibPars::pixel_bkgd_t*   bkgd_data = calibpars->pixel_bkgd();
00104  *  const PSCalib::CalibPars::pixel_rms_t*    rms_data  = calibpars->pixel_rms();
00105  *  const PSCalib::CalibPars::pixel_status_t* stat_data = calibpars->pixel_status();
00106  *  const PSCalib::CalibPars::common_mode_t*  cmod_data = calibpars->common_mode();
00107  *  @endcode
00108  */
00109 
00110 //----------------
00111 
00112 class CalibParsStore  {
00113 public:
00114 
00115   //CalibParsStore () {}
00116   //virtual ~CalibParsStore () {}
00117 
00118 
00119   /**
00120    *  @brief Regular constructor, which use const std::string& str_src
00121    *  
00122    *  @param[in] calibdir       Calibration directory for current experiment.
00123    *  @param[in] group          Data type and group names.
00124    *  @param[in] str_src        The data source name, ex.: Camp.0:pnCCD.0
00125    *  @param[in] runnum         Run number to search the valid file name.
00126    *  @param[in] print_bits     Print control bit-word.
00127    */ 
00128   static PSCalib::CalibPars*
00129   Create ( const std::string&   calibdir,     //  /reg/d/psdm/AMO/amoa1214/calib
00130            const std::string&   group,        //  PNCCD::CalibV1
00131            const std::string&   str_src,      //  Camp.0:pnCCD.0
00132            const unsigned long& runnum,       //  10
00133            unsigned             print_bits=255 )
00134   {
00135         unsigned prbits = (print_bits & 8) ? 255 : 0;
00136 
00137         /*
00138         if ( str_src.find(":Cspad.") != std::string::npos ) {
00139            MsgLog("CalibParsStore", info, "Get access to calibration store for Cspad source: " << str_src);
00140            std::string type_group = (group==std::string()) ? "CsPad::CalibV1" : group;
00141            unsigned prbits = (print_bits & 1) ? 255 : 0;
00142            return new PSCalib::CSPadCalibIntensity(calibdir, type_group, src, runnum, prbits);
00143         }
00144 
00145         if ( str_src.find(":Cspad2x2.") != std::string::npos ) {
00146            MsgLog("CalibParsStore", info, "Get access to calibration store for Cspad2x2 source: " << str_src);
00147            std::string type_group = (group==std::string()) ? "CsPad2x2::CalibV1" : group;
00148            unsigned prbits = (print_bits & 2) ? 255 : 0;
00149            return new PSCalib::CSPad2x2CalibIntensity(calibdir, type_group, src, runnum, prbits);
00150         }
00151 
00152         if ( str_src.find(":pnCCD.") != std::string::npos ) {
00153            MsgLog("CalibParsStore", info, "Get access to calibration store for pnCCD source: " << str_src);
00154            std::string type_group = (group==std::string()) ? "PNCCD::CalibV1" : group;
00155            unsigned prbits = (print_bits & 4) ? 255 : 0;
00156            return new PSCalib::PnccdCalibPars(calibdir, type_group, src, runnum, prbits);
00157         }
00158 
00159         if ( str_src.find(":Princeton.") != std::string::npos ) {
00160            MsgLog("CalibParsStore", info, "Get access to calibration store for Princeton source: " << str_src);
00161            std::string type_group = (group==std::string()) ? "Princeton::CalibV1" : group;
00162            unsigned prbits = (print_bits & 8) ? 40 : 0;
00163            return new PSCalib::PrincetonCalibPars(calibdir, type_group, src, runnum, prbits);
00164         }
00165         */
00166 
00167         // Generic approach to calibration 
00168 
00169         if ( str_src.find(":Cspad.") != std::string::npos ) {
00170            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Cspad source: " << str_src);
00171            std::string type_group = (group==std::string()) ? "CsPad::CalibV1" : group;
00172            return new PSCalib::GenericCalibPars<pdscalibdata::CsPadBaseV2>(calibdir, type_group, str_src, runnum, prbits);
00173         }
00174 
00175         if ( str_src.find(":Cspad2x2.") != std::string::npos ) {
00176            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Cspad2x2 source: " << str_src);
00177            std::string type_group = (group==std::string()) ? "CsPad2x2::CalibV1" : group;
00178            return new PSCalib::GenericCalibPars<pdscalibdata::CsPad2x2BaseV2>(calibdir, type_group, str_src, runnum, prbits);
00179         }
00180 
00181         if ( str_src.find(":pnCCD.") != std::string::npos ) {
00182            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for pnCCD source: " << str_src);
00183            std::string type_group = (group==std::string()) ? "PNCCD::CalibV1" : group;
00184            return new PSCalib::GenericCalibPars<pdscalibdata::PnccdBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00185         }
00186 
00187         if ( str_src.find(":Princeton.") != std::string::npos ) {
00188            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Princeton source: " << str_src);
00189            std::string type_group = (group==std::string()) ? "Princeton::CalibV1" : group;
00190            return new PSCalib::GenericCalibPars<pdscalibdata::PrincetonBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00191         }
00192 
00193         if ( str_src.find(":DualAndor.") != std::string::npos ) {
00194            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Andor source: " << str_src);
00195            std::string type_group = (group==std::string()) ? "Andor3d::CalibV1" : group;
00196            return new PSCalib::GenericCalibPars<pdscalibdata::Andor3dBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00197         }
00198 
00199         if ( str_src.find(":Andor.") != std::string::npos ) {
00200            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Andor source: " << str_src);
00201            std::string type_group = (group==std::string()) ? "Andor::CalibV1" : group;
00202            return new PSCalib::GenericCalibPars<pdscalibdata::AndorBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00203         }
00204 
00205         if ( str_src.find(":Epix100a.") != std::string::npos ) {
00206            if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for Epix100a source: " << str_src);
00207            std::string type_group = (group==std::string()) ? "Epix100a::CalibV1" : group;
00208            return new PSCalib::GenericCalibPars<pdscalibdata::Epix100aBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00209         }
00210 
00211         std::vector<std::string> v_camera_names;
00212         v_camera_names.push_back(":Opal1000.");
00213         v_camera_names.push_back(":Opal2000.");
00214         v_camera_names.push_back(":Opal4000.");
00215         v_camera_names.push_back(":Opal8000.");
00216         v_camera_names.push_back(":Tm6740.");
00217         v_camera_names.push_back(":OrcaFl40.");
00218         v_camera_names.push_back(":Fccd960.");
00219         v_camera_names.push_back(":Rayonix.");
00220 
00221         prbits = (print_bits & 8) ? 255 : 0;
00222 
00223         for (std::vector<std::string>::iterator it = v_camera_names.begin(); it != v_camera_names.end(); ++it) {
00224           if ( str_src.find(*it) != std::string::npos ) {
00225             std::string type_group = (group==std::string()) ? "Camera::CalibV1" : group;
00226             if (print_bits & 1) MsgLog("CalibParsStore", info, "Get access to calibration store for det " << *it 
00227                                            << " source: " << str_src << " group: " << type_group);
00228             return new PSCalib::GenericCalibPars<pdscalibdata::VarShapeCameraBaseV1>(calibdir, type_group, str_src, runnum, prbits);
00229             //return new PSCalib::GenericCalibPars<pdscalibdata::Opal1000BaseV1>(calibdir, type_group, src, runnum, prbits);
00230           }
00231         }
00232 
00233         std::string msg = "Calibration parameters for source: " + str_src + " are not implemented yet...";
00234         MsgLog("CalibParsStore", error, msg);  
00235 
00236         abort();
00237 
00238         //return NULL;
00239   }
00240 
00241 
00242 
00243   /**
00244    *  @brief Regular constructor, which use Pds::Src& src
00245    *  
00246    *  @param[in] calibdir       Calibration directory for current experiment.
00247    *  @param[in] group          Data type and group names.
00248    *  @param[in] src            The data source object, for example Pds::Src m_src; defined in the env.get(...,&m_src)
00249    *  @param[in] runnum         Run number to search the valid file name.
00250    *  @param[in] print_bits     Print control bit-word.
00251    */ 
00252   static PSCalib::CalibPars*
00253   Create ( const std::string&   calibdir,     //  /reg/d/psdm/mec/mec73313/calib
00254            const std::string&   group,        //  CsPad2x2::CalibV1
00255            const Pds::Src&      src,          //  Pds::Src m_src; <- is defined in env.get(...,&m_src)
00256            const unsigned long& runnum,       //  10
00257            unsigned             print_bits=255 )
00258   {
00259     return Create(calibdir, group, ImgAlgos::srcToString(src), runnum, print_bits);
00260   }
00261 
00262 };
00263 
00264 } // namespace PSCalib
00265 
00266 #endif // PSCALIB_CALIBPARSSTORE_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7