cspad_mod/src/CalibDataProxy.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: CalibDataProxy.cpp 3244 2012-04-24 01:00:31Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class CalibDataProxy...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "cspad_mod/CalibDataProxy.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "MsgLogger/MsgLogger.h"
00026 #include "pdscalibdata/CsPad2x2PedestalsV1.h"
00027 #include "pdscalibdata/CsPad2x2PixelGainV1.h"
00028 #include "pdscalibdata/CsPad2x2PixelStatusV1.h"
00029 #include "pdscalibdata/CsPadCommonModeSubV1.h"
00030 #include "pdscalibdata/CsPadFilterV1.h"
00031 #include "pdscalibdata/CsPadPedestalsV1.h"
00032 #include "pdscalibdata/CsPadPixelGainV1.h"
00033 #include "pdscalibdata/CsPadPixelStatusV1.h"
00034 #include "pdsdata/xtc/DetInfo.hh"
00035 #include "PSCalib/CalibFileFinder.h"
00036 
00037 //-----------------------------------------------------------------------
00038 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00039 //-----------------------------------------------------------------------
00040 
00041 namespace {
00042 
00043   const char logger[] = "CalibDataProxy";
00044 
00045   /// Return calibration class (like CsPad::CalibV1) for given source
00046   std::string source2class(const Pds::Src& src)
00047   {
00048     if (src.level() == Pds::Level::Source) {
00049       const Pds::DetInfo& info = static_cast<const Pds::DetInfo&>(src);
00050       if (info.device() == Pds::DetInfo::Cspad2x2) return "CsPad2x2::CalibV1";
00051       if (info.device() == Pds::DetInfo::Cspad) return "CsPad::CalibV1";
00052     }
00053     return std::string();
00054   }
00055 
00056 }
00057 
00058 //              ----------------------------------------
00059 //              -- Public Function Member Definitions --
00060 //              ----------------------------------------
00061 
00062 namespace cspad_mod {
00063 
00064 //----------------
00065 // Constructors --
00066 //----------------
00067 template <typename T>
00068 CalibDataProxy<T>::CalibDataProxy (const std::string& calibDir, const std::string& calibType, int run)
00069   : PSEvt::Proxy<T>()
00070   , m_calibDir(calibDir)
00071   , m_calibType(calibType)
00072   , m_run(run)
00073   , m_data()
00074 {
00075 }
00076 
00077 //--------------
00078 // Destructor --
00079 //--------------
00080 template <typename T>
00081 CalibDataProxy<T>::~CalibDataProxy ()
00082 {
00083 }
00084 
00085 template <typename T>
00086 boost::shared_ptr<T>
00087 CalibDataProxy<T>::getTypedImpl(PSEvt::ProxyDictI* dict,
00088                                 const Pds::Src& source,
00089                                 const std::string& key)
00090 {
00091   _Src src(source);
00092 
00093   // check cache first
00094   typename Src2Data::iterator it = m_data.find(src);
00095   if (it != m_data.end()) return it->second;
00096 
00097   // make a new one
00098   boost::shared_ptr<T> ptr;
00099 
00100   const std::string& cclass = ::source2class(source);
00101   if (not cclass.empty()) {
00102 
00103     PSCalib::CalibFileFinder finder(m_calibDir, cclass);
00104     std::string calibFileName = finder.findCalibFile(source, m_calibType, m_run);
00105     if (not calibFileName.empty()) {
00106       MsgLog(logger, trace, "CalibDataProxy: found calibration file " << calibFileName);
00107       // make new instance that will read data from file
00108       ptr.reset(new T(calibFileName));
00109     }
00110 
00111   }
00112 
00113   // store it in cache
00114   m_data.insert(typename Src2Data::value_type(src, ptr));
00115 
00116   return ptr;
00117 }
00118 
00119 
00120 // explicit instantiation
00121 template class CalibDataProxy<pdscalibdata::CsPad2x2PedestalsV1>;
00122 template class CalibDataProxy<pdscalibdata::CsPad2x2PixelGainV1>;
00123 template class CalibDataProxy<pdscalibdata::CsPad2x2PixelStatusV1>;
00124 template class CalibDataProxy<pdscalibdata::CsPadCommonModeSubV1>;
00125 template class CalibDataProxy<pdscalibdata::CsPadFilterV1>;
00126 template class CalibDataProxy<pdscalibdata::CsPadPedestalsV1>;
00127 template class CalibDataProxy<pdscalibdata::CsPadPixelGainV1>;
00128 template class CalibDataProxy<pdscalibdata::CsPadPixelStatusV1>;
00129 
00130 } // namespace cspad_mod

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7