ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MuonCalib::CalibRtDbOperations Class Reference

#include <CalibRtDbOperations.h>

Collaboration diagram for MuonCalib::CalibRtDbOperations:

Public Member Functions

 CalibRtDbOperations (CalibDbConnection &db_conn)
 
virtual ~CalibRtDbOperations ()=default
 
bool LoadRt (const NtupleStationId &id, int head_id, bool validated, const std::string &, std::vector< SamplePoint > &points, RtFullInfo *full_info)
 
bool WriteUpdateRt (const NtupleStationId &id, int head_id, const std::string &, const std::vector< SamplePoint > &points, int validflag, const RtFullInfo *full_info)
 
bool SetValidflag (int validflag, bool commit=true)
 
bool ReadForConditions (const std::string &, int head_id, IConditionsStorage &storage)
 

Private Member Functions

bool getRtId (bool validated, RtFullInfo *full_info)
 
bool readRTS (std::vector< SamplePoint > &points)
 
bool updateFullInfo (const RtFullInfo *full_info, const int &validflag, const int &n_points)
 
bool updateRTSable (const std::vector< SamplePoint > &points)
 
bool insertFullInfo (const RtFullInfo *full_info, const int &validflag, const int &n_points)
 
bool insertRTSable (const std::vector< SamplePoint > &points)
 
void fullInfoInitData (const RtFullInfo *full_info, const int &validflag, coral::AttributeList &updateData, const int &n_bins, const bool &for_insert)
 
void rtTableInitData (coral::AttributeList &rowBuffer)
 
bool getRTMapTId ()
 
bool checkRtPresent (const int &head_id, const std::string &, const NtupleStationId &id, const int &validflag)
 

Private Attributes

CalibDbConnectionm_db_conn
 
coral::IQuery * m_query
 
int m_rt_id
 
int m_rt_map_t_id
 
int m_head_id
 
int m_region_id
 
std::string m_prev_algs
 
int m_n_points
 

Detailed Description

Definition at line 25 of file CalibRtDbOperations.h.

Constructor & Destructor Documentation

◆ CalibRtDbOperations()

MuonCalib::CalibRtDbOperations::CalibRtDbOperations ( CalibDbConnection db_conn)

Definition at line 37 of file CalibRtDbOperations.cxx.

37  :
38  m_db_conn(db_conn), m_rt_id(-1), m_rt_map_t_id(-1), m_head_id(-1), m_region_id(-1), m_n_points(0) {
39  m_query = nullptr;
40  }

◆ ~CalibRtDbOperations()

virtual MuonCalib::CalibRtDbOperations::~CalibRtDbOperations ( )
virtualdefault

Member Function Documentation

◆ checkRtPresent()

bool MuonCalib::CalibRtDbOperations::checkRtPresent ( const int &  head_id,
const std::string &  ,
const NtupleStationId id,
const int &  validflag 
)
inlineprivate

Definition at line 505 of file CalibRtDbOperations.cxx.

506  {
508  // select count(MDT_RT.MDT_RT_ID) as N_TUBES, MDT_RT.VALIDFLAG as VALIDFLAG from MDT_RT where MDT_RT.HEAD_ID = :hid and
509  // MDT_RT.REGION_ID = :chamb and SITE_NAME=:sn group by MDT_RT.VALIDFLAG;
510  m_query->addToTableList("MDT_RT");
511  coral::AttributeList conditionData;
512  conditionData.extend<int>("hid");
513  conditionData[0].data<int>() = head_id;
514  // as long as the chamber id is stored as a string, it is more efficient to pass the chamber id as a string in the query
515  std::ostringstream ostr;
516  ostr << id.FixedId();
517  conditionData.extend<std::string>("chamb");
518  conditionData[1].data<std::string>() = ostr.str();
519  std::string condition = "MDT_RT.HEAD_ID = :hid and MDT_RT.REGION_ID = :chamb";
520  m_query->setCondition(condition, conditionData);
521  m_query->addToOutputList("count(MDT_RT.CALIBFLAG)", "N_RTS");
522  m_query->addToOutputList("MDT_RT.VALIDFLAG", "VALIDFLAG");
523  m_query->groupBy("MDT_RT.VALIDFLAG");
524  coral::ICursor& cursor = m_query->execute();
525  bool has_unvalidated(false), has_validated(false);
526  while (cursor.next()) {
527  const coral::AttributeList& al = cursor.currentRow();
528  if (al["VALIDFLAG"].data<short>() > 0) {
529  if (al["N_RTS"].data<double>() > 0) { has_validated = true; }
530  } else {
531  if (al["N_RTS"].data<double>() > 0) { has_unvalidated = true; }
532  }
533  }
534  if (validflag == 0 && has_unvalidated) return false;
535  if (validflag > 0 && has_validated) return false;
536  return true;
537  }

