CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, ProxyP
ProxyMap
 
typedef boost::shared_ptr
< cond::DataProxyWrapperBase
ProxyP
 
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, boost::shared_ptr
< DataProxy > > > 
KeyedProxies
 
typedef std::vector
< EventSetupRecordKey
Keys
 
typedef std::map
< EventSetupRecordKey,
KeyedProxies
RecordProxies
 

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 ()
 
- Public Member Functions inherited from edm::EventSetupRecordIntervalFinder
const
eventsetup::ComponentDescription
descriptionForFinder () const
 
 EventSetupRecordIntervalFinder ()
 
std::set
< eventsetup::EventSetupRecordKey
findingForRecords () const
 
const ValidityIntervalfindIntervalFor (const eventsetup::EventSetupRecordKey &, const IOVSyncValue &)
 
void setDescriptionForFinder (const eventsetup::ComponentDescription &iDescription)
 
virtual ~EventSetupRecordIntervalFinder ()
 

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_t
TagCollection
 

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 32 of file CondDBESSource.h.

Member Typedef Documentation

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

Definition at line 36 of file CondDBESSource.h.

Definition at line 35 of file CondDBESSource.h.

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

Definition at line 64 of file CondDBESSource.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

required by eventsetup

Definition at line 101 of file CondDBESSource.cc.

References b, cond::persistency::ConnectionPool::configure(), cond::persistency::convertoToOracleConnection(), cond::persistency::ConnectionPool::createReadOnlySession(), alignCSCRings::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(), align_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(), dbtoconf::pfn, RECONNECT_EACH_RUN, REFRESH_ALWAYS, REFRESH_EACH_RUN, REFRESH_OPEN_IOVS, alignCSCRings::s, cond::persistency::ConnectionPool::setParameters(), cond::GTMetadata_t::snapshotTime, split, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, convertSQLitetoXML_cfg::toGet, edm::eventsetup::EventSetupRecordKey::type(), and edm::eventsetup::DataProxyProvider::usingRecordWithKey().

101  :
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 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
list pfn
Definition: dbtoconf.py:76
list globaltag
Definition: align_cfg.py:7
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
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:61
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
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)
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
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
CondDBESSource::~CondDBESSource ( )

Definition at line 281 of file CondDBESSource.cc.

References b, gather_cfg::cout, alignCSCRings::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.

281  {
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 }
double b
Definition: hdecay.h:120
ProxyMap m_proxies
tuple cout
Definition: gather_cfg.py:121

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 266 of file CondDBESSource.cc.

References edm::hlt::Exception, i, split, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by CondDBESSource().

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 }
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 579 of file CondDBESSource.cc.

References NewTree::fid, fillTagCollectionFromGT(), m_tagCollection, prof2calltree::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

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 }
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
list fid
Definition: NewTree.py:51
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 550 of file CondDBESSource.cc.

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

Referenced by fillTagCollectionFromDB().

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 }
void start(bool readOnly=true)
Definition: Session.cc:22
boost::posix_time::ptime snapshotTime
Definition: Types.h:106
Transaction & transaction()
Definition: Session.cc:66
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Definition: Utils.h:61
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
cond::persistency::ConnectionPool m_connection
boost::posix_time::ptime snapshotTime() const
Definition: GTProxy.cc:166
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 541 of file CondDBESSource.cc.

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

543 {
544  //LogDebug ("CondDBESSource")<<"newInterval";
545  invalidateProxies(iRecordType);
546 }
void invalidateProxies(const EventSetupRecordKey &iRecordKey)
void CondDBESSource::registerProxies ( const edm::eventsetup::EventSetupRecordKey iRecordKey,
KeyedProxies aProxyList 
)
protectedvirtual

Implements edm::eventsetup::DataProxyProvider.

Definition at line 519 of file CondDBESSource.cc.

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

519  {
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 }
type
Definition: HCALResponse.h:21
Container::value_type value_type
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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 314 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, python.multivaluedict::map(), bookConverter::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(), dqm_diff::start, AlCaHLTBitMon_QueryRunRegistry::string, edm::IOVSyncValue::time(), cond::TIMELIMIT(), dtNoiseCalibration_cfg::timetype, cond::timeTypeNames(), cond::timeTypeSpecs, cond::time::toIOVSyncValue(), and edm::Timestamp::value().

314  {
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 }
RunNumber_t run() const
Definition: EventID.h:39
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
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
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
volatile std::atomic< bool > shutdown_flag false
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 57 of file CondDBESSource.h.

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

std::string CondDBESSource::m_connectionString
private

Definition at line 58 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

bool CondDBESSource::m_doDump
private

Definition at line 87 of file CondDBESSource.h.

Referenced by ~CondDBESSource().

unsigned int CondDBESSource::m_lastLumi
private

Definition at line 84 of file CondDBESSource.h.

Referenced by setIntervalFor().

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

Definition at line 68 of file CondDBESSource.h.

Referenced by setIntervalFor().

unsigned int CondDBESSource::m_lastRun
private

Definition at line 83 of file CondDBESSource.h.

Referenced by setIntervalFor().

RefreshPolicy CondDBESSource::m_policy
private

Definition at line 85 of file CondDBESSource.h.

Referenced by CondDBESSource(), and setIntervalFor().

ProxyMap CondDBESSource::m_proxies
private

Definition at line 61 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 67 of file CondDBESSource.h.

Referenced by setIntervalFor().

Stats CondDBESSource::m_stats
private

Definition at line 81 of file CondDBESSource.h.

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

TagCollection CondDBESSource::m_tagCollection
private

Definition at line 66 of file CondDBESSource.h.

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