Skip to content

Commit 612adc0

Browse files
authored
Merge pull request #46632 from perrotta/introducePopConO2O_141X
Introduce OnlinePopCon mechanism and HLT-compatible LHCInfoPer* PopCon (duringFill mode) - 14_1_O2OTest
2 parents d108f18 + be1fc65 commit 612adc0

21 files changed

+2117
-1395
lines changed

CondCore/PopCon/interface/Exception.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace popcon {
77
class Exception : public cms::Exception {
88
public:
99
explicit Exception(const std::string& message) : cms::Exception("PopCon", message) {}
10+
Exception(const std::string& category, const std::string& message) : cms::Exception(category, message) {}
1011
~Exception() throw() override {}
1112
};
1213
} // namespace popcon
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#ifndef CONDCORE_POPCON_ONLINEPOPCON_H
2+
#define CONDCORE_POPCON_ONLINEPOPCON_H
3+
4+
//
5+
// Authors:
6+
// - Francesco Brivio (Milano-Bicocca)
7+
// - Jan Chyczynski (AGH University of Krakow)
8+
//
9+
10+
#include "CondCore/DBOutputService/interface/OnlineDBOutputService.h"
11+
#include "CondCore/PopCon/interface/Exception.h"
12+
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
13+
#include "FWCore/ServiceRegistry/interface/Service.h"
14+
15+
#include <algorithm>
16+
#include <functional>
17+
#include <iostream>
18+
#include <string>
19+
#include <vector>
20+
21+
namespace popcon {
22+
23+
// Populator of the Condition DB.
24+
// Specific implementation for online lumi-based conditions (OnlineDBOutputService)
25+
26+
class OnlinePopCon {
27+
public:
28+
typedef cond::Time_t Time_t;
29+
30+
OnlinePopCon(const edm::ParameterSet& pset);
31+
32+
virtual ~OnlinePopCon();
33+
34+
template <typename Source>
35+
void write(Source const& source);
36+
37+
private:
38+
cond::persistency::Session initialize();
39+
cond::persistency::Session preparePopCon();
40+
void finalize();
41+
42+
private:
43+
// DB service
44+
edm::Service<cond::service::OnlineDBOutputService> m_dbService;
45+
46+
// PopCon infrastructure
47+
cond::persistency::Session m_targetSession;
48+
std::string m_targetConnectionString;
49+
std::string m_authPath;
50+
int m_authSys;
51+
std::string m_recordName;
52+
cond::TagInfo_t m_tagInfo;
53+
cond::LogDBEntry_t m_logDBEntry;
54+
55+
// OnlinePopCon specific
56+
int m_dbLoggerReturn_; // DB logger return value
57+
bool m_useLockRecors; // whether to lock the records or not
58+
59+
// Version
60+
static constexpr const char* const s_version = "1.0";
61+
};
62+
63+
template <typename Source>
64+
void OnlinePopCon::write(Source const& source) {
65+
// Get data to be uploaded
66+
typedef typename Source::Container Container;
67+
std::pair<Container const*, std::string const> ret = source(initialize(), m_tagInfo, m_logDBEntry);
68+
Container const& iovs = *ret.first;
69+
70+
// Check that only 1 iov/payload is provided
71+
if (iovs.size() > 1) {
72+
throw Exception("OnlinePopCon", "[write] More than one iov/payload provided!");
73+
}
74+
75+
// If zero payloads to transfer, finalize and return
76+
if (iovs.empty()) {
77+
m_dbService->logger().logInfo() << "OnlinePopCon::write - Nothing to transfer";
78+
finalize();
79+
return;
80+
}
81+
82+
// Upload
83+
// Check if DB service is available
84+
if (!m_dbService.isAvailable()) {
85+
throw Exception("OnlinePopCon", "[write] DBService not available");
86+
}
87+
88+
// Get the only payload to transfer
89+
auto [originalSince, payload] = *iovs.begin();
90+
91+
// Log the original since
92+
m_dbService->logger().logInfo() << "OnlinePopCon::write - original since: " << originalSince;
93+
94+
// Upload the payload
95+
try {
96+
auto targetSince = m_dbService->writeIOVForNextLumisection(*payload, m_recordName);
97+
m_dbService->logger().logInfo() << "OnlinePopCon::write - writeForNextLumisection successful!";
98+
m_dbService->logger().logInfo() << "OnlinePopCon::write - uploaded with since: " << targetSince;
99+
} catch (const std::exception& e) {
100+
m_dbService->logger().logError() << "OnlinePopCon::write - Error writing record: " << m_recordName;
101+
m_dbService->logger().logError() << "Error is: " << e.what();
102+
m_dbLoggerReturn_ = 2;
103+
}
104+
105+
// Finalize
106+
finalize();
107+
}
108+
109+
} // namespace popcon
110+
111+
#endif // CONDCORE_POPCON_ONLINEPOPCON_H
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef CONDCORE_POPCON_ONLINEPOPCONANALYZER_H
2+
#define CONDCORE_POPCON_ONLINEPOPCONANALYZER_H
3+
4+
//
5+
// Authors:
6+
// - Francesco Brivio (Milano-Bicocca)
7+
// - Jan Chyczynski (AGH University of Krakow)
8+
//
9+
10+
#include "CondCore/PopCon/interface/OnlinePopCon.h"
11+
#include "FWCore/Framework/interface/Frameworkfwd.h"
12+
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
13+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
14+
15+
#include <vector>
16+
17+
namespace popcon {
18+
template <typename S>
19+
class OnlinePopConAnalyzer : public edm::one::EDAnalyzer<> {
20+
public:
21+
typedef S SourceHandler;
22+
23+
OnlinePopConAnalyzer(const edm::ParameterSet& pset)
24+
: m_populator(pset), m_source(pset.getParameter<edm::ParameterSet>("Source")) {}
25+
26+
~OnlinePopConAnalyzer() override {}
27+
28+
protected:
29+
SourceHandler& source() { return m_source; }
30+
31+
private:
32+
void beginJob() override {}
33+
void endJob() override { write(); }
34+
35+
void analyze(const edm::Event&, const edm::EventSetup&) override {}
36+
37+
void write() { m_populator.write(m_source); }
38+
39+
private:
40+
OnlinePopCon m_populator;
41+
SourceHandler m_source;
42+
};
43+
44+
} // namespace popcon
45+
#endif // CONDCORE_POPCON_ONLINEPOPCONANALYZER_H