◆ fullInfoInitData()

void MuonCalib::CalibRtDbOperations::fullInfoInitData ( const RtFullInfo full_info,
const int &  validflag,
coral::AttributeList &  updateData,
const int &  n_bins,
const bool &  for_insert 
)
inlineprivate

Definition at line 411 of file CalibRtDbOperations.cxx.

412  {
413  if (for_insert) {
414  updateData.extend<int>("REGION_ID");
415  updateData["REGION_ID"].data<int>() = m_region_id;
416  updateData.extend<int>("HEAD_ID");
417  updateData["HEAD_ID"].data<int>() = m_head_id;
418  updateData.extend<int>("LOWRUN");
419  updateData["LOWRUN"].data<int>() = 0;
420  updateData.extend<int>("UPRUN");
421  updateData["UPRUN"].data<int>() = 1;
422  updateData.extend<std::string>("HISTOGRAM");
423  updateData["HISTOGRAM"].data<std::string>() = "DUMMY";
424  }
425  if (m_prev_algs != "") { m_prev_algs += ":"; }
426  if (full_info->implementation() == "RtCalibrationIntegration") {
427  m_prev_algs += "Int";
428  } else if (full_info->implementation() == "RtCalibrationCruved") {
429  m_prev_algs += "Cur";
430  } else if (full_info->implementation() == "RtCalibrationAnalytic") {
431  m_prev_algs += "Ana";
432  } else if (full_info->implementation() == "RtCalibrationAnalyticExt") {
433  m_prev_algs += "AnaExt";
434  } else if (full_info->implementation() == "Validation") {
435  m_prev_algs += "Val";
436  } else {
437  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
438  log << MSG::WARNING << "Unknown implementation '" << full_info->implementation() << "'!" << endmsg;
439  m_prev_algs += "UU";
440  }
441  if (m_prev_algs.size() > 25) {
442  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
443  log << MSG::WARNING << "m_prev_algs exceeds size: " << m_prev_algs << endmsg;
444  m_prev_algs = "..";
445  }
446  updateData.extend<std::string>("ALGO_FLAG");
447  updateData["ALGO_FLAG"].data<std::string>() = m_prev_algs;
448  updateData.extend<int>("N_SEGS");
449  updateData["N_SEGS"].data<int>() = full_info->numSeg();
450  updateData.extend<float>("AVER_ANGLE");
451  updateData["AVER_ANGLE"].data<float>() = full_info->meanAng();
452  if (std::abs(full_info->meanAng()) > 9.9999) {
453  updateData["AVER_ANGLE"].data<float>() = ((full_info->meanAng() < 0) ? -1 : 1) * 9.9999;
454  }
455  updateData.extend<float>("DELTA_AVER_ANGLE");
456  updateData["DELTA_AVER_ANGLE"].data<float>() = full_info->rmsAng();
457  if (std::abs(full_info->rmsAng()) > 9.9999) {
458  updateData["DELTA_AVER_ANGLE"].data<float>() = ((full_info->rmsAng() < 0) ? -1 : 1) * 9.9999;
459  }
460  updateData.extend<float>("AVER_SPREAD");
461  updateData["AVER_SPREAD"].data<float>() = full_info->meanPos();
462  if (std::abs(full_info->meanPos()) > 9.9999) {
463  updateData["AVER_SPREAD"].data<float>() = ((full_info->meanPos() < 0) ? -1 : 1) * 9.9999;
464  }
465  updateData.extend<float>("DELTA_AVER_SPREAD");
466  updateData["DELTA_AVER_SPREAD"].data<float>() = full_info->rmsPos();
467  if (std::abs(full_info->rmsPos()) > 9.9999) {
468  updateData["DELTA_AVER_SPREAD"].data<float>() = ((full_info->rmsPos() < 0) ? -1 : 1) * 9.9999;
469  }
470  updateData.extend<float>("CONVERGENCE");
471  updateData["CONVERGENCE"].data<float>() = full_info->convEst();
472  if (std::abs(full_info->convEst()) > 999.999) {
473  updateData["CONVERGENCE"].data<float>() = ((full_info->convEst() < 0) ? -1 : 1) * 999.999;
474  }
475  if (for_insert) {
476  updateData.extend<float>("B_AVER");
477  updateData["B_AVER"].data<float>() = 0.;
478  updateData.extend<float>("T_AVER");
479  updateData["T_AVER"].data<float>() = 0.;
480  updateData.extend<float>("HV");
481  updateData["HV"].data<float>() = 0.;
482  updateData.extend<float>("CURR");
483  updateData["CURR"].data<float>() = 0.;
484  updateData.extend<float>("GAS");
485  updateData["GAS"].data<float>() = 0.;
486  updateData.extend<int>("CALIBFLAG");
487  updateData["CALIBFLAG"].data<int>() = static_cast<int>(validflag > 3);
488  }
489  updateData.extend<int>("VALIDFLAG");
490  updateData["VALIDFLAG"].data<int>() = validflag;
491  updateData.extend<short>("BINS");
492  updateData["BINS"].data<short>() = n_bins;
493  }

