REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestMySQLToAnalysisProcess.h
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see http://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see http://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
23 #ifndef RestCore_TRestMySQLToAnalysisProcess
24 #define RestCore_TRestMySQLToAnalysisProcess
25 
26 #include "TRestEventProcess.h"
27 
30  private:
32  TRestEvent* fEvent = nullptr;
33 
35  std::string fDBServerName;
36 
38  std::string fDBUserName;
39 
41  std::string fDBUserPass;
42 
44  std::string fDBName; //<
45 
47  std::string fDBTable; //<
48 
50  std::vector<TString> fSQLVariables; //<
51 
53  std::vector<TString> fAnaTreeVariables; //<
54 
56  std::vector<Double_t> fMinValues; //<
57 
59  std::vector<Double_t> fMaxValues; //<
60 
62  Bool_t fDataBaseExists = true; //<
63 
65  Double_t fStartTimestamp;
66 
68  Double_t fEndTimestamp;
69 
71  Double_t fSampling;
72 
74  std::vector<std::vector<Double_t> > fDBdata;
75 
77  Bool_t fCheckSQL = true;
78 
79  std::string BuildQueryString();
80 
81  void FillDBArrays();
82 
83  Double_t GetDBValueAtTimestamp(Int_t index, Double_t timestamp);
84 
85  protected:
86  void InitProcess() override;
87 
88  void InitFromConfigFile() override;
89 
90  void Initialize() override;
91 
92  void LoadDefaultConfig();
93 
94  public:
95  RESTValue GetInputEvent() const override { return fEvent; }
96  RESTValue GetOutputEvent() const override { return fEvent; }
97 
98  TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;
99 
100  void LoadConfig(const std::string& configFilename, const std::string& name = "");
101 
102  void PrintMetadata() override;
103 
106 
108  const char* GetProcessName() const override { return "SQLToAnalysisProces"; }
109 
111  TRestMySQLToAnalysisProcess(const char* configFilename);
112 
114 
117 };
118 #endif
A base class for any REST event process.
A base class for any REST event.
Definition: TRestEvent.h:38
This process connects to a SQL database and adds new observables inside the analysis tree.
std::vector< TString > fAnaTreeVariables
The name of the varibles will be renamed to these values in the analysisTree.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
Double_t fSampling
Defines the internal sampling of the retrieved data for quick access.
std::string fDBServerName
The host indentification name or IP.
void InitFromConfigFile() override
Function reading input parameters from the RML TRestMySQLToAnalysisProcess section.
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 give...
std::string BuildQueryString()
Dedicated method to help building the SQL query string.
ClassDefOverride(TRestMySQLToAnalysisProcess, 2)
If new members are added, removed or modified in this class version number must be increased!
Double_t fStartTimestamp
Stores the start timestamp used to extract the SQL data.
TRestEvent * fEvent
A pointer to the event data.
std::string fDBTable
The database table.
std::vector< Double_t > fMinValues
The minimum value of the corresponding extracted field variable.
void InitProcess() override
Function to use in initialization of process members before starting to process the event.
std::string fDBName
The database name.
const char * GetProcessName() const override
Returns the name of this process.
void FillDBArrays()
This method is the one accessing the SQL database and filling the internal arrays with data that will...
RESTValue GetOutputEvent() const override
Get pointer to output event. Must be implemented in the derived class.
TRestEventProcess * Maker()
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....
void Initialize() override
Function to initialize input/output event members and define the section name and library version.
TRestMySQLToAnalysisProcess()
Default constructor.
Double_t fEndTimestamp
Stores the end timestamp used to extract the SQL data.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
Bool_t fCheckSQL
A boolean to output a warning message just once inside the process.
std::vector< Double_t > fMaxValues
The maximum value of the corresponding extracted field variable.
RESTValue GetInputEvent() const override
Get pointer to input event. Must be implemented in the derived class.
Bool_t fDataBaseExists
It will be true in case the database found some entries for the timestamp range.
std::string fDBUserName
The database username.
std::vector< std::vector< Double_t > > fDBdata
A matrix containing extracted SQL data with fixed time bin.
std::string fDBUserPass
The database user password.
std::vector< TString > fSQLVariables
The name of the entries defined by user that will be retrieved at the SQL database.