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

Detailed Description

This process connects to a SQL database and adds new observables inside the analysis tree.

It will open a connection to an existing SQL database and during the process initialization it will dump the required fields into a temporary buffer internally managed.

The database entries will be correlated with the event timestamp, and the corresponding database field value will be assigned to the corresponding event entry at the analysis tree. Therefore, it is required that the SQL database contains a field entry named timestamp, which name is for the moment hardcoded inside.

Linear interpolation has been considered when retrieving the fields from the database for intermediate timestamps.

We must specify the fields from the SQL database that we wish to be extracted, and associate it to a given future name in the analysis tree. For each field we want to extract we need to defined a new <dbEntry key specifying the correspoding database field, as sqlName, and the corresponging new name it will take at the analysis tree anaName.

The following example shows a RML process definition as it would be written inside a TRestProcessRunner chain.

<addProcess type="TRestMySQLToAnalysisProcess" name="sc" value="ON" verboseLevel="warning"
observable="all" >
<parameter name="server" value="localhost" />
<parameter name="database" value="dbname" />
<parameter name="user" value="dbuser" />
<parameter name="password" value="%i8X$s±^7K1" />
<parameter name="table" value="tablename" />
<dbEntry sqlName="db_field_1" anaName="Pressure" />
<dbEntry sqlName="db_field_2" anaName="Voltage" />
<dbEntry sqlName="db_field_3" anaName="Temperaturet" />
</addProcess>
Note
If no DB entries were found, the branches will still be created inside the analysis tree, but their value will be equal to -1.

RESTsoft - Software for Rare Event Searches with TPCs

History of developments:

2020-May: First implementation Javier Galan

Author
Javier Galan

Definition at line 29 of file TRestMySQLToAnalysisProcess.h.

#include <TRestMySQLToAnalysisProcess.h>

Inheritance diagram for TRestMySQLToAnalysisProcess:
TRestEventProcess TRestMetadata

Public Member Functions

 ClassDefOverride (TRestMySQLToAnalysisProcess, 2)
 If new members are added, removed or modified in this class version number must be increased!
 
RESTValue GetInputEvent () const override
 Get pointer to input event. Must be implemented in the derived class. More...
 
RESTValue GetOutputEvent () const override
 Get pointer to output event. Must be implemented in the derived class. More...
 
const char * GetProcessName () const override
 Returns the name of this process. More...
 
void LoadConfig (const std::string &configFilename, const std::string &name="")
 Function to load the configuration from an external configuration file. More...
 
TRestEventProcessMaker ()
 Returns a new instance of this class. More...
 
void PrintMetadata () override
 It prints out basic information of the SQL database used to generate the analysis tree observables. And the SQL fields extracted together with its corresponding analysis tree name, and minimum and maximum values during the duration of the run. More...
 
TRestEventProcessEvent (TRestEvent *inputEvent) override
 The main processing event function. More...
 
 TRestMySQLToAnalysisProcess ()
 Default constructor. More...
 
 TRestMySQLToAnalysisProcess (const char *configFilename)
 Constructor loading data from a config file. More...
 
 ~TRestMySQLToAnalysisProcess ()
 Default destructor. More...
 
- Public Member Functions inherited from TRestEventProcess
virtual Bool_t AddInputFile (const std::string &file)
 
bool ApplyCut ()
 
virtual void BeginOfEventProcess (TRestEvent *inputEvent=nullptr)
 Begin of event process, preparation work. Called right before ProcessEvent() More...
 
 ClassDefOverride (TRestEventProcess, 3)
 
virtual void EndOfEventProcess (TRestEvent *inputEvent=nullptr)
 End of event process. Nothing to do. Called directly after ProcessEvent() More...
 
virtual void EndProcess ()
 To be executed at the end of the run (outside event loop) More...
 
TRestAnalysisTreeGetAnalysisTree () const
 Return the local analysis tree (dummy) More...
 
TCanvas * GetCanvas () const
 Get canvas. More...
 
TRestAnalysisTreeGetFullAnalysisTree ()
 
