REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
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
13#define TIME_MEASUREMENT
14
15class TRestThread;
16class TRestManager;
17
18enum ProcStatus {
19 kNormal,
20 kPause,
21 kStep,
22 kStopping,
23 kIgnore,
24 kFinished,
25};
26
29 private:
30 // global variable
31 TRestRun* fRunInfo;
32
33 // event variables
34 TRestEvent* fInputEvent;
35 TRestEvent* fOutputEvent;
36
37 // self variables for processing
38 std::vector<TRestThread*> fThreads;
39 TFile* fOutputDataFile;
42 TTree* fEventTree;
43 TRestAnalysisTree* fAnalysisTree;
44 ProcStatus fProcStatus;
45 Int_t fNBranches;
46 Int_t fNFilesSplit;
47
48 // metadata
50 Bool_t fUsePauseMenu;
51 Bool_t fValidateObservables;
52 Bool_t fSortOutputEvents;
53 Bool_t fInputAnalysisStorage;
54 Bool_t fInputEventStorage;
55 Bool_t fOutputEventStorage;
56 Bool_t fOutputAnalysisStorage;
57 Int_t fThreadNumber;
58 Int_t fProcessNumber;
59 Int_t fFirstEntry;
60 Int_t fEventsToProcess;
61 Int_t fProcessedEvents;
62
63 Long64_t fFileSplitSize; // in bytes
64 Int_t fFileCompression; // 1~9
65 std::map<std::string, std::string> fProcessInfo;
66
67 // bool fOutputItem[4] = {
68 // false}; // the on/off status for item: inputAnalysis, inputEvent, outputEvent, outputAnalysis
69
70 public:
72 void Initialize() override;
73 void InitFromConfigFile() override {
75 if (fElement != nullptr) {
76 TiXmlElement* e = fElement->FirstChildElement();
77 while (e != nullptr) {
78 std::string value = e->Value();
79 if (value == "variable" || value == "myParameter" || value == "constant") {
80 e = e->NextSiblingElement();
81 continue;
82 }
83 ReadConfig((std::string)e->Value(), e);
84 e = e->NextSiblingElement();
85 }
86 }
87 EndOfInit();
88 }
89 void BeginOfInit();
90 Int_t ReadConfig(const std::string& keydeclare, TiXmlElement* e);
91 void EndOfInit();
92 void PrintMetadata() override;
93
94 // core functionality
95 void ReadProcInfo();
96 void RunProcess();
97 void PauseMenu();
98 Int_t GetNextevtFunc(TRestEvent* targetevt, TRestAnalysisTree* targettree);
100 void ConfigOutputFile();
101 void MergeOutputFile();
103
104 // tools
105 void ResetRunTimes();
106 TRestEventProcess* InstantiateProcess(TString type, TiXmlElement* ele);
107 void PrintProcessedEvents(Int_t rateE);
108 std::string MakeProgressBar(int progress100, int length = 100);
109
110 // getters and setters
111 TRestEvent* GetInputEvent();
112 TRestAnalysisTree* GetInputAnalysisTree();
113 TRestAnalysisTree* GetOutputAnalysisTree() { return fAnalysisTree; }
114 TFile* GetOutputDataFile() { return fOutputDataFile; }
115 std::string GetProcInfo(std::string infoname) {
116 return fProcessInfo[infoname] == "" ? infoname : fProcessInfo[infoname];
117 }
118 inline int GetNThreads() const { return fThreadNumber; }
119 inline int GetNProcesses() const { return fProcessNumber; }
120 inline int GetNProcessedEvents() const { return fProcessedEvents; }
121 double GetReadingSpeed();
122 bool UseTestRun() const { return fUseTestRun; }
123 inline ProcStatus GetStatus() const { return fProcStatus; }
124 inline Long64_t GetFileSplitSize() const { return fFileSplitSize; }
125
126 // Constructor & Destructor
129
130 ClassDefOverride(TRestProcessRunner, 7);
131};
132
133#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.
Definition: TRestManager.h:16
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
TiXmlElement * fElement
Saving the sectional element together with global element.
Running the processes efficiently with fantastic display.
TString fOutputDataFileName
the TFile pointer being used
void ReadProcInfo()
Create a process info list which used called by TRestRun::FormFormat().
void WriteProcessesMetadata()
Write process metadata to fOutputDataFile.
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.
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