Diana Software
QCOFParametersHandle.cc
Go to the documentation of this file.
1 #include "QGlobalDataManager.hh"
3 #include "QObject.hh"
4 #include "QMessage.hh"
5 #include "QDianaDb.hh"
6 
7 using namespace Diana;
8 
10 {
11  QError err = QERR_NOT_IMPLEMENTED; // (yet)
12  err.SetDescription("FillFromDB() not implemented for QCOFParametersHandle");
13  return err;
14 }
15 
17 {
19 
20  std::string bareOwner, extraLabel;
21  GetLabel().GetBareOwnerAndExtraLabel(bareOwner,extraLabel);
22  if (extraLabel=="") extraLabel="None";
23 
24  std::string ap_algo, ap_extralabel;
25  QGlobalLabel ap_label = fAPLabel;
26  if (ap_label.GetStringLabel()!=Q_STRING_DEFAULT) {
27  ap_label.GetBareOwnerAndExtraLabel(ap_algo,ap_extralabel);
28  }
29  if(ap_extralabel=="") ap_extralabel = "None";
30 
31  std::string nps_algo, nps_extralabel;
32  QGlobalLabel nps_label = fNPSLabel;
33  if (nps_label.GetStringLabel()!=Q_STRING_DEFAULT) {
34  nps_label.GetBareOwnerAndExtraLabel(nps_algo,nps_extralabel);
35  }
36  if(nps_extralabel=="") nps_extralabel = "None";
37 
38  // first FILL cof_amp_algo
39 
40  std::stringstream squery;
41  QDb::QDbTable av,vv;
42 
43  // first check if the table is already filled
44  squery<<"select amp_version from " <<bareOwner<<"_amp_algo where amp_version='" << GetVersion() <<"' and amp_extralabel='"<< extraLabel<< "'";
45 
46  try {
47  QDianaDb *db = QDianaDb::Get();
48  av = db->DoQuery(squery.str());
49  }
50  catch(const QError& cerr) {
51  err = cerr;
52  return err;
53  }
54 
55  if(av.empty()) {
56 
57  squery.str("");
58 
59  squery<<"INSERT into "<<bareOwner<<"_amp_algo (amp_version, amp_extralabel) values " << "('" << GetVersion() << "','" << extraLabel << "')";
60 
61  try {
62  QDianaDb *db = QDianaDb::Get();
63  db->DoExec(squery.str());
64  }
65 
66  catch(const QError& cerr) {
67  if(cerr!=QERR_SUCCESS) {
68  err = cerr;
69  return err;
70  }
71  }
72  }
73 
74  // FILL cof_amp_params
75 
76  squery.str("");
77 
78  // first check if the table is already filled
79  squery<<"select amp_version from " <<bareOwner<<"_amp_params where amp_version='" << GetVersion() <<"' and amp_extralabel='"<< extraLabel << "' and channel=" << GetChannel() << " and ap_algo='" << ap_algo << "' and ap_extralabel='" << ap_extralabel << "' and ap_validity_kind ='"<< fAPValidityKind << "' and nps_algo='" << nps_algo << "' and nps_extralabel='" << nps_extralabel << "' and nps_validity_kind ='"<< fNPSValidityKind << "'";
80 
81  try {
82  QDianaDb *db = QDianaDb::Get();
83  vv = db->DoQuery(squery.str());
84  }
85  catch(const QError& cerr) {
86  err = cerr;
87  return err;
88  }
89 
90  if(vv.empty()) {
91 
92  QVdt::QVdt_vector fields,values;
93  fields.push_back((std::string)"amp_version"); values.push_back("'"+GetVersion()+"'");
94  fields.push_back((std::string)"amp_extralabel"); values.push_back("'"+extraLabel+"'");
95  fields.push_back((std::string)"channel"); values.push_back(GetChannel());
96  fields.push_back((std::string)"ap_algo"); values.push_back("'"+ap_algo+"'");
97  fields.push_back((std::string)"ap_version"); values.push_back("'"+fAPVersion+"'");
98  fields.push_back((std::string)"ap_extralabel"); values.push_back("'"+ap_extralabel+"'");
99  fields.push_back((std::string)"ap_validity_kind"); values.push_back("'"+fAPValidityKind+"'");
100  fields.push_back((std::string)"nps_algo"); values.push_back("'"+nps_algo+"'");
101  fields.push_back((std::string)"nps_version"); values.push_back("'"+fNPSVersion+"'");
102  fields.push_back((std::string)"nps_extralabel"); values.push_back("'"+nps_extralabel+"'");
103  fields.push_back((std::string)"nps_validity_kind"); values.push_back("'"+fNPSValidityKind+"'");
104 
105  try {
106  QDianaDb *db = QDianaDb::Get();
107  db->Insert(bareOwner+"_amp_params",fields,values);
108  }
109 
110  catch(const QError& cerr) {
111  if(cerr!=QERR_SUCCESS) {
112  err = cerr;
113  return err;
114  }
115  }
116  }
117 
118  return err;
119 }
120 
err
Definition: CheckOF.C:114
#define Q_STRING_DEFAULT
Definition: QDiana.hh:38
@ QERR_NOT_IMPLEMENTED
Definition: QError.hh:109
@ 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 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
std::string GetStringLabel() const
convert label to string
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...