◆ getRtId()

bool MuonCalib::CalibRtDbOperations::getRtId ( bool  validated,
RtFullInfo full_info 
)
private

Definition at line 212 of file CalibRtDbOperations.cxx.

212  {
213  // select MDT_RT, ... from MDT_RT where head_id=:hid and site_name=:sn and region_id=:rid and [and validflag>0| and validflag=0]
215  m_query->addToTableList("MDT_RT");
216  coral::AttributeList conditionData;
217  conditionData.extend<int>("hid");
218  conditionData[0].data<int>() = m_head_id;
219  conditionData.extend<int>("rid");
220  conditionData[1].data<int>() = m_region_id;
221  m_prev_algs = "";
222  std::string condition = "HEAD_ID=:hid and REGION_ID=:rid";
223  if (validated) {
224  condition += " and VALIDFLAG>1";
225  } else {
226  condition += " and VALIDFLAG=0";
227  }
228  m_query->setCondition(condition, conditionData);
229  m_query->addToOutputList("CALIBFLAG");
230  m_query->addToOutputList("BINS");
231  m_query->addToOutputList("ALGO_FLAG");
232  if (full_info != nullptr) {
233  m_query->addToOutputList("N_SEGS");
234  m_query->addToOutputList("AVER_ANGLE");
235  m_query->addToOutputList("DELTA_AVER_ANGLE");
236  m_query->addToOutputList("AVER_SPREAD");
237  m_query->addToOutputList("DELTA_AVER_SPREAD");
238  m_query->addToOutputList("CONVERGENCE");
239  m_query->addToOutputList("B_AVER");
240  m_query->addToOutputList("T_AVER");
241  }
242  coral::ICursor& cursor = m_query->execute();
243  int n_rows = 0;
244  m_rt_id = -9999;
245  while (cursor.next()) {
246  n_rows++;
247  const coral::AttributeList& al = cursor.currentRow();
248  m_rt_id = al["CALIBFLAG"].data<short>();
249  m_n_points = static_cast<int>(al["BINS"].data<short>());
250  m_prev_algs = al["ALGO_FLAG"].data<std::string>();
251  if (full_info != nullptr) {
252  full_info->setNumSeg(static_cast<int>(al["N_SEGS"].data<int>()));
253  full_info->setMeanAng(al["AVER_ANGLE"].data<float>());
254  full_info->setRmsAng(al["DELTA_AVER_ANGLE"].data<float>());
255  full_info->setMeanPos(al["AVER_SPREAD"].data<float>());
256  full_info->setRmsPos(al["DELTA_AVER_SPREAD"].data<float>());
257  full_info->setConvEst(al["CONVERGENCE"].data<float>());
258  full_info->setImplementation(m_prev_algs);
259  }
260  }
261  if (n_rows > 1) {
262  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
263  log << MSG::WARNING << "Found " << n_rows << " in MDT_RT instead of 0 or 1" << endmsg;
264  return false;
265  }
267  return true;
268  }

