38 : m_logger(iConfig.getUntrackedParameter<std::
string>(
"jobName",
"DBOutputService")),
41 m_transactionActive(
false),
42 m_dbInitialised(
false),
47 m_autoCommit =
iConfig.getUntrackedParameter<
bool>(
"autoCommit",
false);
48 m_writeTransactionDelay =
iConfig.getUntrackedParameter<
unsigned int>(
"writeTransactionDelay", 0);
50 m_connection.setParameters(connectionPset);
51 m_connection.setLogDestination(m_logger);
52 m_connection.configure();
54 m_session = m_connection.createSession(connectionString,
true);
55 bool saveLogsOnDb =
iConfig.getUntrackedParameter<
bool>(
"saveLogsOnDB",
false);
57 m_logger.setDbDestination(connectionString);
60 typedef std::vector<edm::ParameterSet>
Parameters;
61 Parameters
toPut =
iConfig.getParameter<Parameters>(
"toPut");
62 for (Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
63 fillRecord(*itToPut, timetypestr);
88 ret = m_connection.createReadOnlySession(connectionString, transactionId);
95 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
99 for (
auto& iR : m_records) {
100 if (iR.second.m_isNewTag ==
false) {
105 doCommitTransaction();
110 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
111 doStartTransaction();
114 for (
auto& iR : m_records) {
115 if (iR.second.m_isNewTag ==
false) {
120 doCommitTransaction();
125 return this->lookUpRecord(recordName).m_tag;
129 Record& myrecord = this->lookUpRecord(recordName);
134 if (!m_transactionActive) {
135 m_session.transaction().start(
false);
136 m_transactionActive =
true;
141 if (m_transactionActive) {
142 m_session.transaction().commit();
143 m_transactionActive =
false;
148 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
149 doStartTransaction();
153 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
154 doCommitTransaction();
158 if (!m_dbInitialised) {
159 if (!m_session.existsDatabase())
160 m_session.createDatabase();
162 for (
auto& iR : m_records) {
163 if (m_session.existsIov(iR.second.m_tag))
164 iR.second.m_isNewTag =
false;
167 m_dbInitialised =
true;
188 for (
auto& time : m_currentTimes) {
194 for (
auto& time : m_currentTimes) {
202 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
203 doStartTransaction();
225 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
226 Record& myrecord = this->lookUpRecord(recordName);
230 m_logger.logInfo() <<
"Creating new tag " << myrecord.
m_tag <<
", adding iov with since " << firstSinceTime
231 <<
" pointing to payload id " << firstPayloadId;
232 doStartTransaction();
239 editor.
insert(firstSinceTime, firstPayloadId);
253 m_logger.logInfo() <<
"Creating new tag " << myrecord.
m_tag <<
" for payload type " << payloadType
254 <<
", adding iov with since " << firstSinceTime;
259 editor.
insert(firstSinceTime, firstPayloadId);
268 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
269 Record& myrecord = this->lookUpRecord(recordName);
272 "PoolDBOutputService::appendSinceTime");
275 doStartTransaction();
278 ret = appendSinceTime(payloadId, time, myrecord);
289 m_logger.logInfo() <<
"Updating existing tag " << myrecord.
m_tag <<
", adding iov with since " << time;
292 editor.
insert(time, payloadId);
304 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
305 Record& myrecord = this->lookUpRecord(recordName);
308 "PoolDBOutputService::appendSinceTime");
310 m_logger.logInfo() <<
"Updating existing tag " << myrecord.
m_tag <<
", removing iov with since " << sinceTime
311 <<
" pointing to payload id " << payloadId;
312 doStartTransaction();
316 editor.
erase(sinceTime, payloadId);
328 std::map<std::string, Record>::iterator it = m_records.find(recordName);
329 if (it == m_records.end()) {
331 "PoolDBOutputService::lookUpRecord");
337 std::map<std::string, cond::UserLogInfo>::iterator it = m_logheaders.find(recordName);
338 if (it == m_logheaders.end())
340 " from PoolDBOutputService::lookUpUserLogInfo");
345 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
346 Record& myrecord = lookUpRecord(recordName);
349 "PoolDBOutputService::closeIOV");
351 m_logger.logInfo() <<
"Updating existing tag " << myrecord.
m_tag <<
", closing with end of validity " << lastTill;
352 doStartTransaction();
357 editor.
flush(
"Tag closed.");
376 m_logger.logDebug() <<
"Fetching tag info for " << record.
m_tag;
377 doStartTransaction();
382 if (m_session.existsIov(record.
m_tag)) {
396 std::lock_guard<std::recursive_mutex>
lock(m_mutex);
397 return getTagInfo(recordName, result);
static thread_local int s_streamIndex
const TimeTypeSpecs timeTypeSpecs[]
T getUntrackedParameter(std::string const &, T const &) const
tuple ret
prodAgent to be discontinued
Base exception class for the object to relational access.
void preEventProcessing(edm::StreamContext const &)
void fillRecord(edm::ParameterSet &pset, const std::string &gTimeTypeStr)
std::map< std::string, cond::UserLogInfo > m_logheaders
cond::persistency::Session session() const
void doStartTransaction()
LuminosityBlockID const & luminosityBlockID() const
void setDescription(const std::string &description)
void preGlobalBeginLumi(edm::GlobalContext const &)
void throwException(const std::string &message, const std::string &methodName)
std::string tag(const std::string &recordName)
void appendSinceTime(const T *payloadPtr, cond::Time_t sinceTime, const std::string &recordName)
unsigned int maxNumberOfStreams() const
void closeIOV(Time_t lastTill, const std::string &recordName)
unsigned long long Time_t
vector< ParameterSet > Parameters
TimeType timeTypeFromName(const std::string &name)
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
cond::Time_t beginOfTime() const
void erase(cond::Time_t since, const cond::Hash &payloadHash)
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
StreamID const & streamID() const
std::map< std::string, Record > m_records
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
unsigned int value() const
virtual ~PoolDBOutputService()
T getParameter(std::string const &) const
cond::Time_t endOfTime() const
void preGlobalBeginRun(edm::GlobalContext const &)
bool m_onlyAppendUpdatePolicy
bool getTagInfo(const std::string &recordName, cond::TagInfo_t &result)
cond::persistency::Session newReadOnlySession(const std::string &connectionString, const std::string &transactionId)
cond::Time_t currentTime() const
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
void setEndOfValidity(cond::Time_t validity)
cond::TimeType m_timetype
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
void eraseSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)
cond::UserLogInfo & lookUpUserLogInfo(const std::string &recordName)
TimeValue_t value() const
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
void createNewIOV(const T *payloadPtr, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Timestamp const & timestamp() const
void doCommitTransaction()