CondCore/PopCon/src/OnlinePopCon.cc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include "CondCore/CondDB/interface/ConnectionPool.h"
2+
#include "CondCore/PopCon/interface/OnlinePopCon.h"
3+
#include "FWCore/MessageLogger/interface/MessageLogger.h"
4+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
5+
6+
//#include <iostream>
7+
8+
namespace popcon {
9+
10+
constexpr const char* const OnlinePopCon::s_version;
11+
12+
OnlinePopCon::OnlinePopCon(const edm::ParameterSet& pset)
13+
: m_targetSession(),
14+
m_targetConnectionString(pset.getUntrackedParameter<std::string>("targetDBConnectionString", "")),
15+
m_authPath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
16+
m_authSys(pset.getUntrackedParameter<int>("authenticationSystem", 1)),
17+
m_recordName(pset.getParameter<std::string>("record")),
18+
m_useLockRecors(pset.getUntrackedParameter<bool>("useLockRecords", false)) {
19+
edm::LogInfo("OnlinePopCon")
20+
<< "This is OnlinePopCon (Populator of Condition) v" << s_version << ".\n"
21+
<< "Please report any problem and feature request through the JIRA project CMSCONDDB.\n";
22+
}
23+
24+
OnlinePopCon::~OnlinePopCon() {
25+
if (!m_targetConnectionString.empty()) {
26+
m_targetSession.transaction().commit();
27+
}
28+
}
29+
30+
cond::persistency::Session OnlinePopCon::preparePopCon() {
31+
// Initialization almost identical to PopCon
32+
const std::string& connectionStr = m_dbService->session().connectionString();
33+
m_dbService->forceInit();
34+
std::string tagName = m_dbService->tag(m_recordName);
35+
m_tagInfo.name = tagName;
36+
if (m_targetConnectionString.empty()) {
37+
m_targetSession = m_dbService->session();
38+
m_dbService->startTransaction();
39+
} else {
40+
cond::persistency::ConnectionPool connPool;
41+
connPool.setAuthenticationPath(m_authPath);
42+
connPool.setAuthenticationSystem(m_authSys);
43+
connPool.configure();
44+
m_targetSession = connPool.createSession(m_targetConnectionString);
45+
m_targetSession.transaction().start();
46+
}
47+
48+
m_dbService->logger().logInfo() << "OnlinePopCon::preparePopCon";
49+
m_dbService->logger().logInfo() << " destination DB: " << connectionStr;
50+
m_dbService->logger().logInfo() << " target DB: "
51+
<< (m_targetConnectionString.empty() ? connectionStr : m_targetConnectionString);
52+
53+
if (m_targetSession.existsDatabase() && m_targetSession.existsIov(tagName)) {
54+
cond::persistency::IOVProxy iov = m_targetSession.readIov(tagName);
55+
m_tagInfo.size = iov.sequenceSize();
56+
if (m_tagInfo.size > 0) {
57+
m_tagInfo.lastInterval = iov.getLast();
58+
}
59+
m_dbService->logger().logInfo() << " TAG: " << tagName << ", last since/till: " << m_tagInfo.lastInterval.since
60+
<< "/" << m_tagInfo.lastInterval.till;
61+
m_dbService->logger().logInfo() << " size: " << m_tagInfo.size;
62+
} else {
63+
m_dbService->logger().logInfo() << " TAG: " << tagName << "; First writer to this new tag.";
64+
}
65+
return m_targetSession;
66+
}
67+
68+
cond::persistency::Session OnlinePopCon::initialize() {
69+
// Check if DB service is available
70+
if (!m_dbService.isAvailable()) {
71+
throw Exception("OnlinePopCon", "[initialize] DBService not available");
72+
}
73+
74+
// Start DB logging service
75+
m_dbLoggerReturn_ = 0;
76+
m_dbService->logger().start();
77+
m_dbService->logger().logInfo() << "OnlinePopCon::initialize - begin logging for record: " << m_recordName;
78+
79+
// If requested, lock records
80+
if (m_useLockRecors) {
81+
m_dbService->logger().logInfo() << "OnlinePopCon::initialize - locking records";
82+
m_dbService->lockRecords();
83+
}
84+
85+
// Prepare the rest of PopCon infrastructure
86+
auto session = preparePopCon();
87+
return session;
88+
}
89+
90+
void OnlinePopCon::finalize() {
91+
// Check if DB service is available
92+
if (!m_dbService.isAvailable()) {
93+
throw Exception("OnlinePopCon", "[finalize] DBService not available");
94+
}
95+
96+
// Release locks if previously locked
97+
if (m_useLockRecors) {
98+
m_dbService->logger().logInfo() << "OnlinePopCon::finalize - releasing locks";
99+
m_dbService->releaseLocks();
100+
}
101+
102+
// Finalize PopCon infrastructure
103+
if (m_targetConnectionString.empty()) {
104+
m_dbService->commitTransaction();
105+
} else {
106+
m_targetSession.transaction().commit();
107+
}
108+
109+
// Stop DB logging service
110+
m_dbService->logger().logInfo() << "OnlinePopCon::finalize - end logging for record: " << m_recordName;
111+
m_dbService->logger().end(m_dbLoggerReturn_);
112+
}
113+
114+
} // namespace popcon