◆ getRTMapTId()

bool MuonCalib::CalibRtDbOperations::getRTMapTId ( )
inlineprivate

◆ insertFullInfo()

bool MuonCalib::CalibRtDbOperations::insertFullInfo ( const RtFullInfo full_info,
const int &  validflag,
const int &  n_points 
)
inlineprivate

Definition at line 382 of file CalibRtDbOperations.cxx.

382  {
383  coral::ITableDataEditor& editor = m_db_conn.GetTableEditor("MDT_RT");
384  coral::AttributeList rowBuffer;
385  fullInfoInitData(full_info, validflag, rowBuffer, n_points, true);
386  editor.insertRow(rowBuffer);
387  return getRtId((validflag > 1), nullptr);
388  }

◆ insertRTSable()

bool MuonCalib::CalibRtDbOperations::insertRTSable ( const std::vector< SamplePoint > &  points)
inlineprivate

Definition at line 390 of file CalibRtDbOperations.cxx.

390  {
391  coral::ITableDataEditor& editor = m_db_conn.GetTableEditor("MDT_RT_MAP");
392  coral::AttributeList table_data;
393  rtTableInitData(table_data);
394  table_data["CALIBFLAG"].data<int>() = m_rt_id;
395  table_data["HEAD_ID"].data<int>() = m_head_id;
396  table_data["REGION_ID"].data<int>() = m_region_id;
397  coral::IBulkOperation* bulk_inserter = editor.bulkInsert(table_data, 100);
398  // use trigger to fill in MDT_RT_ID
399  for (int i = 0; i < static_cast<int>(points.size()); i++) {
400  table_data["POINT_NR"].data<int>() = i;
401  table_data["T"].data<float>() = points[i].x1();
402  table_data["R"].data<float>() = points[i].x2();
403  table_data["S"].data<float>() = points[i].error();
404  bulk_inserter->processNextIteration();
405  }
406  bulk_inserter->flush();
407  delete bulk_inserter;
408  return true;
409  }

◆ LoadRt()

bool MuonCalib::CalibRtDbOperations::LoadRt ( const NtupleStationId id,
int  head_id,
bool  validated,
const std::string &  ,
std::vector< SamplePoint > &  points,
RtFullInfo full_info 
)

Definition at line 42 of file CalibRtDbOperations.cxx.

43  {
45  m_region_id = id.FixedId();
46  try {
47  points.clear();
49  m_rt_id = -1;
50  if (!getRtId(validated, full_info)) {
51  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
52  log << MSG::WARNING << "Header query failed!" << endmsg;
54  return false;
55  }
56  if (m_rt_id < 0) {
58  return false;
59  }
60  if (!readRTS(points)) {
62  return false;
63  }
64  return true;
65  } catch (coral::SchemaException& e) {
66  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
67  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
68  return false;
69  }
70  }

◆ ReadForConditions()

bool MuonCalib::CalibRtDbOperations::ReadForConditions ( const std::string &  ,
int  head_id,
IConditionsStorage storage 
)

Definition at line 157 of file CalibRtDbOperations.cxx.

