cspad_mod/src/CsPadCalib.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: CsPadCalib.cpp 3244 2012-04-24 01:00:31Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class CsPadCalib...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "cspad_mod/CsPadCalib.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "cspad_mod/CalibDataProxy.h"
00026 #include "cspad_mod/DataProxy2x2.h"
00027 #include "cspad_mod/DataProxyT.h"
00028 #include "MsgLogger/MsgLogger.h"
00029 #include "pdscalibdata/CsPadCommonModeSubV1.h"
00030 #include "pdscalibdata/CsPad2x2PedestalsV1.h"
00031 #include "pdscalibdata/CsPad2x2PixelGainV1.h"
00032 #include "pdscalibdata/CsPad2x2PixelStatusV1.h"
00033 #include "pdscalibdata/CsPadPedestalsV1.h"
00034 #include "pdscalibdata/CsPadPixelGainV1.h"
00035 #include "pdscalibdata/CsPadPixelStatusV1.h"
00036 #include "PSCalib/CalibFileFinder.h"
00037 #include "psddl_psana/cspad.ddl.h"
00038 #include "psddl_psana/cspad2x2.ddl.h"
00039 #include "PSEvt/EventId.h"
00040 
00041 //-----------------------------------------------------------------------
00042 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00043 //-----------------------------------------------------------------------
00044 
00045 // This declares this class as psana module
00046 using namespace cspad_mod;
00047 PSANA_MODULE_FACTORY(CsPadCalib)
00048 
00049 //              ----------------------------------------
00050 //              -- Public Function Member Definitions --
00051 //              ----------------------------------------
00052 
00053 namespace cspad_mod {
00054 
00055 //----------------
00056 // Constructors --
00057 //----------------
00058 CsPadCalib::CsPadCalib (const std::string& name)
00059   : Module(name)
00060   , m_inkey()
00061   , m_outkey()
00062   , m_doPedestals()
00063   , m_doPixelStatus()
00064   , m_doCommonMode()
00065 {
00066   m_inkey = configStr("inputKey", "");
00067   m_outkey = configStr("outputKey", "calibrated");
00068   m_doPedestals = config("doPedestals", true);
00069   m_doPixelStatus = config("doPixelStatus", true);
00070   m_doCommonMode = config("doCommonMode", true);
00071   m_doPixelGain = config("doPixelGain", true);
00072 }
00073 
00074 //--------------
00075 // Destructor --
00076 //--------------
00077 CsPadCalib::~CsPadCalib ()
00078 {
00079 }
00080 
00081 /// Method which is called once at the beginning of the job
00082 void 
00083 CsPadCalib::beginJob(Event& evt, Env& env)
00084 {
00085 }
00086 
00087 /// Method which is called at the beginning of the run
00088 void 
00089 CsPadCalib::beginRun(Event& evt, Env& env)
00090 {
00091   // get run number
00092   shared_ptr<EventId> eventId = evt.get();
00093   int run = 0;
00094   if (eventId.get()) {
00095     run = eventId->run();
00096   } else {
00097     MsgLog(name(), warning, name() << ": Cannot determine run number, will use 0.");
00098   }
00099 
00100   // add proxies to calib store
00101   PSEnv::EnvObjectStore& calibStore = env.calibStore();
00102 
00103   if (m_doPedestals) {
00104     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPad2x2PedestalsV1> > proxy1(
00105         new CalibDataProxy<pdscalibdata::CsPad2x2PedestalsV1>(env.calibDir(), "pedestals", run));
00106     calibStore.putProxy(proxy1, PSEvt::EventKey::anySource());
00107 
00108     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPadPedestalsV1> > proxy2(
00109         new CalibDataProxy<pdscalibdata::CsPadPedestalsV1>(env.calibDir(), "pedestals", run));
00110     calibStore.putProxy(proxy2, PSEvt::EventKey::anySource());
00111   }
00112 
00113   if (m_doPixelStatus) {
00114     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPad2x2PixelStatusV1> > proxy1(
00115         new CalibDataProxy<pdscalibdata::CsPad2x2PixelStatusV1>(env.calibDir(), "pixel_status", run));
00116     calibStore.putProxy(proxy1, PSEvt::EventKey::anySource());
00117 
00118     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPadPixelStatusV1> > proxy2(
00119         new CalibDataProxy<pdscalibdata::CsPadPixelStatusV1>(env.calibDir(), "pixel_status", run));
00120     calibStore.putProxy(proxy2, PSEvt::EventKey::anySource());
00121   }
00122 
00123   if (m_doCommonMode) {
00124     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPadCommonModeSubV1> > proxy(
00125         new CalibDataProxy<pdscalibdata::CsPadCommonModeSubV1>(env.calibDir(), "common_mode", run));
00126     calibStore.putProxy(proxy, PSEvt::EventKey::anySource());
00127   }
00128 
00129   if (m_doPixelGain) {
00130     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPad2x2PixelGainV1> > proxy1(
00131         new CalibDataProxy<pdscalibdata::CsPad2x2PixelGainV1>(env.calibDir(), "pixel_gain", run));
00132     calibStore.putProxy(proxy1, PSEvt::EventKey::anySource());
00133 
00134     boost::shared_ptr< PSEvt::Proxy<pdscalibdata::CsPadPixelGainV1> > proxy2(
00135         new CalibDataProxy<pdscalibdata::CsPadPixelGainV1>(env.calibDir(), "pixel_gain", run));
00136     calibStore.putProxy(proxy2, PSEvt::EventKey::anySource());
00137   }
00138 
00139 }
00140 
00141 /// Method which is called at the beginning of the calibration cycle
00142 void 
00143 CsPadCalib::beginCalibCycle(Event& evt, Env& env)
00144 {
00145 }
00146 
00147 /// Method which is called with event data, this is the only required 
00148 /// method, all other methods are optional
00149 void 
00150 CsPadCalib::event(Event& evt, Env& env)
00151 {
00152 
00153   // loop over all objects in event and find CsPad stuff
00154   const std::list<PSEvt::EventKey>& keys = evt.keys();
00155   for (std::list<PSEvt::EventKey>::const_iterator it = keys.begin(); it != keys.end(); ++ it) {
00156 
00157     const PSEvt::EventKey& key = *it;
00158     if (key.key() != m_inkey) continue;
00159 
00160     if (*key.typeinfo() == typeid(Psana::CsPad::DataV1)) {
00161       MsgLog(name(), debug, name() << ": found Psana::CsPad::DataV1 " << key);
00162 
00163       addProxyV1(key, evt, env);
00164       
00165     } else if (*key.typeinfo() == typeid(Psana::CsPad::DataV2)) {
00166       MsgLog(name(), debug, name() << ": found Psana::CsPad::DataV2 " << key);
00167 
00168       addProxyV2(key, evt, env);
00169 
00170     } else if (*key.typeinfo() == typeid(Psana::CsPad2x2::ElementV1)) {
00171       MsgLog(name(), debug, name() << ": found Psana::CsPad2x2::ElementV1 " << key);
00172 
00173       addProxy2x2(key, evt, env);
00174 
00175     }
00176 
00177   }
00178 
00179 }
00180   
00181 /// Method which is called at the end of the calibration cycle
00182 void 
00183 CsPadCalib::endCalibCycle(Event& evt, Env& env)
00184 {
00185 }
00186 
00187 /// Method which is called at the end of the run
00188 void 
00189 CsPadCalib::endRun(Event& evt, Env& env)
00190 {
00191 }
00192 
00193 /// Method which is called once at the end of the job
00194 void 
00195 CsPadCalib::endJob(Event& evt, Env& env)
00196 {
00197 }
00198 
00199 void
00200 CsPadCalib::addProxyV1(const PSEvt::EventKey& key, Event& evt, Env& env)
00201 {
00202   // need an access to calib store
00203   PSEnv::EnvObjectStore& calibStore = env.calibStore();
00204 
00205   boost::shared_ptr< PSEvt::Proxy<Psana::CsPad::DataV1> > proxy(new DataProxyV1(key, calibStore));
00206   evt.putProxy(proxy, key.src(), m_outkey);
00207 }
00208 
00209 void
00210 CsPadCalib::addProxyV2(const PSEvt::EventKey& key, Event& evt, Env& env)
00211 {
00212   // need an access to calib store
00213   PSEnv::EnvObjectStore& calibStore = env.calibStore();
00214 
00215   boost::shared_ptr< PSEvt::Proxy<Psana::CsPad::DataV2> > proxy(new DataProxyV2(key, calibStore));
00216   evt.putProxy(proxy, key.src(), m_outkey);
00217 }
00218 
00219 void
00220 CsPadCalib::addProxy2x2(const PSEvt::EventKey& key, Event& evt, Env& env)
00221 {
00222   // need an access to calib store
00223   PSEnv::EnvObjectStore& calibStore = env.calibStore();
00224 
00225   boost::shared_ptr< PSEvt::Proxy<Psana::CsPad2x2::ElementV1> > proxy(new DataProxy2x2(key, calibStore));
00226   evt.putProxy(proxy, key.src(), m_outkey);
00227 }
00228 
00229 } // namespace cspad_mod

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7