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  std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime" );
139  if( !snapshotTimeString.empty() ) snapshotTime = boost::posix_time::time_from_string( snapshotTimeString );
140  }
141 
142  // connection configuration
143  if( iConfig.exists("DBParameters") ) {
144  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>( "DBParameters" );
145  m_connection.setParameters( connectionPset );
146  }
148 
149  // load specific record/tag info - it will overwrite the global tag ( if any )
150  std::map<std::string,cond::GTEntry_t> replacements;
151  std::map<std::string,boost::posix_time::ptime> specialSnapshots;
152  if( iConfig.exists( "toGet" ) ) {
153  typedef std::vector< edm::ParameterSet > Parameters;
154  Parameters toGet = iConfig.getParameter<Parameters>( "toGet" );
155  for( Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet ) {
156  std::string recordname = itToGet->getParameter<std::string>( "record" );
157  if( recordname.empty() ) throw cond::Exception( "ESSource: The record name has not been provided in a \"toGet\" entry." );
158  std::string labelname = itToGet->getUntrackedParameter<std::string>( "label", "" );
159  std::string pfn("");
160  if( m_connectionString.empty() || itToGet->exists("connect") ) pfn = itToGet->getParameter<std::string>( "connect" );
161  std::string tag("");
162  std::string fqTag("");
163  if( itToGet->exists("tag") ) {
164  tag = itToGet->getParameter<std::string>( "tag" );
166  }
167  boost::posix_time::ptime tagSnapshotTime = boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP) );
168  if( itToGet->exists("snapshotTime") ) tagSnapshotTime = boost::posix_time::time_from_string( itToGet->getParameter<std::string>("snapshotTime" ) );
169  std::string recordLabelKey = joinRecordAndLabel( recordname, labelname );
170  replacements.insert( std::make_pair( recordLabelKey, cond::GTEntry_t( std::make_tuple(recordname, labelname, fqTag ) ) ) );
171  specialSnapshots.insert( std::make_pair( recordLabelKey, tagSnapshotTime ) );
172  }
173  }
174 
175  // get the global tag, merge with "replacement" store in "tagCollection"
176  std::vector<std::string> globaltagList;
177  std::vector<std::string> connectList;
178  std::vector<std::string> pfnPrefixList;
179  std::vector<std::string> pfnPostfixList;
180  if( !globaltag.empty() ) {
181  std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>( "pfnPrefix", "" ));
182  std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>( "pfnPostfix", "" ));
183  boost::split( globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off );
184  fillList(m_connectionString, connectList, globaltagList.size(), "connection");
185  fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix");
186  fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix");
187  }
188 
189  cond::GTMetadata_t gtMetadata;
190  fillTagCollectionFromDB(connectList,
191  pfnPrefixList,
192  pfnPostfixList,
193  globaltagList,
194  replacements,
195  gtMetadata);
196  // if no job specific setting has been found, use the GT timestamp
197  if(snapshotTime.is_not_a_date_time())
198  snapshotTime = gtMetadata.snapshotTime;
199 
200  TagCollection::iterator it;
201  TagCollection::iterator itBeg = m_tagCollection.begin();
202  TagCollection::iterator itEnd = m_tagCollection.end();
203 
204  std::map<std::string, cond::persistency::Session> sessions;
205 
206  /* load DataProxy Plugin (it is strongly typed due to EventSetup ideosyncrasis)
207  * construct proxy
208  * contrary to EventSetup the "object-name" is not used as identifier: multiple entries in a record are
209  * dinstinguished only by their label...
210  * done in two step: first create ProxyWrapper loading ALL required dictionaries
211  * this will allow to initialize POOL in one go for each "database"
212  * The real initialization of the Data-Proxies is done in the second loop
213  */
214  std::vector<cond::DataProxyWrapperBase *> proxyWrappers(m_tagCollection.size());
215  size_t ipb=0;
216  for(it=itBeg;it!=itEnd;++it){
217  proxyWrappers[ipb++] =
218  cond::ProxyFactory::get()->create(buildName(it->second.recordName()));
219  }
220 
221  // now all required libraries have been loaded
222  // init sessions and DataProxies
223  ipb=0;
224  for(it=itBeg;it!=itEnd;++it){
226  std::string tag = it->second.tagName();
227  std::pair<std::string,std::string> tagParams = cond::persistency::parseTag( it->second.tagName() );
228  if( !tagParams.second.empty() ) {
229  connStr = tagParams.second;
230  tag = tagParams.first;
231  }
232  std::map<std::string, cond::persistency::Session>::iterator p = sessions.find( connStr );
234  if (p == sessions.end()) {
236  std::tuple<std::string,std::string,std::string> connPars = cond::persistency::parseConnectionString( oracleConnStr );
237  std::string dbService = std::get<1>( connPars );
238  std::string dbAccount = std::get<2>( connPars );
239  if( (dbService == "cms_orcon_prod" || dbService == "cms_orcon_adg") && dbAccount != "CMS_CONDITIONS" )
240  edm::LogWarning( "CondDBESSource" )<<"[WARNING] You are reading tag \""<<tag<<"\" from V1 account \""<<connStr<<"\". The concerned Conditions might be out of date."<<std::endl;
241  //open db get tag info (i.e. the IOV token...)
242  nsess = m_connection.createReadOnlySession( connStr, "" );
243  sessions.insert(std::make_pair( connStr, nsess));
244  } else nsess = (*p).second;
245 
246  // ownership...
247  ProxyP proxy(proxyWrappers[ipb++]);
248  // instert in the map
249  m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
250  // initialize
251  boost::posix_time::ptime tagSnapshotTime = snapshotTime;
252  auto tagSnapshotIter = specialSnapshots.find( it->first );
253  if( tagSnapshotIter != specialSnapshots.end() ) tagSnapshotTime = tagSnapshotIter->second;
254  // finally, if the snapshot is set to infinity, reset the snapshot to null, to take the full iov set...
255  if(tagSnapshotTime == boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP) ) )
256  tagSnapshotTime = boost::posix_time::ptime();
257 
258  proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr);
259  }
260 
261  // one loaded expose all other tags to the Proxy!
262  CondGetterFromESSource visitor( m_proxies );
263  ProxyMap::iterator b = m_proxies.begin();
264  ProxyMap::iterator e = m_proxies.end();
265  for ( ;b != e; b++ ) {
266 
267  (*b).second->proxy()->loadMore( visitor );
268 
271  if( recordKey.type() != edm::eventsetup::EventSetupRecordKey::TypeTag() ) {
272  findingRecordWithKey( recordKey );
273  usingRecordWithKey( recordKey );
274  }
275  }
276 
277  m_stats.nData=m_proxies.size();
278 
279 }
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:111
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 296 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.

