15 std::string bareOwner, extraLabel;
16 GetLabel().GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
17 if (extraLabel==
"") extraLabel=
"None";
19 std::string name, formula;
20 int npar =0,npeaks = 0;
21 std::vector<double> params, err_params, peak_energies, residuals, err_residuals;
23 std::vector<int> sruns;
28 std::stringstream squery;
32 squery<<
"select calib_function_name from "<<bareOwner<<
"_calib_algo"
33 <<
" where calib_version = '"<<GetVersion()
34 <<
"' and calib_extralabel= '"<<extraLabel <<
"'";
40 catch(
const QError& cerr) {
51 squery<<
"select calib_function_formula from "<<bareOwner<<
"_calib_algo"
52 <<
" where calib_version = '"<<GetVersion()
53 <<
"' and calib_extralabel= '"<<extraLabel <<
"'";
59 catch(
const QError& cerr) {
69 squery<<
"select calib_source from "<<bareOwner<<
"_calib_algo"
70 <<
" where calib_version = '"<<GetVersion()
71 <<
"' and calib_extralabel= '"<<extraLabel <<
"'";
77 catch(
const QError& cerr) {
87 squery<<
"select calib_function_par_number from "<<bareOwner<<
"_calib_algo"
88 <<
" where calib_version = '"<<GetVersion()
89 <<
"' and calib_extralabel= '"<<extraLabel <<
"'";
95 catch(
const QError& cerr) {
105 squery<<
"select params from calibrations where calib_algo = '"<<bareOwner
106 <<
"' and calib_version = '"<<GetVersion()
107 <<
"' and calib_extralabel= '"<<extraLabel
108 <<
"' and channel = "<<GetChannel()
109 <<
" and data_set = "<<GetDataset();
115 catch(
const QError& cerr) {
125 squery<<
"select err_params from calibrations where calib_algo = '"<<bareOwner
126 <<
"' and calib_version = '"<<GetVersion()
127 <<
"' and calib_extralabel= '"<<extraLabel
128 <<
"' and channel = "<<GetChannel()
129 <<
" and data_set = "<<GetDataset();
135 catch(
const QError& cerr) {
145 squery<<
"select npeaks from calibrations where calib_algo = '"<<bareOwner
146 <<
"' and calib_version = '"<<GetVersion()
147 <<
"' and calib_extralabel= '"<<extraLabel
148 <<
"' and channel = "<<GetChannel()
149 <<
" and data_set = "<<GetDataset();
155 catch(
const QError& cerr) {
165 squery<<
"select peak_energies from calibrations where calib_algo = '"<<bareOwner
166 <<
"' and calib_version = '"<<GetVersion()
167 <<
"' and calib_extralabel= '"<<extraLabel
168 <<
"' and channel = "<<GetChannel()
169 <<
" and data_set = "<<GetDataset();
175 catch(
const QError& cerr) {
185 squery<<
"select residuals from calibrations where calib_algo = '"<<bareOwner
186 <<
"' and calib_version = '"<<GetVersion()
187 <<
"' and calib_extralabel= '"<<extraLabel
188 <<
"' and channel = "<<GetChannel()
189 <<
" and data_set = "<<GetDataset();
195 catch(
const QError& cerr) {
205 squery<<
"select err_residuals from calibrations where calib_algo = '"<<bareOwner
206 <<
"' and calib_version = '"<<GetVersion()
207 <<
"' and calib_extralabel= '"<<extraLabel
208 <<
"' and channel = "<<GetChannel()
209 <<
" and data_set = "<<GetDataset();
215 catch(
const QError& cerr) {
225 squery<<
"select chi_square from calibrations where calib_algo = '"<<bareOwner
226 <<
"' and calib_version = '"<<GetVersion()
227 <<
"' and calib_extralabel= '"<<extraLabel
228 <<
"' and channel = "<<GetChannel()
229 <<
" and data_set = "<<GetDataset();
235 catch(
const QError& cerr) {
245 squery<<
"select ndf from calibrations where calib_algo = '"<<bareOwner
246 <<
"' and calib_version = '"<<GetVersion()
247 <<
"' and calib_extralabel= '"<<extraLabel
248 <<
"' and channel = "<<GetChannel()
249 <<
" and data_set = "<<GetDataset();
255 catch(
const QError& cerr) {
265 squery<<
"select source_runs from calibrations where calib_algo = '"<<bareOwner
266 <<
"' and calib_version= '"<<GetVersion()
267 <<
"' and calib_extralabel= '"<<extraLabel
268 <<
"' and channel= "<< GetChannel()
269 <<
" and data_set = "<<GetDataset();
275 catch(
const QError& cerr) {
284 TF1 func(name.c_str(),formula.c_str());
287 for(Int_t i=0; i<npar; i++) {
288 calpar.
fFunction.SetParameter(i,params[i]);
289 calpar.
fFunction.SetParError(i,err_params[i]);
292 calpar.
fFunction.SetChisquare(chi_square);
296 for(Int_t i=0; i<npeaks; i++) {
297 calpar.
fResiduals[i].PeakEnergy = peak_energies[i];
299 calpar.
fResiduals[i].ErrorResidual = err_residuals[i];
302 for(
size_t i=0; i<sruns.size(); i++)
311 std::string stab_algo, stab_version, stab_extralabel;
317 squery<<
"select stab_algo, stab_version, stab_extralabel from calibrations where calib_algo = '"<<bareOwner
318 <<
"' and calib_version= '"<<GetVersion()
319 <<
"' and calib_extralabel= '"<<extraLabel
320 <<
"' and channel= "<< GetChannel()
321 <<
" and data_set= "<<GetDataset();
324 table = db->
DoQuery(squery.str());
327 catch(
const QError& cerr) {
333 if(table[
"stab_algo"].size() == 1) {
334 stab_algo = table[
"stab_algo"].begin()->GetString();
335 stab_version = table[
"stab_version"].begin()->GetString();
336 stab_extralabel = table[
"stab_extralabel"].begin()->GetString();
339 std::string errMsg(
"The primary key was not found in DB; Check you input.\nFill the object with default values.\nQuery: ");
340 errMsg +=squery.str();
341 err.SetDescription(__FILE__, __LINE__, errMsg);
345 catch(
const QError& cerr) {
352 fStabLabel = stab_algo +
"_" + stab_extralabel;
353 if(stab_extralabel==
"None") fStabLabel = stab_algo;
354 fStabVersion = stab_version;
365 std::string bareOwner, extraLabel;
366 GetLabel().GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
367 if (extraLabel==
"") extraLabel=
"None";
369 std::string stab_algo, stab_extralabel;
375 if (stab_extralabel==
"") stab_extralabel =
"None";
376 if(stab_algo.empty() && fStabLabel.find_first_of(
"@") == std::string::npos) stab_algo = fStabLabel;
380 const std::string &name = cp.
fFunction.GetName();
381 const std::string &formula = cp.
fFunction.GetTitle();
382 const std::string &source = cp.
fSource;
387 std::stringstream list_par;
390 std::stringstream list_par_err;
393 for(Int_t i=0; i<npar; i++) {
395 list_par<<cp.
fFunction.GetParameter(i)<<
"}'";
396 list_par_err<<cp.
fFunction.GetParError(i)<<
"}'";
398 list_par<<cp.
fFunction.GetParameter(i)<<
",";
399 list_par_err<<cp.
fFunction.GetParError(i)<<
",";
404 list_par.str(
"NULL");
405 list_par_err.str(
"NULL");
414 std::stringstream list_en;
417 std::stringstream list_res;
420 std::stringstream list_res_err;
423 for(Int_t i=0; i<npeaks; i++) {
427 list_res_err<< cp.
fResiduals[i].ErrorResidual<<
"}'";
431 list_res_err<< cp.
fResiduals[i].ErrorResidual<<
",";
436 list_res.str(
"NULL");
437 list_res_err.str(
"NULL");
440 std::stringstream squery;
445 squery<<
"select calib_function_name from "<<bareOwner<<
"_calib_algo"
446 <<
" where calib_version = '"<<GetVersion()
447 <<
"' and calib_extralabel= '"<<extraLabel<<
"'";
454 catch(
const QError& cerr) {
459 squery<<
"INSERT into "<<bareOwner<<
"_calib_algo (calib_version, calib_extralabel, calib_source, calib_function_name, calib_function_formula, calib_function_par_number) values "
461 << GetVersion()<<
"','"
473 catch(
const QError& cerr) {
485 std::stringstream list_run;
500 fields.push_back((std::string)
"calib_algo");
501 fields.push_back((std::string)
"calib_version");
502 fields.push_back((std::string)
"calib_extralabel");
503 fields.push_back((std::string)
"channel");
504 fields.push_back((std::string)
"data_set");
505 fields.push_back((std::string)
"stab_algo");
506 fields.push_back((std::string)
"stab_version");
507 fields.push_back((std::string)
"stab_extralabel");
508 fields.push_back((std::string)
"params");
509 fields.push_back((std::string)
"err_params");
510 fields.push_back((std::string)
"npeaks");
511 fields.push_back((std::string)
"peak_energies");
512 fields.push_back((std::string)
"residuals");
513 fields.push_back((std::string)
"err_residuals");
514 fields.push_back((std::string)
"chi_square");
515 fields.push_back((std::string)
"ndf");
516 fields.push_back((std::string)
"source_runs");
517 values.push_back(
"'"+bareOwner+
"'");
518 values.push_back(
"'"+GetVersion()+
"'");
519 values.push_back(
"'"+extraLabel+
"'");
520 values.push_back(GetChannel());
521 values.push_back(GetDataset());
522 values.push_back(
"'"+stab_algo+
"'");
523 values.push_back(
"'"+fStabVersion+
"'");
524 values.push_back(
"'"+stab_extralabel+
"'");
525 values.push_back(list_par.str());
526 values.push_back(list_par_err.str());
527 values.push_back(npeaks);
528 values.push_back(list_en.str());
529 values.push_back(list_res.str());
530 values.push_back(list_res_err.str());
531 values.push_back(cp.
fFunction.GetChisquare());
533 values.push_back(list_run.str());
537 db->
Insert(
"calibrations",fields,values);
539 catch(
const QError& cerr) {
dm Get("DAQ",&rHandle,"DB")
object containing calibration data (function, coefficients, source and residuals) and run numbers of ...
std::vector< int > fSourceRuns
std::vector< QCalibrationResiduals > fResiduals
std::vector< double > DoQueryVectorDouble(const std::string &query)
std::vector< int > DoQueryVectorInt(const std::string &query)
QError DoQuery(const std::string &query, QDbTable &table)
std::map< std::string, column > QDbTable
int DoQueryInt(const std::string &query)
double DoQueryDouble(const std::string &query)
int DoExec(const std::string &Query)
Execute an INSERT, UPDATE, DELETE, FETCH, or MOVE statement.
std::string DoQueryString(const std::string &query)
int Insert(const std::string &tableName, const column &fields, const column &values)
error class with error type and description
Label for global QObject's.
void GetBareOwnerAndExtraLabel(std::string &bOwner, std::string &el) const
split extra label and bare module name
std::string GetStringLabel() const
convert label to string
std::vector< QVdt > QVdt_vector
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...