virtual RESTValue GetInputEvent () const =0
 Get pointer to input event. Must be implemented in the derived class. More...
 
std::vector< std::string > GetListOfAddedObservables ()
 
virtual RESTValue GetOutputEvent () const =0
 Get pointer to output event. Must be implemented in the derived class. More...
 
virtual const char * GetProcessName () const =0
 
TRestRunGetRunInfo () const
 Return the pointer of the hosting TRestRun object. More...
 
virtual Long64_t GetTotalBytes () const
 
virtual Long64_t GetTotalBytesRead () const
 Interface to external file reading, get the read bytes. To be implemented in external processes. More...
 
virtual void InitFromConfigFile () override
 To make settings from rml file. This method must be implemented in the derived class. More...
 
virtual void InitProcess ()
 To be executed at the beginning of the run (outside event loop) More...
 
Bool_t isExternal () const
 Return whether this process is external process. More...
 
Int_t LoadSectionMetadata () override
 This method does some preparation of xml section. More...
 
virtual void NotifyAnalysisTreeReset ()
 In case the analysis tree is reset(switched to new file), some process needs to have action. More...
 
virtual Bool_t OpenInputFiles (const std::vector< std::string > &files)
 
virtual TRestEventProcessEvent (TRestEvent *inputEvent)=0
 Process one event. More...
 
std::vector< std::string > ReadObservables ()
 
void RegisterAllObservables (Bool_t value=true)
 
virtual Bool_t ResetEntry ()
 
void SetAnalysisTree (TRestAnalysisTree *tree)
 Set analysis tree of this process, then add observables to it.
 
void SetCanvasSize (Int_t x, Int_t y)
 Set canvas size. More...
 
void SetFriendProcess (TRestEventProcess *p)
 Add friendly process to this process.
 
void SetObservableValidation (bool validate)
 
void SetParallelProcess (TRestEventProcess *p)
 Add parallel process to this process.
 
void SetRunInfo (TRestRun *r)
 Set TRestRun for this process. More...
 
Bool_t singleThreadOnly () const
 Return whether this process is single std::thread only. More...
 
 TRestEventProcess ()
 
 ~TRestEventProcess ()
 

Protected Member Functions

void InitFromConfigFile () override
 Function reading input parameters from the RML TRestMySQLToAnalysisProcess section. More...
 
void Initialize () override
 Function to initialize input/output event members and define the section name and library version. More...
 
void InitProcess () override
 Function to use in initialization of process members before starting to process the event. More...
 
void LoadDefaultConfig ()
 Function to load the default config in absence of RML input. More...
 
- Protected Member Functions inherited from TRestEventProcess
void BeginPrintProcess ()
 [name, cut range]
 
void CreateCanvas ()
 Create the canvas. More...
 
void EndPrintProcess ()
 
TRestEventProcessGetFriend (const std::string &nameOrType)
 
TRestEventProcessGetFriendLive (const std::string &nameOrType)
 
template<class T >
T * GetMetadata ()
 Get a metadata object from the host TRestRun. More...
 
TRestMetadataGetMetadata (const std::string &nameOrType)
 
size_t GetNumberOfParallelProcesses () const
 
template<class T >
GetObservableValue (const std::string &name)
 
TRestEventProcessGetParallel (int i)
 
template<class T >
std::vector< T > GetParallelDataMembers (T *member_of_process)
 Get a list of data members from parallel processes which is same to this process's certain data member. More...
 
template<class T >
void SetObservableValue (const std::string &name, const T &value)
 Set observable value for AnalysisTree. More...
 

Private Member Functions

std::string BuildQueryString ()
 Dedicated method to help building the SQL query string. More...
 
void FillDBArrays ()
 This method is the one accessing the SQL database and filling the internal arrays with data that will be directly used to fill the analysisTree. More...
 
Double_t GetDBValueAtTimestamp (Int_t index, Double_t timestamp)
 This method will retrieve the given data field component, specified by the argument index at the given timestamp. The returned value will be interpolated with 2 known values of the neighbouring timestamps inside the fDBdata dataset. More...
 

Private Attributes

