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.
 
RESTValue GetOutputEvent () const override
 Get pointer to output event. Must be implemented in the derived class.
 
const char * GetProcessName () const override
 Returns the name of this process.
 
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.
 
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.
 
TRestEventProcessEvent (TRestEvent *inputEvent) override
 The main processing event function.
 
 TRestMySQLToAnalysisProcess ()
 Default constructor.
 
 TRestMySQLToAnalysisProcess (const char *configFilename)
 Constructor loading data from a config file. More...
 
 ~TRestMySQLToAnalysisProcess ()
 Default destructor.
 
- 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()
 
 ClassDefOverride (TRestEventProcess, 3)
 
virtual void EndOfEventProcess (TRestEvent *inputEvent=nullptr)
 End of event process. Nothing to do. Called directly after ProcessEvent()
 
virtual void EndProcess ()
 To be executed at the end of the run (outside event loop)
 
TRestAnalysisTreeGetAnalysisTree () const
 Return the local analysis tree (dummy)
 
TCanvas * GetCanvas () const
 Get canvas.
 
TRestAnalysisTreeGetFullAnalysisTree ()
 
std::vector< std::string > GetListOfAddedObservables ()
 
TRestRunGetRunInfo () const
 Return the pointer of the hosting TRestRun object.
 
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.
 
Bool_t isExternal () const
 Return whether this process is external process.
 
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.
 
virtual Bool_t OpenInputFiles (const std::vector< std::string > &files)
 
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.
 
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.
 
Bool_t singleThreadOnly () const
 Return whether this process is single std::thread only.
 
 TRestEventProcess ()
 
 ~TRestEventProcess ()
 

Protected Member Functions

void InitFromConfigFile () override
 Function reading input parameters from the RML TRestMySQLToAnalysisProcess section.
 
void Initialize () override
 Function to initialize input/output event members and define the section name and library version.
 
void InitProcess () override
 Function to use in initialization of process members before starting to process the event.
 
void LoadDefaultConfig ()
 Function to load the default config in absence of RML input.
 
- Protected Member Functions inherited from TRestEventProcess
void BeginPrintProcess ()
 [name, cut range]
 
void CreateCanvas ()
 Create the canvas.
 
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.
 
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.
 

Private Attributes

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

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
 
TVector2 fCanvasSize
 Canvas size.
 
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.
 
bool fIsExternal = false
 It defines if the process reads event data from an external source.
 
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.
 
bool fReadOnly = false
 not used, keep for compatibility
 
TRestRunfRunInfo = nullptr
 < Pointer to TRestRun object where to find metadata.
 
bool fSingleThreadOnly = false
 
bool fValidateObservables = false
 It defines if observable names should be added to the validation list.
 

Constructor & Destructor Documentation

◆ TRestMySQLToAnalysisProcess()

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.

Member Function Documentation

◆ 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.

◆ 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.


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