296  {
297  //dump info FIXME: find a more suitable place...
298  if (m_doDump) {
299  std::cout << "CondDBESSource Statistics" << std::endl
300  << "DataProxy " << m_stats.nData
301  << " setInterval " << m_stats.nSet
302  << " Runs " << m_stats.nRun
303  << " Lumis " << m_stats.nLumi
304  << " Refresh " << m_stats.nRefresh
305  << " Actual Refresh " << m_stats.nActualRefresh
306  << " Reconnect " << m_stats.nReconnect
307  << " Actual Reconnect " << m_stats.nActualReconnect;
308  std::cout << std::endl;
309 
310 
311  ProxyMap::iterator b= m_proxies.begin();
312  ProxyMap::iterator e= m_proxies.end();
313  for ( ;b != e; b++ ) {
314  dumpInfo( std::cout, (*b).first, *(*b).second );
315  std::cout << "\n" << std::endl;
316  }
317 
318  // FIXME
319  // We shall eventually close transaction and session...
320  }
321 }
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 281 of file CondDBESSource.cc.

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

Referenced by CondDBESSource().

282 {
283  boost::split( listToFill, stringList, boost::is_any_of("|"), boost::token_compress_off );
284  // If it is one clone it for each GT
285  if( listToFill.size() == 1 ) {
286  for( unsigned int i=1; i<listSize; ++i ) {
287  listToFill.push_back(stringList);
288  }
289  }
290  // else if they don't match the number of GTs throw an exception
291  else if( listSize != listToFill.size() ) {
292  throw cond::Exception( std::string( "ESSource: number of global tag components does not match number of "+type+" strings" ) );
293  }
294 }
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 594 of file CondDBESSource.cc.