std::vector< TString > fAnaTreeVariables
 The name of the varibles will be renamed to these values in the analysisTree. More...
 
Bool_t fCheckSQL = true
 A boolean to output a warning message just once inside the process. More...
 
Bool_t fDataBaseExists = true
 It will be true in case the database found some entries for the timestamp range. More...
 
std::vector< std::vector< Double_t > > fDBdata
 A matrix containing extracted SQL data with fixed time bin. More...
 
std::string fDBName
 The database name. More...
 
std::string fDBServerName
 The host indentification name or IP. More...
 
std::string fDBTable
 The database table. More...
 
std::string fDBUserName
 The database username. More...
 
std::string fDBUserPass
 The database user password. More...
 
Double_t fEndTimestamp
 Stores the end timestamp used to extract the SQL data. More...
 
TRestEventfEvent = nullptr
 A pointer to the event data. More...
 
std::vector< Double_t > fMaxValues
 The maximum value of the corresponding extracted field variable. More...
 
std::vector< Double_t > fMinValues
 The minimum value of the corresponding extracted field variable. More...
 
Double_t fSampling
 Defines the internal sampling of the retrieved data for quick access. More...
 
std::vector< TString > fSQLVariables
 The name of the entries defined by user that will be retrieved at the SQL database. More...
 
Double_t fStartTimestamp
 Stores the start timestamp used to extract the SQL data. More...
 

Additional Inherited Members

- Protected Types inherited from TRestEventProcess
enum  REST_Process_Output { No_Output , Observable , Internal_Var , Full_Output }
 
- Protected Attributes inherited from TRestEventProcess
TRestAnalysisTreefAnalysisTree = nullptr
 
TCanvas * fCanvas = nullptr
 < Canvas for some viewer event More...
 
TVector2 fCanvasSize
 Canvas size. More...
 
std::vector< std::pair< std::string, TVector2 > > fCuts
 Stores cut definitions. Any listed observables should be in the range. More...
 
bool fDynamicObs = false
 It defines whether to use added observables only or all the observables appear in the code. More...
 
bool fIsExternal = false
 It defines if the process reads event data from an external source. More...
 
std::map< std::string, int > fObservablesDefined
 Stores the list of all the appeared process observables in the code. More...
 
std::map< std::string, int > fObservablesUpdated
 Stores the list of process observables updated when processing this event. More...
 
bool fReadOnly = false
 not used, keep for compatibility More...
 
TRestRunfRunInfo = nullptr
 < Pointer to TRestRun object where to find metadata. More...
 
bool fSingleThreadOnly = false
 
bool fValidateObservables = false
 It defines if observable names should be added to the validation list. More...
 

Constructor & Destructor Documentation

◆ TRestMySQLToAnalysisProcess() [1/2]

TRestMySQLToAnalysisProcess::TRestMySQLToAnalysisProcess ( )

Default constructor.

Definition at line 91 of file TRestMySQLToAnalysisProcess.cxx.

◆ TRestMySQLToAnalysisProcess() [2/2]

TRestMySQLToAnalysisProcess::TRestMySQLToAnalysisProcess ( const char *  configFilename)

Constructor loading data from a config file.

The path to the config file can be specified using full path, absolute or relative.

If the file is not found then REST will try to find the file on the default paths defined in REST Framework, usually at the REST_PATH installation directory. Additional search paths may be defined using the parameter searchPath in globals section. See TRestMetadata description.

Parameters
configFilenameA const char* giving the path to an RML file.

Definition at line 107 of file TRestMySQLToAnalysisProcess.cxx.

◆ ~TRestMySQLToAnalysisProcess()

TRestMySQLToAnalysisProcess::~TRestMySQLToAnalysisProcess ( )

Default destructor.

Definition at line 115 of file TRestMySQLToAnalysisProcess.cxx.

Member Function Documentation

◆ BuildQueryString()

string TRestMySQLToAnalysisProcess::BuildQueryString ( )
private

Dedicated method to help building the SQL query string.

Definition at line 407 of file TRestMySQLToAnalysisProcess.cxx.

