ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalib::CalibT0DbOperations Class Reference

#include <CalibT0DbOperations.h>

Inheritance diagram for MuonCalib::CalibT0DbOperations:
Collaboration diagram for MuonCalib::CalibT0DbOperations:

Public Member Functions

 CalibT0DbOperations (CalibDbConnection &db_conn)
virtual ~CalibT0DbOperations ()=default
MdtStationT0ContainerLoadT0Calibration (const NtupleStationId &id, int head_id, std::string &site_name)
MdtTubeFitContainerLoadT0Validation (const NtupleStationId &id, int head_id, std::string &site_name)
bool WriteT0Chamber (const NtupleStationId &id, const MdtTubeFitContainer *t0, std::vector< int > &validation_flag, int head_id, const std::string &site_name)
bool ReadForConditions (const std::string &site_name, int head_id, IConditionsStorage &storage)
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void initRowBuffer (std::vector< coral::AttributeList > &rowBuffer, const NtupleStationId &id, const int head_id, const std::string &site_name, const MdtTubeFitContainer *t0)
void fillRowBuffer (std::vector< coral::AttributeList > &rowBuffer, const MdtTubeFitContainer *t0, const int ml1, const int ly, const int ml2, const MuonFixedId &fixId)
bool setValidFlag (const std::string &site_name, const int head_id, const int tube_id, const int new_validflag, coral::ITableDataEditor &editor)
bool insertTubes (const std::string &site_name, int head_id, const NtupleStationId &id, const MdtTubeFitContainer *t0, const std::vector< int > &validation_flag, coral::ITableDataEditor *editor[])
bool setValidationFlag (const std::string &site_name, int head_id, const NtupleStationId &id, int from, int to, coral::ITableDataEditor &editor)
bool checkTubesPresent (const int head_id, const std::string &site_name, const NtupleStationId &id, const std::vector< int > &validflag)
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

ServiceHandle< Muon::IMuonIdHelperSvcm_idHelperSvc {"Muon::MuonIdHelperSvc/MuonIdHelperSvc", "CalibT0DbOperations"}
CalibDbConnectionm_db_conn
coral::IQuery * m_query {nullptr}
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Detailed Description

Definition at line 29 of file CalibT0DbOperations.h.

Constructor & Destructor Documentation

◆ CalibT0DbOperations()

MuonCalib::CalibT0DbOperations::CalibT0DbOperations ( CalibDbConnection & db_conn)

Definition at line 34 of file CalibT0DbOperations.cxx.

34 :
35 AthMessaging{"CalibT0DbOperations"}, m_db_conn(db_conn) {
36 m_idHelperSvc.retrieve().ignore();
37 }
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc

◆ ~CalibT0DbOperations()

virtual MuonCalib::CalibT0DbOperations::~CalibT0DbOperations ( )
virtualdefault

Member Function Documentation

◆ checkTubesPresent()

bool MuonCalib::CalibT0DbOperations::checkTubesPresent ( const int head_id,
const std::string & site_name,
const NtupleStationId & id,
const std::vector< int > & validflag )
inlineprivate

Definition at line 560 of file CalibT0DbOperations.cxx.

561 {
562 m_query = m_db_conn.GetQuery();
563 // select count(MDT_TUBE.TUBE_ID) as N_TUBES, MDT_TUBE.VALIDFLAG as VALIDFLAG from MDT_TUBE where MDT_TUBE.HEAD_ID = :hid and
564 // MDT_TUBE.CHAMBER = :chamb and SITE_NAME=:sn group by MDT_TUBE.VALIDFLAG;
565 m_query->addToTableList("MDT_TUBE");
566 coral::AttributeList conditionData;
567 conditionData.extend<int>("hid");
568 conditionData[0].data<int>() = head_id;
569 // 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
570 std::ostringstream ostr;
571 ostr << id.FixedId();
572 conditionData.extend<std::string>("chamb");
573 conditionData[1].data<std::string>() = ostr.str();
574 std::string condition = "MDT_TUBE.HEAD_ID = :hid and MDT_TUBE.CHAMBER = :chamb";
575 m_query->setCondition(condition, conditionData);
576 m_query->addToOutputList("count(MDT_TUBE.TUBE_ID)", "N_TUBES");
577 m_query->addToOutputList("MDT_TUBE.VALIDFLAG", "VALIDFLAG");
578 m_query->groupBy("MDT_TUBE.VALIDFLAG");
579 coral::ICursor &cursor = m_query->execute();
580 bool has_unvalidated(false), has_validated(false);
581 while (cursor.next()) {
582 const coral::AttributeList &al = cursor.currentRow();
583 if (al["VALIDFLAG"].data<short>() > 0) {
584 if (al["N_TUBES"].data<double>() > 0) { has_validated = true; }
585 } else {
586 if (al["N_TUBES"].data<double>() > 0) { has_unvalidated = true; }
587 }
588 }
589 // check what has to be done
590 if (validflag.size() == 0) return !has_unvalidated;
591 for (int it : validflag) {
592 if (it > 0 && has_validated) return false;
593 if (it == 0 && has_unvalidated) return false;
594 }
595 return true;
596 }
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t al

