Skip to content

Commit 28b9451

Browse files
authored
Merge pull request #47171 from cms-AlCaDB/hlt-crash-diag
Print diagnostics on ProductResolver's loadTag setIntervalFor and IOVProxy's fetchSequence
2 parents 9692325 + 4b8c72c commit 28b9451

File tree

9 files changed

+103
-29
lines changed

9 files changed

+103
-29
lines changed

CondCore/CondDB/interface/IOVProxy.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,11 @@ namespace cond {
9898
// value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
9999
class IOVProxy {
100100
public:
101-
//
102-
IOVProxy();
101+
IOVProxy() = default;
103102

104103
// the only way to construct it from scratch...
105104
explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
106105

107-
//
108-
IOVProxy(const IOVProxy& rhs);
109-
110-
//
111-
IOVProxy& operator=(const IOVProxy& rhs);
112-
113106
IOVArray selectAll();
114107
IOVArray selectAll(const boost::posix_time::ptime& snapshottime);
115108

@@ -160,6 +153,8 @@ namespace cond {
160153
// maybe will be removed with a re-design of the top level interface (ESSources )
161154
const std::shared_ptr<SessionImpl>& session() const;
162155

156+
void setPrintDebug(bool printDebug) { m_printDebug = printDebug; }
157+
163158
private:
164159
void checkTransaction(const std::string& ctx) const;
165160
void resetIOVCache();
@@ -169,6 +164,9 @@ namespace cond {
169164
private:
170165
std::shared_ptr<IOVProxyData> m_data;
171166
std::shared_ptr<SessionImpl> m_session;
167+
168+
// whether additional debug info should be printed in fetchSequence
169+
bool m_printDebug = false;
172170
};
173171

174172
} // namespace persistency

CondCore/CondDB/interface/Time.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ namespace cond {
5454

5555
Time_t tillTimeForIOV(Time_t since, unsigned int iovSize, TimeType timeType);
5656

57-
Time_t lumiTime(unsigned int run, unsigned int lumiId);
57+
// LumiNr is the number of the luminosity block (LumiSection) in a run.
58+
// LumiTime also called LumiId is an unique identifier for a luminosity block,
59+
// being a combination of run number and LumiNr
60+
Time_t lumiTime(unsigned int run, unsigned int lumiNr);
61+
62+
Time_t lumiIdToRun(Time_t lumiId);
63+
64+
Time_t lumiIdToLumiNr(Time_t lumiId);
5865

5966
// conversion from framework types
6067
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop);

CondCore/CondDB/src/IOVProxy.cc

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include <memory>
22

33
#include "CondCore/CondDB/interface/IOVProxy.h"
4+
#include "CondCore/CondDB/interface/Time.h"
45
#include "FWCore/MessageLogger/interface/MessageLogger.h"
56
#include "SessionImpl.h"
67

8+
using cond::time::lumiIdToLumiNr;
9+
using cond::time::lumiIdToRun;
710
namespace cond {
811

912
namespace persistency {
@@ -125,18 +128,8 @@ namespace cond {
125128
size_t numberOfQueries = 0;
126129
};
127130

128-
IOVProxy::IOVProxy() : m_data(), m_session() {}
129-
130131
IOVProxy::IOVProxy(const std::shared_ptr<SessionImpl>& session) : m_data(new IOVProxyData), m_session(session) {}
131132

132-
IOVProxy::IOVProxy(const IOVProxy& rhs) : m_data(rhs.m_data), m_session(rhs.m_session) {}
133-
134-
IOVProxy& IOVProxy::operator=(const IOVProxy& rhs) {
135-
m_data = rhs.m_data;
136-
m_session = rhs.m_session;
137-
return *this;
138-
}
139-
140133
void IOVProxy::load(const std::string& tagName) {
141134
boost::posix_time::ptime notime;
142135
load(tagName, notime);
@@ -293,8 +286,47 @@ namespace cond {
293286
throwException("The transaction is not active.", ctx);
294287
}
295288

289+
void printTagInfoAndRanges(edm::LogSystem& log,
290+
const IOVProxyData& iovProxyData,
291+
cond::Time_t lowerGroup,
292+
cond::Time_t higherGroup) {
293+
log << "Fetched new IOV for '" << iovProxyData.tagInfo.name << "'\n"
294+
<< "payload type: " << iovProxyData.tagInfo.payloadType << "\n"
295+
<< "request interval [ " << lowerGroup << " , " << higherGroup << " ]\n"
296+
<< "new range [ " << iovProxyData.groupLowerIov << " , " << iovProxyData.groupHigherIov << " ]\n";
297+
if (iovProxyData.tagInfo.timeType == cond::TimeType::lumiid) {
298+
log << "request interval (run, LS): [ (" // comments to override code-format
299+
<< lumiIdToRun(lowerGroup) << ", " << lumiIdToLumiNr(lowerGroup) << ") , (" //
300+
<< lumiIdToRun(higherGroup) << ", " << lumiIdToLumiNr(higherGroup) << ") ]\n"
301+
<< "new range (run, LS): [ (" //
302+
<< lumiIdToRun(iovProxyData.groupLowerIov) << ", " << lumiIdToLumiNr(iovProxyData.groupLowerIov) << ") , ("
303+
<< lumiIdToRun(iovProxyData.groupHigherIov) << ", " << lumiIdToLumiNr(iovProxyData.groupHigherIov)
304+
<< ") ]\n";
305+
}
306+
}
307+
308+
void printIovsAndHashesOfSequence(edm::LogSystem& log, const IOVProxyData& iovProxyData) {
309+
const bool isLumiid = iovProxyData.tagInfo.timeType == cond::TimeType::lumiid;
310+
log << "#entries " << iovProxyData.iovSequence.size() << "\n"
311+
<< "sequence [iov " << (isLumiid ? "(run, LS)" : "") << ", hash]:\n";
312+
for (const auto& [iov, hash] : iovProxyData.iovSequence) {
313+
log << iov << " ";
314+
if (isLumiid) {
315+
log << "(" << lumiIdToRun(iov) << ", " << lumiIdToLumiNr(iov) << ")";
316+
}
317+
log << ", " << hash << ",\n";
318+
}
319+
}
320+
321+
void printIOVSequenceDiagnostics(const IOVProxyData& iovProxyData,
322+
cond::Time_t lowerGroup,
323+
cond::Time_t higherGroup) {
324+
edm::LogSystem log("NewIOV"); // creating here so everything is in one message
325+
printTagInfoAndRanges(log, iovProxyData, lowerGroup, higherGroup);
326+
printIovsAndHashesOfSequence(log, iovProxyData);
327+
}
328+
296329
void IOVProxy::fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup) {
297-
bool firstTime = m_data->iovSequence.empty();
298330
m_data->iovSequence.clear();
299331
m_session->iovSchema().iovTable().select(
300332
m_data->tagInfo.name, lowerGroup, higherGroup, m_data->snapshotTime, m_data->iovSequence);
@@ -315,13 +347,11 @@ namespace cond {
315347
m_data->groupHigherIov = cond::time::MAX_VAL;
316348
}
317349
}
318-
if (not firstTime) {
319-
edm::LogSystem("NewIOV") << "Fetched new IOV for '" << m_data->tagInfo.name << "' request interval [ "
320-
<< lowerGroup << " , " << higherGroup << " ] new range [ " << m_data->groupLowerIov
321-
<< " , " << m_data->groupHigherIov << " ] #entries " << m_data->iovSequence.size();
322-
}
323-
324350
m_data->numberOfQueries++;
351+
352+
if (m_printDebug) {
353+
printIOVSequenceDiagnostics(*m_data, lowerGroup, higherGroup);
354+
}
325355
}
326356

327357
cond::Iov_t IOVProxy::getInterval(cond::Time_t time) {

CondCore/CondDB/src/Time.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ namespace cond {
6363
}
6464
}
6565

66-
Time_t lumiTime(unsigned int run, unsigned int lumiId) { return cond::time::pack(std::make_pair(run, lumiId)); }
66+
Time_t lumiTime(unsigned int run, unsigned int lumiNr) { return cond::time::pack(std::make_pair(run, lumiNr)); }
67+
68+
Time_t lumiIdToRun(Time_t lumiId) { return cond::time::unpack(lumiId).first; }
69+
70+
Time_t lumiIdToLumiNr(Time_t lumiId) { return cond::time::unpack(lumiId).second; }
6771

6872
Time_t sinceGroupSize(TimeType tp) {
6973
if (tp == TIMESTAMP)

CondCore/ESSources/interface/ProductResolver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ namespace cond {
107107
ValidityInterval setIntervalFor(Time_t target);
108108
TimeType timeType() const { return m_iovProxy.tagInfo().timeType; }
109109

110+
void setPrintDebug(bool printDebug) { m_printDebug = printDebug; }
111+
110112
private:
111113
std::string m_label;
112114
std::string m_connString;
@@ -115,6 +117,9 @@ namespace cond {
115117
Iov_t m_currentIov;
116118
persistency::Session m_session;
117119
std::shared_ptr<std::vector<Iov_t>> m_requests;
120+
121+
// whether additional debug info should be printed in loadTag and setIntervalFor
122+
bool m_printDebug = false;
118123
};
119124
} // namespace cond
120125

CondCore/ESSources/plugins/CondDBESSource.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig)
127127
m_connectionString(iConfig.getParameter<std::string>("connect")),
128128
m_globalTag(iConfig.getParameter<std::string>("globaltag")),
129129
m_frontierKey(iConfig.getUntrackedParameter<std::string>("frontierKey", "")),
130+
m_recordsToDebug(
131+
iConfig.getUntrackedParameter<std::vector<std::string>>("recordsToDebug", std::vector<std::string>())),
130132
m_lastRun(0), // for the stat
131133
m_lastLumi(0), // for the stat
132134
m_policy(NOREFRESH),
@@ -254,11 +256,20 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig)
254256
*/
255257
std::vector<std::unique_ptr<cond::ProductResolverWrapperBase>> resolverWrappers(m_tagCollection.size());
256258
size_t ipb = 0;
259+
257260
for (it = itBeg; it != itEnd; ++it) {
258261
size_t ind = ipb++;
259262
resolverWrappers[ind] = std::unique_ptr<cond::ProductResolverWrapperBase>{
260263
cond::ProductResolverFactory::get()->tryToCreate(buildName(it->second.recordName()))};
261-
if (!resolverWrappers[ind].get()) {
264+
265+
if (resolverWrappers[ind].get()) {
266+
// Enable debug if the record name is in m_recordsToDebug or if "*" is present, meaning debug for all records.
267+
bool printDebug = std::find(m_recordsToDebug.begin(), m_recordsToDebug.end(), "*") != m_recordsToDebug.end() ||
268+
std::find(m_recordsToDebug.begin(), m_recordsToDebug.end(), it->second.recordName()) !=
269+
m_recordsToDebug.end();
270+
271+
resolverWrappers[ind]->setPrintDebug(printDebug);
272+
} else {
262273
edm::LogWarning("CondDBESSource") << "Plugin for Record " << it->second.recordName() << " has not been found.";
263274
}
264275
}
@@ -774,6 +785,7 @@ void CondDBESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptio
774785
desc.addUntracked<bool>("RefreshOpenIOVs", false);
775786
desc.addUntracked<std::string>("pfnPostfix", "");
776787
desc.addUntracked<std::string>("pfnPrefix", "");
788+
desc.addUntracked<std::vector<std::string>>("recordsToDebug", {});
777789

778790
descriptions.add("default_CondDBESource", desc);
779791
}

CondCore/ESSources/plugins/CondDBESSource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class CondDBESSource : public edm::eventsetup::ESProductResolverProvider, public
124124
typedef std::map<std::string, cond::GTEntry_t> TagCollection;
125125
// the collections of tag, record/label used in this ESSource
126126
TagCollection m_tagCollection;
127+
std::vector<std::string> m_recordsToDebug;
128+
127129
std::map<std::string, std::pair<cond::Time_t, bool> > m_refreshTimeForRecord;
128130
std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPool;
129131
std::map<std::string, std::pair<cond::persistency::Session, std::string> > m_sessionPoolForLumiConditions;

CondCore/ESSources/python/CondDBESSource_cfi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
RefreshEachRun = False,
2121
RefreshOpenIOVs = False,
2222
pfnPostfix = '',
23-
pfnPrefix = '' ,
23+
pfnPrefix = '',
24+
recordsToDebug = [],
2425
)

CondCore/ESSources/src/ProductResolverFactory.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// user include files
1616
#include "CondCore/ESSources/interface/ProductResolverFactory.h"
1717
#include "CondCore/ESSources/interface/ProductResolver.h"
18+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
1819

1920
cond::ProductResolverWrapperBase::ProductResolverWrapperBase() {}
2021

@@ -29,17 +30,26 @@ void cond::ProductResolverWrapperBase::addInfo(std::string const& il, std::strin
2930
void cond::ProductResolverWrapperBase::loadTag(std::string const& tag) {
3031
m_session.transaction().start(true);
3132
m_iovProxy = m_session.readIov(tag);
33+
m_iovProxy.setPrintDebug(m_printDebug);
3234
m_session.transaction().commit();
3335
m_currentIov.clear();
3436
m_requests = std::make_shared<std::vector<cond::Iov_t>>();
37+
if (m_printDebug) {
38+
edm::LogSystem("ProductResolverWrapperBase") << "loadTag executed with tag: " << tag;
39+
}
3540
}
3641

3742
void cond::ProductResolverWrapperBase::loadTag(std::string const& tag, boost::posix_time::ptime const& snapshotTime) {
3843
m_session.transaction().start(true);
3944
m_iovProxy = m_session.readIov(tag, snapshotTime);
45+
m_iovProxy.setPrintDebug(m_printDebug);
4046
m_session.transaction().commit();
4147
m_currentIov.clear();
4248
m_requests = std::make_shared<std::vector<cond::Iov_t>>();
49+
if (m_printDebug) {
50+
edm::LogSystem("ProductResolverWrapperBase")
51+
<< "loadTag executed with tag: " << tag << " and snapshotTime: " << snapshotTime;
52+
}
4353
}
4454

4555
void cond::ProductResolverWrapperBase::reload() {
@@ -55,6 +65,11 @@ cond::ValidityInterval cond::ProductResolverWrapperBase::setIntervalFor(Time_t t
5565
m_currentIov = m_iovProxy.getInterval(time);
5666
m_session.transaction().commit();
5767
}
68+
if (m_printDebug) {
69+
edm::LogSystem("ProductResolverWrapperBase")
70+
<< "setIntervalFor for tag:" << m_iovProxy.tagInfo().name << " executed with time: " << time << "\n"
71+
<< " set ValidityInterval: since: " << m_currentIov.since << " till: " << m_currentIov.till;
72+
}
5873
return cond::ValidityInterval(m_currentIov.since, m_currentIov.till);
5974
}
6075

0 commit comments

Comments
 (0)