CondTools/RunInfo/interface/LHCInfoHelper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace cond {
1111
// Large number of LS for the OMS query, covering around 25 hours
1212
static constexpr unsigned int kLumisectionsQueryLimit = 4000;
1313

14+
// last Run number and LS number of the specified Fill
15+
std::pair<int, unsigned short> getFillLastRunAndLS(const cond::OMSService& oms, unsigned short fillId);
16+
1417
// Returns lumi-type IOV from last LS of last Run of the specified Fill
1518
cond::Time_t getFillLastLumiIOV(const cond::OMSService& oms, unsigned short fillId);
1619

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "CondCore/PopCon/interface/PopConSourceHandler.h"
2+
#include "CondFormats/RunInfo/interface/LHCInfoPerFill.h"
3+
#include "CondTools/RunInfo/interface/OMSAccess.h"
4+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
5+
6+
class LHCInfoPerFillPopConSourceHandler : public popcon::PopConSourceHandler<LHCInfoPerFill> {
7+
public:
8+
LHCInfoPerFillPopConSourceHandler(edm::ParameterSet const& pset);
9+
~LHCInfoPerFillPopConSourceHandler() override = default;
10+
11+
void getNewObjects() override;
12+
std::string id() const override;
13+
14+
private:
15+
void addEmptyPayload(cond::Time_t iov);
16+
17+
// Add payload to buffer and store corresponding lumiid IOV in m_timestampToLumiid map
18+
void addPayloadToBuffer(cond::OMSServiceResultRef& row);
19+
void convertBufferedIovsToLumiid(std::map<cond::Time_t, cond::Time_t> timestampToLumiid);
20+
21+
size_t getLumiData(const cond::OMSService& oms,
22+
unsigned short fillId,
23+
const boost::posix_time::ptime& beginFillTime,
24+
const boost::posix_time::ptime& endFillTime);
25+
26+
void getDipData(const cond::OMSService& oms,
27+
const boost::posix_time::ptime& beginFillTime,
28+
const boost::posix_time::ptime& endFillTime);
29+
30+
bool getCTPPSData(cond::persistency::Session& session,
31+
const boost::posix_time::ptime& beginFillTime,
32+
const boost::posix_time::ptime& endFillTime);
33+
34+
bool getEcalData(cond::persistency::Session& session,
35+
const boost::posix_time::ptime& lowerTime,
36+
const boost::posix_time::ptime& upperTime);
37+
38+
private:
39+
bool m_debug;
40+
// starting date for sampling
41+
boost::posix_time::ptime m_startTime;
42+
boost::posix_time::ptime m_endTime;
43+
bool m_endFillMode = true;
44+
std::string m_name;
45+
//for reading from relational database source
46+
std::string m_connectionString, m_ecalConnectionString;
47+
std::string m_authpath;
48+
std::string m_omsBaseUrl;
49+
std::unique_ptr<LHCInfoPerFill> m_fillPayload;
50+
std::shared_ptr<LHCInfoPerFill> m_prevPayload;
51+
std::vector<std::pair<cond::Time_t, std::shared_ptr<LHCInfoPerFill>>> m_tmpBuffer;
52+
bool m_lastPayloadEmpty = false;
53+
// to hold correspondance between timestamp-type IOVs and lumiid-type IOVs
54+
std::map<cond::Time_t, cond::Time_t> m_timestampToLumiid;
55+
};

0 commit comments

Comments
 (0)