ATLAS Offline Software
Loading...
Searching...
No Matches
ReadLumiBlock.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Trigger
7
8// COOL
9#include "CoolKernel/ValidityKey.h"
10#include "CoolKernel/IFolder.h"
11#include "CoolKernel/Exception.h"
12#include "CoolKernel/IObject.h"
13#include "CoolKernel/IObjectIterator.h"
14#include "CoolKernel/IDatabaseSvc.h"
15#include "CoralKernel/Context.h"
16
17// C/C++
18#include <cmath>
19#include <iomanip>
20#include <iostream>
21#include <sstream>
22
23using namespace std;
24
25//-----------------------------------------------------------------------------
27 :m_cool_id(),
28 m_cool_id_run1("COOLONL_TRIGGER/COMP200"),
29 m_cool_id_run2("COOLONL_TRIGGER/CONDBR2"),
31 m_run(0),
32 m_triedSetup(false)
33{
34}
35
36//-----------------------------------------------------------------------------
40
41//-----------------------------------------------------------------------------
42bool ReadLumiBlock::updateLumiBlocks(const uint32_t run, MsgStream& msg)
43{
44 //
45 // Read configuration keys from COOL
46 //
47 m_triedSetup = true;
48 m_cool_source.clear();
49 m_run = run;
50
51 if (m_run < 238742) m_cool_id = m_cool_id_run1;
53
54 cool::ValidityKey since(run);
55 cool::ValidityKey until(run);
56 cool::ValidityKey maskLB(0xffffffff);
57
58 since <<= 32; // upper 31 bits are run number
59 until <<= 32; // upper 31 bits are run number
60 until += maskLB;
61
62 if (!dbIsOpen()) {
63 if (!openDb(true, msg)) {
64 msg << MSG::FATAL << "updateLumiBlocks - failed to open DB... " << m_cool_id << endmsg;
65 return false;
66 }
67 }
68
69 if (m_cool_ptr->existsFolder("/TRIGGER/LUMI/LBLB")) {
70
71 msg << MSG::INFO << "ReadRunData - reading folder: /TRIGGER/LUMI/LBLB" << endmsg;
72
73 cool::IFolderPtr folderLB = m_cool_ptr->getFolder("/TRIGGER/LUMI/LBLB");
74 cool::IObjectIteratorPtr objectsLB = folderLB->browseObjects(since, until, 0);
75
76 while ( objectsLB -> goToNext() ) {
77 const cool::IObject &obj = objectsLB->currentRef();
78 const cool::IRecord &payload = obj.payload();
79 const uint32_t lumi = (obj.since() & 0xffff);
80
81 const uint64_t start = payload["StartTime"].data<cool::UInt63>();
82 const uint64_t end = payload["EndTime"].data<cool::UInt63>();
83 const uint64_t length = end - start;
84
85 m_lbLength[lumi] = length;
86
87 msg << MSG::DEBUG << " run=" << run
88 << " LB=" << lumi
89 << " Start=" << start
90 << " End=" << end
91 << " Length=" << length << endmsg;
92 }
93 } else {
94 msg << MSG::INFO << "ReadRunData - missing COOL folder: /TRIGGER/LUMI/LBLB in " << m_cool_id << endmsg;
95 }
96 // more lumi info can be got from http://acode-browser.usatlas.bnl.gov/lxr/source/atlas/Trigger/TrigCost/TrigCostRate/src/ReadCool.cxx
97
98 closeDb(msg);
99 return true;
100}
101
102float ReadLumiBlock::getLumiBlockLength(const uint32_t lb, MsgStream& msg) const
103{
104
105 if (m_lbLength.count(lb) != 1) {
106 msg << MSG::INFO << "Unknown lumiblock number " << lb << endmsg;
107 return 60.0; // Sensible default
108 }
109 return m_lbLength.at(lb) * 1e-9; // Convert from ns
110}
111
112//---------------------------------------------------------------------------------------
114{
115 return m_cool_ptr.use_count() > 0 && m_cool_ptr->isOpen();
116}
117
118//---------------------------------------------------------------------------------------
119bool ReadLumiBlock::openDb(bool readOnly, MsgStream& msg)
120{
121 if(dbIsOpen()) return true;
122
123 try {
124 msg << MSG::DEBUG << "ReadLumiBlock::openDb - opening database '" << m_cool_id << "'" << endmsg;
125 m_cool_ptr = databaseService().openDatabase(m_cool_id, readOnly);
126
127 return true;
128 } catch(cool::DatabaseDoesNotExist& e) {
129 msg << MSG::ERROR << "ReadLumiBlock::openDb - COOL exception caught: " << e.what() << endmsg;
130 msg << MSG::ERROR << " could not open database: " << m_cool_id << endmsg;
131 return false;
132 }
133
134 return false;
135}
136
137//---------------------------------------------------------------------------------------
139{
140 try {
141 if(dbIsOpen()) {
142 msg << MSG::DEBUG << "ReadLumiBlock::closeDd - closing database '" << m_cool_id << endmsg;
143 m_cool_ptr->closeDatabase();
144 }
145 } catch(std::exception& e) {
146 msg << MSG::ERROR << "ReadLumiBlock::closeDB - COOL exception caught: " << e.what() << endmsg;
147 msg << MSG::ERROR << " could not close COOL database: " << m_cool_id << endmsg;
148 }
149 return;
150}
#define endmsg
double length(const pvec &v)
bool updateLumiBlocks(uint32_t run, MsgStream &msg)
Load information for.
cool::IDatabasePtr m_cool_ptr
std::map< uint32_t, uint64_t > m_lbLength
float getLumiBlockLength(uint32_t lb, MsgStream &msg) const
cool::DatabaseId m_cool_id_run1
bool dbIsOpen()
Check if DB connection is open.
void closeDb(MsgStream &msg)
Close DB connection.
cool::DatabaseId m_cool_id
ReadLumiBlock()
Construct helper class for reading in lumi block length from COOL.
bool openDb(bool readOnly, MsgStream &msg)
Open a DB connection.
std::string m_cool_source
cool::DatabaseId m_cool_id_run2
int lb
Definition globals.cxx:23
Definition run.py:1
STL namespace.
MsgStream & msg
Definition testRead.cxx:32