CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
CondDBESSource Class Reference

#include <CondDBESSource.h>

Inheritance diagram for CondDBESSource:
edm::eventsetup::DataProxyProvider edm::EventSetupRecordIntervalFinder PoolDBESSource

Classes

struct  Stats
 

Public Types

typedef std::multimap< std::string, ProxyPProxyMap
 
typedef std::shared_ptr< cond::DataProxyWrapperBaseProxyP
 
enum  RefreshPolicy {
  NOREFRESH, REFRESH_ALWAYS, REFRESH_OPEN_IOVS, REFRESH_EACH_RUN,
  RECONNECT_EACH_RUN
}
 
- Public Types inherited from edm::eventsetup::DataProxyProvider
typedef std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
 
typedef std::vector< EventSetupRecordKeyKeys
 
typedef std::map< EventSetupRecordKey, KeyedProxiesRecordProxies
 

Public Member Functions

 CondDBESSource (const edm::ParameterSet &)
 
 ~CondDBESSource ()
 
- Public Member Functions inherited from edm::eventsetup::DataProxyProvider
 DataProxyProvider ()
 
const ComponentDescriptiondescription () const
 
bool isUsingRecord (const EventSetupRecordKey &) const
 
const KeyedProxieskeyedProxies (const EventSetupRecordKey &iRecordKey) const
 
void resetProxies (const EventSetupRecordKey &iRecordType)
 
void resetProxiesIfTransient (const EventSetupRecordKey &iRecordType)
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~DataProxyProvider () noexcept(false)
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
const eventsetup::ComponentDescriptiondescriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
std::set< eventsetup::EventSetupRecordKeyfindingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder () noexcept(false)
 

Protected Member Functions

virtual void newInterval (const edm::eventsetup::EventSetupRecordKey &iRecordType, const edm::ValidityInterval &iInterval)
 called when a new interval of validity occurs for iRecordType More...
 
virtual void registerProxies (const edm::eventsetup::EventSetupRecordKey &iRecordKey, KeyedProxies &aProxyList)
 
virtual void setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
 
- Protected Member Functions inherited from edm::eventsetup::DataProxyProvider
void eraseAll (const EventSetupRecordKey &iRecordKey)
 deletes all the Proxies in aStream More...
 
void invalidateProxies (const EventSetupRecordKey &iRecordKey)
 
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &)
 
- Protected Member Functions inherited from edm::EventSetupRecordIntervalFinder
template<class T >
void findingRecord ()
 
void findingRecordWithKey (const eventsetup::EventSetupRecordKey &)
 

Private Types

typedef std::map< std::string, cond::GTEntry_tTagCollection
 

Private Member Functions

void fillList (const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
 
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)
 
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)
 

Private Attributes

cond::persistency::ConnectionPool m_connection
 
std::string m_connectionString
 
bool m_doDump
 
unsigned int m_lastLumi
 
std::map< std::string, unsigned int > m_lastRecordRuns
 
unsigned int m_lastRun
 
RefreshPolicy m_policy
 
ProxyMap m_proxies
 
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
 
Stats m_stats
 
TagCollection m_tagCollection
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::eventsetup::DataProxyProvider
static void prevalidate (ConfigurationDescriptions &)
 

Detailed Description

Definition at line 33 of file CondDBESSource.h.

Member Typedef Documentation

typedef std::multimap< std::string, ProxyP> CondDBESSource::ProxyMap

Definition at line 37 of file CondDBESSource.h.

Definition at line 36 of file CondDBESSource.h.

typedef std::map< std::string, cond::GTEntry_t > CondDBESSource::TagCollection
private

Definition at line 65 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CondDBESSource::CondDBESSource ( const edm::ParameterSet iConfig)
explicit

required by eventsetup

Definition at line 100 of file CondDBESSource.cc.