157  {
158  try {
161  m_query->addToTableList("MDT_RT");
162  m_query->addToTableList("MDT_RT_MAP");
163  coral::AttributeList conditionData;
164  conditionData.extend<int>("hid");
165  conditionData[0].data<int>() = head_id;
166  std::string condition =
167  "MDT_RT.HEAD_ID=:hid and MDT_RT_MAP.HEAD_ID=:hid and MDT_RT.REGION_ID = MDT_RT_MAP.REGION_ID and MDT_RT.CALIBFLAG = "
168  "MDT_RT_MAP.CALIBFLAG and MDT_RT.VALIDFLAG>1";
169  m_query->setCondition(condition, conditionData);
170  m_query->addToOrderList("MDT_RT.REGION_ID");
171  m_query->addToOutputList("MDT_RT.REGION_ID", "REGION_ID");
172  m_query->addToOutputList("MDT_RT_MAP.POINT_NR", "POINT_NR");
173  m_query->addToOutputList("MDT_RT_MAP.T", "T");
174  m_query->addToOutputList("MDT_RT_MAP.R", "R");
175  m_query->addToOutputList("MDT_RT_MAP.S", "S");
176  m_query->setRowCacheSize(100000);
177  // execute query
178  int last_region_id(-1);
179  std::map<int, SamplePoint> points;
180  coral::ICursor& cursor = m_query->execute();
181  while (cursor.next()) {
182  const coral::AttributeList& al = cursor.currentRow();
183  int rt_id = static_cast<int>(al["REGION_ID"].data<float>());
184  if (last_region_id > 0 && rt_id != last_region_id) {
185  if (!storage.StoreRtChamber(last_region_id, points)) {
186  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
187  log << MSG::WARNING << "Storage_failed" << endmsg;
188  return false;
189  }
190  points.clear();
191  }
192  last_region_id = rt_id;
193  SamplePoint pt(al["T"].data<float>(), al["R"].data<float>(), al["S"].data<float>());
194  points[static_cast<int>(al["POINT_NR"].data<short>())] = pt;
195  }
196  if (last_region_id > 0) {
197  if (!storage.StoreRtChamber(last_region_id, points)) {
198  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
199  log << MSG::WARNING << "Storage_failed" << endmsg;
200  return false;
201  }
202  }
203  return true;
204  } catch (coral::SchemaException& e) {
205  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
206  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
208  return false;
209  }
210  }

◆ readRTS()

bool MuonCalib::CalibRtDbOperations::readRTS ( std::vector< SamplePoint > &  points)
inlineprivate

Definition at line 270 of file CalibRtDbOperations.cxx.

270  {
272  m_query->addToTableList("MDT_RT_MAP");
273  coral::AttributeList conditionData;
274  conditionData.extend<int>("rtid");
275  conditionData[0].data<int>() = m_rt_id;
276  conditionData.extend<int>("hid");
277  conditionData[1].data<int>() = m_head_id;
278  conditionData.extend<int>("rid");
279  conditionData[2].data<int>() = m_region_id;
280  std::string condition = "HEAD_ID=:hid and REGION_ID=:rid and CALIBFLAG=:rtid";
281  m_query->setCondition(condition, conditionData);
282  m_query->addToOutputList("MDT_RT_MAP.POINT_NR", "POINT_NR");
283  m_query->addToOutputList("MDT_RT_MAP.R", "R");
284  m_query->addToOutputList("MDT_RT_MAP.T", "T");
285  m_query->addToOutputList("MDT_RT_MAP.S", "S");
286  m_query->addToOrderList("MDT_RT_MAP.POINT_NR");
287  m_query->setRowCacheSize(100);
288  coral::ICursor& cursor = m_query->execute();
289  points.clear();
290  points.resize(m_n_points);
291  int count(0);
292  while (cursor.next()) {
293  const coral::AttributeList& al = cursor.currentRow();
294  int pt_nr(static_cast<int>(al["POINT_NR"].data<short>()));
295  if (pt_nr >= m_n_points) {
296  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
297  log << MSG::WARNING << "Illegal point number " << pt_nr << endmsg;
298  return false;
299  }
300  SamplePoint point(al["T"].data<float>(), al["R"].data<float>(), al["S"].data<float>());
301  points[pt_nr] = point;
302  count++;
303  }
304  if (count != m_n_points) {
305  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
306  log << MSG::WARNING << m_n_points << " points expected, " << count << " found!" << endmsg;
307  return false;
308  }
310  return true;
311  }

◆ rtTableInitData()

void MuonCalib::CalibRtDbOperations::rtTableInitData ( coral::AttributeList &  rowBuffer)
inlineprivate

Definition at line 495 of file CalibRtDbOperations.cxx.

495  {
496  rowBuffer.extend<int>("HEAD_ID");
497  rowBuffer.extend<int>("REGION_ID");
498  rowBuffer.extend<int>("CALIBFLAG");
499  rowBuffer.extend<int>("POINT_NR");
500  rowBuffer.extend<float>("T");
501  rowBuffer.extend<float>("R");
502  rowBuffer.extend<float>("S");
503  }

◆ SetValidflag()

bool MuonCalib::CalibRtDbOperations::SetValidflag ( int  validflag,
bool  commit = true 
)

