Diana Software
QJitterHandle.cc
Go to the documentation of this file.
1 #include "QJitterHandle.hh"
2 #include "QJitter.hh"
3 #include "QDianaDb.hh"
4 
5 using namespace Diana;
6 
8 {
10 
11  QJitter jitter;
12  jitter.Clear();
13 
14  std::string bareOwner, extraLabel;
15  GetLabel().GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
16  if (extraLabel=="") extraLabel="None";
17 
18  int refCh;
19  double jitt;
20  double jittErr;
21 
22  QDianaDb *db = QDianaDb::Get();
23 
24  std::stringstream squery;
25 
26  // query reference channel
27 
28  squery<<"select ref_channel from jitters where jitter_algo = '" <<bareOwner
29  << "' and jitter_version = '"<<GetVersion()
30  << "' and jitter_extralabel= '"<<extraLabel
31  << "' and channel = "<<GetChannel()
32  << " and data_set = "<<GetDataset();
33 
34  try {
35  refCh = db->DoQueryInt(squery.str());
36  }
37 
38  catch(const QError& cerr) {
39  if(cerr!=QERR_SUCCESS) {
40  err = cerr;
41  return err;
42  }
43  }
44 
45  squery.str("");
46 
47  // query jitter
48 
49  squery<<"select jitter from jitters where jitter_algo = '" <<bareOwner
50  << "' and jitter_version = '"<<GetVersion()
51  << "' and jitter_extralabel= '"<<extraLabel
52  << "' and channel = "<<GetChannel()
53  << " and data_set = "<<GetDataset();
54 
55  try {
56  jitt = db->DoQueryDouble(squery.str());
57  }
58 
59  catch(const QError& cerr) {
60  if(cerr!=QERR_SUCCESS) {
61  err = cerr;
62  return err;
63  }
64  }
65 
66  squery.str("");
67 
68  // query jitter error
69 
70  squery<<"select err_jitter from jitters where jitter_algo = '" <<bareOwner
71  << "' and jitter_version = '"<<GetVersion()
72  << "' and jitter_extralabel= '"<<extraLabel
73  << "' and channel = "<<GetChannel()
74  << " and data_set = "<<GetDataset();
75 
76  try {
77  jittErr = db->DoQueryDouble(squery.str());
78  }
79 
80  catch(const QError& cerr) {
81  if(cerr!=QERR_SUCCESS) {
82  err = cerr;
83  return err;
84  }
85  }
86 
87  jitter.fRefChannel = refCh;
88  jitter.fJitter = jitt;
89  jitter.fJitterError = jittErr;
90 
91  Set(jitter);
92 
93  // fill fCalibLabel from table xxx_jitter_algo where xxx is the name of the jitter module (now JitterByCoincidence)
94 
95  std::string calib_algo, calib_version, calib_extralabel;
96 
97  QDb::QDbTable table;
98 
99  squery.str("");
100 
101  squery<<"select calib_algo, calib_version, calib_extralabel from "<<bareOwner<<"_jitter_algo"
102  <<" where jitter_version= '"<<GetVersion()
103  <<"' and jitter_extralabel= '"<<extraLabel <<"'";
104 
105  try {
106  table = db->DoQuery(squery.str());
107  }
108 
109  catch(const QError& cerr) {
110  err = cerr;
111  return err;
112  }
113 
114  try {
115  if(table["calib_algo"].size() == 1) {
116  calib_algo = table["calib_algo"].begin()->GetString();
117  calib_version = table["calib_version"].begin()->GetString();
118  calib_extralabel = table["calib_extralabel"].begin()->GetString();
119  } else {
121  std::string errMsg("The primary key was not found in DB; Check you input.\nFill the object with default values.\nQuery: ");
122  errMsg +=squery.str();
123  err.SetDescription(__FILE__, __LINE__, errMsg);
124  return err;
125  }
126  }
127  catch(const QError& cerr) {
128  if(cerr!=QERR_SUCCESS) {
129  err = cerr;
130  return err;
131  }
132  }
133 
134  fCalibLabel = calib_algo + "_" + calib_extralabel;
135  if(calib_extralabel=="None") fCalibLabel = calib_algo;
136  fCalibVersion = calib_version;
137 
138  return err;
139 }
140 
142 {
144 
145  const QJitter& jitter = Get();
146 
147  std::string bareOwner, extraLabel;
148  GetLabel().GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
149  if (extraLabel=="") extraLabel="None";
150 
151  std::string calib_algo, calib_version, calib_extralabel;
152  calib_version = GetCalibVersion();
153  QGlobalLabel calib_label = GetCalibLabel();
154 
155  if (calib_label.GetStringLabel()!=Q_STRING_DEFAULT) {
156  calib_label.GetBareOwnerAndExtraLabel(calib_algo,calib_extralabel);
157  }
158  if (calib_extralabel=="") calib_extralabel = "None";
159  if(calib_algo.empty() && fCalibLabel.find_first_of("@") == std::string::npos) calib_algo = fCalibLabel;
160 
161  std::stringstream squery;
162 
163  // query insert into xxx_jitter_algo where xxx is the name of the jitter module (now JitterByCoincidence)
164 
165  // first check if the table is already filled
166  squery<<"select calib_algo from "<<bareOwner<<"_jitter_algo"
167  << " where jitter_version = '"<<GetVersion()
168  << "' and jitter_extralabel= '"<<extraLabel<<"'";
169 
170  try {
171  QDianaDb *db = QDianaDb::Get();
172  std::string ca = db->DoQueryString(squery.str());
173  }
174 
175  catch(const QError& cerr) {
176  if(cerr!=QERR_SUCCESS) {
177 
178  squery.str("");
179 
180  squery<<"INSERT into "<<bareOwner<<"_jitter_algo (jitter_version, jitter_extralabel, calib_algo, calib_version, calib_extralabel) values "
181  <<"('"
182  << GetVersion()<<"','"
183  << extraLabel<<"','"
184  << calib_algo<<"','"
185  << calib_version<<"','"
186  << calib_extralabel<<"')";
187 
188  try {
189  QDianaDb *db = QDianaDb::Get();
190  db->DoExec(squery.str());
191  }
192 
193  catch(const QError& cerr) {
194  if(cerr!=QERR_SUCCESS) {
195  err = cerr;
196  return err;
197  }
198  }
199  }
200  }
201 
202  // query insert into jitters
203 
204  QVdt::QVdt_vector fields,values;
205  fields.push_back((std::string)"jitter_algo");
206  fields.push_back((std::string)"jitter_version");
207  fields.push_back((std::string)"jitter_extralabel");
208  fields.push_back((std::string)"channel");
209  fields.push_back((std::string)"data_set");
210  fields.push_back((std::string)"ref_channel");
211  fields.push_back((std::string)"jitter");
212  fields.push_back((std::string)"err_jitter");
213  values.push_back("'"+bareOwner+"'");
214  values.push_back("'"+GetVersion()+"'");
215  values.push_back("'"+extraLabel+"'");
216  values.push_back(GetChannel());
217  values.push_back(GetDataset());
218  values.push_back(jitter.fRefChannel);
219  values.push_back(jitter.fJitter);
220  values.push_back(jitter.fJitterError);
221 
222  try {
223  QDianaDb *db = QDianaDb::Get();
224  db->Insert("jitters",fields,values);
225  }
226  catch(const QError& cerr) {
227  if(cerr!=QERR_SUCCESS) {
228  err = cerr;
229  return err;
230  }
231  }
232 
233  return err;
234 }
err
Definition: CheckOF.C:114
dm Get("DAQ",&rHandle,"DB")
hvec Set(vec)
#define Q_STRING_DEFAULT
Definition: QDiana.hh:38
@ QERR_DB_NULL_RESULT
Definition: QError.hh:104
@ QERR_SUCCESS
Definition: QError.hh:27
QError DoQuery(const std::string &query, QDbTable &table)
Definition: QDb.cc:409
std::map< std::string, column > QDbTable
Definition: QDb.hh:34
int DoQueryInt(const std::string &query)
Definition: QDb.cc:197
double DoQueryDouble(const std::string &query)
Definition: QDb.cc:181
int DoExec(const std::string &Query)
Execute an INSERT, UPDATE, DELETE, FETCH, or MOVE statement.
Definition: QDb.cc:305
std::string DoQueryString(const std::string &query)
Definition: QDb.cc:229
int Insert(const std::string &tableName, const column &fields, const column &values)
Definition: QDb.cc:320
static QDianaDb * Get()
Definition: QDianaDb.cc:21
error class with error type and description
Definition: QError.hh:115
Label for global QObject's.
Definition: QGlobalLabel.hh:19
void GetBareOwnerAndExtraLabel(std::string &bOwner, std::string &el) const
split extra label and bare module name
std::string GetStringLabel() const
convert label to string
QError StoreOnDB() const
QError FillFromDB()
Definition: QJitterHandle.cc:7
jitter by coincidence
Definition: QJitter.hh:17
void Clear()
Definition: QJitter.hh:21
int fRefChannel
Definition: QJitter.hh:28
double fJitterError
Definition: QJitter.hh:30
double fJitter
Definition: QJitter.hh:29
std::vector< QVdt > QVdt_vector
Definition: QVdt.hh:38
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...