00001 #ifndef EVENT_LOOP_WORKER_HH
00002 #define EVENT_LOOP_WORKER_HH
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00018 
00019 
00020 
00021 #include <EventLoop/Global.h>
00022 
00023 #include <map>
00024 #include <memory>
00025 #include <vector>
00026 #include <Rtypes.h>
00027 #include <TList.h>
00028 #include <SampleHandler/Global.h>
00029 
00030 class TFile;
00031 class TH1;
00032 class TString;
00033 class TTree;
00034 class TStopwatch;
00035 
00036 namespace xAOD
00037 {
00038   class TEvent;
00039   class TStore;
00040 }
00041 
00042 namespace EL
00043 {
00044   class Worker
00045   {
00046     
00047     
00048     
00049 
00052   public:
00053     void testInvariant () const;
00054 
00055 
00059   public:
00060     virtual ~Worker ();
00061 
00062 
00072   public:
00073     void addOutput (TObject *output_swallow);
00074 
00075 
00086   public:
00087     void addOutputList (const std::string& name, TObject *output_swallow);
00088 
00089 
00099   public:
00100     TH1 *getOutputHist (const std::string& name) const;
00101 
00102 
00112   public:
00113     TFile *getOutputFile (const std::string& label) const;
00114 
00115 
00129   public:
00130     TFile *getOutputFileNull (const std::string& label) const;
00131 
00132 
00137   public:
00138     const SH::MetaObject *metaData () const;
00139 
00140 
00143   public:
00144     TTree *tree () const;
00145 
00146 
00149   public:
00150     Long64_t treeEntry () const;
00151 
00152 
00155   public:
00156     TFile *inputFile () const;
00157 
00158 
00163   public:
00164     std::string inputFileName () const;
00165 
00166 
00171   public:
00172     TTree *triggerConfig () const;
00173 
00174 
00180   public:
00181     xAOD::TEvent *xaodEvent () const;
00182     xAOD::TStore *xaodStore () const;
00183 
00184 
00189   public:
00190     EL::Algorithm *getAlg (const std::string& name) const;
00191 
00192 
00200   public:
00201     void skipEvent ();
00202 
00203 
00204 
00205     
00206     
00207     
00208 
00216   protected:
00217     Worker (const SH::MetaObject *val_metaData, TList *output);
00218 
00219 
00225   protected:
00226     void addOutputFile (const std::string& label, TFile *file_swallow);
00227     void addOutputWriter (const std::string& label,
00228               SH::DiskWriter *writer_swallow);
00229 
00230 
00235   protected:
00236     void addAlg (EL::Algorithm *alg_swallow);
00237 
00238 
00246   protected:
00247     void algsChangeInput ();
00248 
00249 
00256   protected:
00257     void algsExecute ();
00258 
00259 
00271   protected:
00272     void algsEndOfFile ();
00273 
00274 
00280   protected:
00281     void algsFinalize ();
00282 
00283 
00285   protected:
00286     void treeEntry (Long64_t val_treeEntry);
00287 
00288 
00297   protected:
00298     void setInputFile (TFile *val_inputFile);
00299 
00300 
00310   protected:
00311     void setTreeProofOnly (TTree *val_tree);
00312 
00313 
00318   protected:
00319     Long64_t inputFileNumEntries () const;
00320 
00321 
00322 
00323     
00324     
00325     
00326 
00327 
00328 
00329     
00330     
00331     
00332 
00334   private:
00335     const SH::MetaObject *m_metaData = nullptr;
00336 
00338   private:
00339     TFile *m_inputFile = nullptr;
00340 
00342   private:
00343     TTree *m_tree = nullptr;
00344 
00345   private:
00346     Long64_t m_treeEntry;
00347 
00349   private:
00350     TList *m_output = nullptr;
00351 
00352 
00354   private:
00355     typedef std::map<std::string,TH1*>::const_iterator OutputHistMapIter;
00356     std::map<std::string,TH1*> m_outputHistMap;
00357 
00358 
00360   private:
00361     typedef std::map<std::string,SH::DiskWriter*>::const_iterator outputFilesIter;
00362     std::map<std::string,SH::DiskWriter*> m_outputFiles;
00363 
00364 
00366   private:
00367     typedef std::vector<EL::Algorithm*>::const_iterator algsIter;
00368     std::vector<EL::Algorithm*> m_algs;
00369 
00370 
00372   private:
00373     TH1 *m_eventCount = nullptr;
00374 
00375 
00377   private:
00378     TH1 *m_runTime = nullptr;
00379 
00380 
00383   private:
00384     TTree *m_fileExecutedTree = nullptr;
00385 
00388   private:
00389     TString *m_fileExecutedName = nullptr;
00390 
00391 
00393   private:
00394     bool m_skipEvent;
00395 
00396 
00398   private:
00399     std::unique_ptr<TStopwatch> m_stopwatch;
00400 
00401 
00403   private:
00404     enum AlgInitState
00405     {
00408       AIS_NEW,
00409 
00412       AIS_HIST_INITIALIZED,
00413 
00416       AIS_INITIALIZED,
00417 
00420       AIS_FINALIZED,
00421 
00424       AIS_HIST_FINALIZED,
00425 
00429       AIS_NONE
00430     };
00431 
00433   private:
00434     AlgInitState m_initState;
00435 
00436 
00438   private:
00439     enum AlgExecState
00440     {
00443       AES_BLANK,
00444 
00447       AES_FILE_EXECUTED,
00448 
00451       AES_INPUT_CHANGED,
00452 
00456       AES_NONE
00457     };
00458 
00460   private:
00461     AlgExecState m_execState;
00462 
00463 
00465   private:
00466     enum InputState
00467     {
00469       VALID_NONE,
00470 
00473       VALID_FILE,
00474 
00476       VALID_EVENT
00477     };
00478 
00479 
00486   private:
00487     void changeAlgState (AlgInitState targetInit, AlgExecState targetExec,
00488              InputState inputState);
00489   };
00490 }
00491 
00492 #endif