Definition at line 119 of file CalibRtDbOperations.cxx.

119  {
120  if (m_rt_id < 0) {
121  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
122  log << MSG::WARNING << "No current rt!" << endmsg;
123  return false;
124  }
125  try {
127  coral::ITableDataEditor& editor = m_db_conn.GetTableEditor("MDT_RT");
128  std::string updateAction = "VALIDFLAG=:val";
129  std::string updateCondition = "HEAD_ID=:hid and REGION_ID=:rid and CALIBFLAG=:rtid";
130  coral::AttributeList updateData;
131  updateData.extend<int>("val");
132  updateData[0].data<int>() = validflag;
133  updateData.extend<int>("rtid");
134  updateData["rtid"].data<int>() = m_rt_id;
135  updateData.extend<int>("hid");
136  updateData["hid"].data<int>() = m_head_id;
137  updateData.extend<int>("rid");
138  updateData["rid"].data<int>() = m_region_id;
139 
140  int n_rows = editor.updateRows(updateAction, updateCondition, updateData);
141  if (n_rows != 1) {
142  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
143  log << MSG::WARNING << "Invalid number of rows updated in MDT_RT! " << n_rows << " instead of 1" << endmsg;
145  return false;
146  }
147  if (commit) m_db_conn.Commit();
148  return true;
149  } catch (coral::SchemaException& e) {
150  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
151  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
153  return false;
154  }
155  }

◆ updateFullInfo()

bool MuonCalib::CalibRtDbOperations::updateFullInfo ( const RtFullInfo full_info,
const int &  validflag,
const int &  n_points 
)
inlineprivate

Definition at line 313 of file CalibRtDbOperations.cxx.

313  {
314  coral::ITableDataEditor& editor = m_db_conn.GetTableEditor("MDT_RT");
315  std::string updateAction =
316  "N_SEGS = :N_SEGS, AVER_ANGLE = :AVER_ANGLE, DELTA_AVER_ANGLE = :DELTA_AVER_ANGLE, AVER_SPREAD = :AVER_SPREAD, "
317  "DELTA_AVER_SPREAD = :DELTA_AVER_SPREAD, CONVERGENCE = :CONVERGENCE, VALIDFLAG=:VALIDFLAG, BINS=:BINS, ALGO_FLAG=:ALGO_FLAG";
318  std::string updateCondition = "HEAD_ID=:hid and REGION_ID=:rid and CALIBFLAG=:rtid";
319  coral::AttributeList updateData;
320  fullInfoInitData(full_info, validflag, updateData, n_points, false);
321  updateData.extend<int>("rtid");
322  updateData["rtid"].data<int>() = m_rt_id;
323  updateData.extend<int>("hid");
324  updateData["hid"].data<int>() = m_head_id;
325  updateData.extend<int>("rid");
326  updateData["rid"].data<int>() = m_region_id;
327  if (editor.updateRows(updateAction, updateCondition, updateData) != 1) {
328  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
329  log << MSG::WARNING << "Invalid number of rows updated in MDT_RT!" << endmsg;
330  return false;
331  }
332  return true;
333  }

◆ updateRTSable()

bool MuonCalib::CalibRtDbOperations::updateRTSable ( const std::vector< SamplePoint > &  points)
inlineprivate

Definition at line 335 of file CalibRtDbOperations.cxx.

