REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Public Member Functions | Private Attributes
TRestThread Class Reference

Detailed Description

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
 
TRestAnalysisTreeGetAnalysisTree () const
 
TTree * GetEventTree ()
 
TRestEventGetInputEvent ()
 
TRestEventGetOutputEvent ()
 
TFile * GetOutputFile ()
 
TRestEventProcessGetProcess (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

TRestAnalysisTreefAnalysisTree
 
Int_t fCompressionLevel
 
TTree * fEventTree
 
TRestProcessRunnerfHostRunner
 
TRestEventfInputEvent
 
TRestEventfOutputEvent
 
TFile * fOutputFile
 
std::vector< TRestEventProcess * > fProcessChain
 
Bool_t fProcessNullReturned
 
Int_t fThreadId
 
TRestStringOutput::REST_Verbose_Level fVerboseLevel
 
Bool_t isFinished
 
std::thread t
 

Constructor & Destructor Documentation

◆ TRestThread()

TRestThread::TRestThread ( )
inline

Definition at line 75 of file TRestThread.h.

◆ ~TRestThread()

TRestThread::~TRestThread ( )
inline

Definition at line 76 of file TRestThread.h.

Member Function Documentation

◆ AddProcess()

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.

◆ EndProcess()

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.

◆ Finished()

Bool_t TRestThread::Finished ( ) const
inline

Definition at line 71 of file TRestThread.h.

◆ GetAnalysisTree()

TRestAnalysisTree * TRestThread::GetAnalysisTree ( ) const
inline

Definition at line 69 of file TRestThread.h.

◆ GetEventTree()

TTree * TRestThread::GetEventTree ( )
inline

Definition at line 70 of file TRestThread.h.

◆ GetInputEvent()

TRestEvent * TRestThread::GetInputEvent ( )
inline

Definition at line 64 of file TRestThread.h.

◆ GetOutputEvent()

TRestEvent * TRestThread::GetOutputEvent ( )
inline

Definition at line 66 of file TRestThread.h.

◆ GetOutputFile()

TFile * TRestThread::GetOutputFile ( )
inline

Definition at line 65 of file TRestThread.h.

◆ GetProcess()

TRestEventProcess * TRestThread::GetProcess ( int  i) const
inline

Definition at line 68 of file TRestThread.h.

◆ GetProcessnum()

Int_t TRestThread::GetProcessnum ( ) const
inline

Definition at line 67 of file TRestThread.h.

◆ GetThreadId()

Int_t TRestThread::GetThreadId ( ) const
inline

Definition at line 63 of file TRestThread.h.

◆ GetVerboseLevel()

TRestStringOutput::REST_Verbose_Level TRestThread::GetVerboseLevel ( ) const
inline

Definition at line 72 of file TRestThread.h.

◆ Initialize()

void TRestThread::Initialize ( )

Set variables by default during initialization.

Definition at line 38 of file TRestThread.cxx.

◆ PrepareToProcess()

void TRestThread::PrepareToProcess ( bool *  outputConfig = nullptr)

Prepare some thing before we can start process.

This method will:

  1. Setup the processes in process chain:(set analysis tree, set readonly, call the method InitProcess())
  2. Instantiate the input event and make a test run, calling TestRun(). The address of output event is fixed after the test run.
  3. Open the output file and create output tree inside it. Creating branches according to the output level.
  4. Reset the processes by calling InitProcess() again

Note: this methed runs under single thread node, so there is no conflict when creating files.

Definition at line 223 of file TRestThread.cxx.

◆ ProcessEvent()

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.

◆ SetCompressionLevel()

void TRestThread::SetCompressionLevel ( Int_t  comp)
inline

Definition at line 60 of file TRestThread.h.

◆ SetOutputTree()

void TRestThread::SetOutputTree ( TRestAnalysisTree t)
inline

Definition at line 58 of file TRestThread.h.

◆ SetProcessRunner()

void TRestThread::SetProcessRunner ( TRestProcessRunner r)
inline

Definition at line 59 of file TRestThread.h.

◆ SetThreadId()

void TRestThread::SetThreadId ( Int_t  id)

Definition at line 123 of file TRestThread.cxx.

◆ SetVerboseLevel()

void TRestThread::SetVerboseLevel ( TRestStringOutput::REST_Verbose_Level  verb)
inline

Definition at line 61 of file TRestThread.h.

◆ StartProcess()

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.

◆ StartThread()

void TRestThread::StartThread ( )

Create a thread with the method StartProcess().

The thread will be detached afterwards.

Definition at line 449 of file TRestThread.cxx.

◆ TestRun()

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:

TRestEvent *inputEvent )
{
fSignalEvent = (TRestRawSignalEvent *)inputEvent;
fOutputEvent = fSignalEvent;
...
}
A base class for any REST event.
Definition: TRestEvent.h:38
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
An event container for time rawdata signals with fixed length.

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.

◆ ValidateChain()

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.

Field Documentation

◆ fAnalysisTree

TRestAnalysisTree* TRestThread::fAnalysisTree
private

Definition at line 30 of file TRestThread.h.

◆ fCompressionLevel

Int_t TRestThread::fCompressionLevel
private

Definition at line 39 of file TRestThread.h.

◆ fEventTree

TTree* TRestThread::fEventTree
private

Definition at line 34 of file TRestThread.h.

◆ fHostRunner

TRestProcessRunner* TRestThread::fHostRunner
private

Definition at line 28 of file TRestThread.h.

◆ fInputEvent

TRestEvent* TRestThread::fInputEvent
private

Definition at line 31 of file TRestThread.h.

◆ fOutputEvent

TRestEvent* TRestThread::fOutputEvent
private

Definition at line 32 of file TRestThread.h.

◆ fOutputFile

TFile* TRestThread::fOutputFile
private

Definition at line 33 of file TRestThread.h.

◆ fProcessChain

std::vector<TRestEventProcess*> TRestThread::fProcessChain
private

Definition at line 29 of file TRestThread.h.

◆ fProcessNullReturned

Bool_t TRestThread::fProcessNullReturned
private

Definition at line 38 of file TRestThread.h.

◆ fThreadId

Int_t TRestThread::fThreadId
private

Definition at line 26 of file TRestThread.h.

◆ fVerboseLevel

TRestStringOutput::REST_Verbose_Level TRestThread::fVerboseLevel
private

Definition at line 40 of file TRestThread.h.

◆ isFinished

Bool_t TRestThread::isFinished
private

Definition at line 37 of file TRestThread.h.

◆ t

std::thread TRestThread::t
private

Definition at line 36 of file TRestThread.h.


The documentation for this class was generated from the following files: