QwAnalysis
QwDBInterface.h
Go to the documentation of this file.
1 /*
2  * QwDBInterface.h
3  *
4  * Created on: Dec 14, 2010
5  * Author: jhlee
6  */
7 
8 #ifndef QWDBINTERFACE_H_
9 #define QWDBINTERFACE_H_
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 //#include "QwParityDB.h"
25 
26 // Forward declarations
27 class QwParityDB;
28 
29 // QwDBInterface GetDBEntry(TString subname);
30 
31 // I extend a DB interface for QwIntegrationPMT to all subsystem,
32 // because the table structure are the same in the lumi_data table,
33 // the md_data table, and the beam table of MySQL database.
34 // Now every device-specified action will be done in
35 // the FillDB(QwParityDB *db, TString datatype) of QwBeamLine,
36 // QwMainCerenkovDetector, and QwLumi class.
37 
39  public:
42  private:
43  static std::map<TString, TString> fPrefix;
44 
45  UInt_t fAnalysisId;
46  UInt_t fDeviceId;
47  UInt_t fSubblock;
48  UInt_t fN;
49  Double_t fValue;
50  Double_t fError;
51  Char_t fMeasurementTypeId[4];
52 
53  TString fDeviceName;
54 
55  private:
56  template <class T>
57  T TypedDBClone();
58 
59  public:
60  static TString DetermineMeasurementTypeID(TString type, TString suffix = "",
61  Bool_t forcediffs = kFALSE);
62 
63  public:
64 
66  : fAnalysisId(0),fDeviceId(0),fSubblock(0),fN(0),fValue(0.0),fError(0.0) {
67  std::strcpy(fMeasurementTypeId, "");fDeviceName ="";
68  }
69  virtual ~QwDBInterface() { }
70 
71  void SetAnalysisID(UInt_t id) {fAnalysisId = id;};
72  void SetDetectorName(TString &in) {fDeviceName = in;};
73  void SetDeviceID(UInt_t id) {fDeviceId = id;};
74  void SetMonitorID(QwParityDB *db);
75  void SetMainDetectorID(QwParityDB *db);
76  void SetLumiDetectorID(QwParityDB *db);
78  void SetMeasurementTypeID(const TString& in) {
79  std::strncpy(fMeasurementTypeId, in.Data(), 3);
80  fMeasurementTypeId[3] = '\0';
81  };
82  void SetMeasurementTypeID(const char* in) {
83  std::strncpy(fMeasurementTypeId, in, 3);
84  fMeasurementTypeId[3] = '\0';
85  };
86  void SetSubblock(UInt_t in) {fSubblock = in;};
87  void SetN(UInt_t in) {fN = in;};
88  void SetValue(Double_t in) {fValue = in;};
89  void SetError(Double_t in) {fError = in;};
90 
91  TString GetDeviceName() {return fDeviceName;};
92 
93  void Reset() {
94  fAnalysisId = 0;
95  fDeviceId = 0;
96  fSubblock = 0;
97  fN = 0;
98  fValue = 0.0;
99  fError = 0.0;
100  std::strcpy(fMeasurementTypeId,"");
101  fDeviceName = "";
102  };
103 
104  template <class T> inline
105  void AddThisEntryToList(std::vector<T> &list);
106 
107 
108  void PrintStatus(Bool_t print_flag) {
109  if(print_flag) {
110  QwMessage << std::setw(12)
111  << " AnalysisID " << fAnalysisId
112  << " Device :" << std::setw(30) << fDeviceName
113  << ":" << std::setw(4) << fDeviceId
114  << " Subblock " << fSubblock
115  << " n " << fN
116  << " Type " << fMeasurementTypeId
117  << " [ave, err] "
118  << " [" << std::setw(14) << fValue
119  << "," << std::setw(14) << fError
120  << "]"
121  << QwLog::endl;
122  }
123  }
124 };
125 
126 //
127 // Template definitions for the QwDBInterface class.
128 //
129 //
130 
131 template <class T>
132 inline void QwDBInterface::AddThisEntryToList(std::vector<T> &list)
133 {
134  Bool_t okay = kTRUE;
135  if (fAnalysisId == 0) {
136  QwError << "QwDBInterface::AddDBEntryToList: Analysis ID invalid; entry dropped"
137  << QwLog::endl;
138  okay = kFALSE;
139  }
140  if (fDeviceId == 0) {
141  QwError << "QwDBInterface::AddDBEntryToList: Device ID invalid; entry dropped"
142  << QwLog::endl;
143  okay = kFALSE;
144  }
145  if (okay) {
146  T row = TypedDBClone<T>();
147  if (row.analysis_id == 0){
148  QwError << "QwDBInterface::AddDBEntryToList: Unknown list type; entry dropped"
149  << QwLog::endl;
150  okay = kFALSE;
151  } else {
152  list.push_back(row);
153  }
154  }
155  if (okay == kFALSE) {
156  PrintStatus(kTRUE);
157  };
158 }
159 
160 
161 
162 
163 
164 
166 
167  private:
168 
169  UInt_t fAnalysisId;
170  UInt_t fDeviceId;
171  UInt_t fErrorCodeId;
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 
213  void PrintStatus(Bool_t print_flag) {
214  if(print_flag) {
215  QwMessage << std::setw(12)
216  << " AnalysisID " << fAnalysisId
217  << " Device :" << std::setw(30) << fDeviceName
218  << ":" << std::setw(4) << fDeviceId
219  << " ErrorCode " << fErrorCodeId
220  << " n " << fN
221  << QwLog::endl;
222  }
223  }
224 };
225 
226 template <class T>
227 inline void QwErrDBInterface::AddThisEntryToList(std::vector<T> &list)
228 {
229  Bool_t okay = kTRUE;
230  if (fAnalysisId == 0) {
231  QwError << "QwErrDBInterface::AddDBEntryToList: Analysis ID invalid; entry dropped"
232  << QwLog::endl;
233  okay = kFALSE;
234  }
235  if (fDeviceId == 0) {
236  QwError << "QwErrDBInterface::AddDBEntryToList: Device ID invalid; entry dropped"
237  << QwLog::endl;
238  okay = kFALSE;
239  }
240  if (okay) {
241  T row = TypedDBClone<T>();
242  if (row.analysis_id == 0){
243  QwError << "QwErrDBInterface::AddDBEntryToList: Unknown list type; entry dropped"
244  << QwLog::endl;
245  okay = kFALSE;
246  } else {
247  list.push_back(row);
248  }
249  }
250  if (okay == kFALSE) {
251  PrintStatus(kTRUE);
252  };
253 }
254 
255 #endif /* QWDBINTERFACE_H_ */
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void SetLumiDetectorID(QwParityDB *db)
void SetError(Double_t in)
Definition: QwDBInterface.h:89
UInt_t fSubblock
Definition: QwDBInterface.h:47
void SetMeasurementTypeID(const TString &in)
Definition: QwDBInterface.h:78
Char_t fMeasurementTypeId[4]
Definition: QwDBInterface.h:51
void SetMainDetectorID(QwParityDB *db)
static const double in
Definition: QwUnits.h:66
Double_t fValue
Definition: QwDBInterface.h:49
void PrintStatus(Bool_t print_flag)
EQwDBIDataTableType SetDetectorID(QwParityDB *db)
static std::map< TString, TString > fPrefix
Definition: QwDBInterface.h:43
void SetN(UInt_t in)
Definition: QwDBInterface.h:87
void SetDetectorName(TString &in)
Definition: QwDBInterface.h:72
void SetLumiDetectorID(QwParityDB *db)
void SetMonitorID(QwParityDB *db)
void SetAnalysisID(UInt_t id)
void SetSubblock(UInt_t in)
Definition: QwDBInterface.h:86
A logfile class, based on an identical class in the Hermes analyzer.
TString fDeviceName
Definition: QwDBInterface.h:53
TString GetDeviceName()
Definition: QwDBInterface.h:91
UInt_t fDeviceId
Definition: QwDBInterface.h:46
Double_t fError
Definition: QwDBInterface.h:50
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
void SetN(UInt_t in)
virtual ~QwDBInterface()
Definition: QwDBInterface.h:69
void SetMonitorID(QwParityDB *db)
virtual ~QwErrDBInterface()
void SetMainDetectorID(QwParityDB *db)
void SetErrorCodeId(UInt_t in)
void AddThisEntryToList(std::vector< T > &list)
void SetValue(Double_t in)
Definition: QwDBInterface.h:88
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void SetDeviceID(UInt_t id)
void SetAnalysisID(UInt_t id)
Definition: QwDBInterface.h:71
void SetMeasurementTypeID(const char *in)
Definition: QwDBInterface.h:82
void SetDeviceName(TString &in)
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)
TString GetDeviceName()
void PrintStatus(Bool_t print_flag)
void SetDeviceID(UInt_t id)
Definition: QwDBInterface.h:73
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
UInt_t fAnalysisId
Definition: QwDBInterface.h:45
void AddThisEntryToList(std::vector< T > &list)