REST-for-Physics
v2.3
Rare Event Searches ToolKit for Physics
|
Threaded worker of a process chain.
Multiple instances of TRestThread is created inside TRestProcessRunner. Each of them can detach a thread containing a process chain, which implements multi thread functionality. Preparation of process chain is also done inside this class.
RESTsoft - Software for Rare Event Searches with TPCs
History of developments:
2014-june: First concept. As part of conceptualization of previous REST code (REST v2) Igor G. Irastorza
2017-Aug: Major change: added for multi-thread capability Kaixiang Ni
Definition at line 24 of file TRestThread.h.
#include <TRestThread.h>
Public Member Functions | |
void | AddProcess (TRestEventProcess *process) |
Add a process. More... | |
void | EndProcess () |
Write and close the output file. More... | |
Bool_t | Finished () const |
TRestAnalysisTree * | GetAnalysisTree () const |
TTree * | GetEventTree () |
TRestEvent * | GetInputEvent () |
TRestEvent * | GetOutputEvent () |
TFile * | GetOutputFile () |
TRestEventProcess * | GetProcess (int i) const |
Int_t | GetProcessnum () const |
Int_t | GetThreadId () const |
TRestStringOutput::REST_Verbose_Level | GetVerboseLevel () const |
void | Initialize () |
Set variables by default during initialization. More... | |
void | PrepareToProcess (bool *outputConfig=nullptr) |
Prepare some thing before we can start process. More... | |
void | ProcessEvent () |
Process a single event. More... | |
void | SetCompressionLevel (Int_t comp) |
void | SetOutputTree (TRestAnalysisTree *t) |
void | SetProcessRunner (TRestProcessRunner *r) |
void | SetThreadId (Int_t id) |
void | SetVerboseLevel (TRestStringOutput::REST_Verbose_Level verb) |
void | StartProcess () |
The main function of this class. Thread will run this function until the end. More... | |
void | StartThread () |
Create a thread with the method StartProcess(). More... | |
bool | TestRun () |
Make a test run of our process chain. More... | |
Int_t | ValidateChain (TRestEvent *input) |
Check if the input/output of each process in the process chain matches. More... | |
Private Attributes | |
TRestAnalysisTree * | fAnalysisTree |
Int_t | fCompressionLevel |
TTree * | fEventTree |
TRestProcessRunner * | fHostRunner |
TRestEvent * | fInputEvent |
TRestEvent * | fOutputEvent |
TFile * | fOutputFile |
std::vector< TRestEventProcess * > | fProcessChain |
Bool_t | fProcessNullReturned |
Int_t | fThreadId |
TRestStringOutput::REST_Verbose_Level | fVerboseLevel |
Bool_t | isFinished |
std::thread | t |
|
inline |
Definition at line 75 of file TRestThread.h.
|
inline |
Definition at line 76 of file TRestThread.h.
void TRestThread::AddProcess | ( | TRestEventProcess * | process | ) |
Add a process.
The process will be added to the end of the process chain. It will also increase TRestThread's verbose level if the added process's verbose level is higher. Note that we cannot use "debug" verbose level under compatibility output mode, i.e. in condor jobs.
Definition at line 462 of file TRestThread.cxx.
void TRestThread::EndProcess | ( | ) |
Write and close the output file.
This method is called back at the end of TRestProcessRunner::RunProcess() in TRestProcessRunner.
Definition at line 573 of file TRestThread.cxx.
|
inline |
Definition at line 71 of file TRestThread.h.
|
inline |
Definition at line 69 of file TRestThread.h.
|
inline |
Definition at line 70 of file TRestThread.h.
|
inline |
Definition at line 64 of file TRestThread.h.
|
inline |
Definition at line 66 of file TRestThread.h.
|
inline |
Definition at line 65 of file TRestThread.h.
|
inline |
Definition at line 68 of file TRestThread.h.
|
inline |
Definition at line 67 of file TRestThread.h.
|
inline |
Definition at line 63 of file TRestThread.h.
|
inline |
Definition at line 72 of file TRestThread.h.
void TRestThread::Initialize | ( | ) |
Set variables by default during initialization.
Definition at line 38 of file TRestThread.cxx.
void TRestThread::PrepareToProcess | ( | bool * | outputConfig = nullptr | ) |
Prepare some thing before we can start process.
This method will:
Note: this methed runs under single thread node, so there is no conflict when creating files.
Definition at line 223 of file TRestThread.cxx.
void TRestThread::ProcessEvent | ( | ) |
Process a single event.
This is the only method that can running purely under multi thread mode here. It gives the input event to the first process in process chain, then it gives the process result to the next process, so on. Finally it gets a result and saves it in the local output event.
Definition at line 483 of file TRestThread.cxx.
|
inline |
Definition at line 60 of file TRestThread.h.
|
inline |
Definition at line 58 of file TRestThread.h.
|
inline |
Definition at line 59 of file TRestThread.h.
void TRestThread::SetThreadId | ( | Int_t | id | ) |
Definition at line 123 of file TRestThread.cxx.
|
inline |
Definition at line 61 of file TRestThread.h.
void TRestThread::StartProcess | ( | ) |
The main function of this class. Thread will run this function until the end.
It will start a loop, calling GetNextevtFunc(), ProcessEvent(), and FillThreadEventFunc() repeatedly. If the function GetNextEvent() returns false, the loop will break, meaning that we are at the end of the process. Before return it will set "isFinished" to true.
Note: The methods GetNextevtFunc() and FillThreadEventFunc() are all from TRestProcessRunner. The later two will call back the method FillEvent(), EndProcess() in this class. The idea to do so is to make a unified management of these i-o related methods. In TRestRun the three methods are mutex locked. They will be paused until the host run allows it to run. This prevents segmentation violation due to simultaneously read/write.
Definition at line 433 of file TRestThread.cxx.
void TRestThread::StartThread | ( | ) |
Create a thread with the method StartProcess().
The thread will be detached afterwards.
Definition at line 449 of file TRestThread.cxx.
bool TRestThread::TestRun | ( | ) |
Make a test run of our process chain.
The reason we use test run is that we need to determine the real output event address of a process chain. This is because when we write our code like this:
The output event address can be changed after running.
Test run calls TRestEventProcess::ProcessEvent() first, and uses the output of TRestEventProcess::GetOutputEvent() as the next process's input event. This avoids NULL returned events from ProcessEvent due to cut. In debug mode, we can also observe a process sequence printed by this method
returns false when fOutputEvent is null after 5 times of retry, returns true when fOutputEvent address is determined.
Definition at line 151 of file TRestThread.cxx.
Int_t TRestThread::ValidateChain | ( | TRestEvent * | input | ) |
Check if the input/output of each process in the process chain matches.
Input event of the whole process chain(i.e., the input event of first process) should match the one read from input file.
Outevent of the previous process should be of the same type as the input event of the later process. Both of them cannot be null.
Definition at line 65 of file TRestThread.cxx.
|
private |
Definition at line 30 of file TRestThread.h.
|
private |
Definition at line 39 of file TRestThread.h.
|
private |
Definition at line 34 of file TRestThread.h.
|
private |
Definition at line 28 of file TRestThread.h.
|
private |
Definition at line 31 of file TRestThread.h.
|
private |
Definition at line 32 of file TRestThread.h.
|
private |
Definition at line 33 of file TRestThread.h.
|
private |
Definition at line 29 of file TRestThread.h.
|
private |
Definition at line 38 of file TRestThread.h.
|
private |
Definition at line 26 of file TRestThread.h.
|
private |
Definition at line 40 of file TRestThread.h.
|
private |
Definition at line 37 of file TRestThread.h.
|
private |
Definition at line 36 of file TRestThread.h.