CMS 3D CMS Logo

CondDBESSource.cc
Go to the documentation of this file.
1 //
2 // Package: CondCore/ESSources
3 // Module: CondDBESSource
4 //
5 // Description: <one line class summary>
6 //
7 // Implementation:
8 // <Notes on implementation>
9 //
10 // Author: Zhen Xie
11 // Fixes and other changes: Giacomo Govi
12 //
13 #include "CondDBESSource.h"
14 
15 #include <boost/algorithm/string.hpp>
20 
23 
29 #include <exception>
30 
31 #include <iomanip>
32 
33 namespace {
34  /* utility ot build the name of the plugin corresponding to a given record
35  se ESSources
36  */
37  std::string buildName(std::string const& iRecordName) { return iRecordName + std::string("@NewProxy"); }
38 
39  std::string joinRecordAndLabel(std::string const& iRecordName, std::string const& iLabelName) {
40  return iRecordName + std::string("@") + iLabelName;
41  }
42 
43  /* utility class to return a IOVs associated to a given "name"
44  This implementation return the IOV associated to a record...
45  It is essentialy a workaround to get the full IOV out of the tag colector
46  that is not accessible as hidden in the ESSource
47  FIXME: need to support label??
48  */
49  class CondGetterFromESSource : public cond::persistency::CondGetter {
50  public:
51  CondGetterFromESSource(CondDBESSource::ProxyMap const& ip) : m_proxies(ip) {}
52  ~CondGetterFromESSource() override {}
53 
54  cond::persistency::IOVProxy get(std::string name) const override {
55  CondDBESSource::ProxyMap::const_iterator p = m_proxies.find(name);
56  if (p != m_proxies.end())
57  return (*p).second->iovProxy();
59  }
60 
61  CondDBESSource::ProxyMap const& m_proxies;
62  };
63 
64  // This needs to be re-design and implemented...
65  // dump the state of a DataProxy
66  void dumpInfo(std::ostream& out, std::string const& recName, cond::DataProxyWrapperBase const& proxy) {
67  //cond::SequenceState state(proxy.proxy()->iov().state());
68  out << recName << " / " << proxy.label() << ": " << proxy.connString() << ", " << proxy.tag()
69  << "\n "
70  // << state.size() << ", " << state.revision() << ", "
71  // << cond::time::to_boost(state.timestamp()) << "\n "
72  // << state.comment()
73  << "\n "
74  // << "refresh " << proxy.proxy()->stats.nRefresh
75  // << "/" << proxy.proxy()->stats.nArefresh
76  // << ", reconnect " << proxy.proxy()->stats.nReconnect
77  // << "/" << proxy.proxy()->stats.nAreconnect
78  // << ", make " << proxy.proxy()->stats.nMake
79  // << ", load " << proxy.proxy()->stats.nLoad
80  ;
81  //if ( proxy.proxy()->stats.nLoad>0) {
82  out << "Time look up, payloadIds:" << std::endl;
83  const auto& pids = *proxy.requests();
84  for (const auto& id : pids)
85  out << " " << id.since << " - " << id.till << " : " << id.payloadId << std::endl;
86  }
87 
88 } // namespace
89 
90 /*
91  * config Param
92  * RefreshEachRun: if true will refresh the IOV at each new run (or lumiSection)
93  * DumpStat: if true dump the statistics of all DataProxy (currently on cout)
94  * DBParameters: configuration set of the connection
95  * globaltag: The GlobalTag
96  * toGet: list of record label tag connection-string to add/overwrite the content of the global-tag
97  */
99  : m_connection(),
100  m_connectionString(""),
101  m_frontierKey(""),
102  m_lastRun(0), // for the stat
103  m_lastLumi(0), // for the stat
104  m_policy(NOREFRESH),
105  m_doDump(iConfig.getUntrackedParameter<bool>("DumpStat", false)) {
106  if (iConfig.getUntrackedParameter<bool>("RefreshAlways", false)) {
108  }
109  if (iConfig.getUntrackedParameter<bool>("RefreshOpenIOVs", false)) {
111  }
112  if (iConfig.getUntrackedParameter<bool>("RefreshEachRun", false)) {
114  }
115  if (iConfig.getUntrackedParameter<bool>("ReconnectEachRun", false)) {
117  }
118 
119  Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
120  m_stats = s;
121 
122  /*parameter set parsing
123  */
125  if (iConfig.exists("globaltag")) {
126  globaltag = iConfig.getParameter<std::string>("globaltag");
127  // the global tag _requires_ a connection string
128  m_connectionString = iConfig.getParameter<std::string>("connect");
129 
130  if (!globaltag.empty()) {
132  if (siteLocalConfig.isAvailable()) {
133  if (siteLocalConfig->useLocalConnectString()) {
134  std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix();
135  std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix();
136  m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
137  }
138  }
139  }
140  } else if (iConfig.exists("connect")) // default connection string
141  m_connectionString = iConfig.getParameter<std::string>("connect");
142 
143  // frontier key
144  m_frontierKey = iConfig.getUntrackedParameter<std::string>("frontierKey", "");
145 
146  // snapshot
147  boost::posix_time::ptime snapshotTime;
148  if (iConfig.exists("snapshotTime")) {
149  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime");
150  if (!snapshotTimeString.empty())
151  snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
152  }
153 
154  // connection configuration
155  if (iConfig.exists("DBParameters")) {
156  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
157  m_connection.setParameters(connectionPset);
158  }
160 
161  // load specific record/tag info - it will overwrite the global tag ( if any )
162  std::map<std::string, cond::GTEntry_t> replacements;
163  std::map<std::string, boost::posix_time::ptime> specialSnapshots;
164  if (iConfig.exists("toGet")) {
165  typedef std::vector<edm::ParameterSet> Parameters;
166  Parameters toGet = iConfig.getParameter<Parameters>("toGet");
167  for (Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet) {
168  std::string recordname = itToGet->getParameter<std::string>("record");
169  if (recordname.empty())
170  throw cond::Exception("ESSource: The record name has not been provided in a \"toGet\" entry.");
171  std::string labelname = itToGet->getUntrackedParameter<std::string>("label", "");
172  std::string pfn("");
173  if (m_connectionString.empty() || itToGet->exists("connect"))
174  pfn = itToGet->getParameter<std::string>("connect");
175  std::string tag("");
176  std::string fqTag("");
177  if (itToGet->exists("tag")) {
178  tag = itToGet->getParameter<std::string>("tag");
180  }
181  boost::posix_time::ptime tagSnapshotTime =
182  boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP));
183  if (itToGet->exists("snapshotTime"))
184  tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<std::string>("snapshotTime"));
185  if (itToGet->exists("refreshTime")) {
186  cond::Time_t refreshTime = itToGet->getParameter<unsigned long long>("refreshTime");
187  m_refreshTimeForRecord.insert(std::make_pair(recordname, std::make_pair(refreshTime, true)));
188  }
189 
190  std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
191  replacements.insert(
192  std::make_pair(recordLabelKey, cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
193  specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
194  }
195  }
196 
197  // get the global tag, merge with "replacement" store in "tagCollection"
198  std::vector<std::string> globaltagList;
199  std::vector<std::string> connectList;
200  std::vector<std::string> pfnPrefixList;
201  std::vector<std::string> pfnPostfixList;
202  if (!globaltag.empty()) {
203  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>("pfnPrefix", ""));
204  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>("pfnPostfix", ""));
205  boost::split(globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off);
206  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
207  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
208  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
209  }
210 
211  cond::GTMetadata_t gtMetadata;
212  fillTagCollectionFromDB(connectList, pfnPrefixList, pfnPostfixList, globaltagList, replacements, gtMetadata);
213  // if no job specific setting has been found, use the GT timestamp
214  if (snapshotTime.is_not_a_date_time())
215  snapshotTime = gtMetadata.snapshotTime;
216 
217  TagCollection::iterator it;
218  TagCollection::iterator itBeg = m_tagCollection.begin();
219  TagCollection::iterator itEnd = m_tagCollection.end();
220 
221  std::map<std::string, cond::persistency::Session> sessions;
222 
223  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
224  * construct proxy
225  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
226  * dinstinguished only by their label...
227  * done in two step: first create ProxyWrapper loading ALL required dictionaries
228  * this will allow to initialize POOL in one go for each "database"
229  * The real initialization of the Data-Proxies is done in the second loop
230  */
231  std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(m_tagCollection.size());
232  size_t ipb = 0;
233  for (it = itBeg; it != itEnd; ++it) {
234  size_t ind = ipb++;
235  proxyWrappers[ind] = std::unique_ptr<cond::DataProxyWrapperBase>{
236  cond::ProxyFactory::get()->tryToCreate(buildName(it->second.recordName()))};
237  if (!proxyWrappers[ind].get()) {
238  edm::LogWarning("CondDBESSource") << "Plugin for Record " << it->second.recordName() << " has not been found.";
239  }
240  }
241 
242  // now all required libraries have been loaded
243  // init sessions and DataProxies
244  ipb = 0;
245  for (it = itBeg; it != itEnd; ++it) {
247  std::string tag = it->second.tagName();
248  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(it->second.tagName());
249  if (!tagParams.second.empty()) {
250  connStr = tagParams.second;
251  tag = tagParams.first;
252  }
253  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
255  if (p == sessions.end()) {
257  std::tuple<std::string, std::string, std::string> connPars =
259  std::string dbService = std::get<1>(connPars);
260  std::string dbAccount = std::get<2>(connPars);
261  if ((dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS")
262  edm::LogWarning("CondDBESSource")
263  << "[WARNING] You are reading tag \"" << tag << "\" from V1 account \"" << connStr
264  << "\". The concerned Conditions might be out of date." << std::endl;
265  //open db get tag info (i.e. the IOV token...)
266  nsess = m_connection.createReadOnlySession(connStr, "");
267  sessions.insert(std::make_pair(connStr, nsess));
268  } else
269  nsess = (*p).second;
270 
271  // ownership...
272  ProxyP proxy(std::move(proxyWrappers[ipb++]));
273  // instert in the map
274  if (proxy.get()) {
275  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
276  // initialize
277  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
278  auto tagSnapshotIter = specialSnapshots.find(it->first);
279  if (tagSnapshotIter != specialSnapshots.end())
280  tagSnapshotTime = tagSnapshotIter->second;
281  // finally, if the snapshot is set to infinity, reset the snapshot to null, to take the full iov set...
282  if (tagSnapshotTime == boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP)))
283  tagSnapshotTime = boost::posix_time::ptime();
284 
285  proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr, &m_queue, &m_mutex);
286  }
287  }
288 
289  // one loaded expose all other tags to the Proxy!
290  CondGetterFromESSource visitor(m_proxies);
291  ProxyMap::iterator b = m_proxies.begin();
292  ProxyMap::iterator e = m_proxies.end();
293  for (; b != e; b++) {
294  (*b).second->proxy(0)->loadMore(visitor);
295 
298  if (recordKey.type() != EventSetupRecordKey::TypeTag()) {
299  findingRecordWithKey(recordKey);
300  usingRecordWithKey(recordKey);
301  }
302  }
303 
304  m_stats.nData = m_proxies.size();
305 }
306 
307 void CondDBESSource::fillList(const std::string& stringList,
308  std::vector<std::string>& listToFill,
309  const unsigned int listSize,
310  const std::string& type) {
311  boost::split(listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off);
312  // If it is one clone it for each GT
313  if (listToFill.size() == 1) {
314  for (unsigned int i = 1; i < listSize; ++i) {
315  listToFill.push_back(stringList);
316  }
317  }
318  // else if they don't match the number of GTs throw an exception
319  else if (listSize != listToFill.size()) {
320  throw cond::Exception(
321  std::string("ESSource: number of global tag components does not match number of " + type + " strings"));
322  }
323 }
324 
326  //dump info FIXME: find a more suitable place...
327  if (m_doDump) {
328  std::cout << "CondDBESSource Statistics" << std::endl
329  << "DataProxy " << m_stats.nData << " setInterval " << m_stats.nSet << " Runs " << m_stats.nRun
330  << " Lumis " << m_stats.nLumi << " Refresh " << m_stats.nRefresh << " Actual Refresh "
331  << m_stats.nActualRefresh << " Reconnect " << m_stats.nReconnect << " Actual Reconnect "
333  std::cout << std::endl;
334 
335  ProxyMap::iterator b = m_proxies.begin();
336  ProxyMap::iterator e = m_proxies.end();
337  for (; b != e; b++) {
338  dumpInfo(std::cout, (*b).first, *(*b).second);
339  std::cout << "\n" << std::endl;
340  }
341 
342  // FIXME
343  // We shall eventually close transaction and session...
344  }
345 }
346 
347 //
348 // invoked by EventSetUp: for a given record return the smallest IOV for which iTime is valid
349 // limit to next run/lumisection of Refresh is required
350 //
352  const edm::IOVSyncValue& iTime,
353  edm::ValidityInterval& oInterval) {
354  std::string recordname = iKey.name();
355 
356  edm::LogInfo("CondDBESSource") << "Getting data for record \"" << recordname
357  << "\" to be consumed on Run: " << iTime.eventID().run()
358  << " - Lumiblock:" << iTime.luminosityBlockNumber()
359  << " - Timestamp: " << iTime.time().value() << "; from CondDBESSource::setIntervalFor";
360 
361  std::lock_guard<std::mutex> guard(m_mutex);
362  m_stats.nSet++;
363 
364  if (iTime.eventID().run() != m_lastRun) {
365  m_lastRun = iTime.eventID().run();
366  m_stats.nRun++;
367  }
368  if (iTime.luminosityBlockNumber() != m_lastLumi) {
370  m_stats.nLumi++;
371  }
372 
373  bool doRefresh = false;
374  cond::Time_t defaultIovSize = cond::time::MAX_VAL;
375  bool refreshThisRecord = false;
376  bool reconnectThisRecord = false;
377 
378  auto iR = m_refreshTimeForRecord.find(recordname);
379  refreshThisRecord = iR != m_refreshTimeForRecord.end();
380  if (refreshThisRecord) {
381  defaultIovSize = iR->second.first;
382  reconnectThisRecord = iR->second.second;
383  iR->second.second = false;
384  }
385 
387  // find out the last run number for the proxy of the specified record
388  std::map<std::string, unsigned int>::iterator iRec = m_lastRecordRuns.find(recordname);
389  if (iRec != m_lastRecordRuns.end()) {
390  cond::Time_t lastRecordRun = iRec->second;
391  if (lastRecordRun != m_lastRun) {
392  // a refresh is required!
393  doRefresh = true;
394  iRec->second = m_lastRun;
395  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname
396  << "\" since there has been a transition from run/lumi " << lastRecordRun
397  << " to run/lumi " << m_lastRun << "; from CondDBESSource::setIntervalFor";
398  }
399  } else {
400  doRefresh = true;
401  m_lastRecordRuns.insert(std::make_pair(recordname, m_lastRun));
402  edm::LogInfo("CondDBESSource") << "Preparing refresh for record \"" << recordname << "\" for " << iTime.eventID()
403  << ", timestamp: " << iTime.time().value()
404  << "; from CondDBESSource::setIntervalFor";
405  }
406  if (!doRefresh)
407  edm::LogInfo("CondDBESSource") << "Though enabled, refresh not needed for record \"" << recordname << "\" for "
408  << iTime.eventID() << ", timestamp: " << iTime.time().value()
409  << "; from CondDBESSource::setIntervalFor";
410  } else if (m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS) {
411  doRefresh = true;
412  edm::LogInfo("CondDBESSource") << "Forcing refresh for record \"" << recordname << "\" for " << iTime.eventID()
413  << ", timestamp: " << iTime.time().value()
414  << "; from CondDBESSource::setIntervalFor";
415  }
416 
418 
419  // compute the smallest interval (assume all objects have the same timetype....)
420  cond::ValidityInterval recordValidity(1, cond::TIMELIMIT);
421  cond::TimeType timetype = cond::TimeType::invalid;
422  bool userTime = true;
423 
424  //FIXME use equal_range
425  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
426  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
427  if (pmBegin == pmEnd) {
428  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
429  << "\"; from CondDBESSource::setIntervalFor";
430  return;
431  }
432 
433  for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
434  edm::LogInfo("CondDBESSource") << "Processing record \"" << recordname << "\" and label \""
435  << pmIter->second->label() << "\" for " << iTime.eventID()
436  << ", timestamp: " << iTime.time().value()
437  << "; from CondDBESSource::setIntervalFor";
438 
439  timetype = (*pmIter).second->timeType();
440 
442  userTime = (0 == abtime);
443 
444  if (userTime)
445  return; // oInterval invalid to avoid that make is called...
446 
447  if (doRefresh || refreshThisRecord) {
448  std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
449  TagCollection::const_iterator tcIter = m_tagCollection.find(recKey);
450  if (tcIter == m_tagCollection.end()) {
451  edm::LogInfo("CondDBESSource") << "No Tag found for record \"" << recordname << "\" and label \""
452  << pmIter->second->label() << "\"; from CondDBESSource::setIntervalFor";
453  return;
454  }
455 
456  // first reconnect if required
457  if (m_policy == RECONNECT_EACH_RUN || reconnectThisRecord) {
458  edm::LogInfo("CondDBESSource")
459  << "Checking if the session must be closed and re-opened for getting correct conditions"
460  << "; from CondDBESSource::setIntervalFor";
461  std::string transId;
462  if (!reconnectThisRecord) {
463  transId = std::to_string(abtime);
464  } else {
465  transId = cond::time::transactionIdForLumiTime(abtime, defaultIovSize, m_frontierKey);
466  }
468  std::pair<std::string, std::string> tagParams = cond::persistency::parseTag(tcIter->second.tagName());
469  if (!tagParams.second.empty())
470  connStr = tagParams.second;
471  std::map<std::string, std::pair<cond::persistency::Session, std::string>>* sessionPool = &m_sessionPool;
472  if (refreshThisRecord) {
473  sessionPool = &m_sessionPoolForLumiConditions;
474  }
475  auto iSess = sessionPool->find(connStr);
476  bool reopen = false;
477  if (iSess != sessionPool->end()) {
478  if (iSess->second.second != transId) {
479  // the available session is open for a different run: reopen
480  reopen = true;
481  iSess->second.second = transId;
482  }
483  } else {
484  // no available session: probably first run analysed...
485  iSess =
486  sessionPool->insert(std::make_pair(connStr, std::make_pair(cond::persistency::Session(), transId))).first;
487  reopen = true;
488  }
489  if (reopen) {
490  iSess->second.first = m_connection.createReadOnlySession(connStr, transId);
491  edm::LogInfo("CondDBESSource") << "Re-opening the session with connection string " << connStr
492  << " and new transaction Id " << transId
493  << "; from CondDBESSource::setIntervalFor";
494  }
495 
496  edm::LogInfo("CondDBESSource") << "Reconnecting to \"" << connStr << "\" for getting new payload for record \""
497  << recordname << "\" and label \"" << pmIter->second->label()
498  << "\" from IOV tag \"" << tcIter->second.tagName() << "\" to be consumed by "
499  << iTime.eventID() << ", timestamp: " << iTime.time().value()
500  << "; from CondDBESSource::setIntervalFor";
501  pmIter->second->session() = iSess->second.first;
502  pmIter->second->reload();
504  } else {
505  edm::LogInfo("CondDBESSource") << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
506  << "\" for getting new payload for record \"" << recordname << "\" and label \""
507  << pmIter->second->label() << "\" to be consumed by " << iTime.eventID()
508  << ", timestamp: " << iTime.time().value()
509  << "; from CondDBESSource::setIntervalFor";
510  pmIter->second->reload();
511  m_stats.nRefresh++;
512  }
513  }
514 
515  //query the IOVSequence
516  cond::ValidityInterval validity = (*pmIter).second->setIntervalFor(abtime);
517 
518  edm::LogInfo("CondDBESSource") << "Validity coming from IOV sequence for record \"" << recordname
519  << "\" and label \"" << pmIter->second->label() << "\": (" << validity.first << ", "
520  << validity.second << ") for time (type: " << cond::timeTypeNames(timetype) << ") "
521  << abtime << "; from CondDBESSource::setIntervalFor";
522 
523  recordValidity.first = std::max(recordValidity.first, validity.first);
524  recordValidity.second = std::min(recordValidity.second, validity.second);
525  if (refreshThisRecord && recordValidity.second == cond::TIMELIMIT) {
526  iR->second.second = true;
527  if (defaultIovSize)
528  recordValidity.second = cond::time::tillTimeForIOV(abtime, defaultIovSize, timetype);
529  else {
530  recordValidity.second = 0;
531  }
532  }
533  }
534 
535  if (m_policy == REFRESH_OPEN_IOVS) {
536  doRefresh = (recordValidity.second == cond::timeTypeSpecs[timetype].endValue);
537  edm::LogInfo("CondDBESSource") << "Validity for record \"" << recordname
538  << "\" and the corresponding label(s) coming from Condition DB: ("
539  << recordValidity.first << ", " << recordValidity.first
540  << ") as the last IOV element in the IOV sequence is infinity"
541  << "; from CondDBESSource::setIntervalFor";
542  }
543 
544  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
545  if ((!userTime) && recordValidity.second != 0) {
546  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
548  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
549 
552  }
553  oInterval = edm::ValidityInterval(start, stop);
554  }
555 
556  edm::LogInfo("CondDBESSource") << "Setting validity for record \"" << recordname
557  << "\" and corresponding label(s): starting at " << oInterval.first().eventID()
558  << ", timestamp: " << oInterval.first().time().value() << ", ending at "
559  << oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
560  << ", for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
561  << "; from CondDBESSource::setIntervalFor";
562 }
563 
564 //required by EventSetup System
566  const EventSetupRecordKey& iRecordKey, unsigned int iovIndex) {
567  KeyedProxiesVector keyedProxiesVector;
568 
569  std::string recordname = iRecordKey.name();
570 
571  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
572  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
573  if (b == e) {
574  edm::LogInfo("CondDBESSource") << "No DataProxy (Pluging) found for record \"" << recordname
575  << "\"; from CondDBESSource::registerProxies";
576  return keyedProxiesVector;
577  }
578 
579  for (ProxyMap::const_iterator p = b; p != e; ++p) {
580  if (nullptr != (*p).second.get()) {
581  edm::eventsetup::TypeTag type = (*p).second->type();
582  DataKey key(type, edm::eventsetup::IdTags((*p).second->label().c_str()));
583  keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
584  }
585  }
586  return keyedProxiesVector;
587 }
588 
589 void CondDBESSource::initConcurrentIOVs(const EventSetupRecordKey& key, unsigned int nConcurrentIOVs) {
590  std::string recordname = key.name();
591  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
592  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
593  for (ProxyMap::const_iterator p = b; p != e; ++p) {
594  if (p->second) {
595  p->second->initConcurrentIOVs(nConcurrentIOVs);
596  }
597  }
598 }
599 
600 // Fills tag collection from the given globaltag
602  const std::string& prefix,
603  const std::string& postfix,
604  const std::string& roottag,
605  std::set<cond::GTEntry_t>& tagcoll,
606  cond::GTMetadata_t& gtMetadata) {
607  if (!roottag.empty()) {
608  if (connectionString.empty())
609  throw cond::Exception(std::string("ESSource: requested global tag ") + roottag +
610  std::string(" but not connection string given"));
611  std::tuple<std::string, std::string, std::string> connPars =
613  if (std::get<2>(connPars) == "CMS_COND_31X_GLOBALTAG") {
614  edm::LogWarning("CondDBESSource")
615  << "[WARNING] You are reading Global Tag \"" << roottag
616  << "\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
617  << std::endl;
618  } else if (roottag.rfind("::All") != std::string::npos && std::get<2>(connPars) == "CMS_CONDITIONS") {
619  edm::LogWarning("CondDBESSource") << "[WARNING] You are trying to read Global Tag \"" << roottag
620  << "\" - postfix \"::All\" should not be used for V2." << std::endl;
621  }
623  session.transaction().start(true);
624  cond::persistency::GTProxy gtp = session.readGlobalTag(roottag, prefix, postfix);
625  gtMetadata.snapshotTime = gtp.snapshotTime();
626  for (const auto& gte : gtp) {
627  tagcoll.insert(gte);
628  }
629  session.transaction().commit();
630  }
631 }
632 
633 // fills tagcollection merging with replacement
634 // Note: it assumem the coraldbList and roottagList have the same length. This checked in the constructor that prepares the two lists before calling this method.
635 void CondDBESSource::fillTagCollectionFromDB(const std::vector<std::string>& connectionStringList,
636  const std::vector<std::string>& prefixList,
637  const std::vector<std::string>& postfixList,
638  const std::vector<std::string>& roottagList,
639  std::map<std::string, cond::GTEntry_t>& replacement,
640  cond::GTMetadata_t& gtMetadata) {
641  std::set<cond::GTEntry_t> tagcoll;
642 
643  auto connectionString = connectionStringList.begin();
644  auto prefix = prefixList.begin();
645  auto postfix = postfixList.begin();
646  for (auto roottag = roottagList.begin(); roottag != roottagList.end();
647  ++roottag, ++connectionString, ++prefix, ++postfix) {
648  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
649  }
650 
651  std::set<cond::GTEntry_t>::iterator tagCollIter;
652  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
653  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
654 
655  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
656  for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
657  std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
658  std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
659  if (fid != replacement.end()) {
660  if (!fid->second.tagName().empty()) {
661  cond::GTEntry_t tagMetadata(
662  std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
663  m_tagCollection.insert(std::make_pair(recordLabelKey, tagMetadata));
664  edm::LogInfo("CondDBESSource") << "Replacing tag \"" << tagCollIter->tagName() << "\" for record \""
665  << tagMetadata.recordName() << "\" and label \"" << tagMetadata.recordLabel()
666  << "\" with tag " << tagMetadata.tagName()
667  << "\"; from CondDBESSource::fillTagCollectionFromDB";
668  } else {
669  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
670  }
671  replacement.erase(fid);
672  } else {
673  m_tagCollection.insert(std::make_pair(recordLabelKey, *tagCollIter));
674  }
675  }
676  std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
677  std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
678  std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
679  for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
680  if (replacementIter->second.tagName().empty()) {
681  std::stringstream msg;
682  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
683  if (!replacementIter->second.recordLabel().empty())
684  msg << " and label " << replacementIter->second.recordLabel();
685  throw cond::Exception(msg.str());
686  }
687  m_tagCollection.insert(*replacementIter);
688  }
689 }
690 
691 // backward compatibility for configuration files
693 public:
694  explicit PoolDBESSource(const edm::ParameterSet& ps) : CondDBESSource(ps) {}
695 };
696 
698 //define this as a plug-in
persistency::Exception Exception
Definition: Exception.h:25
const std::string & recordName() const
Definition: Types.h:120
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
Definition: start.py:1
const IOVSyncValue & last() const
std::map< std::string, std::pair< cond::Time_t, bool > > m_refreshTimeForRecord
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:95
std::mutex m_mutex
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const IOVSyncValue & first() const
Base exception class for the object to relational access.
Definition: Exception.h:11
std::string const & label() const
Definition: DataProxy.h:92
std::shared_ptr< std::vector< Iov_t > > const & requests() const
Definition: DataProxy.h:100
void usingRecordWithKey(const EventSetupRecordKey &key)
void start(bool readOnly=true)
Definition: Session.cc:18
bool exists(std::string const &parameterName) const
checks if a parameter exists
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
boost::posix_time::ptime snapshotTime
Definition: Types.h:106
static constexpr const char *const MAX_TIMESTAMP
Definition: Time.h:26
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
std::string to_string(const V &value)
Definition: OMSAccess.h:77
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
RefreshPolicy m_policy
Transaction & transaction()
Definition: Session.cc:52
std::string transactionIdForLumiTime(Time_t time, unsigned int iovSize, const std::string &secretKey)
Definition: Time.cc:150
TimeType
Definition: Time.h:19
void setParameters(const edm::ParameterSet &connectionPset)
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll, cond::GTMetadata_t &gtMetadata)
Time_t tillTimeForIOV(Time_t since, unsigned int iovSize, TimeType timeType)
Definition: Time.cc:54
T getUntrackedParameter(std::string const &, T const &) const
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:97
edm::SerialTaskQueue m_queue
std::string const & timeTypeNames(int)
Definition: Time.cc:11
unsigned long long Time_t
Definition: Time.h:14
std::string convertoToOracleConnection(const std::string &input)
Definition: Utils.h:120
std::pair< std::string, std::string > parseTag(const std::string &tag)
Definition: GTProxy.cc:14
std::string const & connString() const
Definition: DataProxy.h:93
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
cond::persistency::ConnectionPool m_connection
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:79
Session createSession(const std::string &connectionString, bool writeCapable=false)
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
Definition: GTProxy.cc:8
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
std::multimap< std::string, ProxyP > ProxyMap
def dumpInfo(run)
Definition: getInfo.py:88
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:135
std::shared_ptr< cond::DataProxyWrapperBase > ProxyP
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy > >> KeyedProxiesVector
std::string const & tag() const
Definition: DataProxy.h:94
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
const std::string & tagName() const
Definition: Types.h:122
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
PoolDBESSource(const edm::ParameterSet &ps)
TimeValue_t value() const
Definition: Timestamp.h:38
TagCollection m_tagCollection
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
double b
Definition: hdecay.h:118
~CondDBESSource() override
tuple msg
Definition: mps_check.py:286
void fillTagCollectionFromDB(const std::vector< std::string > &connectionStringList, const std::vector< std::string > &prefixList, const std::vector< std::string > &postfixList, const std::vector< std::string > &roottagList, std::map< std::string, cond::GTEntry_t > &replacement, cond::GTMetadata_t &gtMetadata)
const EventID & eventID() const
Definition: IOVSyncValue.h:40
std::vector< AlignmentParameters * > Parameters
Definition: Utilities.h:32
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
ProxyMap m_proxies
const Timestamp & time() const
Definition: IOVSyncValue.h:42
unsigned int m_lastRun
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
std::string m_frontierKey
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:113
#define get
Log< level::Warning, false > LogWarning
Time_t endValue
Definition: Time.h:42
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:163
std::map< std::string, unsigned int > m_lastRecordRuns
const std::string & recordLabel() const
Definition: Types.h:121
unsigned int m_lastLumi
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
def move(src, dest)
Definition: eostools.py:511
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:78
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121