References autoCondHLT::connectionString, Exception, NewTree::fid, fillTagCollectionFromGT(), m_tagCollection, visualization-live-secondInstance_cfg::msg, prof2calltree::prefix, cond::GTEntry_t::recordLabel(), cond::GTEntry_t::recordName(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::GTEntry_t::tagName().

Referenced by CondDBESSource().

600 {
601  std::set< cond::GTEntry_t > tagcoll;
602 
603  auto connectionString = connectionStringList.begin();
604  auto prefix = prefixList.begin();
605  auto postfix = postfixList.begin();
606  for( auto roottag = roottagList.begin(); roottag != roottagList.end(); ++roottag, ++connectionString, ++prefix, ++postfix) {
607  fillTagCollectionFromGT(*connectionString, *prefix, *postfix, *roottag, tagcoll, gtMetadata);
608  }
609 
610  std::set<cond::GTEntry_t>::iterator tagCollIter;
611  std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
612  std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
613 
614  // FIXME the logic is a bit perverse: can be surely linearized (at least simplified!) ....
615  for( tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter ) {
616  std::string recordLabelKey = joinRecordAndLabel( tagCollIter->recordName(), tagCollIter->recordLabel() );
617  std::map<std::string,cond::GTEntry_t>::iterator fid = replacement.find( recordLabelKey );
618  if( fid != replacement.end() ) {
619  if( !fid->second.tagName().empty() ){
620  cond::GTEntry_t tagMetadata( std::make_tuple( tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName() ) );
621  m_tagCollection.insert( std::make_pair( recordLabelKey, tagMetadata ) );
622  edm::LogInfo( "CondDBESSource" ) << "Replacing tag \"" << tagCollIter->tagName()
623  << "\" for record \"" << tagMetadata.recordName()
624  << "\" and label \"" << tagMetadata.recordLabel()
625  << "\" with tag " << tagMetadata.tagName()
626  << "\"; from CondDBESSource::fillTagCollectionFromDB";
627  } else {
628  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
629  }
630  replacement.erase( fid );
631  } else {
632  m_tagCollection.insert( std::make_pair( recordLabelKey, *tagCollIter) );
633  }
634  }
635  std::map<std::string,cond::GTEntry_t>::iterator replacementIter;
636  std::map<std::string,cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
637  std::map<std::string,cond::GTEntry_t>::iterator replacementEnd = replacement.end();
638  for( replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter ){
639  if( replacementIter->second.tagName().empty() ){
640  std::stringstream msg;
641  msg << "ESSource: no tag provided for record " << replacementIter->second.recordName();
642  if( !replacementIter->second.recordLabel().empty() ) msg << " and label "<<replacementIter->second.recordLabel();
643  throw cond::Exception( msg.str() );
644  }
645  m_tagCollection.insert( *replacementIter );
646  }
647 }
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)
string connectionString
Definition: autoCondHLT.py:4
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 565 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().

