REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestProcessRunner.h
1#ifndef RestCore_TRestProcessRunner
2#define RestCore_TRestProcessRunner
3
4#include <mutex>
5#include <thread>
6
7#include "TRestAnalysisTree.h"
8#include "TRestEvent.h"
9#include "TRestEventProcess.h"
10#include "TRestMetadata.h"
11#include "TRestRun.h"
12#include "TRestTools.h"
13
14#define TIME_MEASUREMENT
15
16class TRestThread;
17class TRestManager;
18
19enum ProcStatus {
20 kNormal,
21 kPause,
22 kStep,
23 kStopping,
24 kIgnore,
25 kFinished,
26};
27
29class TRestProcessRunner : public TRestMetadata {
30 private:
31 // global variable
32 TRestRun* fRunInfo;
33
34 // event variables
35 TRestEvent* fInputEvent;
36 TRestEvent* fOutputEvent;
37
38 // self variables for processing
39 std::vector<TRestThread*> fThreads;
40 TRestRootFileHandle fOutputDataFileOwner;
41 TFile* fOutputDataFile;
44 TTree* fEventTree;
45 TRestAnalysisTree* fAnalysisTree;
46 ProcStatus fProcStatus;
47 Int_t fNBranches;
48 Int_t fNFilesSplit;
49
50 // metadata
52 Bool_t fUsePauseMenu;
53 Bool_t fValidateObservables;
54 Bool_t fSortOutputEvents;
55 Bool_t fInputAnalysisStorage;
56 Bool_t fInputEventStorage;
57 Bool_t fOutputEventStorage;
58 Bool_t fOutputAnalysisStorage;
59 Int_t fThreadNumber;
60 Int_t fProcessNumber;
61 Int_t fFirstEntry;
62 Int_t fEventsToProcess;
63 Int_t fProcessedEvents;
64
65 Long64_t fFileSplitSize; // in bytes
66 Int_t fFileCompression; // 1~9
67 std::map<std::string, std::string> fProcessInfo;
68
69 // bool fOutputItem[4] = {
70 // false}; // the on/off status for item: inputAnalysis, inputEvent, outputEvent, outputAnalysis
71
72 public:
74 void Initialize() override;
75 void InitFromConfigFile() override {
77 if (fElement != nullptr) {
78 TiXmlElement* e = fElement->FirstChildElement();
79 while (e != nullptr) {
80 std::string value = e->Value();
81 if (value == "variable" || value == "myParameter" || value == "constant") {
82 e = e->NextSiblingElement();
83 continue;
84 }
85 ReadConfig((std::string)e->Value(), e);
86 e = e->NextSiblingElement();
87 }
88 }
89 EndOfInit();
90 }
91 void BeginOfInit();
92 Int_t ReadConfig(const std::string& keydeclare, TiXmlElement* e);
93 void EndOfInit();
94 void PrintMetadata() override;
95
96 // core functionality
97 void ReadProcInfo();
98 void RunProcess();
99 void PauseMenu();
100 Int_t GetNextevtFunc(TRestEvent* targetevt, TRestAnalysisTree* targettree);
102 void ConfigOutputFile();
103 void MergeOutputFile();
104 void WriteProcessesMetadata(TFile* destination = nullptr);
105
106 // tools
107 void ResetRunTimes();
108 TRestEventProcess* InstantiateProcess(TString type, TiXmlElement* ele);
109 void PrintProcessedEvents(Int_t rateE);
110 std::string MakeProgressBar(int progress100, int length = 100);
111
112 // getters and setters
113 TRestEvent* GetInputEvent();
114 TRestAnalysisTree* GetInputAnalysisTree();
115 TRestAnalysisTree* GetOutputAnalysisTree() { return fAnalysisTree; }
116 TFile* GetOutputDataFile() { return fOutputDataFile; }
117 std::string GetProcInfo(std::string infoname) {
118 return fProcessInfo[infoname] == "" ? infoname : fProcessInfo[infoname];
119 }
120 inline int GetNThreads() const { return fThreadNumber; }
121 inline int GetNProcesses() const { return fProcessNumber; }
122 inline int GetNProcessedEvents() const { return fProcessedEvents; }
123 double GetReadingSpeed();
124 bool UseTestRun() const { return fUseTestRun; }
125 inline ProcStatus GetStatus() const { return fProcStatus; }
126 inline Long64_t GetFileSplitSize() const { return fFileSplitSize; }
127
128 // Constructor & Destructor
129 TRestProcessRunner();
130 ~TRestProcessRunner();
131
132 ClassDefOverride(TRestProcessRunner, 7);
133};
134
135#endif
REST core data-saving helper based on TTree.
A base class for any REST event process.
A base class for any REST event.
Definition TRestEvent.h:38
Managing applications and executing tasks.
TRestMetadata()
TRestMetadata default constructor.
TiXmlElement * fElement
Saving the sectional element together with global element.
TString fOutputDataFileName
the TFile pointer being used
void ReadProcInfo()
Create a process info list which used called by TRestRun::FormFormat().
void PrintProcessedEvents(Int_t rateE)
Print number of events processed, file read speed, ETA and a progress bar.
void ResetRunTimes()
Reset running time count to 0.
void BeginOfInit()
Reads information from rml config file.
Int_t ReadConfig(const std::string &keydeclare, TiXmlElement *e)
method to deal with iterated child elements
void MergeOutputFile()
Calls TRestRun::MergeOutputFile() to merge the main file with process's tmp file.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void RunProcess()
The main executer of event process.
void EndOfInit()
Ending of the startup procedure.
TRestEventProcess * InstantiateProcess(TString type, TiXmlElement *ele)
InstantiateProcess in sequential start up.
void PauseMenu()
A pause menu providing some functions during the process.
void Initialize() override
REST run class.
std::string MakeProgressBar(int progress100, int length=100)
Make a string of progress bar with given length and percentage.
void WriteProcessesMetadata(TFile *destination=nullptr)
Write process metadata to the requested file, or fOutputDataFile by default.
Int_t GetNextevtFunc(TRestEvent *targetevt, TRestAnalysisTree *targettree)
Get next event and copy it to the address of targetevt.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
Bool_t fUseTestRun
Number of files being split.
void FillThreadEventFunc(TRestThread *t)
Calling back the FillEvent() method in TRestThread.
void ConfigOutputFile()
Forming an output file.
Data provider and manager in REST.
Definition TRestRun.h:18
Threaded worker of a process chain.
Definition TRestThread.h:24