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