◆ fillRowBuffer()

void MuonCalib::CalibT0DbOperations::fillRowBuffer ( std::vector< coral::AttributeList > & rowBuffer,
const MdtTubeFitContainer * t0,
const int ml1,
const int ly,
const int ml2,
const MuonFixedId & fixId )
inlineprivate

Definition at line 417 of file CalibT0DbOperations.cxx.

418 {
419 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
420 const Identifier channelID = idHelper.channelID(fixId.stationName(),
421 fixId.eta(),
422 fixId.phi(),
423 ml, ly, tb);
424
425 for (unsigned int i = 0; i < 3; i++) { rowBuffer[i]["TUBE_ID"].data<int>() = fixId.getIdInt(); }
426 rowBuffer[1]["ENTRIES"].data<int>() = t0->getFit(channelID)->statistics;
427 rowBuffer[1]["CHISQUARE_1"].data<float>() = t0->getFit(channelID)->chi2Tdc;
428 rowBuffer[1]["CHISQUARE_2"].data<float>() = t0->getFit(channelID)->chi2TdcEnd;
429 rowBuffer[1]["TUBE_GROUPING"].data<std::string>() = t0->getFit(channelID)->group_by;
430 for (int i = 0; i < 8; i++) {
431 double val = t0->getFit(channelID)->par[i];
432 if (std::isnan(val)) val = -99999.;
433 std::ostringstream ostr2;
434 ostr2 << "P" << i;
435 if (i == 4)
436 rowBuffer[0][ostr2.str()].data<float>() = val;
437 else
438 rowBuffer[1][ostr2.str()].data<float>() = val;
439 ostr2 << "_ERR";
440 val = t0->getFit(channelID)->cov[i];
441 if (std::isnan(val)) val = -99999.;
442 if (i > 3 && i < 7)
443 rowBuffer[1][ostr2.str()].data<float>() = val;
444 else
445 rowBuffer[2][ostr2.str()].data<float>() = val;
446 }
447 for (int i = 0; i < 4; i++) {
448 std::ostringstream ostr2;
449 ostr2 << "ADC_" << i;
450 rowBuffer[0][ostr2.str()].data<float>() = t0->getFit(channelID)->adc_par[i];
451 ostr2 << "_ERR";
452 rowBuffer[2][ostr2.str()].data<float>() = t0->getFit(channelID)->adc_err[i];
453 }
454 rowBuffer[2]["ADC_CHISQUARE"].data<float>() = t0->getFit(channelID)->adc_chi2;
455 rowBuffer[0]["NHITS"].data<int>() = t0->getFit(channelID)->n_hits;
456 if (t0->getFit(channelID)->n_hits > 999999) rowBuffer[0]["NHITS"].data<int>() = 999999;
457 rowBuffer[0]["NHITS_ABOVE_ADC_CUT"].data<int>() = t0->getFit(channelID)->n_hits_above_adc_cut;
458 if (t0->getFit(channelID)->n_hits_above_adc_cut > 999999) rowBuffer[0]["NHITS_ABOVE_ADC_CUT"].data<int>() = 999999;
459 }
static Double_t t0
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ initRowBuffer()

void MuonCalib::CalibT0DbOperations::initRowBuffer ( std::vector< coral::AttributeList > & rowBuffer,
const NtupleStationId & id,
const int head_id,
const std::string & site_name,
const MdtTubeFitContainer * t0 )
inlineprivate

!!!!!ADC_0 should be moved to MDT_TUBE

Definition at line 367 of file CalibT0DbOperations.cxx.

