Diana Software
QEnergyRangesHandle.cc
Go to the documentation of this file.
1 #include "QEnergyRangesHandle.hh"
2 #include "QDianaDb.hh"
3 
4 using namespace Diana;
5 
7 {
9 
10  QInterval er;
11  er.Clear();
12 
13  std::string bareOwner, extraLabel;
14  QGlobalLabel calibLabel = GetCalibLabel();
15  calibLabel.GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
16  if (extraLabel=="") extraLabel="None";
17 
18  QDianaDb *db = QDianaDb::Get();
19 
20  // query peak energy
21  std::stringstream squery;
22 
23  // query peak range min
24  squery<<"select energy_range_min from data_sets_analyses where calib_algo = '"<<bareOwner
25  <<"' and calib_version= '"<<GetCalibVersion()
26  <<"' and calib_extralabel= '"<<extraLabel
27  <<"' and channel= "<< GetChannel()
28  <<" and data_set= "<<GetDataset();
29 
30  try {
31  er.SetMin ( db->DoQueryDouble(squery.str()));
32  }
33 
34  catch(const QError& cerr) {
35  if(cerr!=QERR_SUCCESS) {
36  err = cerr;
37  return err;
38  }
39  }
40 
41  squery.str("");
42 
43  // query peak range max
44  squery<<"select energy_range_max from data_sets_analyses where calib_algo = '"<<bareOwner
45  <<"' and calib_version= '"<<GetCalibVersion()
46  <<"' and calib_extralabel= '"<<extraLabel
47  <<"' and channel= "<< GetChannel()
48  <<" and data_set= "<<GetDataset();
49 
50  try {
51  er.SetMax ( db->DoQueryDouble(squery.str()));
52  }
53 
54  catch(const QError& cerr) {
55  if(cerr!=QERR_SUCCESS) {
56  err = cerr;
57  return err;
58  }
59  }
60 
61  Set(er);
62 
63  return err;
64 }
65 
66 
68 {
70  const QInterval& epar = Get();
71 
72 
73  std::string calib_algo, calib_version, calib_extralabel;
74  calib_version = GetCalibVersion();
75  QGlobalLabel calibLabel = GetCalibLabel();
76  calibLabel.GetBareOwnerAndExtraLabel(calib_algo,calib_extralabel);
77  if (calib_extralabel=="") calib_extralabel="None";
78 
79  std::stringstream squery;
80 
81  // first check if the table is already filled
82  squery<<"SELECT energy_range_min from data_sets_analyses "
83  << " where channel = "<< GetChannel()
84  << " and data_set = "<< GetDataset()
85  << " and calib_algo = '"<< calib_algo
86  << "' and calib_version = '"<< calib_version
87  << "' and calib_extralabel= '"<< calib_extralabel<<"'";
88  try {
89  QDianaDb *db = QDianaDb::Get();
90  db->DoQueryDouble(squery.str());
91  }
92 
93 
94  catch(const QError& cerr) {
95  err = cerr;
96  if(err == QERR_TYPE_CONVERSION) {
97  // campo vuoto, faccio update;
98  squery.str("");
99  squery<<"UPDATE data_sets_analyses set "
100  <<" energy_range_min = "<<epar.GetMin()
101  <<", energy_range_max = "<<epar.GetMax()
102  <<" where data_set="
103  << GetDataset()<<" and channel="
104  << GetChannel()<<" and calib_algo='"
105  << calib_algo<<"' and calib_version='"
106  << calib_version<<"' and calib_extralabel ='"
107  << calib_extralabel<<"'";
108 
109  try {
110  QDianaDb *db = QDianaDb::Get();
111  db->DoExec(squery.str());
112  err =QERR_SUCCESS;
113  return err;
114  }
115 
116  catch(const QError& cerror) {
117  if(cerror!=QERR_SUCCESS) {
118  err = cerror;
119  return err;
120  }
121  }
122  } else if(err != QERR_DB_NULL_RESULT) {
123  return err;
124 
125  }
126  }
127 
128  if(err == QERR_DB_NULL_RESULT || err == QERR_SUCCESS) {
129  // riga inesistente o uguale
130  squery.str("");
131 
132  QVdt::QVdt_vector fields,values;
133  fields.push_back((std::string)"data_set"); values.push_back(GetDataset());
134  fields.push_back((std::string)"calib_algo"); values.push_back("'"+calib_algo+"'");
135  fields.push_back((std::string)"calib_version"); values.push_back("'"+calib_version+"'");
136  fields.push_back((std::string)"calib_extralabel"); values.push_back("'"+calib_extralabel+"'");
137  fields.push_back((std::string)"channel"); values.push_back(GetChannel());
138  fields.push_back((std::string)"energy_range_min"); values.push_back(epar.GetMin());
139  fields.push_back((std::string)"energy_range_max"); values.push_back(epar.GetMax());
140 
141  try {
142  QDianaDb *db = QDianaDb::Get();
143  db->Insert("data_sets_analyses",fields,values);
144  }
145 
146  catch(const QError& cerror) {
147  if(cerror!=QERR_SUCCESS) {
148  err = cerror;
149  return err;
150  }
151  }
152  err = QERR_SUCCESS;
153  }
154 
155  return err;
156 }
err
Definition: CheckOF.C:114
dm Get("DAQ",&rHandle,"DB")
hvec Set(vec)
@ QERR_TYPE_CONVERSION
Definition: QError.hh:36
@ QERR_DB_NULL_RESULT
Definition: QError.hh:104
@ QERR_SUCCESS
Definition: QError.hh:27
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
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
Interval of real numbers.
Definition: QInterval.hh:17
void Clear()
Clear.
Definition: QInterval.hh:29
void SetMin(const double min)
Set minimum of the interval.
Definition: QInterval.hh:71
void SetMax(const double max)
Set maximum of the interval.
Definition: QInterval.hh:68
double GetMax() const
Get maximum of interval.
Definition: QInterval.hh:54
double GetMin() const
Get minimum of interval.
Definition: QInterval.hh:57
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...