References b, cond::persistency::ConnectionPool::configure(), cond::persistency::convertoToOracleConnection(), cond::persistency::ConnectionPool::createReadOnlySession(), MillePedeFileConverter_cfg::e, edm::ParameterSet::exists(), fillList(), fillTagCollectionFromDB(), edm::EventSetupRecordIntervalFinder::findingRecordWithKey(), edm::eventsetup::heterocontainer::HCTypeTag::findType(), cond::persistency::fullyQualifiedTag(), reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), download_sqlite_cfg::globaltag, m_connection, m_connectionString, m_policy, m_proxies, m_stats, m_tagCollection, cond::time::MAX_TIMESTAMP, CondDBESSource::Stats::nData, cond::persistency::parseConnectionString(), cond::persistency::parseTag(), loadRecoTauTagMVAsFromPrepDB_cfi::pfnPostfix, loadRecoTauTagMVAsFromPrepDB_cfi::pfnPrefix, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::persistency::ConnectionPool::setParameters(), loadRecoTauTagMVAsFromPrepDB_cfi::snapshotTime, split, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, DBConfiguration_cff::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

100  :
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" );
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<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
214  size_t ipb=0;
215  for(it=itBeg;it!=itEnd;++it){
216  proxyWrappers[ipb++] =
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(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 }
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
bool exists(std::string const &parameterName) const
checks if a parameter exists
static constexpr const char *const MAX_TIMESTAMP
Definition: Time.h:23
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
void setParameters(const edm::ParameterSet &connectionPset)
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:93
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
cond::persistency::ConnectionPool m_connection
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::shared_ptr< cond::DataProxyWrapperBase > ProxyP
TagCollection m_tagCollection
double b
Definition: hdecay.h:120
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
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
unsigned int m_lastLumi
double split
Definition: MVATrainer.cc:139
T get(const Candidate &c)
Definition: component.h:55
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
CondDBESSource::~CondDBESSource ( )

Definition at line 295 of file CondDBESSource.cc.

References b, gather_cfg::cout, MillePedeFileConverter_cfg::e, m_doDump, m_proxies, m_stats, CondDBESSource::Stats::nActualReconnect, CondDBESSource::Stats::nActualRefresh, CondDBESSource::Stats::nData, CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, and CondDBESSource::Stats::nSet.

295  {
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 }
double b
Definition: hdecay.h:120
ProxyMap m_proxies

Member Function Documentation

void CondDBESSource::fillList ( const std::string &  pfn,
std::vector< std::string > &  pfnList,
const unsigned int  listSize,
const std::string &  type 
)
private

Definition at line 280 of file CondDBESSource.cc.

References i, split, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CondDBESSource().

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 }
persistency::Exception Exception
Definition: Exception.h:25
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
double split
Definition: MVATrainer.cc:139
void CondDBESSource::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 
)
private

Definition at line 593 of file CondDBESSource.cc.

References fillTagCollectionFromGT(), m_tagCollection, mps_alisetup::msg, tablePrinter::postfix, tablePrinter::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

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 }
persistency::Exception Exception
Definition: Exception.h:25
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)
TagCollection m_tagCollection
void CondDBESSource::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 
)
private

Definition at line 564 of file CondDBESSource.cc.

References cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::createSession(), m_connection, cond::persistency::parseConnectionString(), cond::persistency::Session::readGlobalTag(), dataDML::session, cond::persistency::GTProxy::snapshotTime(), cond::GTMetadata_t::snapshotTime, cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::Session::transaction().

Referenced by fillTagCollectionFromDB().

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 }
Base exception class for the object to relational access.
Definition: Exception.h:11
void start(bool readOnly=true)
Definition: Session.cc:22
boost::posix_time::ptime snapshotTime
Definition: Types.h:110
Transaction & transaction()
Definition: Session.cc:66
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:93
cond::persistency::ConnectionPool m_connection
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:166
Session createSession(const std::string &connectionString, bool writeCapable=false)
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:173
void CondDBESSource::newInterval ( const edm::eventsetup::EventSetupRecordKey iRecordType,
const edm::ValidityInterval iInterval 
)
protectedvirtual

called when a new interval of validity occurs for iRecordType

Implements edm::eventsetup::DataProxyProvider.

Definition at line 555 of file CondDBESSource.cc.

References edm::eventsetup::DataProxyProvider::invalidateProxies().