368 {
369 for (unsigned int i = 0; i < 3; i++) {
370 rowBuffer[i].extend<int>("TUBE_ID");
371 rowBuffer[i].extend<int>("HEAD_ID");
372 rowBuffer[i]["HEAD_ID"].data<int>() = head_id;
373 rowBuffer[i].extend<int>("CALIBFLAG");
374 }
375 rowBuffer[0].extend<int>("CHAMBER");
376 rowBuffer[0]["CHAMBER"].data<int>() = id.FixedId();
377 rowBuffer[0].extend<int>("VALIDFLAG");
378 rowBuffer[1].extend<int>("ENTRIES");
379 rowBuffer[1].extend<float>("CHISQUARE_1");
380 rowBuffer[1].extend<float>("CHISQUARE_2");
381 for (int i = 0; i < 8; i++) {
382 std::ostringstream ostr2;
383 ostr2 << "P" << i;
384 if (i == 4)
385 rowBuffer[0].extend<float>(ostr2.str());
386 else
387 rowBuffer[1].extend<float>(ostr2.str());
388 ostr2 << "_ERR";
389 if (i > 3 && i < 7)
390 rowBuffer[1].extend<float>(ostr2.str());
391 else
392 rowBuffer[2].extend<float>(ostr2.str());
393 }
394 for (int i = 0; i < 4; i++) {
395 std::ostringstream ostr2;
396 ostr2 << "ADC_" << i;
398 rowBuffer[0].extend<float>(ostr2.str());
399 ostr2 << "_ERR";
400 rowBuffer[2].extend<float>(ostr2.str());
401 }
402 rowBuffer[2].extend<float>("ADC_CHISQUARE");
403 rowBuffer[0].extend<int>("NHITS");
404 rowBuffer[0].extend<int>("NHITS_ABOVE_ADC_CUT");
405 rowBuffer[1].extend<std::string>("ALGO_FLAG");
406 if (t0->implementation() == "T0CalibrationClassic") {
407 rowBuffer[1]["ALGO_FLAG"].data<std::string>() = "T0Classic";
408 } else if (t0->implementation() == "T0CalibrationMT") {
409 rowBuffer[1]["ALGO_FLAG"].data<std::string>() = "T0MT";
410 } else {
411 rowBuffer[1]["ALGO_FLAG"].data<std::string>() = "Unknown";
412 }
413 rowBuffer[1].extend<std::string>("TUBE_GROUPING");
414 rowBuffer[1]["TUBE_GROUPING"].data<std::string>() = "UNKNOWN";
415 }

◆ insertTubes()

bool MuonCalib::CalibT0DbOperations::insertTubes ( const std::string & site_name,
int head_id,
const NtupleStationId & id,
const MdtTubeFitContainer * t0,
const std::vector< int > & validation_flag,
coral::ITableDataEditor * editor[] )
private

Definition at line 478 of file CalibT0DbOperations.cxx.

480 {
481 std::vector<coral::AttributeList> rowBuffer(3);
482 std::vector<coral::IBulkOperation *> bulk_inserter(3);
483 bool row_buffer_initialized(false);
484 unsigned int nml = t0->numMultilayers();
485 unsigned int nly = t0->numLayers();
486 unsigned int ntb = t0->numTubes();
487 // do not insert completely dead chambers
488 bool all_dead(true);
489 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
490 const Identifier elementID = idHelper.elementID(id.GetStation(), id.GetEta(), id.GetPhi());
491 for (unsigned int ml = 1; ml <= nml; ml++) {
492 for (unsigned int ly = 1; ly <= nly; ly++) {
493 for (unsigned int tb = 1; tb <= ntb; tb++) {
494 const Identifier channelID = idHelper.channelID(elementID, ml, ly, tb);
495 if (t0->getFit(channelID)->statistics > 0) {
496 all_dead = false;
497 break;
498 }
499 }
500 }
501 }
502 if (all_dead) {
503 ATH_MSG_WARNING( "Refusing to insert completely dead chamber" );
504 return false;
505 }
506 MuonFixedId fixId(0);
507 fixId.setTechnology(0);
508 fixId.setStationName(id.GetStation());
509 fixId.setStationEta(id.GetEta());
510 fixId.setStationPhi(id.GetPhi());
511 for (unsigned int ml = 1; ml <= nml; ml++) {
512 for (unsigned int ly = 1; ly <= nly; ly++) {
513 for (unsigned int tb = 1; tb <= ntb; tb++) {
514 int tb_index = (tb -1) + ntb * (ly -1) + ntb * nly * (ml -1);
515 fixId.setMdtTube(tb);
516 fixId.setMdtTubeLayer(ly);
517 fixId.setMdtMultilayer(ml);
518 int v_flag = 0;
519 if (static_cast<int>(validation_flag.size()) > tb_index) { v_flag = validation_flag[tb_index]; }
520 if (!row_buffer_initialized) {
521 initRowBuffer(rowBuffer, id, head_id, site_name, t0);
522 for (int i = 0; i < 3; i++) { bulk_inserter[i] = editor[i]->bulkInsert(rowBuffer[i], 432); }
523 row_buffer_initialized = true;
524 }
525 fillRowBuffer(rowBuffer, t0, ml, ly, tb, fixId);
526 rowBuffer[0]["VALIDFLAG"].data<int>() = v_flag;
527 for (unsigned int i = 0; i < 3; i++) {
528 rowBuffer[i]["CALIBFLAG"].data<int>() = static_cast<int>(v_flag > 3);
529 bulk_inserter[i]->processNextIteration();
530 }
531 }
532 }
533 }
534 for (unsigned int i = 0; i < 3; i++) {
535 bulk_inserter[i]->flush();
536 delete bulk_inserter[i];
537 }
538 return true;
539 }
#define ATH_MSG_WARNING(x)
Identifier elementID(int stationName, int stationEta, int stationPhi) const
void initRowBuffer(std::vector< coral::AttributeList > &rowBuffer, const NtupleStationId &id, const int head_id, const std::string &site_name, const MdtTubeFitContainer *t0)
void fillRowBuffer(std::vector< coral::AttributeList > &rowBuffer, const MdtTubeFitContainer *t0, const int ml1, const int ly, const int ml2, const MuonFixedId &fixId)

