JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwDBInterface.h
Go to the documentation of this file.
1
2/*!
3 * \file QwDBInterface.h
4 * \brief Database interface for QwIntegrationPMT and subsystems
5 * \author jhlee
6 * \date 2010-12-14
7 */
8
9#pragma once
10
11// System headers
12#include <iostream>
13#include <iomanip>
14#include <cstring>
15#include <vector>
16#include <map>
17
18// ROOT headers
19#include "Rtypes.h"
20#include "TString.h"
21
22// Qweak headers
23#include "QwLog.h"
24
25// Forward declarations
26class QwParityDB;
27
28#ifdef __USE_DATABASE__
29#include "QwDatabase.h"
30#include "QwParitySchema.h"
31#include "QwParitySchemaRow.h"
32#endif // __USE_DATABASE__
33
34// QwDBInterface GetDBEntry(TString subname);
35
36// I extend a DB interface for QwIntegrationPMT to all subsystem,
37// because the table structure are the same in the lumi_data table,
38// the md_data table, and the beam table of MySQL database.
39// Now every device-specified action will be done in
40// the FillDB(QwParityDB *db, TString datatype) of QwBeamLine,
41// QwMainCerenkovDetector, and QwLumi class.
42
44 public:
47 private:
48 static std::map<TString, TString> fPrefix;
49
51 UInt_t fDeviceId;
52 UInt_t fSubblock;
53 UInt_t fN;
54 Double_t fValue;
55 Double_t fError;
57
58 TString fDeviceName;
59
60 private:
61 template <class T>
62 T TypedDBClone();
63
64 public:
65 static TString DetermineMeasurementTypeID(TString type, TString suffix = "",
66 Bool_t forcediffs = kFALSE);
67
68 public:
69
71 : fAnalysisId(0),fDeviceId(0),fSubblock(0),fN(0),fValue(0.0),fError(0.0) {
72 std::strcpy(fMeasurementTypeId, "");fDeviceName ="";
73 }
74 virtual ~QwDBInterface() { }
75
76 void SetAnalysisID(UInt_t id) {fAnalysisId = id;};
77 void SetDetectorName(TString &in) {fDeviceName = in;};
78 void SetDeviceID(UInt_t id) {fDeviceId = id;};
79 void SetMonitorID(QwParityDB *db);
80 void SetMainDetectorID(QwParityDB *db);
81 void SetLumiDetectorID(QwParityDB *db);
83 void SetMeasurementTypeID(const TString& in) {
84 std::strncpy(fMeasurementTypeId, in.Data(), 3);
85 fMeasurementTypeId[3] = '\0';
86 };
87 void SetMeasurementTypeID(const char* in) {
88 std::strncpy(fMeasurementTypeId, in, 3);
89 fMeasurementTypeId[3] = '\0';
90 };
91 void SetSubblock(UInt_t in) {fSubblock = in;};
92 void SetN(UInt_t in) {fN = in;};
93 void SetValue(Double_t in) {fValue = in;};
94 void SetError(Double_t in) {fError = in;};
95
96 TString GetDeviceName() {return fDeviceName;};
97
98 void Reset() {
99 fAnalysisId = 0;
100 fDeviceId = 0;
101 fSubblock = 0;
102 fN = 0;
103 fValue = 0.0;
104 fError = 0.0;
105 std::strcpy(fMeasurementTypeId,"");
106 fDeviceName = "";
107 };
108
109 template <class T> inline
110 void AddThisEntryToList(std::vector<T> &list);
111
112
113 void PrintStatus(Bool_t print_flag) {
114 if(print_flag) {
115 QwMessage << std::setw(12)
116 << " AnalysisID " << fAnalysisId
117 << " Device :" << std::setw(30) << fDeviceName
118 << ":" << std::setw(4) << fDeviceId
119 << " Subblock " << fSubblock
120 << " n " << fN
121 << " Type " << fMeasurementTypeId
122 << " [ave, err] "
123 << " [" << std::setw(14) << fValue
124 << "," << std::setw(14) << fError
125 << "]"
126 << QwLog::endl;
127 }
128 }
129};
130
131//
132// Template definitions for the QwDBInterface class.
133//
134//
135
136template <class T>
137inline void QwDBInterface::AddThisEntryToList(std::vector<T> &list)
138{
139 Bool_t okay = kTRUE;
140 if (fAnalysisId == 0) {
141 QwError << "QwDBInterface::AddDBEntryToList: Analysis ID invalid; entry dropped"
142 << QwLog::endl;
143 okay = kFALSE;
144 }
145 if (fDeviceId == 0) {
146 QwError << "QwDBInterface::AddDBEntryToList: Device ID invalid; entry dropped"
147 << QwLog::endl;
148 okay = kFALSE;
149 }
150 if (okay) {
151 T row = TypedDBClone<T>();
152 // Note: analysis_id validation done above with fAnalysisId check
153 list.push_back(row);
154 }
155 if (okay == kFALSE) {
156 PrintStatus(kTRUE);
157 };
158}
159
160
161
162
163
164
166
167 private:
168
170 UInt_t fDeviceId;
172 UInt_t fN;
173
174 TString fDeviceName;
175
176 template <class T>
177 T TypedDBClone();
178
179
180 public:
181
183 : fAnalysisId(0),fDeviceId(0),fErrorCodeId(0),fN(0) {
184 fDeviceName ="";
185 }
186 virtual ~QwErrDBInterface() { }
187
188 void SetAnalysisID(UInt_t id) {fAnalysisId = id;};
189 void SetDeviceName(TString &in) {fDeviceName = in;};
190 void SetDeviceID(UInt_t id) {fDeviceId = id;};
191
192 void SetMonitorID(QwParityDB *db);
193 void SetMainDetectorID(QwParityDB *db);
194 void SetLumiDetectorID(QwParityDB *db);
195
196 void SetErrorCodeId(UInt_t in) {fErrorCodeId = in;};
197 void SetN(UInt_t in) {fN = in;};
198
199 TString GetDeviceName() {return fDeviceName;};
200
201 void Reset() {
202 fAnalysisId = 0;
203 fDeviceId = 0;
204 fErrorCodeId = 0;
205 fN = 0;
206 fDeviceName = "";
207 };
208
209 template <class T> inline
210 void AddThisEntryToList(std::vector<T> &list);
211
212 void PrintStatus(Bool_t print_flag) {
213 if(print_flag) {
214 QwMessage << std::setw(12)
215 << " AnalysisID " << fAnalysisId
216 << " Device :" << std::setw(30) << fDeviceName
217 << ":" << std::setw(4) << fDeviceId
218 << " ErrorCode " << fErrorCodeId
219 << " n " << fN
220 << QwLog::endl;
221 }
222 }
223};
224
225template <class T>
226inline void QwErrDBInterface::AddThisEntryToList(std::vector<T> &list)
227{
228 Bool_t okay = kTRUE;
229 if (fAnalysisId == 0) {
230 QwError << "QwErrDBInterface::AddDBEntryToList: Analysis ID invalid; entry dropped"
231 << QwLog::endl;
232 okay = kFALSE;
233 }
234 if (fDeviceId == 0) {
235 QwError << "QwErrDBInterface::AddDBEntryToList: Device ID invalid; entry dropped"
236 << QwLog::endl;
237 okay = kFALSE;
238 }
239 if (okay) {
240 T row = TypedDBClone<T>();
241 // Note: analysis_id validation done above with fAnalysisId check
242 list.push_back(row);
243 }
244 if (okay == kFALSE) {
245 PrintStatus(kTRUE);
246 };
247}
A class for handling connections to the Qweak database.
A logfile class, based on an identical class in the Hermes analyzer.
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
void SetSubblock(UInt_t in)
void SetError(Double_t in)
void SetN(UInt_t in)
void AddThisEntryToList(std::vector< T > &list)
void SetMonitorID(QwParityDB *db)
TString GetDeviceName()
void SetMeasurementTypeID(const TString &in)
Double_t fValue
static std::map< TString, TString > fPrefix
virtual ~QwDBInterface()
void SetDeviceID(UInt_t id)
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
void SetValue(Double_t in)
void SetMainDetectorID(QwParityDB *db)
Double_t fError
void PrintStatus(Bool_t print_flag)
void SetMeasurementTypeID(const char *in)
Char_t fMeasurementTypeId[4]
TString fDeviceName
void SetAnalysisID(UInt_t id)
EQwDBIDataTableType SetDetectorID(QwParityDB *db)
void SetLumiDetectorID(QwParityDB *db)
void SetDetectorName(TString &in)
void SetN(UInt_t in)
void SetDeviceName(TString &in)
void SetErrorCodeId(UInt_t in)
void SetDeviceID(UInt_t id)
void SetAnalysisID(UInt_t id)
void SetMonitorID(QwParityDB *db)
void AddThisEntryToList(std::vector< T > &list)
void SetLumiDetectorID(QwParityDB *db)
void SetMainDetectorID(QwParityDB *db)
void PrintStatus(Bool_t print_flag)
TString GetDeviceName()
virtual ~QwErrDBInterface()
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297