335  {
336  coral::ITableDataEditor& editor = m_db_conn.GetTableEditor("MDT_RT_MAP");
337  // check if there are now less points than before
338  if (static_cast<int>(points.size()) < m_n_points) {
339  std::string deleteCondition = "HEAD_ID = :hid and REGION_ID=:rid and CALIBFLAG=:rtid and POINT_NR>=:max_point";
340  coral::AttributeList deleteData;
341  deleteData.extend<int>("hid");
342  deleteData[0].data<int>() = m_head_id;
343  deleteData.extend<int>("rid");
344  deleteData[1].data<int>() = m_region_id;
345  deleteData.extend<int>("rtid");
346  deleteData[2].data<int>() = m_rt_id;
347  deleteData.extend<int>("max_point");
348  deleteData[3].data<int>() = static_cast<int>(points.size());
349  long rowsDeleted = editor.deleteRows(deleteCondition, deleteData);
350  if (rowsDeleted != m_n_points - static_cast<int>(points.size())) {
351  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
352  log << MSG::WARNING << rowsDeleted << " Points removed instead of " << m_n_points - static_cast<int>(points.size())
353  << "! Rolling back!" << endmsg;
354  return false;
355  }
356  }
357  coral::AttributeList table_data;
358  rtTableInitData(table_data);
359  table_data["CALIBFLAG"].data<int>() = m_rt_id;
360  table_data["HEAD_ID"].data<int>() = m_head_id;
361  table_data["REGION_ID"].data<int>() = m_region_id;
362  for (int i = 0; i < static_cast<int>(points.size()); i++) {
363  table_data["POINT_NR"].data<int>() = i;
364  table_data["T"].data<float>() = points[i].x1();
365  table_data["R"].data<float>() = points[i].x2();
366  table_data["S"].data<float>() = points[i].error();
367  if (i < m_n_points) {
368  std::string updateAction = "R=:R, T=:T, S=:S";
369  std::string updateCondition = "CALIBFLAG=:CALIBFLAG and POINT_NR=:POINT_NR and HEAD_ID=:HEAD_ID and REGION_ID=:REGION_ID";
370  if (editor.updateRows(updateAction, updateCondition, table_data) != 1) {
371  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
372  log << MSG::WARNING << "Wrong number of points updated!" << endmsg;
373  return false;
374  }
375  } else {
376  editor.insertRow(table_data);
377  }
378  }
379  return true;
380  }

◆ WriteUpdateRt()

bool MuonCalib::CalibRtDbOperations::WriteUpdateRt ( const NtupleStationId id,
int  head_id,
const std::string &  ,
const std::vector< SamplePoint > &  points,
int  validflag,
const RtFullInfo full_info 
)

Definition at line 72 of file CalibRtDbOperations.cxx.

73  {
74  m_prev_algs = "";
76  m_region_id = id.FixedId();
77  try {
79  if (!getRtId((validflag > 1), nullptr)) {
81  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
82  log << MSG::WARNING << "Questing RT header failed!" << endmsg;
83  return false;
84  }
85  if (m_rt_id >= 0) {
86  if (!updateFullInfo(full_info, validflag, static_cast<int>(points.size()))) {
87  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
88  log << MSG::WARNING << "Failed update header" << endmsg;
90  return false;
91  }
92  if (!updateRTSable(points)) {
94  return false;
95  }
96 
97  } else {
98  if (!insertFullInfo(full_info, validflag, static_cast<int>(points.size()))) {
99  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
100  log << MSG::WARNING << "Failed update header" << endmsg;
102  return false;
103  }
104  if (!insertRTSable(points)) {
106  return false;
107  }
108  }
109  m_db_conn.Commit();
110  return true;
111  } catch (coral::SchemaException& e) {
112  MsgStream log(Athena::getMessageSvc(), "CalibRtDbOperations");
113  log << MSG::WARNING << "Schema exception : " << e.what() << endmsg;
115  return false;
116  }
117  }

Member Data Documentation

◆ m_db_conn

CalibDbConnection& MuonCalib::CalibRtDbOperations::m_db_conn
private

Definition at line 45 of file CalibRtDbOperations.h.

◆ m_head_id

int MuonCalib::CalibRtDbOperations::m_head_id
private

Definition at line 48 of file CalibRtDbOperations.h.

◆ m_n_points

int MuonCalib::CalibRtDbOperations::m_n_points
private

Definition at line 50 of file CalibRtDbOperations.h.

◆ m_prev_algs

std::string MuonCalib::CalibRtDbOperations::m_prev_algs
private

Definition at line 49 of file CalibRtDbOperations.h.

◆ m_query

coral::IQuery* MuonCalib::CalibRtDbOperations::m_query
private

Definition at line 46 of file CalibRtDbOperations.h.

◆ m_region_id

int MuonCalib::CalibRtDbOperations::m_region_id
private

Definition at line 48 of file CalibRtDbOperations.h.

◆ m_rt_id

int MuonCalib::CalibRtDbOperations::m_rt_id
private

Definition at line 48 of file CalibRtDbOperations.h.

◆ m_rt_map_t_id

int MuonCalib::CalibRtDbOperations::m_rt_map_t_id
private

