QwAnalysis
QwDBInterface.cc
Go to the documentation of this file.
1 /*
2  * QwDBInterface.cc
3  *
4  * Created on: Dec 14, 2010
5  * Author: wdconinc
6  * Author: jhlee
7  */
8 
9 #include "QwDBInterface.h"
10 
11 // Qweak headers
12 //#define MYSQLPP_SSQLS_NO_STATICS
13 #include "QwParitySSQLS.h"
14 #include "QwParityDB.h"
15 
16 std::map<TString, TString> QwDBInterface::fPrefix;
17 
18 TString QwDBInterface::DetermineMeasurementTypeID(TString type, TString suffix,
19  Bool_t forcediffs)
20 {
21  if (fPrefix.empty()){
22  fPrefix["yield"] = "y";
23  fPrefix["difference"] = "d";
24  fPrefix["asymmetry"] = "a";
25  fPrefix["asymmetry1"] = "a12";
26  fPrefix["asymmetry2"] = "aeo";
27  }
28  TString measurement_type("");
29  if (fPrefix.count(type)==1){
30  measurement_type = fPrefix[type];
31  if (measurement_type[0] == 'a' &&
32  (forcediffs
33  || (suffix == "p" || suffix == "a"
34  || suffix == "m")) ){
35  // Change the type to difference for position,
36  // angle, or slope asymmetry variables.
37  measurement_type[0] = 'd';
38  } else if (measurement_type[0] == 'y') {
39  measurement_type += suffix;
40  }
41  }
42  QwDebug << "\n"
43  << type << ", " << suffix
44  << " \'" << measurement_type.Data() << "\'" << QwLog::endl;
45  return measurement_type;
46 }
47 
48 
50 {
51  fDeviceId = db->GetMonitorID(fDeviceName.Data());
52 }
53 
55 {
57 }
58 
60 {
62 }
63 
65 {
66  fDeviceId = db->GetMonitorID(fDeviceName.Data(),kFALSE);
67  if (fDeviceId!=0) return kQwDBI_BeamTable;
68  fDeviceId = db->GetMainDetectorID(fDeviceName.Data(),kFALSE);
69  if (fDeviceId!=0) return kQwDBI_MDTable;
70  fDeviceId = db->GetLumiDetectorID(fDeviceName.Data(),kFALSE);
71  if (fDeviceId!=0) return kQwDBI_LumiTable;
72  return kQwDBI_OtherTable;
73 }
74 
75 template <class T>
77 {
78  T row(0);
79  return row;
80 }
81 
82 
83 
84 /// Specifications of the templated function
85 /// template \verbatim<class T>\endverbatim inline T QwDBInterface::TypedDBClone();
86 template<> QwParitySSQLS::md_data
87 QwDBInterface::TypedDBClone<QwParitySSQLS::md_data>() {
88  QwParitySSQLS::md_data row(0);
89  row.analysis_id = fAnalysisId;
90  row.main_detector_id = fDeviceId;
91  row.measurement_type_id = fMeasurementTypeId;
92  row.subblock = fSubblock;
93  row.n = fN;
94  row.value = fValue;
95  row.error = fError;
96  return row;
97 }
98 template<> QwParitySSQLS::lumi_data
99 QwDBInterface::TypedDBClone<QwParitySSQLS::lumi_data>() {
100  QwParitySSQLS::lumi_data row(0);
101  row.analysis_id = fAnalysisId;
102  row.lumi_detector_id = fDeviceId;
103  row.measurement_type_id = fMeasurementTypeId;
104  row.subblock = fSubblock;
105  row.n = fN;
106  row.value = fValue;
107  row.error = fError;
108  return row;
109 }
110 template<> QwParitySSQLS::beam
111 QwDBInterface::TypedDBClone<QwParitySSQLS::beam>() {
112  QwParitySSQLS::beam row(0);
113  row.analysis_id = fAnalysisId;
114  row.monitor_id = fDeviceId;
115  row.measurement_type_id = fMeasurementTypeId;
116  row.subblock = fSubblock;
117  row.n = fN;
118  row.value = fValue;
119  row.error = fError;
120  return row;
121 }
122 
123 
124 
125 
126 
127 // QwErrDBInterface
128 
129 
131 {
132  fDeviceId = db->GetMonitorID(fDeviceName.Data());
133 }
134 
136 {
138 }
139 
141 {
143 }
144 
145 template <class T>
147 {
148  T row(0);
149  return row;
150 }
151 
152 template<> QwParitySSQLS::md_errors
153 QwErrDBInterface::TypedDBClone<QwParitySSQLS::md_errors>() {
154  QwParitySSQLS::md_errors row(0);
155  row.analysis_id = fAnalysisId;
156  row.main_detector_id = fDeviceId;
157  row.error_code_id = fErrorCodeId;
158  row.n = fN;
159  return row;
160 };
161 
162 
163 template<> QwParitySSQLS::lumi_errors
164 QwErrDBInterface::TypedDBClone<QwParitySSQLS::lumi_errors>() {
165  QwParitySSQLS::lumi_errors row(0);
166  row.analysis_id = fAnalysisId;
167  row.lumi_detector_id = fDeviceId;
168  row.error_code_id = fErrorCodeId;
169  row.n = fN;
170  return row;
171 };
172 
173 
174 
175 
176 template<> QwParitySSQLS::beam_errors
177 QwErrDBInterface::TypedDBClone<QwParitySSQLS::beam_errors>() {
178  QwParitySSQLS::beam_errors row(0);
179  row.analysis_id = fAnalysisId;
180  row.monitor_id = fDeviceId;
181  row.error_code_id = fErrorCodeId;
182  row.n = fN;
183  return row;
184 };
185 
186 
187 template<> QwParitySSQLS::general_errors
188 QwErrDBInterface::TypedDBClone<QwParitySSQLS::general_errors>() {
189  QwParitySSQLS::general_errors row(0);
190  row.analysis_id = fAnalysisId;
191  row.error_code_id = fErrorCodeId;
192  row.n = fN;
193  return row;
194 };
195 
196 
197 
void SetLumiDetectorID(QwParityDB *db)
UInt_t GetMonitorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:618
void SetMainDetectorID(QwParityDB *db)
UInt_t GetMainDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:661
EQwDBIDataTableType SetDetectorID(QwParityDB *db)
static std::map< TString, TString > fPrefix
Definition: QwDBInterface.h:43
UInt_t GetLumiDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:790
void SetLumiDetectorID(QwParityDB *db)
void SetMonitorID(QwParityDB *db)
#define QwDebug
Predefined log drain for debugging output.
Definition: QwLog.h:60
TString fDeviceName
Definition: QwDBInterface.h:53
UInt_t fDeviceId
Definition: QwDBInterface.h:46
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
void SetMonitorID(QwParityDB *db)
void SetMainDetectorID(QwParityDB *db)
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
static TString DetermineMeasurementTypeID(TString type, TString suffix="", Bool_t forcediffs=kFALSE)