571 {
572  if ( !roottag.empty() ) {
573  if ( connectionString.empty() )
574  throw cond::Exception( std::string( "ESSource: requested global tag ") + roottag + std::string( " but not connection string given" ) );
575  std::tuple<std::string,std::string,std::string> connPars = cond::persistency::parseConnectionString( connectionString );
576  if( std::get<2>( connPars ) == "CMS_COND_31X_GLOBALTAG" ){
577  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;
578  } else if( roottag.rfind("::All")!=std::string::npos && std::get<2>( connPars ) == "CMS_CONDITIONS" ){
579  edm::LogWarning( "CondDBESSource" )<<"[WARNING] You are trying to read Global Tag \""<<roottag<<"\" - postfix \"::All\" should not be used for V2."<<std::endl;
580  }
582  session.transaction().start( true );
583  cond::persistency::GTProxy gtp = session.readGlobalTag( roottag, prefix, postfix );
584  gtMetadata.snapshotTime = gtp.snapshotTime();
585  for( const auto& gte : gtp ){
586  tagcoll.insert( gte );
587  }
588  session.transaction().commit();
589  }
590 }
void start(bool readOnly=true)
Definition: Session.cc:22
boost::posix_time::ptime snapshotTime
Definition: Types.h:111
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
string connectionString
Definition: autoCondHLT.py:4
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 556 of file CondDBESSource.cc.

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

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

Implements edm::eventsetup::DataProxyProvider.

Definition at line 534 of file CondDBESSource.cc.

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

534  {
535  std::string recordname=iRecordKey.name();
536 
537  ProxyMap::const_iterator b = m_proxies.lower_bound(recordname);
538  ProxyMap::const_iterator e = m_proxies.upper_bound(recordname);
539  if ( b == e) {
540  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
541  << "\"; from CondDBESSource::registerProxies";
542  return;
543  }
544 
545  for (ProxyMap::const_iterator p=b;p!=e;++p) {
546  if(0 != (*p).second.get()) {
547  edm::eventsetup::TypeTag type = (*p).second->type();
548  edm::eventsetup::DataKey key( type, edm::eventsetup::IdTags((*p).second->label().c_str()) );
549  aProxyList.push_back(KeyedProxies::value_type(key,(*p).second->edmProxy()));
550  }
551  }
552 }
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 329 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().

