REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestThread.h
1
2#ifndef RestCore_TRestThread
3#define RestCore_TRestThread
4
5#include <TFile.h>
6#include <TFileMerger.h>
7#include <TKey.h>
8#include <TObject.h>
9#include <TString.h>
10#include <TTree.h>
11
12#include <iostream>
13#include <mutex>
14#include <string>
15#include <thread>
16
17#include "TRestAnalysisTree.h"
18#include "TRestEvent.h"
19#include "TRestEventProcess.h"
20#include "TRestMetadata.h"
21#include "TRestProcessRunner.h"
22
25 private:
26 Int_t fThreadId;
27
28 TRestProcessRunner* fHostRunner;
29 std::vector<TRestEventProcess*> fProcessChain;
30 TRestAnalysisTree* fAnalysisTree;
31 TRestEvent* fInputEvent;
32 TRestEvent* fOutputEvent;
33 TFile* fOutputFile;
34 TTree* fEventTree;
35
36 std::thread t;
37 Bool_t isFinished;
38 Bool_t fProcessNullReturned;
39 Int_t fCompressionLevel;
41
42 public:
43 void Initialize();
44
45 void AddProcess(TRestEventProcess* process);
46 void PrepareToProcess(bool* outputConfig = nullptr);
47 bool TestRun();
48 void StartProcess();
49
50 void ProcessEvent();
51 void EndProcess();
52 void StartThread();
53
54 Int_t ValidateChain(TRestEvent* input);
55
56 // getter and setter
57 void SetThreadId(Int_t id);
58 inline void SetOutputTree(TRestAnalysisTree* t) { fAnalysisTree = t; }
59 inline void SetProcessRunner(TRestProcessRunner* r) { fHostRunner = r; }
60 inline void SetCompressionLevel(Int_t comp) { fCompressionLevel = comp; }
61 inline void SetVerboseLevel(TRestStringOutput::REST_Verbose_Level verb) { fVerboseLevel = verb; }
62
63 inline Int_t GetThreadId() const { return fThreadId; }
64 inline TRestEvent* GetInputEvent() { return fInputEvent; }
65 inline TFile* GetOutputFile() { return fOutputFile; };
66 inline TRestEvent* GetOutputEvent() { return fProcessNullReturned ? 0 : fOutputEvent; }
67 inline Int_t GetProcessnum() const { return fProcessChain.size(); }
68 inline TRestEventProcess* GetProcess(int i) const { return fProcessChain[i]; }
69 inline TRestAnalysisTree* GetAnalysisTree() const { return fAnalysisTree; }
70 inline TTree* GetEventTree() { return fEventTree; }
71 inline Bool_t Finished() const { return isFinished; }
72 inline TRestStringOutput::REST_Verbose_Level GetVerboseLevel() const { return fVerboseLevel; }
73
74 // Constructor & Destructor
75 TRestThread() { Initialize(); }
76 ~TRestThread(){};
77};
78
79#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
Running the processes efficiently with fantastic display.
REST_Verbose_Level
Enumerate of verbose level, containing five levels.
Threaded worker of a process chain.
Definition: TRestThread.h:24
void AddProcess(TRestEventProcess *process)
Add a process.
bool TestRun()
Make a test run of our process chain.
void Initialize()
Set variables by default during initialization.
Definition: TRestThread.cxx:38
void StartProcess()
The main function of this class. Thread will run this function until the end.
void EndProcess()
Write and close the output file.
void ProcessEvent()
Process a single event.
void PrepareToProcess(bool *outputConfig=nullptr)
Prepare some thing before we can start process.
Int_t ValidateChain(TRestEvent *input)
Check if the input/output of each process in the process chain matches.
Definition: TRestThread.cxx:65
void StartThread()
Create a thread with the method StartProcess().