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 <TKey.h>
7#include <TObject.h>
8#include <TString.h>
9#include <TTree.h>
10
11#include <iostream>
12#include <mutex>
13#include <string>
14#include <thread>
15
16#include "TRestAnalysisTree.h"
17#include "TRestEvent.h"
18#include "TRestEventProcess.h"
19#include "TRestMetadata.h"
20#include "TRestProcessRunner.h"
21#include "TRestTools.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 TRestRootFileHandle fOutputFileOwner;
34 TFile* fOutputFile;
35 TTree* fEventTree;
36
37 std::thread t;
38 Bool_t isFinished;
39 Bool_t fProcessNullReturned;
40 Int_t fCompressionLevel;
42
43 public:
44 void Initialize();
45
46 void AddProcess(TRestEventProcess* process);
47 void PrepareToProcess(bool* outputConfig = nullptr);
48 bool TestRun();
49 void StartProcess();
50
51 void ProcessEvent();
52 void EndProcess();
53 void StartThread();
54
55 Int_t ValidateChain(TRestEvent* input);
56
57 // getter and setter
58 void SetThreadId(Int_t id);
59 inline void SetOutputTree(TRestAnalysisTree* t) { fAnalysisTree = t; }
60 inline void SetProcessRunner(TRestProcessRunner* r) { fHostRunner = r; }
61 inline void SetCompressionLevel(Int_t comp) { fCompressionLevel = comp; }
62 inline void SetVerboseLevel(TRestStringOutput::REST_Verbose_Level verb) { fVerboseLevel = verb; }
63
64 inline Int_t GetThreadId() const { return fThreadId; }
65 inline TRestEvent* GetInputEvent() { return fInputEvent; }
66 inline TFile* GetOutputFile() { return fOutputFile; };
67 bool CloseOutputFile() {
68 const bool result = fOutputFileOwner.Close();
69 fOutputFile = nullptr;
70 return result;
71 }
72 inline TRestEvent* GetOutputEvent() { return fProcessNullReturned ? 0 : fOutputEvent; }
73 inline Int_t GetProcessnum() const { return fProcessChain.size(); }
74 inline TRestEventProcess* GetProcess(int i) const { return fProcessChain[i]; }
75 inline TRestAnalysisTree* GetAnalysisTree() const { return fAnalysisTree; }
76 inline TTree* GetEventTree() { return fEventTree; }
77 inline Bool_t Finished() const { return isFinished; }
78 inline TRestStringOutput::REST_Verbose_Level GetVerboseLevel() const { return fVerboseLevel; }
79
80 // Constructor & Destructor
81 TRestThread() { Initialize(); }
82 ~TRestThread(){};
83};
84
85#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.
bool Close() noexcept
Definition: TRestTools.cxx:662
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().