◆ FillDBArrays()

void TRestMySQLToAnalysisProcess::FillDBArrays ( )
private

This method is the one accessing the SQL database and filling the internal arrays with data that will be directly used to fill the analysisTree.

The resulting fDBdata will contain equi-spaced temporal points of the retrieved SQL data with a sampling rate, fSampling, initialized by this method.

This method will also initialize the value of the fMinValues and fMaxValues vectors.

Definition at line 281 of file TRestMySQLToAnalysisProcess.cxx.

◆ GetDBValueAtTimestamp()

Double_t TRestMySQLToAnalysisProcess::GetDBValueAtTimestamp ( Int_t  index,
Double_t  timestamp 
)
private

This method will retrieve the given data field component, specified by the argument index at the given timestamp. The returned value will be interpolated with 2 known values of the neighbouring timestamps inside the fDBdata dataset.

Definition at line 428 of file TRestMySQLToAnalysisProcess.cxx.

◆ GetInputEvent()

RESTValue TRestMySQLToAnalysisProcess::GetInputEvent ( ) const
inlineoverridevirtual

Get pointer to input event. Must be implemented in the derived class.

Implements TRestEventProcess.

Definition at line 95 of file TRestMySQLToAnalysisProcess.h.

◆ GetOutputEvent()

RESTValue TRestMySQLToAnalysisProcess::GetOutputEvent ( ) const
inlineoverridevirtual

Get pointer to output event. Must be implemented in the derived class.

Implements TRestEventProcess.

Definition at line 96 of file TRestMySQLToAnalysisProcess.h.

◆ GetProcessName()

const char * TRestMySQLToAnalysisProcess::GetProcessName ( ) const
inlineoverridevirtual

Returns the name of this process.

Implements TRestEventProcess.

Definition at line 108 of file TRestMySQLToAnalysisProcess.h.

◆ InitFromConfigFile()

void TRestMySQLToAnalysisProcess::InitFromConfigFile ( )
overrideprotectedvirtual

Function reading input parameters from the RML TRestMySQLToAnalysisProcess section.

Reimplemented from TRestEventProcess.

Definition at line 215 of file TRestMySQLToAnalysisProcess.cxx.

◆ Initialize()

void TRestMySQLToAnalysisProcess::Initialize ( )
overrideprotectedvirtual

Function to initialize input/output event members and define the section name and library version.

Reimplemented from TRestMetadata.

Definition at line 163 of file TRestMySQLToAnalysisProcess.cxx.

◆ InitProcess()

void TRestMySQLToAnalysisProcess::InitProcess ( )
overrideprotectedvirtual

Function to use in initialization of process members before starting to process the event.

Reimplemented from TRestEventProcess.

Definition at line 145 of file TRestMySQLToAnalysisProcess.cxx.

◆ LoadConfig()

void TRestMySQLToAnalysisProcess::LoadConfig ( const std::string &  configFilename,
const std::string &  name = "" 
)

Function to load the configuration from an external configuration file.

If no configuration path is defined in TRestMetadata::SetConfigFilePath the path to the config file must be specified using full path, absolute or relative.

Parameters
configFilenameA const char* giving the path to an RML file.
nameThe name of the specific metadata. It will be used to find the corresponding TRestMySQLToAnalysisProcess section inside the RML.

Definition at line 137 of file TRestMySQLToAnalysisProcess.cxx.

◆ LoadDefaultConfig()

void TRestMySQLToAnalysisProcess::LoadDefaultConfig ( )
protected

Function to load the default config in absence of RML input.

Definition at line 120 of file TRestMySQLToAnalysisProcess.cxx.

◆ Maker()

TRestEventProcess * TRestMySQLToAnalysisProcess::Maker ( )
inline

Returns a new instance of this class.

Definition at line 105 of file TRestMySQLToAnalysisProcess.h.

◆ PrintMetadata()

void TRestMySQLToAnalysisProcess::PrintMetadata ( )
overridevirtual

It prints out basic information of the SQL database used to generate the analysis tree observables. And the SQL fields extracted together with its corresponding analysis tree name, and minimum and maximum values during the duration of the run.