Definition at line 48 of file CalibRtDbOperations.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
MuonCalib::CalibDbConnection::Commit
void Commit()
Definition: CalibDbConnection.cxx:109
MuonCalib::CalibRtDbOperations::m_n_points
int m_n_points
Definition: CalibRtDbOperations.h:50
MuonCalib::CalibDbConnection::Rollback
void Rollback()
Definition: CalibDbConnection.cxx:119
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
test_pyathena.pt
pt
Definition: test_pyathena.py:11
MuonCalib::CalibRtDbOperations::m_query
coral::IQuery * m_query
Definition: CalibRtDbOperations.h:46
LArG4GenerateShowerLib.condition
condition
Definition: LArG4GenerateShowerLib.py:19
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
MuonCalib::CalibRtDbOperations::m_prev_algs
std::string m_prev_algs
Definition: CalibRtDbOperations.h:49
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
MuonCalib::CalibRtDbOperations::m_rt_id
int m_rt_id
Definition: CalibRtDbOperations.h:48
MuonCalib::CalibDbConnection::DestroyQuery
void DestroyQuery(coral::IQuery *query)
Definition: CalibDbConnection.cxx:151
MuonCalib::CalibRtDbOperations::updateRTSable
bool updateRTSable(const std::vector< SamplePoint > &points)
Definition: CalibRtDbOperations.cxx:335
MuonCalib::CalibRtDbOperations::fullInfoInitData
void fullInfoInitData(const RtFullInfo *full_info, const int &validflag, coral::AttributeList &updateData, const int &n_bins, const bool &for_insert)
Definition: CalibRtDbOperations.cxx:411
MuonCalib::CalibRtDbOperations::getRtId
bool getRtId(bool validated, RtFullInfo *full_info)
Definition: CalibRtDbOperations.cxx:212
MuonCalib::CalibDbConnection::GetQuery
coral::IQuery * GetQuery()
Definition: CalibDbConnection.cxx:136
CalibDbCompareRT.n_points
n_points
Definition: CalibDbCompareRT.py:76
MuonCalib::CalibRtDbOperations::insertFullInfo
bool insertFullInfo(const RtFullInfo *full_info, const int &validflag, const int &n_points)
Definition: CalibRtDbOperations.cxx:382
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonCalib::CalibRtDbOperations::updateFullInfo
bool updateFullInfo(const RtFullInfo *full_info, const int &validflag, const int &n_points)
Definition: CalibRtDbOperations.cxx:313
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::CalibRtDbOperations::readRTS
bool readRTS(std::vector< SamplePoint > &points)
Definition: CalibRtDbOperations.cxx:270
MuonCalib::CalibDbConnection::OpenTransaction
void OpenTransaction()
Definition: CalibDbConnection.cxx:99
MuonCalib::CalibRtDbOperations::insertRTSable
bool insertRTSable(const std::vector< SamplePoint > &points)
Definition: CalibRtDbOperations.cxx:390
calibdata.head_id
head_id
Definition: calibdata.py:29
MuonCalib::CalibRtDbOperations::rtTableInitData
void rtTableInitData(coral::AttributeList &rowBuffer)
Definition: CalibRtDbOperations.cxx:495
query_example.cursor
cursor
Definition: query_example.py:21
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
calibdata.commit
bool commit
Definition: calibdata.py:832
MuonCalib::CalibRtDbOperations::m_region_id
int m_region_id
Definition: CalibRtDbOperations.h:48
get_generator_info.error
error
Definition: get_generator_info.py:40
MuonCalib::CalibRtDbOperations::m_rt_map_t_id
int m_rt_map_t_id
Definition: CalibRtDbOperations.h:48
MuonCalib::CalibRtDbOperations::m_db_conn
CalibDbConnection & m_db_conn
Definition: CalibRtDbOperations.h:45
jobOptions.points
points
Definition: jobOptions.GenevaPy8_Zmumu.py:97
MuonCalib::CalibDbConnection::GetTableEditor
coral::ITableDataEditor & GetTableEditor(const std::string &table_name)
Definition: CalibDbConnection.cxx:129
MuonCalib::CalibRtDbOperations::m_head_id
int m_head_id
Definition: CalibRtDbOperations.h:48