◆ LoadT0Calibration()

MdtStationT0Container * MuonCalib::CalibT0DbOperations::LoadT0Calibration ( const NtupleStationId & id,
int head_id,
std::string & site_name )

Definition at line 39 of file CalibT0DbOperations.cxx.

39 {
40 try {
41 // select MDT_TUBE.TUBE_ID, MDT_TUBE.P4 from MDT_TUBE where MDT_TUBE.HEAD_ID = :hid and MDT_TUBE.CHAMBER = :chamb and
42 // MDT_TUBE.VALIDFLAG>1
43 m_db_conn.OpenTransaction();
44 m_query = m_db_conn.GetQuery();
45 m_query->setRowCacheSize(432);
46 m_query->addToTableList("MDT_TUBE");
47 coral::AttributeList conditionData;
48 conditionData.extend<int>("hid");
49 conditionData[0].data<int>() = head_id;
50 // 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
51 conditionData.extend<int>("chamb");
52 conditionData[1].data<int>() = id.FixedId();
53 std::string condition = "MDT_TUBE.HEAD_ID = :hid and MDT_TUBE.CHAMBER = :chamb and MDT_TUBE.VALIDFLAG>1";
54 m_query->setCondition(condition, conditionData);
55 m_query->addToOutputList("MDT_TUBE.TUBE_ID", "TUBE_ID");
56 m_query->addToOutputList("MDT_TUBE.P4", "T0");
57 m_query->addToOutputList("MDT_TUBE.ADC_1", "ADC_1");
58 coral::ICursor &cursor = m_query->execute();
59 MdtStationT0Container *ret = new MdtStationT0Container();
60 int count(0);
61 while (cursor.next()) {
62 const coral::AttributeList &al = cursor.currentRow();
63 MuonFixedId fid(al[0].data<int>());
64 ret->Sett0(fid.mdtMultilayer(), fid.mdtTubeLayer(), fid.mdtTube(), al[1].data<float>(), al[2].data<float>());
65 count++;
66 }
67 if (count == 0) {
68 ATH_MSG_WARNING( "No tubes found for " << id.regionId() << " Header " << site_name << head_id );
69 delete ret;
70 return nullptr;
71 }
72 return ret;
73 } // try
74 catch (coral::SchemaException &e) {
75 ATH_MSG_WARNING( "Schema exception : " << e.what() );
76 return nullptr;
77 }
78 }
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

◆ LoadT0Validation()

MdtTubeFitContainer * MuonCalib::CalibT0DbOperations::LoadT0Validation ( const NtupleStationId & id,
int head_id,
std::string & site_name )

Definition at line 80 of file CalibT0DbOperations.cxx.