Reimplemented from TRestMetadata.

Definition at line 252 of file TRestMySQLToAnalysisProcess.cxx.

◆ ProcessEvent()

TRestEvent * TRestMySQLToAnalysisProcess::ProcessEvent ( TRestEvent inputEvent)
overridevirtual

The main processing event function.

Implements TRestEventProcess.

Definition at line 175 of file TRestMySQLToAnalysisProcess.cxx.

Field Documentation

◆ fAnaTreeVariables

std::vector<TString> TRestMySQLToAnalysisProcess::fAnaTreeVariables
private

The name of the varibles will be renamed to these values in the analysisTree.

Definition at line 53 of file TRestMySQLToAnalysisProcess.h.

◆ fCheckSQL

Bool_t TRestMySQLToAnalysisProcess::fCheckSQL = true
private

A boolean to output a warning message just once inside the process.

Definition at line 77 of file TRestMySQLToAnalysisProcess.h.

◆ fDataBaseExists

Bool_t TRestMySQLToAnalysisProcess::fDataBaseExists = true
private

It will be true in case the database found some entries for the timestamp range.

Definition at line 62 of file TRestMySQLToAnalysisProcess.h.

◆ fDBdata

std::vector<std::vector<Double_t> > TRestMySQLToAnalysisProcess::fDBdata
private

A matrix containing extracted SQL data with fixed time bin.

Definition at line 74 of file TRestMySQLToAnalysisProcess.h.

◆ fDBName

std::string TRestMySQLToAnalysisProcess::fDBName
private

The database name.

Definition at line 44 of file TRestMySQLToAnalysisProcess.h.

◆ fDBServerName

std::string TRestMySQLToAnalysisProcess::fDBServerName
private

The host indentification name or IP.

Definition at line 35 of file TRestMySQLToAnalysisProcess.h.

◆ fDBTable

std::string TRestMySQLToAnalysisProcess::fDBTable
private

The database table.

Definition at line 47 of file TRestMySQLToAnalysisProcess.h.

◆ fDBUserName

std::string TRestMySQLToAnalysisProcess::fDBUserName
private

The database username.

Definition at line 38 of file TRestMySQLToAnalysisProcess.h.

◆ fDBUserPass

std::string TRestMySQLToAnalysisProcess::fDBUserPass
private

The database user password.

Definition at line 41 of file TRestMySQLToAnalysisProcess.h.

◆ fEndTimestamp

Double_t TRestMySQLToAnalysisProcess::fEndTimestamp
private

Stores the end timestamp used to extract the SQL data.

Definition at line 68 of file TRestMySQLToAnalysisProcess.h.

◆ fEvent

TRestEvent* TRestMySQLToAnalysisProcess::fEvent = nullptr
private

A pointer to the event data.

Definition at line 32 of file TRestMySQLToAnalysisProcess.h.

◆ fMaxValues

std::vector<Double_t> TRestMySQLToAnalysisProcess::fMaxValues
private

The maximum value of the corresponding extracted field variable.

Definition at line 59 of file TRestMySQLToAnalysisProcess.h.

◆ fMinValues

std::vector<Double_t> TRestMySQLToAnalysisProcess::fMinValues
private

The minimum value of the corresponding extracted field variable.

Definition at line 56 of file TRestMySQLToAnalysisProcess.h.

◆ fSampling

Double_t TRestMySQLToAnalysisProcess::fSampling
private

Defines the internal sampling of the retrieved data for quick access.

Definition at line 71 of file TRestMySQLToAnalysisProcess.h.

◆ fSQLVariables

std::vector<TString> TRestMySQLToAnalysisProcess::fSQLVariables
private

The name of the entries defined by user that will be retrieved at the SQL database.

Definition at line 50 of file TRestMySQLToAnalysisProcess.h.

◆ fStartTimestamp

Double_t TRestMySQLToAnalysisProcess::fStartTimestamp
private

Stores the start timestamp used to extract the SQL data.

Definition at line 65 of file TRestMySQLToAnalysisProcess.h.


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