ATLAS Offline Software
CoolMdt.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 //*************************************************
6 // Class for the MDT interface with the COOL DB
7 // author Monica Verducci monica.verducci@cern.ch
8 //************************************************
10 
11 //CORAL API include files
12 #include "CoralBase/Attribute.h"
13 
14 //COOL API include files (CoolKernel)
15 #include "CoolKernel/IDatabase.h"
16 #include "CoolKernel/IFolder.h"
17 #include "CoolKernel/IObjectIterator.h"
18 #include "CoolKernel/IObject.h"
19 #include "CoolKernel/Record.h"
20 #include "CoolKernel/Exception.h"
21 #include "CoolKernel/IDatabaseSvc.h"
22 #include "CoolKernel/StorageType.h"
23 #include "CoolKernel/ConstRecordAdapter.h"
24 
26 
27 namespace dqutils {
28  void CoolMdt::initialize() {m_fist_folder = true;}
29 
30  cool::IDatabasePtr
31  CoolMdt::
32  coolDbInstance(const std::string& dbStr, bool readOnly) {
33  try {
34  // std::cout << "Opening database '" << dbStr << "'...";
35  cool::IDatabaseSvc& dbSvc = this->databaseService();
36  // std::cout << "done." << std::endl;
37  return dbSvc.openDatabase(dbStr.c_str(), readOnly);
38  }
39  catch (cool::DatabaseDoesNotExist&) {
40  std::cerr << "Error! Database does not exist!" << std::endl;
41  throw;
42  }
43  }
44 
45  cool::IFolderPtr
46  CoolMdt::
47  coolFolderInstance(const std::string& folderStr) {
48  try {
49  cool::IFolderPtr folder = m_coolDb->getFolder(folderStr.c_str());
50  // std::cout << "Browsing objects of '" << folderStr << "'" << std::endl;
51  return folder;
52  }
53  catch (cool::FolderNotFound&) {
54  std::cerr << "Error! Folder '" << folderStr << "' does not exist!" << std::endl;
55  throw;
56  }
57  }
58 
59  void
60  CoolMdt::coolDbFolder(const std::string& dbStr, const std::string& folderStr) {
61  m_coolDb = this->coolDbInstance(dbStr, false);
62  m_coolFolder = this->coolFolderInstance(folderStr);
63  }
64 
65  void
66  CoolMdt::
67  setSince(cool::Int64 run, cool::Int64 lumi) {
68  m_since = ((run << 32) + lumi);
69  }
70 
71  void
72  CoolMdt::
73  setUntil(cool::Int64 run, cool::Int64 lumi) {
74  m_until = ((run << 32) + lumi);
75  }
76 
77  void
78  CoolMdt::
79  setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) {
80  this->setSince(runS, lumiS);
81  this->setUntil(runU, lumiU);
82  this->printIOV();
83  }
84 
85  void
86  CoolMdt::
87  setIOV(cool::Int64 run) {
88  this->setSince(run, 0);
89  this->setUntil(run, 4294967295U);
90  this->printIOV();
91  }
92 
93  void
94  CoolMdt::
95  printIOV() {
96  cool::Int64 runS = m_since >> 32;
97  cool::Int64 lumiS = m_since - (runS << 32);
98  cool::Int64 runU = m_until >> 32;
99  cool::Int64 lumiU = m_until - (runU << 32);
100  std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" <<
101  m_since << "," << m_until << "]" << std::endl;
102  }
103 
104  void
105  CoolMdt::
106  CoolOpen(const std::string& dbStr) {
107  m_coolDb = this->coolDbInstance(dbStr, false);
108  }
109 
110  CoolMdt::
111  ~CoolMdt () {
112  m_coolFolder->flushStorageBuffer();
113  m_coolDb->closeDatabase();
114  // std::cout << "Cleared!" << std::endl;
115  }
116 
117  cool::RecordSpecification
118  CoolMdt::
120  //std::cout << "Preparing RecordSpecification" << std::endl;
121  cool::RecordSpecification spec;
122  spec.extend("Chamber_Name", cool::StorageType::String255);
123  spec.extend("Dead_multilayer", cool::StorageType::String255);
124  spec.extend("Dead_layer", cool::StorageType::String255);
125  spec.extend("Dead_mezz", cool::StorageType::String255);
126  spec.extend("Dead_asd", cool::StorageType::String255);
127  spec.extend("Dead_tube", cool::StorageType::String4k);
128 
129  if (m_fist_folder) {
130  m_coolFolder = this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD");
131  m_coolFolder->setupStorageBuffer();
132  //std::cout << "Storage Buffer Setup Dead" << std::endl;
133  m_fist_folder = false;
134  }
135  if (!(spec == m_coolFolder->payloadSpecification())) {
136  std::cerr << "ERROR Source and destination folder specifications differ." << std::endl;
137  }
138  // std::cout << "CREATE DONE" << std::endl;
139  return spec;
140  }
141 
143  CoolMdt::
144  createPayloadDataDead(const std::string& ChamberName,
145  const std::string& DeadMultilayer,
146  const std::string& DeadLayer,
147  const std::string& DeadMezz,
148  const std::string& DeadAsd,
149  const std::string& DeadTube,
150  const cool::RecordSpecification& spec) {
151  // std::cout << "createPayloadData "<< std::endl;
152 
153  coral::AttributeList payload = cool::Record(spec).attributeList();
154 
155  payload["Chamber_Name"].data<cool::String255>() = ChamberName;
156  payload["Dead_multilayer"].data<cool::String255>() = DeadMultilayer;
157  payload["Dead_layer"].data<cool::String255>() = DeadLayer;
158  payload["Dead_mezz"].data<cool::String255>() = DeadMezz;
159  payload["Dead_asd"].data<cool::String255>() = DeadAsd;
160  payload["Dead_tube"].data<cool::String4k>() = DeadTube;
161 
162  return payload;
163  }
164 
165  // noisy
166 
167  cool::RecordSpecification
168  CoolMdt::
170  //std::cout << "Preparing RecordSpecification" << std::endl;
171  cool::RecordSpecification spec;
172  spec.extend("Chamber_Name", cool::StorageType::String255);
173  spec.extend("Noisy_multilayer", cool::StorageType::String255);
174  spec.extend("Noisy_layer", cool::StorageType::String255);
175  spec.extend("Noisy_mezz", cool::StorageType::String255);
176  spec.extend("Noisy_asd", cool::StorageType::String255);
177  spec.extend("Noisy_tube", cool::StorageType::String4k);
178 
179  if (m_fist_folder) {
180  m_coolFolder = this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY");
181  m_coolFolder->setupStorageBuffer();
182  //std::cout << "Storage Buffer Setup Noisy" << std::endl;
183  m_fist_folder = false;
184  }
185  if (!(spec == m_coolFolder->payloadSpecification())) {
186  std::cerr << "ERROR Source and destination folder specifications differ." << std::endl;
187  }
188  // std::cout << "CREATE DONE" << std::endl;
189  return spec;
190  }
191 
193  CoolMdt::
194  createPayloadDataNoisy(const std::string& ChamberName,
195  const std::string& NoisyMultilayer,
196  const std::string& NoisyLayer,
197  const std::string& NoisyMezz,
198  const std::string& NoisyAsd,
199  const std::string& NoisyTube,
200  const cool::RecordSpecification& spec) {
201  // std::cout << "createPayloadData "<< std::endl;
202 
203  coral::AttributeList payload = cool::Record(spec).attributeList();
204 
205  payload["Chamber_Name"].data<cool::String255>() = ChamberName;
206  payload["Noisy_multilayer"].data<cool::String255>() = NoisyMultilayer;
207  payload["Noisy_layer"].data<cool::String255>() = NoisyLayer;
208  payload["Noisy_mezz"].data<cool::String255>() = NoisyMezz;
209  payload["Noisy_asd"].data<cool::String255>() = NoisyAsd;
210  payload["Noisy_tube"].data<cool::String4k>() = NoisyTube;
211 
212  return payload;
213  }
214 
215  //
216 
217 
218  void
219  CoolMdt::
220  dump(cool::ChannelSelection selection) {
221  try {
222  cool::IObjectIteratorPtr objects = m_coolFolder->browseObjects(m_since, m_until, selection, "");
223  while (objects->goToNext()) {
224  const cool::IObject& element = objects->currentRef();
225  std::cout << element << std::endl;
226  }
227  }
228  catch (cool::Exception& e) {
229  std::cout << "Unknown exception caught!" << e.what() << std::endl;
230  std::cout << " dentro create payload" << std::endl;
231  }
232  }
233 
234  std::string
235  CoolMdt::
236  dumpField(cool::ChannelId channelId, std::string field) {
237  std::string result = "";
238  try {
239  cool::ChannelSelection selection = cool::ChannelSelection(channelId);
240  cool::IObjectIteratorPtr objects = m_coolFolder->browseObjects(m_since, m_until, selection, "");
241  while (objects->goToNext()) {
242  const cool::IObject& element = objects->currentRef();
243  result = element.payloadValue(field);
244  }
245  }
246  catch (cool::Exception& e) {
247  std::cout << "Unknown exception caught!" << e.what() << std::endl;
248  }
249  return result;
250  }
251 
252  int
253  CoolMdt::
254  dumpCode(const std::string& channelName) {
255  std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code");
256  return atoi(result.c_str());
257  }
258 
259  void
260  CoolMdt::
261  dumpall() {
263  }
264 
265  void
266  CoolMdt::
267  insertDeadFlag_withTag(cool::Int64 run,
268  cool::ChannelId channelId,
269  const std::string& ChamberName,
270  const std::string& DeadMultilayer,
271  const std::string& DeadLayer,
272  const std::string& DeadMezz,
273  const std::string& DeadAsd,
274  const std::string& DeadTube,
275  const std::string& cool_tag) {
276  try {
277  cool::RecordSpecification spec = this->createSpecDataDead();
278  coral::AttributeList payload = this->createPayloadDataDead(ChamberName, DeadMultilayer, DeadLayer, DeadMezz,
279  DeadAsd, DeadTube, spec);
280  cool::ValidityKey since_u = (run << 32);
281  cool::ValidityKey until_u = (run + 1) << 32;
282  m_coolFolder->storeObject(since_u, until_u, cool::Record(
283  m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
284  // std::cout << "stored! With Tag =" << cool_tag <<std::endl;
285  }
286  catch (cool::Exception& e) {
287  std::cerr << " dentro create insert" << std::endl;
288  std::cerr << "Unknown exception caught!" << e.what() << std::endl;
289  }
290  }
291 
292  void
293  CoolMdt::
294  insertDeadFlag(cool::Int64 run,
295  cool::ChannelId channelId,
296  const std::string& ChamberName,
297  const std::string& DeadMultilayer,
298  const std::string& DeadLayer,
299  const std::string& DeadMezz,
300  const std::string& DeadAsd,
301  const std::string& DeadTube) {
302  std::cout << "Trying to store payload [channel " << std::endl;
303  try {
304  cool::RecordSpecification spec = this->createSpecDataDead();
305  coral::AttributeList payload = this->createPayloadDataDead(ChamberName, DeadMultilayer, DeadLayer, DeadMezz,
306  DeadAsd, DeadTube, spec);
307  cool::ValidityKey since_u = (run << 32);
308  cool::ValidityKey until_u = (run + 1) << 32;
309  m_coolFolder->storeObject(since_u, until_u, cool::Record(m_coolFolder->payloadSpecification(), payload),
310  channelId);
311  // std::cout << "stored! without Tag" << std::endl;
312  }
313  catch (cool::Exception& e) {
314  std::cerr << " dentro create insert" << std::endl;
315  std::cerr << "Unknown exception caught!" << e.what() << std::endl;
316  }
317  }
318 
319  //
320 
321 
322 
323  void
324  CoolMdt::
325  insertNoisyFlag_withTag(cool::Int64 run,
326  cool::ChannelId channelId,
327  const std::string& ChamberName,
328  const std::string& NoisyMultilayer,
329  const std::string& NoisyLayer,
330  const std::string& NoisyMezz,
331  const std::string& NoisyAsd,
332  const std::string& NoisyTube,
333  const std::string& cool_tag) {
334  try {
335  cool::RecordSpecification spec = this->createSpecDataNoisy();
336  coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName, NoisyMultilayer, NoisyLayer, NoisyMezz,
337  NoisyAsd, NoisyTube, spec);
338  cool::ValidityKey since_u = (run << 32);
339  cool::ValidityKey until_u = (run + 1) << 32;
340  m_coolFolder->storeObject(since_u, until_u, cool::Record(
341  m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
342  // std::cout << "stored! With Tag =" << cool_tag <<std::endl;
343  }
344  catch (cool::Exception& e) {
345  std::cerr << " dentro create insert" << std::endl;
346  std::cerr << "Unknown exception caught!" << e.what() << std::endl;
347  }
348  }
349 
350  void
351  CoolMdt::
352  insertNoisyFlag(cool::Int64 run,
353  cool::ChannelId channelId,
354  const std::string& ChamberName,
355  const std::string& NoisyMultilayer,
356  const std::string& NoisyLayer,
357  const std::string& NoisyMezz,
358  const std::string& NoisyAsd,
359  const std::string& NoisyTube) {
360  std::cout << "Trying to store payload [channel " << std::endl;
361  try {
362  cool::RecordSpecification spec = this->createSpecDataNoisy();
363  coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName, NoisyMultilayer, NoisyLayer, NoisyMezz,
364  NoisyAsd, NoisyTube, spec);
365  cool::ValidityKey since_u = (run << 32);
366  cool::ValidityKey until_u = (run + 1) << 32;
367  m_coolFolder->storeObject(since_u, until_u, cool::Record(m_coolFolder->payloadSpecification(), payload),
368  channelId);
369  // std::cout << "stored! without Tag" << std::endl;
370  }
371  catch (cool::Exception& e) {
372  std::cerr << " dentro create insert" << std::endl;
373  std::cerr << "Unknown exception caught!" << e.what() << std::endl;
374  }
375  }
376 
377  cool::IFolderPtr
378  CoolMdt::
379  getCoolFolder() {
380  return this->m_coolFolder;
381  }
382 
383  cool::IDatabasePtr
384  CoolMdt::
385  getCoolDb() {
386  return this->m_coolDb;
387  }
388 } //namespace dqutils
dqutils::CoolMdt::printIOV
void printIOV()
dqutils::CoolMdt::setIOV
void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU)
dqutils::CoolMdt::~CoolMdt
virtual ~CoolMdt()
dqutils::CoolMdt::createPayloadDataNoisy
coral::AttributeList createPayloadDataNoisy(const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyLayer, const std::string &NoisyMezz, const std::string &NoisyAsd, const std::string &NoisyTube, const cool::RecordSpecification &spec)
get_generator_info.result
result
Definition: get_generator_info.py:21
dqutils::CoolMdt::createPayloadDataDead
coral::AttributeList createPayloadDataDead(const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadLayer, const std::string &DeadMezz, const std::string &DeadAsd, const std::string &DeadTube, const cool::RecordSpecification &spec)
LArConditions2Ntuple.objects
objects
Definition: LArConditions2Ntuple.py:56
dqutils::CoolMdt::m_until
cool::ValidityKey m_until
Definition: CoolMdt.h:83
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
dqutils::CoolMdt::coolDbFolder
void coolDbFolder(const std::string &dbStr, const std::string &folderStr)
dqutils::CoolMdt::CoolOpen
void CoolOpen(const std::string &dbStr)
dqutils::CoolMdt::m_fist_folder
bool m_fist_folder
Definition: CoolMdt.h:86
dqutils::CoolMdt::m_coolDb
cool::IDatabasePtr m_coolDb
Definition: CoolMdt.h:84
dqutils::CoolMdt::initialize
void initialize()
dqutils::CoolMdt::insertDeadFlag_withTag
void insertDeadFlag_withTag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadLayer, const std::string &DeadMezz, const std::string &DeadAsd, const std::string &DeadTube, const std::string &cool_tag)
dqutils::CoolMdt::getCoolDb
cool::IDatabasePtr getCoolDb()
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
dqutils::CoolMdt::setSince
void setSince(cool::Int64 run, cool::Int64 lumi)
dqutils::CoolMdt::createSpecDataNoisy
cool::RecordSpecification createSpecDataNoisy()
CoolMdt.h
dqutils::CoolMdt::insertNoisyFlag_withTag
void insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyLayer, const std::string &NoisyMezz, const std::string &NoisyAsd, const std::string &NoisyTube, const std::string &cool_tag)
CalibDbCompareRT.cool_tag
cool_tag
Definition: CalibDbCompareRT.py:12
dqutils::CoolMdt::m_coolFolder
cool::IFolderPtr m_coolFolder
Definition: CoolMdt.h:85
dqutils::CoolMdt::dumpCode
int dumpCode(const std::string &channelName)
dqutils::CoolMdt::m_since
cool::ValidityKey m_since
Definition: CoolMdt.h:82
ClassImp
ClassImp(dqutils::CoolMdt) namespace dqutils
Definition: CoolMdt.cxx:25
run
Definition: run.py:1
dqutils
Definition: CoolMdt.h:76
dqutils::CoolMdt::dumpall
void dumpall()
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
selection
std::string selection
Definition: fbtTestBasics.cxx:73
dqutils::CoolMdt::setUntil
void setUntil(cool::Int64 run, cool::Int64 lumi)
CaloNoise_fillDB.dbSvc
dbSvc
Definition: CaloNoise_fillDB.py:108
dqutils::CoolMdt::coolFolderInstance
cool::IFolderPtr coolFolderInstance(const std::string &folderStr)
dqutils::CoolMdt::dumpField
std::string dumpField(cool::ChannelId channelId, std::string field)
dqutils::CoolMdt::dump
void dump(cool::ChannelSelection selection)
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
dqutils::CoolMdt::insertNoisyFlag
void insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyLayer, const std::string &NoisyMezz, const std::string &NoisyAsd, const std::string &NoisyTube)
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:64
lumiFormat.lumi
lumi
Definition: lumiFormat.py:113
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
dqutils::CoolMdt::createSpecDataDead
cool::RecordSpecification createSpecDataDead()
dqutils::CoolMdt
Definition: CoolMdt.h:77
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
dqutils::CoolMdt::coolDbInstance
cool::IDatabasePtr coolDbInstance(const std::string &dbStr, bool readOnly)
dqutils::CoolMdt::getCoolFolder
cool::IFolderPtr getCoolFolder()
dqutils::CoolMdt::insertDeadFlag
void insertDeadFlag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadLayer, const std::string &DeadMezz, const std::string &DeadAsd, const std::string &DeadTube)