329  {
330 
331  std::string recordname=iKey.name();
332 
333  edm::LogInfo( "CondDBESSource" ) << "Getting data for record \""<< recordname
334  << "\" to be consumed by "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
335  << "; from CondDBESSource::setIntervalFor";
336 
337  m_stats.nSet++;
338  //{
339  // not really required, keep here for the time being
340  if(iTime.eventID().run()!=m_lastRun) {
341  m_lastRun=iTime.eventID().run();
342  m_stats.nRun++;
343  }
344  if(iTime.luminosityBlockNumber()!=m_lastLumi) {
346  m_stats.nLumi++;
347  }
348  //}
349 
350  bool doRefresh = false;
352  // find out the last run number for the proxy of the specified record
353  std::map<std::string,unsigned int>::iterator iRec = m_lastRecordRuns.find( recordname );
354  if( iRec != m_lastRecordRuns.end() ){
355  unsigned int lastRecordRun = iRec->second;
356  if( lastRecordRun != m_lastRun ){
357  // a refresh is required!
358  doRefresh = true;
359  iRec->second = m_lastRun;
360  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
361  << "\" since there has been a transition from run "
362  << lastRecordRun << " to run " << m_lastRun
363  << "; from CondDBESSource::setIntervalFor";
364  }
365  } else {
366  doRefresh = true;
367  m_lastRecordRuns.insert( std::make_pair( recordname, m_lastRun ) );
368  edm::LogInfo( "CondDBESSource" ) << "Preparing refresh for record \"" << recordname
369  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
370  << "; from CondDBESSource::setIntervalFor";
371  }
372  if ( !doRefresh )
373  edm::LogInfo( "CondDBESSource" ) << "Though enabled, refresh not needed for record \"" << recordname
374  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
375  << "; from CondDBESSource::setIntervalFor";
376  } else if( m_policy == REFRESH_ALWAYS || m_policy == REFRESH_OPEN_IOVS ) {
377  doRefresh = true;
378  edm::LogInfo( "CondDBESSource" ) << "Forcing refresh for record \"" << recordname
379  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
380  << "; from CondDBESSource::setIntervalFor";
381  }
382 
384 
385  // compute the smallest interval (assume all objects have the same timetype....)
386  cond::ValidityInterval recordValidity(1,cond::TIMELIMIT);
388  bool userTime=true;
389 
390  //FIXME use equal_range
391  ProxyMap::const_iterator pmBegin = m_proxies.lower_bound(recordname);
392  ProxyMap::const_iterator pmEnd = m_proxies.upper_bound(recordname);
393  if ( pmBegin == pmEnd ) {
394  edm::LogInfo( "CondDBESSource" ) << "No DataProxy (Pluging) found for record \""<< recordname
395  << "\"; from CondDBESSource::setIntervalFor";
396  return;
397  }
398 
399  for ( ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter ) {
400 
401  edm::LogInfo( "CondDBESSource" ) << "Processing record \"" << recordname
402  << "\" and label \""<< pmIter->second->label()
403  << "\" for " << iTime.eventID() << ", timestamp: " << iTime.time().value()
404  << "; from CondDBESSource::setIntervalFor";
405 
406  timetype = (*pmIter).second->proxy()->timeType();
407 
408  cond::Time_t abtime = cond::time::fromIOVSyncValue( iTime, timetype );
409  userTime = ( 0 == abtime );
410 
411  if (userTime) return; // oInterval invalid to avoid that make is called...
412 
413  if( doRefresh ) {
414 
415  std::string recKey = joinRecordAndLabel( recordname, pmIter->second->label() );
416  TagCollection::const_iterator tcIter = m_tagCollection.find( recKey );
417  if ( tcIter == m_tagCollection.end() ) {
418  edm::LogInfo( "CondDBESSource" ) << "No Tag found for record \""<< recordname
419  << "\" and label \""<< pmIter->second->label()
420  << "\"; from CondDBESSource::setIntervalFor";
421  return;
422  }
423 
424  // first reconnect if required
425  if( m_policy == RECONNECT_EACH_RUN ) {
426  edm::LogInfo( "CondDBESSource" ) << "Checking if the session must be closed and re-opened for getting correct conditions"
427  << "; from CondDBESSource::setIntervalFor";
428  std::stringstream transId;
429  //transId << "long" << m_lastRun;
430  transId << m_lastRun;
432  std::pair<std::string,std::string> tagParams = cond::persistency::parseTag( tcIter->second.tagName() );
433  if( !tagParams.second.empty() ) connStr = tagParams.second;
434  std::map<std::string,std::pair<cond::persistency::Session,std::string> >::iterator iSess = m_sessionPool.find( connStr );
435  bool reopen = false;
436  if( iSess != m_sessionPool.end() ){
437  if( iSess->second.second != transId.str() ) {
438  // the available session is open for a different run: reopen
439  reopen = true;
440  iSess->second.second = transId.str();
441  }
442  } else {
443  // no available session: probably first run analysed...
444  iSess = m_sessionPool.insert(std::make_pair( connStr, std::make_pair( cond::persistency::Session(),transId.str()) )).first;
445  reopen = true;
446  }
447  if( reopen ){
448  iSess->second.first = m_connection.createReadOnlySession( connStr, transId.str() );
449  edm::LogInfo( "CondDBESSource" ) << "Re-opening the session with connection string " << connStr
450  << " and new transaction Id " << transId.str()
451  << "; from CondDBESSource::setIntervalFor";
452  }
453 
454  edm::LogInfo( "CondDBESSource" ) << "Reconnecting to \"" << connStr
455  << "\" for getting new payload for record \"" << recordname
456  << "\" and label \""<< pmIter->second->label()
457  << "\" from IOV tag \"" << tcIter->second.tagName()
458  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
459  << "; from CondDBESSource::setIntervalFor";
460  pmIter->second->proxy()->setUp( iSess->second.first );
461  pmIter->second->proxy()->reload();
462  //if( isSizeIncreased )
463  //edm::LogInfo( "CondDBESSource" ) << "After reconnecting, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
464  // << "\" was found; from CondDBESSource::setIntervalFor";
465  //m_stats.nActualReconnect += isSizeIncreased;
467  } else {
468  edm::LogInfo( "CondDBESSource" ) << "Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
469  << "\" for getting new payload for record \"" << recordname
470  << "\" and label \""<< pmIter->second->label()
471  << "\" to be consumed by " << iTime.eventID() << ", timestamp: " << iTime.time().value()
472  << "; from CondDBESSource::setIntervalFor";
473  pmIter->second->proxy()->reload();
474  //if( isSizeIncreased )
475  // edm::LogInfo( "CondDBESSource" ) << "After refreshing, an increased size of the IOV sequence labeled by tag \"" << tcIter->second.tag
476  // << "\" was found; from CondDBESSource::setIntervalFor";
477  //m_stats.nActualRefresh += isSizeIncreased;
478  m_stats.nRefresh++;
479  }
480 
481  }
482 
483  /*
484  // make oInterval valid For Ever
485  {
486  oInterval = edm::ValidityInterval(cond::toIOVSyncValue(recordValidity.first, cond::runnumber, true),
487  cond::toIOVSyncValue(recordValidity.second, cond::runnumber, false));
488  return;
489  }
490  */
491 
492  //query the IOVSequence
493  cond::ValidityInterval validity = (*pmIter).second->proxy()->setIntervalFor( abtime );
494 
495  edm::LogInfo( "CondDBESSource" ) << "Validity coming from IOV sequence for record \"" << recordname
496  << "\" and label \""<< pmIter->second->label()
497  << "\": (" << validity.first << ", " << validity.second
498  << ") for time (type: "<< cond::timeTypeNames( timetype ) << ") " << abtime
499  << "; from CondDBESSource::setIntervalFor";
500 
501  recordValidity.first = std::max(recordValidity.first,validity.first);
502  recordValidity.second = std::min(recordValidity.second,validity.second);
503  }
504 
505  if( m_policy == REFRESH_OPEN_IOVS ) {
506  doRefresh = ( recordValidity.second == cond::timeTypeSpecs[timetype].endValue );
507  edm::LogInfo( "CondDBESSource" ) << "Validity for record \"" << recordname
508  << "\" and the corresponding label(s) coming from Condition DB: (" << recordValidity.first
509  << ", "<< recordValidity.first
510  << ") as the last IOV element in the IOV sequence is infinity"
511  << "; from CondDBESSource::setIntervalFor";
512  }
513 
514  // to force refresh we set end-value to the minimum such an IOV can extend to: current run or lumiblock
515 
516  if ( (!userTime) && recordValidity.second !=0 ) {
517  edm::IOVSyncValue start = cond::time::toIOVSyncValue(recordValidity.first, timetype, true);
518  edm::IOVSyncValue stop = doRefresh ? cond::time::limitedIOVSyncValue (iTime, timetype)
519  : cond::time::toIOVSyncValue(recordValidity.second, timetype, false);
520 
521  oInterval = edm::ValidityInterval( start, stop );
522  }
523 
524  edm::LogInfo( "CondDBESSource" ) << "Setting validity for record \"" << recordname
525  << "\" and corresponding label(s): starting at " << oInterval.first().eventID() << ", timestamp: " << oInterval.first().time().value()
526  << ", ending at "<< oInterval.last().eventID() << ", timestamp: " << oInterval.last().time().value()
527  << ", for "<< iTime.eventID() << ", timestamp: " << iTime.time().value()
528  << "; from CondDBESSource::setIntervalFor";
529 }
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().