80 {
81 const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
82 try {
83 m_db_conn.OpenTransaction();
84 m_query = m_db_conn.GetQuery();
85 m_query->setRowCacheSize(432);
86 m_query->addToTableList("MDT_TUBE");
87 m_query->addToTableList("MDT_TUBE_V");
88 coral::AttributeList conditionData;
89 conditionData.extend<int>("hid");
90 conditionData[0].data<int>() = head_id;
91 // 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
92 std::ostringstream ostr;
93 ostr << id.FixedId();
94 conditionData.extend<std::string>("chamb");
95 conditionData[1].data<std::string>() = ostr.str();
96 std::string condition =
97 "MDT_TUBE.HEAD_ID = :hid and MDT_TUBE.CHAMBER = :chamb and MDT_TUBE.VALIDFLAG=0 and MDT_TUBE_V.HEAD_ID=:hid and "
98 "MDT_TUBE_V.TUBE_ID = MDT_TUBE.TUBE_ID and MDT_TUBE_V.CALIBFLAG=MDT_TUBE.CALIBFLAG";
99 m_query->setCondition(condition, conditionData);
100 m_query->addToOutputList("MDT_TUBE.TUBE_ID", "TUBE_ID");
101 m_query->addToOutputList("MDT_TUBE.P4", "T0");
102 m_query->addToOutputList("MDT_TUBE_V.ENTRIES", "ENTRIES");
103 m_query->addToOutputList("MDT_TUBE_V.CHISQUARE_1", "CHISQUARE_1");
104 m_query->addToOutputList("MDT_TUBE_V.CHISQUARE_2", "CHISQUARE_2");
105 for (int i = 0; i < 7; i++) {
106 std::ostringstream ostr;
107 if (i == 4) {
108 ostr << "MDT_TUBE.P4";
109 } else {
110 ostr << "MDT_TUBE_V.P" << i;
111 }
112 std::ostringstream ostr2;
113 ostr2 << "P" << i;
114 m_query->addToOutputList(ostr.str(), ostr2.str());
115 if (i > 3 && i < 7) {
116 if (i == 4) {
117 m_query->addToOutputList("MDT_TUBE_V.P4_ERR", "P4_ERR");
118 } else {
119 ostr << "_ERR";
120 ostr2 << "_ERR";
121 m_query->addToOutputList(ostr.str(), ostr2.str());
122 }
123 }
124 }
125 m_query->addToOutputList("MDT_TUBE.NHITS", "NHITS");
126 m_query->addToOutputList("MDT_TUBE.NHITS_ABOVE_ADC_CUT", "NHITS_ABOVE_ADC_CUT");
127 m_query->addToOutputList("MDT_TUBE_V.ALGO_FLAG", "ALGO_FLAG");
128 m_query->addToOutputList("MDT_TUBE_V.TUBE_GROUPING", "TUBE_GROUPING");
129 coral::ICursor &cursor = m_query->execute();
130 int n_tubes(0), n_layers(0), n_ml(0);
131 std::map<MuonFixedId, MdtTubeFitContainer::SingleTubeFit> fits;
132 std::map<MuonFixedId, MdtTubeFitContainer::SingleTubeCalib> calibs;
133 std::string alg_flg, tb_grp;
134 bool str_set(false);
135 while (cursor.next()) {
136 const coral::AttributeList &al = cursor.currentRow();
137 MuonFixedId fid(al["TUBE_ID"].data<int>());
138 MdtTubeFitContainer::SingleTubeCalib &calib(calibs[fid]);
139 calib.t0 = al["P4"].data<float>();
140 calib.adcCal = 0;
141 MdtTubeFitContainer::SingleTubeFit &fit(fits[fid]);
142 fit.statistics = al["ENTRIES"].data<int>();
143 fit.n_hits = al["NHITS"].data<int>();
144 fit.n_hits_above_adc_cut = al["NHITS_ABOVE_ADC_CUT"].data<int>();
145 fit.chi2Tdc = 0.0;
146 fit.chi2TdcEnd = 0.0;
147 for (int i = 0; i < 7; i++) {
148 std::ostringstream ostr2;
149 ostr2 << "P" << i;
150 fit.par[i] = al[ostr2.str()].data<float>();
151 if (i > 3 && i < 7) {
152 ostr2 << "_ERR";
153 fit.cov[i] = al[ostr2.str()].data<float>();
154 } else {
155 fit.cov[i] = 0.0;
156 }
157 }
158 if (n_tubes < fid.mdtTube()) n_tubes = fid.mdtTube();
159 if (n_layers < fid.mdtTubeLayer()) n_layers = fid.mdtTubeLayer();
160 if (n_ml < fid.mdtMultilayer()) n_ml = fid.mdtMultilayer();
161 if (!str_set) {
162 alg_flg = al["ALGO_FLAG"].data<std::string>();
163 tb_grp = al["TUBE_GROUPING"].data<std::string>();
164 str_set = true;
165 }
166 }
167
168 // create output class
169 const Identifier moduleID = idHelper.elementID(id.GetStation(), id.GetEta(), id.GetPhi());
170 MdtTubeFitContainer *ret = new MdtTubeFitContainer(m_idHelperSvc.get(), moduleID);
171 for (auto& [tubeId, tubeFit] : fits) {
172 const Identifier thisId = idHelper.channelID(moduleID,
173 tubeId.mdtMultilayer(),
174 tubeId.mdtTubeLayer(),
175 tubeId.mdtTube());
176 ret->setFit(std::move(tubeFit), thisId, msg());
177 ret->setCalib(calibs[tubeId], thisId, msg());
178 }
179 ret->setGroupBy(tb_grp);
180 ret->setImplementation(alg_flg);
181 return ret;
182 } // try
183 catch (coral::SchemaException &e) {
184 ATH_MSG_WARNING( "Schema exception : " << e.what() );
185 return nullptr;
186 }
187 }
MsgStream & msg() const
The standard message stream.

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 163 of file AthMessaging.h.

