CMS 3D CMS Logo

PoolDBOutputService.cc
Go to the documentation of this file.
11 //
12 #include <vector>
13 #include <memory>
14 #include <cassert>
15 
16 //In order to make PoolDBOutputService::currentTime() to work we have to keep track
17 // of which stream is presently being processed on a given thread during the call of
18 // a module which calls that method.
19 static thread_local int s_streamIndex = -1;
20 
22  Record thisrecord;
23 
24  thisrecord.m_idName = pset.getParameter<std::string>("record");
25  thisrecord.m_tag = pset.getParameter<std::string>("tag");
26 
27  thisrecord.m_closeIOV = pset.getUntrackedParameter<bool>("closeIOV", m_closeIOV);
28 
29  thisrecord.m_timetype =
31 
32  m_callbacks.insert(std::make_pair(thisrecord.m_idName, thisrecord));
33 
34  cond::UserLogInfo userloginfo;
35  m_logheaders.insert(std::make_pair(thisrecord.m_idName, userloginfo));
36 }
37 
39  : m_timetypestr(""),
41  m_session(),
42  m_dbstarted(false),
43  m_callbacks(),
44  m_closeIOV(false),
45  m_logheaders() {
46  m_closeIOV = iConfig.getUntrackedParameter<bool>("closeIOV", m_closeIOV);
47 
48  m_timetypestr = iConfig.getUntrackedParameter<std::string>("timetype", "runnumber");
50 
51  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
53  connection.setParameters(connectionPset);
54  connection.configure();
55  std::string connectionString = iConfig.getParameter<std::string>("connect");
56  m_session = connection.createSession(connectionString, true);
57 
58  typedef std::vector<edm::ParameterSet> Parameters;
59  Parameters toPut = iConfig.getParameter<Parameters>("toPut");
60  for (Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
61  fillRecord(*itToPut);
62 
63  iAR.watchPostEndJob(this, &cond::service::PoolDBOutputService::postEndJob);
64  iAR.watchPreallocate(
65  [this](edm::service::SystemBounds const& iBounds) { m_currentTimes.resize(iBounds.maxNumberOfStreams()); });
66  if (m_timetype == cond::timestamp) { //timestamp
68  iAR.watchPreModuleEvent(this, &cond::service::PoolDBOutputService::preModuleEvent);
69  iAR.watchPostModuleEvent(this, &cond::service::PoolDBOutputService::postModuleEvent);
70  } else if (m_timetype == cond::runnumber) { //runnumber
71  //NOTE: this assumes only one run is being processed at a time.
72  // This is true for 7_1_X but plan are to allow multiple in flight at a time
73  s_streamIndex = 0;
74  iAR.watchPreGlobalBeginRun(this, &cond::service::PoolDBOutputService::preGlobalBeginRun);
75  } else if (m_timetype == cond::lumiid) {
76  //NOTE: this assumes only one lumi is being processed at a time.
77  // This is true for 7_1_X but plan are to allow multiple in flight at a time
78  s_streamIndex = 0;
79  iAR.watchPreGlobalBeginLumi(this, &cond::service::PoolDBOutputService::preGlobalBeginLumi);
80  }
81 }
82 
84 
86  return this->lookUpRecord(recordName).m_tag;
87 }
88 
90  Record& myrecord = this->lookUpRecord(recordName);
91  return myrecord.m_isNewTag;
92 }
93 
95  std::lock_guard<std::recursive_mutex> lock(m_mutex);
97  scope.start(false);
98  try {
101 
102  } catch (const std::exception& er) {
103  cond::throwException(std::string(er.what()), "PoolDBOutputService::initDB");
104  }
105  scope.close();
106  m_dbstarted = true;
107 }
108 
110  if (m_dbstarted) {
112  m_dbstarted = false;
113  }
114 }
115 
117  m_currentTimes[iContext.streamID().value()] = iContext.timestamp().value();
118 }
119 
121  edm::ModuleCallingContext const&) {
122  s_streamIndex = iContext.streamID().value();
123 }
124 
126  edm::ModuleCallingContext const&) {
127  s_streamIndex = -1;
128 }
129 
131  for (auto& time : m_currentTimes) {
132  time = iContext.luminosityBlockID().run();
133  }
134 }
135 
137  for (auto& time : m_currentTimes) {
138  time = iContext.luminosityBlockID().value();
139  }
140 }
141 
143  if (m_dbstarted) {
145  }
146 }
147 
149  std::lock_guard<std::recursive_mutex> lock(m_mutex);
150  if (!m_dbstarted)
151  initDB();
152 }
153 
155 
157 
159  assert(-1 != s_streamIndex);
161 }
162 
164  const std::string payloadType,
165  cond::Time_t firstSinceTime,
166  cond::Time_t firstTillTime,
167  const std::string& recordName,
168  bool withlogging) {
169  std::lock_guard<std::recursive_mutex> lock(m_mutex);
170 
172  Record& myrecord = this->lookUpRecord(recordName);
173  if (!myrecord.m_isNewTag) {
174  cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
175  }
176  std::string iovToken;
177 
178  try {
179  // FIX ME: synchronization type and description have to be passed as the other parameters?
181  m_session.createIov(payloadType, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY);
182  editor.setDescription("New Tag");
183  editor.insert(firstSinceTime, firstPayloadId);
184  cond::UserLogInfo a = this->lookUpUserLogInfo(recordName);
185  editor.flush(a.usertext);
186  myrecord.m_isNewTag = false;
187  } catch (const std::exception& er) {
188  cond::throwException(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ",
189  "PoolDBOutputService::createNewIOV");
190  }
191  scope.close();
192 }
193 
195  cond::Time_t firstSinceTime,
196  cond::Time_t firstTillTime,
197  const std::string& recordName,
198  bool withlogging) {
199  std::lock_guard<std::recursive_mutex> lock(m_mutex);
201  Record& myrecord = this->lookUpRecord(recordName);
202  if (!myrecord.m_isNewTag) {
203  cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
204  }
205  std::string iovToken;
207  try {
208  // FIX ME: synchronization type and description have to be passed as the other parameters?
210  m_session.createIovForPayload(firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY);
211  editor.setDescription("New Tag");
212  payloadType = editor.payloadType();
213  editor.insert(firstSinceTime, firstPayloadId);
214  cond::UserLogInfo a = this->lookUpUserLogInfo(recordName);
215  editor.flush(a.usertext);
216  myrecord.m_isNewTag = false;
217  } catch (const std::exception& er) {
218  cond::throwException(std::string(er.what()) + " from PoolDBOutputService::createNewIOV ",
219  "PoolDBOutputService::createNewIOV");
220  }
221  scope.close();
222 }
223 
226  const std::string& recordName,
227  bool withlogging) {
228  std::lock_guard<std::recursive_mutex> lock(m_mutex);
230  Record& myrecord = this->lookUpRecord(recordName);
231  if (myrecord.m_isNewTag) {
232  cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
233  "PoolDBOutputService::appendSinceTime");
234  }
236  try {
237  cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
238  payloadType = editor.payloadType();
239  editor.insert(time, payloadId);
240  cond::UserLogInfo a = this->lookUpUserLogInfo(recordName);
241  editor.flush(a.usertext);
242 
243  } catch (const std::exception& er) {
244  cond::throwException(std::string(er.what()), "PoolDBOutputService::appendSinceTime");
245  }
246  scope.close();
247 }
248 
250  const std::string& recordName) {
251  std::lock_guard<std::recursive_mutex> lock(m_mutex);
252  if (!m_dbstarted)
253  this->initDB();
255  std::map<std::string, Record>::iterator it = m_callbacks.find(recordName);
256  if (it == m_callbacks.end()) {
257  cond::throwException("The record \"" + recordName + "\" has not been registered.",
258  "PoolDBOutputService::lookUpRecord");
259  }
260  if (!m_session.existsIov(it->second.m_tag)) {
261  it->second.m_isNewTag = true;
262  } else {
263  it->second.m_isNewTag = false;
264  }
265  scope.close();
266  return it->second;
267 }
268 
270  std::map<std::string, cond::UserLogInfo>::iterator it = m_logheaders.find(recordName);
271  if (it == m_logheaders.end())
272  throw cond::Exception("Log db was not set for record " + recordName +
273  " from PoolDBOutputService::lookUpUserLogInfo");
274  return it->second;
275 }
276 
278  std::lock_guard<std::recursive_mutex> lock(m_mutex);
279  // not fully working.. not be used for now...
280  Record& myrecord = lookUpRecord(recordName);
282 
283  if (myrecord.m_isNewTag) {
284  cond::throwException(std::string("Cannot close non-existing tag ") + myrecord.m_tag,
285  "PoolDBOutputService::closeIOV");
286  }
288  editor.setEndOfValidity(lastTill);
289  editor.flush("Tag closed.");
290  scope.close();
291 }
292 
294  const std::string& dataprovenance,
295  const std::string& usertext) {
296  cond::UserLogInfo& myloginfo = this->lookUpUserLogInfo(recordName);
297  myloginfo.provenance = dataprovenance;
298  myloginfo.usertext = usertext;
299 }
300 
301 // Still required.
303  //
304  std::lock_guard<std::recursive_mutex> lock(m_mutex);
305  Record& record = lookUpRecord(recordName);
306  result.name = record.m_tag;
307  //use iovproxy to find out.
309  result.size = iov.sequenceSize();
310  if (result.size > 0) {
311  cond::Iov_t last = iov.getLast();
312  result.lastInterval = cond::ValidityInterval(last.since, last.till);
313  result.lastPayloadToken = last.payloadId;
314  }
315 }
static thread_local int s_streamIndex
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
Base exception class for the object to relational access.
Definition: Exception.h:11
void closeIOV(Time_t lastTill, const std::string &recordName, bool withlogging=false)
void preEventProcessing(edm::StreamContext const &)
Time_t beginValue
Definition: Time.h:41
JetCorrectorParameters::Record record
Definition: classes.h:7
std::string provenance
Definition: Types.h:23
void fillRecord(edm::ParameterSet &pset)
std::map< std::string, cond::UserLogInfo > m_logheaders
cond::persistency::Session session() const
Time_t since
Definition: Types.h:53
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:55
std::vector< cond::Time_t > m_currentTimes
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:190
size_t size
Definition: Types.h:76
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
void setDescription(const std::string &description)
Definition: IOVEditor.cc:111
void preGlobalBeginLumi(edm::GlobalContext const &)
Transaction & transaction()
Definition: Session.cc:43
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
void setParameters(const edm::ParameterSet &connectionPset)
std::string tag(const std::string &recordName)
std::string name
Definition: Types.h:72
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
cond::ValidityInterval lastInterval
Definition: Types.h:74
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:54
unsigned long long Time_t
Definition: Time.h:14
vector< ParameterSet > Parameters
TimeType timeTypeFromName(const std::string &name)
Definition: Time.cc:25
bool isNewTagRequest(const std::string &recordName)
Record & lookUpRecord(const std::string &recordName)
Hash payloadId
Definition: Types.h:55
RunNumber_t run() const
void start(bool readOnly=true)
Definition: Session.cc:236
uint64_t value() const
cond::persistency::Session m_session
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
StreamID const & streamID() const
Definition: StreamContext.h:54
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:139
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:136
unsigned int value() const
Definition: StreamID.h:42
void tagInfo(const std::string &recordName, cond::TagInfo_t &result)
std::string lastPayloadToken
Definition: Types.h:75
bool existsIov(const std::string &tag)
Definition: Session.cc:68
void preGlobalBeginRun(edm::GlobalContext const &)
std::string usertext
Definition: Types.h:24
double a
Definition: hdecay.h:119
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
void setEndOfValidity(cond::Time_t validity)
Definition: IOVEditor.cc:101
std::map< std::string, Record > m_callbacks
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.cc:123
Time_t endValue
Definition: Time.h:42
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
std::string payloadType() const
Definition: IOVEditor.cc:85
cond::UserLogInfo & lookUpUserLogInfo(const std::string &recordName)
TimeValue_t value() const
Definition: Timestamp.h:45
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
Timestamp const & timestamp() const
Definition: StreamContext.h:62
Time_t till
Definition: Types.h:54