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