164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 178 of file AthMessaging.h.

179{ return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 if (m_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}

◆ ReadForConditions()

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

Definition at line 301 of file CalibT0DbOperations.cxx.

301 {
302 try {
303 // prepare query
304 m_db_conn.OpenTransaction();
305 m_query = m_db_conn.GetQuery();
306 m_query->addToTableList("MDT_TUBE");
307 m_query->addToOutputList("MDT_TUBE.CHAMBER", "CHAMBER");
308 m_query->addToOutputList("MDT_TUBE.TUBE_ID", "TUBE_ID");
309 m_query->setRowCacheSize(10000);
310 const std::vector<std::string> &rows_tube_table(storage.RowsFromMdtTubeTable());
311 for (const auto & it : rows_tube_table) {
312 if (it == "CHAMBER" || it == "TUBE_ID") continue;
313 m_query->addToOutputList(std::string("MDT_TUBE.") + it, it);
314 }
315 const std::vector<std::string> &rows_tube_v_table(storage.RowsFromMdtTubeVTable());
316 if (rows_tube_v_table.size() != 0) {
317 m_query->addToTableList("MDT_TUBE_V");
318 for (const auto & it : rows_tube_v_table) {
319 m_query->addToOutputList(std::string("MDT_TUBE_V.") + it, it);
320 }
321 }
322 const std::vector<std::string> &rows_tube_c_table(storage.RowsFromMdtTubeCTable());
323 if (rows_tube_c_table.size() != 0) {
324 m_query->addToTableList("MDT_TUBE_C");
325 for (const auto & it : rows_tube_c_table) {
326 m_query->addToOutputList(std::string("MDT_TUBE_C.") + it, it);
327 }
328 }
329 coral::AttributeList conditionData;
330 conditionData.extend<int>("HEAD_ID");
331 conditionData["HEAD_ID"].data<int>() = head_id;
332 std::string condition = "MDT_TUBE.HEAD_ID = :HEAD_ID and MDT_TUBE.VALIDFLAG>1 ";
333 if (rows_tube_v_table.size() != 0)
335 " and MDT_TUBE.HEAD_ID = MDT_TUBE_V.HEAD_ID and MDT_TUBE.TUBE_ID=MDT_TUBE_V.TUBE_ID and "
336 "MDT_TUBE.CALIBFLAG=MDT_TUBE_V.CALIBFLAG";
337 if (rows_tube_c_table.size() != 0)
339 " and MDT_TUBE.HEAD_ID = MDT_TUBE_C.HEAD_ID and MDT_TUBE.TUBE_ID=MDT_TUBE_C.TUBE_ID and "
340 "MDT_TUBE.CALIBFLAG=MDT_TUBE_C.CALIBFLAG";
341 m_query->setCondition(condition, conditionData);
342 m_query->addToOrderList("MDT_TUBE.CHAMBER");
343 // execute query
344 int old_chamber_id(-1);
345 std::map<IConditionsStorage::TubeId, coral::AttributeList> rows_of_a_chamber;
346 coral::ICursor &cursor = m_query->execute();
347 while (cursor.next()) {
348 const coral::AttributeList &al = cursor.currentRow();
349 // if we have a new chamber - call callback
350 if (old_chamber_id != al["CHAMBER"].data<int>() && rows_of_a_chamber.size() != 0) {
351 if (!storage.StoreT0Chamber(old_chamber_id, rows_of_a_chamber)) { return false; }
352 rows_of_a_chamber.clear();
353 }
354 // store row
355 IConditionsStorage::TubeId id(al["TUBE_ID"].data<int>());
356 rows_of_a_chamber[id] = al;
357 old_chamber_id = al["CHAMBER"].data<int>();
358 }
359 if (!storage.StoreT0Chamber(old_chamber_id, rows_of_a_chamber)) { return false; }
360 return true;
361 } catch (coral::SchemaException &e) {
362 ATH_MSG_WARNING( "Schema exception : " << e.what() );
363 return false;
364 }
365 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

◆ setValidationFlag()

bool MuonCalib::CalibT0DbOperations::setValidationFlag ( const std::string & site_name,
int head_id,
const NtupleStationId & id,
int from,
int to,
coral::ITableDataEditor & editor )
private

Definition at line 541 of file CalibT0DbOperations.cxx.

542 {
543 std::string updateAction = "validflag = :newval";
544 std::string updateCondition = "head_id=:hid and chamber=:cham and validflag=:old_val";
545 coral::AttributeList updateData;
546 updateData.extend<int>("hid");
547 updateData[0].data<int>() = head_id;
548 updateData.extend<std::string>("cham");
549 std::ostringstream ostr;
550 ostr << id.FixedId();
551 updateData[1].data<std::string>() = ostr.str();
552 updateData.extend<int>("newval");
553 updateData[2].data<int>() = to;
554 updateData.extend<int>("old_val");
555 updateData[3].data<int>() = from;
556 long rowsUpdated = editor.updateRows(updateAction, updateCondition, updateData);
557 return (rowsUpdated <= 432);
558 }

◆ setValidFlag()

bool MuonCalib::CalibT0DbOperations::setValidFlag ( const std::string & site_name,
const int head_id,
const int tube_id,
const int new_validflag,
coral::ITableDataEditor & editor )
private

Definition at line 461 of file CalibT0DbOperations.cxx.

462 {
463 std::string updateAction = "validflag = :newval";
464 std::string updateCondition = "head_id=:hid and tube_id=:tid and validflag=0";
465 coral::AttributeList updateData;
466 updateData.extend<int>("hid");
467 updateData[0].data<int>() = head_id;
468 updateData.extend<int>("tid");
469 updateData[1].data<int>() = tube_id;
470 // updateData.extend<std::string>("sn");
471 // updateData[2].data<std::string>()=site_name;
472 updateData.extend<int>("newval");
473 updateData[2].data<int>() = new_validflag;
474 long rowsUpdated = editor.updateRows(updateAction, updateCondition, updateData);
475 return rowsUpdated;
476 }

◆ WriteT0Chamber()

bool MuonCalib::CalibT0DbOperations::WriteT0Chamber ( const NtupleStationId & id,
const MdtTubeFitContainer * t0,
std::vector< int > & validation_flag,
int head_id,
const std::string & site_name )

Definition at line 189 of file CalibT0DbOperations.cxx.

190 {
191 try {
192 m_db_conn.OpenTransaction();
193 if (!checkTubesPresent(head_id, site_name, id, validation_flag)) {
194 ATH_MSG_WARNING( "Trying to insert data for chamber " << id.regionId() << " header " << head_id << site_name
195 << " which already exists!" );
196 m_db_conn.Rollback();
197 return false;
198 }
199 coral::ITableDataEditor *editor[] = {&m_db_conn.GetTableEditor(std::string("MDT_TUBE")),
200 &m_db_conn.GetTableEditor(std::string("MDT_TUBE_V")),
201 &m_db_conn.GetTableEditor(std::string("MDT_TUBE_C"))};
202 // insert new tubes
203 if (validation_flag.size() == 0) {
204 if (!insertTubes(site_name, head_id, id, t0, validation_flag, editor)) {
205 m_db_conn.Rollback();
206 return false;
207 }
208 m_db_conn.Commit();
209 return true;
210 }
211 // check if all tubes ar enew or if all tubes a validated good
212 bool all_new(true), all_good(true);
213 for (int it : validation_flag) {
214 if (it != 0) all_new = false;
215 if (it != 3) all_good = false;
216 if (!all_new && !all_good) break;
217 }
218 // insert new tubes
219 if (all_new) {
220 if (!insertTubes(site_name, head_id, id, t0, validation_flag, editor)) {
221 m_db_conn.Rollback();
222 return false;
223 }
224 m_db_conn.Commit();
225 return true;
226 }
227 // all tubes are good. Update the whole chamber in one go
228 if (all_good) {
229 if (!setValidationFlag(site_name, head_id, id, 0, 3, *editor[0])) {
230 m_db_conn.Rollback();
231 return false;
232 }
233 m_db_conn.Commit();
234 return true;
235 }
236 // update flag for failed and dummy tubes - insert for failed
237 std::vector<coral::AttributeList> rowBuffer(3);
238 bool row_buffer_initialized(false);
239 unsigned int nml = t0->numMultilayers();
240 unsigned int nly = t0->numLayers();
241 unsigned int ntb = t0->numTubes();
242 MuonFixedId fixId(0);
243 fixId.setTechnology(0);
244 fixId.setStationName(id.GetStation());
245 fixId.setStationEta(id.GetEta());
246 fixId.setStationPhi(id.GetPhi());
247 for (unsigned int ml = 1; ml <= nml; ml++) {
248 for (unsigned int ly = 1; ly <= nly; ly++) {
249 for (unsigned int tb = 1; tb <= ntb; tb++) {
250 int tb_index = (tb -1) + ntb * (ly -1) + ntb * nly * (ml -1);
251 if (validation_flag[tb_index] == 3) continue;
252 fixId.setMdtTube(tb);
253 fixId.setMdtTubeLayer(ly);
254 fixId.setMdtMultilayer(ml);
255 // new tubes or tubes that are validated bad are inserted
256 int rowsUpdated;
257 if (validation_flag[tb_index] == 5)
258 rowsUpdated = setValidFlag(site_name, head_id, fixId.getIdInt(), 5, *editor[0]);
259 else
260 rowsUpdated = setValidFlag(site_name, head_id, fixId.getIdInt(), 1, *editor[0]);
261
262 if (rowsUpdated != 1) {
263 ATH_MSG_WARNING( id.regionId() << " tb=" << tb << " ly=" << ly << " ml=" << ml << " head_id=" << head_id
264 << ": " << rowsUpdated << " Rows to be updated! This is wrong! Check database!" );
265 m_db_conn.Rollback();
266 return false;
267 }
268 if (validation_flag[tb_index] != 5) {
269 // initialize row buffers
270 if (!row_buffer_initialized) {
271 initRowBuffer(rowBuffer, id, head_id, site_name, t0);
272 row_buffer_initialized = true;
273 }
274 // fill row buffers
275 fillRowBuffer(rowBuffer, t0, ml, ly, tb, fixId);
276 rowBuffer[0]["VALIDFLAG"].data<int>() = validation_flag[tb_index];
277 // loop over 3 t0 tables - get seqid from 1st and insert it into 2nd and 3rd.
278 for (unsigned int i = 0; i < 3; i++) {
279 rowBuffer[i]["CALIBFLAG"].data<int>() = static_cast<int>(validation_flag[tb_index] > 3);
280 editor[i]->insertRow(rowBuffer[i]);
281 }
282 }
283 }
284 }
285 }
286 // now all tubes whit validflag == 0 are good update in one go
287 if (!setValidationFlag(site_name, head_id, id, 0, 3, *editor[0])) {
288 m_db_conn.Rollback();
289 return false;
290 }
291 m_db_conn.Commit();
292 return true;
293 } // try
294 catch (coral::SchemaException &e) {
295 ATH_MSG_WARNING( "Schema exception : " << e.what() );
296 m_db_conn.Rollback();
297 return false;
298 }
299 }
bool setValidationFlag(const std::string &site_name, int head_id, const NtupleStationId &id, int from, int to, coral::ITableDataEditor &editor)
bool insertTubes(const std::string &site_name, int head_id, const NtupleStationId &id, const MdtTubeFitContainer *t0, const std::vector< int > &validation_flag, coral::ITableDataEditor *editor[])
bool checkTubesPresent(const int head_id, const std::string &site_name, const NtupleStationId &id, const std::vector< int > &validflag)
bool setValidFlag(const std::string &site_name, const int head_id, const int tube_id, const int new_validflag, coral::ITableDataEditor &editor)

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_db_conn

CalibDbConnection& MuonCalib::CalibT0DbOperations::m_db_conn
private

Definition at line 51 of file CalibT0DbOperations.h.

◆ m_idHelperSvc

ServiceHandle<Muon::IMuonIdHelperSvc> MuonCalib::CalibT0DbOperations::m_idHelperSvc {"Muon::MuonIdHelperSvc/MuonIdHelperSvc", "CalibT0DbOperations"}
private

Definition at line 48 of file CalibT0DbOperations.h.

48{"Muon::MuonIdHelperSvc/MuonIdHelperSvc", "CalibT0DbOperations"};

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_query

coral::IQuery* MuonCalib::CalibT0DbOperations::m_query {nullptr}
private

Definition at line 52 of file CalibT0DbOperations.h.

52{nullptr};

The documentation for this class was generated from the following files: