ATLAS Offline Software
CoolTgc.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 TGC interface with the COOL DB
7 // copy of CoolMdt.cxx by Monica Verducci
8 // author Akimasa Ishikawa
9 //************************************************
11 
12 //CORAL API include files
13 #include "CoralBase/Attribute.h"
14 
15 //COOL API include files (CoolKernel)
16 #include "CoolKernel/IDatabase.h"
17 #include "CoolKernel/IFolder.h"
18 #include "CoolKernel/IObjectIterator.h"
19 #include "CoolKernel/IObject.h"
20 #include "CoolKernel/Record.h"
21 #include "CoolKernel/Exception.h"
22 #include "CoolKernel/IDatabaseSvc.h"
23 #include "CoolKernel/StorageType.h"
24 #include "CoolKernel/ConstRecordAdapter.h"
25 
27 
28 namespace dqutils {
29  cool::IDatabasePtr
30  CoolTgc::
31  coolDbInstance(const std::string& dbStr, bool readOnly) {
32  try {
33  std::cout << "Opening database '" << dbStr << "'...";
34  cool::IDatabaseSvc& dbSvc = this->databaseService();
35  std::cout << "done." << std::endl;
36  return dbSvc.openDatabase(dbStr.c_str(), readOnly);
37  }
38  catch (cool::DatabaseDoesNotExist&) {
39  std::cout << "Error! Database does not exist!" << std::endl;
40  throw;
41  }
42  }
43 
44  cool::IFolderPtr
45  CoolTgc::
46  coolFolderInstance(const std::string& folderStr) {
47  try {
48  cool::IFolderPtr folder = m_coolDb->getFolder(folderStr.c_str());
49  // std::cout << "Browsing objects of '" << folderStr << "'" << std::endl;
50  return folder;
51  }
52  catch (cool::FolderNotFound&) {
53  std::cout << "Error! Folder '" << folderStr << "' does not exist!" << std::endl;
54  throw;
55  }
56  }
57 
58  void
59  CoolTgc::coolDbFolder(const std::string& dbStr, const std::string& folderStr) {
60  m_coolDb = this->coolDbInstance(dbStr, false);
61  m_coolFolder = this->coolFolderInstance(folderStr);
62  }
63 
64  void
65  CoolTgc::
66  setSince(cool::Int64 run, cool::Int64 lumi) {
67  m_since = ((run << 32) + lumi);
68  }
69 
70  void
71  CoolTgc::
72  setUntil(cool::Int64 run, cool::Int64 lumi) {
73  m_until = ((run << 32) + lumi);
74  }
75 
76  void
77  CoolTgc::
78  setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU) {
79  this->setSince(runS, lumiS);
80  this->setUntil(runU, lumiU);
81  this->printIOV();
82  }
83 
84  void
85  CoolTgc::
86  setIOV(cool::Int64 run) {
87  this->setSince(run, 0);
88  this->setUntil(run, 4294967295U);
89  this->printIOV();
90  }
91 
92  void
93  CoolTgc::
94  printIOV() {
95  cool::Int64 runS = m_since >> 32;
96  cool::Int64 lumiS = m_since - (runS << 32);
97  cool::Int64 runU = m_until >> 32;
98  cool::Int64 lumiU = m_until - (runU << 32);
99  std::cout << "Using IOVrange [(" << runS << "," << lumiS << "),(" << runU << "," << lumiU << ")] " << "[" <<
100  m_since << "," << m_until << "]" << std::endl;
101  }
102 
103  void
104  CoolTgc::
105  CoolOpen(const std::string& dbStr) {
106  m_coolDb = this->coolDbInstance(dbStr, false);
107  }
108 
109  CoolTgc::
110  ~CoolTgc () {
111  m_coolDb->closeDatabase();
112  std::cout << "Cleared!" << std::endl;
113  }
114 
115  cool::RecordSpecification
116  CoolTgc::
118  //std::cout << "Preparing RecordSpecification" << std::endl;
119  cool::RecordSpecification spec;
120  spec.extend("Chamber_Name", cool::StorageType::String255);
121  spec.extend("Dead_multilayer", cool::StorageType::String255);
122  spec.extend("Dead_tube", cool::StorageType::String4k);
123 
124  m_coolFolder = this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_DEAD");
125  if (!(spec == m_coolFolder->payloadSpecification())) {
126  std::cout << "ERROR Source and destination folder specifications differ." << std::endl;
127  }
128  // std::cout << "CREATE DONE" << std::endl;
129  return spec;
130  }
131 
133  CoolTgc::
134  createPayloadDataDead(const std::string& ChamberName,
135  const std::string& DeadMultilayer,
136  const std::string& DeadTube,
137  const cool::RecordSpecification& spec) {
138  // std::cout << "createPayloadData "<< std::endl;
139 
140  coral::AttributeList payload = cool::Record(spec).attributeList();
141 
142  payload["Chamber_Name"].data<cool::String255>() = ChamberName;
143  payload["Dead_multilayer"].data<cool::String255>() = DeadMultilayer;
144  payload["Dead_tube"].data<cool::String4k>() = DeadTube;
145 
146  return payload;
147  }
148 
149  // noisy
150 
151  cool::RecordSpecification
152  CoolTgc::
154  //std::cout << "Preparing RecordSpecification" << std::endl;
155  cool::RecordSpecification spec;
156  spec.extend("Chamber_Name", cool::StorageType::String255);
157  spec.extend("Noisy_multilayer", cool::StorageType::String255);
158  spec.extend("Noisy_tube", cool::StorageType::String4k);
159 
160  m_coolFolder = this->coolFolderInstance("/OFFLINE/DQMFOFFLINE/DQMFOFFLINE_NOISY");
161  if (!(spec == m_coolFolder->payloadSpecification())) {
162  std::cout << "ERROR Source and destination folder specifications differ." << std::endl;
163  }
164  // std::cout << "CREATE DONE" << std::endl;
165  return spec;
166  }
167 
169  CoolTgc::
170  createPayloadDataNoisy(const std::string& ChamberName,
171  const std::string& NoisyMultilayer,
172  const std::string& NoisyTube,
173  const cool::RecordSpecification& spec) {
174  // std::cout << "createPayloadData "<< std::endl;
175 
176  coral::AttributeList payload = cool::Record(spec).attributeList();
177 
178  payload["Chamber_Name"].data<cool::String255>() = ChamberName;
179  payload["Noisy_multilayer"].data<cool::String255>() = NoisyMultilayer;
180  payload["Noisy_tube"].data<cool::String4k>() = NoisyTube;
181 
182  return payload;
183  }
184 
185  //
186 
187 
188  void
189  CoolTgc::
190  dump(cool::ChannelSelection selection) {
191  try {
192  cool::IObjectIteratorPtr objects = m_coolFolder->browseObjects(m_since, m_until, selection, "");
193  while (objects->goToNext()) {
194  const cool::IObject& element = objects->currentRef();
195  std::cout << element << std::endl;
196  }
197  }
198  catch (cool::Exception& e) {
199  std::cout << "Unknown exception caught!" << e.what() << std::endl;
200  std::cout << " dentro create payload" << std::endl;
201  }
202  }
203 
204  std::string
205  CoolTgc::
206  dumpField(cool::ChannelId channelId, std::string field) {
207  std::string result = "";
208  try {
209  cool::ChannelSelection selection = cool::ChannelSelection(channelId);
210  cool::IObjectIteratorPtr objects = m_coolFolder->browseObjects(m_since, m_until, selection, "");
211  while (objects->goToNext()) {
212  const cool::IObject& element = objects->currentRef();
213  result = element.payloadValue(field);
214  }
215  }
216  catch (cool::Exception& e) {
217  std::cout << "Unknown exception caught!" << e.what() << std::endl;
218  }
219  return result;
220  }
221 
222  int
223  CoolTgc::
224  dumpCode(const std::string& channelName) {
225  std::string result = this->dumpField(this->getCoolFolder()->channelId(channelName.c_str()), "Code");
226  return atoi(result.c_str());
227  }
228 
229  void
230  CoolTgc::
231  dumpall() {
233  }
234 
235  void
236  CoolTgc::
237  insertDeadFlag_withTag(cool::Int64 run,
238  cool::ChannelId channelId,
239  const std::string& ChamberName,
240  const std::string& DeadMultilayer,
241  const std::string& DeadTube,
242  const std::string& cool_tag) {
243  try {
244  cool::RecordSpecification spec = this->createSpecDataDead();
245  coral::AttributeList payload = this->createPayloadDataDead(ChamberName, DeadMultilayer, DeadTube, spec);
246  cool::ValidityKey since_u = (run << 32);
247  cool::ValidityKey until_u = (run + 1) << 32;
248  m_coolFolder->storeObject(since_u, until_u, cool::Record(
249  m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
250  std::cout << "stored! With Tag =" << cool_tag << std::endl;
251  }
252  catch (cool::Exception& e) {
253  std::cout << " dentro create insert" << std::endl;
254  std::cout << "Unknown exception caught!" << e.what() << std::endl;
255  }
256  }
257 
258  void
259  CoolTgc::
260  insertDeadFlag(cool::Int64 run,
261  cool::ChannelId channelId,
262  const std::string& ChamberName,
263  const std::string& DeadMultilayer,
264  const std::string& DeadTube) {
265  std::cout << "Trying to store payload [channel " << std::endl;
266  try {
267  cool::RecordSpecification spec = this->createSpecDataDead();
268  coral::AttributeList payload = this->createPayloadDataDead(ChamberName, DeadMultilayer, DeadTube, spec);
269  cool::ValidityKey since_u = (run << 32);
270  cool::ValidityKey until_u = (run + 1) << 32;
271  m_coolFolder->storeObject(since_u, until_u, cool::Record(m_coolFolder->payloadSpecification(), payload),
272  channelId);
273  std::cout << "stored! without Tag" << std::endl;
274  }
275  catch (cool::Exception& e) {
276  std::cout << " dentro create insert" << std::endl;
277  std::cout << "Unknown exception caught!" << e.what() << std::endl;
278  }
279  }
280 
281  //
282 
283 
284 
285  void
286  CoolTgc::
287  insertNoisyFlag_withTag(cool::Int64 run,
288  cool::ChannelId channelId,
289  const std::string& ChamberName,
290  const std::string& NoisyMultilayer,
291  const std::string& NoisyTube,
292  const std::string& cool_tag) {
293  try {
294  cool::RecordSpecification spec = this->createSpecDataNoisy();
295  coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName, NoisyMultilayer, NoisyTube, spec);
296  cool::ValidityKey since_u = (run << 32);
297  cool::ValidityKey until_u = (run + 1) << 32;
298  m_coolFolder->storeObject(since_u, until_u, cool::Record(
299  m_coolFolder->payloadSpecification(), payload), channelId, cool_tag);
300  std::cout << "stored! With Tag =" << cool_tag << std::endl;
301  }
302  catch (cool::Exception& e) {
303  std::cout << " dentro create insert" << std::endl;
304  std::cout << "Unknown exception caught!" << e.what() << std::endl;
305  }
306  }
307 
308  void
309  CoolTgc::
310  insertNoisyFlag(cool::Int64 run,
311  cool::ChannelId channelId,
312  const std::string& ChamberName,
313  const std::string& NoisyMultilayer,
314  const std::string& NoisyTube) {
315  std::cout << "Trying to store payload [channel " << std::endl;
316  try {
317  cool::RecordSpecification spec = this->createSpecDataNoisy();
318  coral::AttributeList payload = this->createPayloadDataNoisy(ChamberName, NoisyMultilayer, NoisyTube, spec);
319  cool::ValidityKey since_u = (run << 32);
320  cool::ValidityKey until_u = (run + 1) << 32;
321  m_coolFolder->storeObject(since_u, until_u, cool::Record(m_coolFolder->payloadSpecification(), payload),
322  channelId);
323  std::cout << "stored! without Tag" << std::endl;
324  }
325  catch (cool::Exception& e) {
326  std::cout << " dentro create insert" << std::endl;
327  std::cout << "Unknown exception caught!" << e.what() << std::endl;
328  }
329  }
330 
331  cool::IFolderPtr
332  CoolTgc::
333  getCoolFolder() {
334  return this->m_coolFolder;
335  }
336 
337  cool::IDatabasePtr
338  CoolTgc::
339  getCoolDb() {
340  return this->m_coolDb;
341  }
342 } //namespace dqutils
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ClassImp
ClassImp(dqutils::CoolTgc) namespace dqutils
Definition: CoolTgc.cxx:26
dqutils::CoolTgc::coolDbInstance
cool::IDatabasePtr coolDbInstance(const std::string &dbStr, bool readOnly)
get_generator_info.result
result
Definition: get_generator_info.py:21
dqutils::CoolTgc::~CoolTgc
virtual ~CoolTgc()
LArConditions2Ntuple.objects
objects
Definition: LArConditions2Ntuple.py:59
dqutils::CoolTgc::dumpall
void dumpall()
dqutils::CoolTgc::createPayloadDataNoisy
coral::AttributeList createPayloadDataNoisy(const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyTube, const cool::RecordSpecification &spec)
dqutils::CoolTgc::setUntil
void setUntil(cool::Int64 run, cool::Int64 lumi)
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
dqutils::CoolTgc::dumpCode
int dumpCode(const std::string &channelName)
dqutils::CoolTgc::getCoolFolder
cool::IFolderPtr getCoolFolder()
dqutils::CoolTgc::createPayloadDataDead
coral::AttributeList createPayloadDataDead(const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadTube, const cool::RecordSpecification &spec)
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
dqutils::CoolTgc::createSpecDataNoisy
cool::RecordSpecification createSpecDataNoisy()
dqutils::CoolTgc::m_since
cool::ValidityKey m_since
Definition: CoolTgc.h:83
dqutils::CoolTgc::dump
void dump(cool::ChannelSelection selection)
dqutils::CoolTgc::coolFolderInstance
cool::IFolderPtr coolFolderInstance(const std::string &folderStr)
dqutils::CoolTgc::insertDeadFlag
void insertDeadFlag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadTube)
dqutils::CoolTgc
Definition: CoolTgc.h:78
CalibDbCompareRT.cool_tag
cool_tag
Definition: CalibDbCompareRT.py:12
dqutils::CoolTgc::m_coolDb
cool::IDatabasePtr m_coolDb
Definition: CoolTgc.h:85
run
Definition: run.py:1
dqutils
Definition: CoolMdt.h:76
dqutils::CoolTgc::dumpField
std::string dumpField(cool::ChannelId channelId, std::string field)
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
dqutils::CoolTgc::insertDeadFlag_withTag
void insertDeadFlag_withTag(cool::Int64, cool::ChannelId channelId, const std::string &ChamberName, const std::string &DeadMultilayer, const std::string &DeadTube, const std::string &cool_tag)
CaloNoise_fillDB.dbSvc
dbSvc
Definition: CaloNoise_fillDB.py:108
dqutils::CoolTgc::coolDbFolder
void coolDbFolder(const std::string &dbStr, const std::string &folderStr)
dqutils::CoolTgc::m_coolFolder
cool::IFolderPtr m_coolFolder
Definition: CoolTgc.h:86
selection
const std::string selection
Definition: fbtTestBasics.cxx:74
CoolTgc.h
dqutils::CoolTgc::setSince
void setSince(cool::Int64 run, cool::Int64 lumi)
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
lumiFormat.lumi
lumi
Definition: lumiFormat.py:106
dqutils::CoolTgc::printIOV
void printIOV()
dqutils::CoolTgc::createSpecDataDead
cool::RecordSpecification createSpecDataDead()
dqutils::CoolTgc::getCoolDb
cool::IDatabasePtr getCoolDb()
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::CoolTgc::CoolOpen
void CoolOpen(const std::string &dbStr)
dqutils::CoolTgc::insertNoisyFlag
void insertNoisyFlag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyTube)
dqutils::CoolTgc::m_until
cool::ValidityKey m_until
Definition: CoolTgc.h:84
dqutils::CoolTgc::setIOV
void setIOV(cool::Int64 runS, cool::Int64 lumiS, cool::Int64 runU, cool::Int64 lumiU)
dqutils::CoolTgc::insertNoisyFlag_withTag
void insertNoisyFlag_withTag(cool::Int64 run, cool::ChannelId channelId, const std::string &ChamberName, const std::string &NoisyMultilayer, const std::string &NoisyTube, const std::string &cool_tag)