PandaRoot
PndProcess.h
Go to the documentation of this file.
1 #ifndef PNDPROCESS_HH
2 #define PNDPROCESS_HH
3 
4 #include <string>
5 #include <typeinfo>
6 #include <vector>
7 
8 #include "TStopwatch.h"
9 #include "TSystem.h"
10 
11 #include "FairLogger.h"
12 
13 #include "PndParameterRegister.h"
14 
23 template <class DataStruct>
24 class PndProcess {
25  public:
27  PndProcess(const std::string &t_processname) : fProcessName(t_processname) {}
28  virtual ~PndProcess() {}
29 
35  virtual void SetDetectorName(const std::string &t_detectorname) { fDetectorName = t_detectorname; }
36 
42  const std::vector<std::string> &GetListOfRequiredParameters() const { return fParameterList; }
43 
49  virtual void SetData(DataStruct *t_data) = 0;
50 
56  virtual void SetupParameters(const PndParameterRegister *t_parameter) = 0;
57 
62  virtual void PreProcess()
63  {
64  gSystem->GetProcInfo(&fProcInfo);
65  fLastMemSize = fProcInfo.fMemResident;
66  fTimer.Reset();
67  fTimer.Start();
68  };
73  virtual void Process() = 0;
74 
80  virtual void PostProcess()
81  {
82  fTimer.Stop();
83  fTotalTime += fTimer.RealTime();
84  gSystem->GetProcInfo(&fProcInfo);
85  LOG_IF(DEBUG1, fProcInfo.fMemResident - fLastMemSize != 0) << "PndProcess" << fDetectorName << " Process() Memory increase after Process " << fProcessName << ". Increase by "
86  << fProcInfo.fMemResident - fLastMemSize << " KB. Total memory used is: " << fProcInfo.fMemResident << " KB.";
87 
88  fLastMemSize = fProcInfo.fMemResident;
89  };
90 
95  virtual void TearDown() { LOG(DEBUG) << fProcessName << " - " << fDetectorName << " took " << fTotalTime << " s processing time."; };
96 
97  protected:
98  std::vector<std::string> fParameterList{};
99  std::string fDetectorName{""};
100  std::string fProcessName{"PndProcess"};
101  TStopwatch fTimer{};
102  Double_t fTotalTime{0};
103  ProcInfo_t fProcInfo;
104  Long_t fLastMemSize;
105 };
107 
108 #endif /*PNDPROCESS_HH*/
Base Process class.
Definition: PndProcess.h:24
virtual void TearDown()
Last actions at the end of the run.
Definition: PndProcess.h:95
std::string fProcessName
Name of current PndProcess (for debugging)
Definition: PndProcess.h:100
virtual ~PndProcess()
Definition: PndProcess.h:28
virtual void Process()=0
The actual data transformation (digitizing, clustering, etc.) should be defined here.
virtual void SetDetectorName(const std::string &t_detectorname)
Set the Detector name. Important, as most EmcParameter need to know for which detector they need to b...
Definition: PndProcess.h:35
ProcInfo_t fProcInfo
Helper to access cpu process Memory Info.
Definition: PndProcess.h:103
TStopwatch fTimer
Timer to monitor Process() time.
Definition: PndProcess.h:101
virtual void PostProcess()
Immediately after calling Process() PostProcess() is called for cleanup of internal process data...
Definition: PndProcess.h:80
PndProcess(const std::string &t_processname)
Definition: PndProcess.h:27
Double_t fTotalTime
Time taken by this Process&#39; Process()
Definition: PndProcess.h:102
Long_t fLastMemSize
Definition: PndProcess.h:104
std::string fDetectorName
Set Detector name this PndProcess transforms data for. Required for example by EMC Processes to fetch...
Definition: PndProcess.h:99
const std::vector< std::string > & GetListOfRequiredParameters() const
Get the List Of Required Parameters.
Definition: PndProcess.h:42
std::vector< std::string > fParameterList
Parameter names required by this PndProcess. Needs to be populated in derived class.
Definition: PndProcess.h:98
Helper class to indirect the Parameter fetching via the FairRuntimeDb.
virtual void SetupParameters(const PndParameterRegister *t_parameter)=0
Fetch all parameters from the PndParameterRegister.
virtual void SetData(DataStruct *t_data)=0
Pass the data container ptrs to the process, and store pointers in class members. ...
virtual void PreProcess()
PreProcess() is called before the actual Process() call in each event.
Definition: PndProcess.h:62