557 {
558  //LogDebug ("CondDBESSource")<<"newInterval";
559  invalidateProxies(iRecordType);
560 }
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
void CondDBESSource::registerProxies ( const edm::eventsetup::EventSetupRecordKey iRecordKey,
KeyedProxies aProxyList 
)
protectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 533 of file CondDBESSource.cc.

References b, MillePedeFileConverter_cfg::e, crabWrapper::key, m_proxies, edm::eventsetup::EventSetupRecordKey::name(), AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

533  {
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(0 != (*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 }
type
Definition: HCALResponse.h:21
double b
Definition: hdecay.h:120
ProxyMap m_proxies
void CondDBESSource::setIntervalFor ( const edm::eventsetup::EventSetupRecordKey iKey,
const edm::IOVSyncValue iTime,
edm::ValidityInterval oInterval 
)
protectedvirtual

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 328 of file CondDBESSource.cc.

References cond::persistency::ConnectionPool::createReadOnlySession(), cond::TimeTypeSpecs::endValue, edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), plotBeamSpotDB::first, cond::time::fromIOVSyncValue(), align::invalid, edm::ValidityInterval::invalidInterval(), edm::ValidityInterval::last(), cond::time::limitedIOVSyncValue(), edm::IOVSyncValue::luminosityBlockNumber(), m_connection, m_connectionString, m_lastLumi, m_lastRecordRuns, m_lastRun, m_policy, m_proxies, m_sessionPool, m_stats, m_tagCollection, genParticles_cff::map, hpstanc_transforms::max, min(), edm::eventsetup::EventSetupRecordKey::name(), CondDBESSource::Stats::nLumi, CondDBESSource::Stats::nReconnect, CondDBESSource::Stats::nRefresh, CondDBESSource::Stats::nRun, CondDBESSource::Stats::nSet, cond::persistency::parseTag(), RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, edm::EventID::run(), AlCaHLTBitMon_QueryRunRegistry::string, edm::IOVSyncValue::time(), cond::TIMELIMIT(), DBConfiguration_cff::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::time::toIOVSyncValue(), and edm::Timestamp::value().

328  {
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);
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 }
RunNumber_t run() const
Definition: EventID.h:39
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
Definition: start.py:1
const EventID & eventID() const
Definition: IOVSyncValue.h:42
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
RefreshPolicy m_policy
TimeType
Definition: Time.h:21
const IOVSyncValue & last() const
U second(std::pair< T, U > const &p)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:74
std::string const & timeTypeNames(int)
Definition: Time.cc:15
unsigned long long Time_t
Definition: Time.h:16
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:52
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
T min(T a, T b)
Definition: MathUtil.h:58
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::string m_connectionString
ProxyMap m_proxies
Definition: plugin.cc:24
unsigned int m_lastRun
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
const Timestamp & time() const
Definition: IOVSyncValue.h:44
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:91
const IOVSyncValue & first() const
Time_t endValue
Definition: Time.h:46
unsigned int m_lastLumi
TimeValue_t value() const
Definition: Timestamp.h:56

Member Data Documentation

cond::persistency::ConnectionPool CondDBESSource::m_connection
private

Definition at line 58 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromGT(), and setIntervalFor().

std::string CondDBESSource::m_connectionString
private

Definition at line 59 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

bool CondDBESSource::m_doDump
private

Definition at line 88 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 85 of file CondDBESSource.h.

Referenced by setIntervalFor().

std::map<std::string,unsigned int> CondDBESSource::m_lastRecordRuns
private

Definition at line 69 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 84 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 86 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

ProxyMap CondDBESSource::m_proxies
private

Definition at line 62 of file CondDBESSource.h.

Referenced by CondDBESSource(), registerProxies(), setIntervalFor(), and ~CondDBESSource().

std::map<std::string,std::pair<cond::persistency::Session,std::string> > CondDBESSource::m_sessionPool
private

Definition at line 68 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 82 of file CondDBESSource.h.

Referenced by CondDBESSource(), setIntervalFor(), and ~CondDBESSource().

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 67 of file CondDBESSource.h.

Referenced by CondDBESSource(), fillTagCollectionFromDB(), and setIntervalFor().