PandaRoot
PndProcess.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef PNDPROCESS_HH
14 #define PNDPROCESS_HH
15 
16 #include <string>
17 #include <typeinfo>
18 #include <vector>
19 
20 #include "TStopwatch.h"
21 #include "TSystem.h"
22 
23 #include "FairLogger.h"
24 
25 #include "PndContainerRegister.h"
26 #include "PndParameterRegister.h"
27 
36 class PndProcess {
37  public:
39  PndProcess(const std::string &t_processname) : fProcessName(t_processname) {}
40  virtual ~PndProcess() {}
41 
47  virtual void SetDetectorName(const std::string &t_detectorname) { fDetectorName = t_detectorname; }
48 
54  const std::vector<std::string> &GetListOfRequiredParameters() const { return fParameterList; }
55 
61  virtual void RequestDataContainer(PndContainerRegister * /*t_register*/){};
62 
68  virtual void GetDataContainer(PndContainerRegister * /*t_register*/){};
69 
75  virtual void SetupParameters(const PndParameterRegister *t_parameter) = 0;
76 
81  virtual void PreProcess()
82  {
83  gSystem->GetProcInfo(&fProcInfo);
84  fLastMemSize = fProcInfo.fMemResident;
85  fTimer.Reset();
86  fTimer.Start();
87  };
92  virtual void Process() = 0;
93 
99  virtual void PostProcess()
100  {
101  fTimer.Stop();
102  fTotalTime += fTimer.RealTime();
103  gSystem->GetProcInfo(&fProcInfo);
104  LOG_IF(debug1, fProcInfo.fMemResident - fLastMemSize != 0) << "PndProcess" << fDetectorName << " Process() Memory increase after Process " << fProcessName << ". Increase by "
105  << fProcInfo.fMemResident - fLastMemSize << " KB. Total memory used is: " << fProcInfo.fMemResident << " KB.";
106 
107  fLastMemSize = fProcInfo.fMemResident;
108  };
109 
114  virtual void TearDown() { LOG(debug) << fProcessName << " - " << fDetectorName << " took " << fTotalTime << " s processing time."; };
115 
121  virtual void SetEventTime(Double_t t_eventtime) { fEventTime = t_eventtime; }
122 
123  protected:
124  std::vector<std::string> fParameterList{};
125  std::string fDetectorName{""};
126  std::string fProcessName{"PndProcess"};
127  TStopwatch fTimer{};
128  Double_t fTotalTime{0};
129  ProcInfo_t fProcInfo;
130  Long_t fLastMemSize;
131  Double_t fEventTime{0};
133 };
134 
135 #endif /*PNDPROCESS_HH*/
Base Process class.
Definition: PndProcess.h:36
virtual void Process()=0
The actual data transformation (digitizing, clustering, etc.) should be defined here.
virtual ~PndProcess()
Definition: PndProcess.h:40
virtual void TearDown()
Last actions at the end of the run.
Definition: PndProcess.h:114
std::vector< std::string > fParameterList
Parameter names required by this PndProcess. Needs to be populated in derived class.
Definition: PndProcess.h:124
std::string fDetectorName
Set Detector name this PndProcess transforms data for. Required for example by EMC Processes to fetch...
Definition: PndProcess.h:125
Double_t fTotalTime
Time taken by this Process&#39; Process()
Definition: PndProcess.h:128
virtual void PreProcess()
PreProcess() is called before the actual Process() call in each event.
Definition: PndProcess.h:81
Long_t fLastMemSize
Definition: PndProcess.h:130
virtual void RequestDataContainer(PndContainerRegister *)
Pass the container register to the process, and get the processes container requirements.
Definition: PndProcess.h:61
const std::vector< std::string > & GetListOfRequiredParameters() const
Get the List Of Required Parameters.
Definition: PndProcess.h:54
virtual void PostProcess()
Immediately after calling Process() PostProcess() is called for cleanup of internal process data...
Definition: PndProcess.h:99
Double_t fEventTime
Definition: PndProcess.h:132
virtual void SetEventTime(Double_t t_eventtime)
Set the Event time.
Definition: PndProcess.h:121
virtual void SetupParameters(const PndParameterRegister *t_parameter)=0
Fetch all parameters from the PndParameterRegister.
std::string fProcessName
Name of current PndProcess (for debugging)
Definition: PndProcess.h:126
PndProcess(const std::string &t_processname)
Definition: PndProcess.h:39
Helper class to indirect the Parameter fetching via the FairRuntimeDb.
ProcInfo_t fProcInfo
Helper to access cpu process Memory Info.
Definition: PndProcess.h:129
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:47
TStopwatch fTimer
Timer to monitor Process() time.
Definition: PndProcess.h:127
virtual void GetDataContainer(PndContainerRegister *)
Pass the container register to the process, and set the processes container requirements.
Definition: PndProcess.h:68