CMS 3D CMS Logo

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