CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
SiStripDetVOffHandler Class Reference
Inheritance diagram for SiStripDetVOffHandler:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

virtual void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup)
 
virtual void endJob ()
 
 SiStripDetVOffHandler (const edm::ParameterSet &iConfig)
 
virtual ~SiStripDetVOffHandler ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

std::string m_condDb
 
cond::persistency::ConnectionPool m_connectionPool
 
std::string m_localCondDbFile
 
std::string m_targetTag
 
int maxTimeBeforeNewIOV_
 
edm::Service< SiStripDetVOffBuildermodHVBuilder
 
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > newPayloads
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 14 of file SiStripDetVOffHandler.cc.

Constructor & Destructor Documentation

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

Definition at line 33 of file SiStripDetVOffHandler.cc.

References cond::persistency::ConnectionPool::configure(), edm::ParameterSet::getParameter(), m_condDb, m_connectionPool, m_localCondDbFile, and cond::persistency::ConnectionPool::setParameters().

33  :
35  m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
36  m_localCondDbFile( iConfig.getParameter< std::string >("condDbFile") ),
37  m_targetTag( iConfig.getParameter< std::string >("targetTag") ),
38  maxTimeBeforeNewIOV_( iConfig.getUntrackedParameter< int >("maxTimeBeforeNewIOV", 24) ){
41  // get last IOV from local sqlite file if "conditionDatabase" is empty
42  if (m_condDb.empty()) m_condDb = m_localCondDbFile;
43 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool m_connectionPool
SiStripDetVOffHandler::~SiStripDetVOffHandler ( )
virtual

Definition at line 45 of file SiStripDetVOffHandler.cc.

45  {
46 }

Member Function Documentation

void SiStripDetVOffHandler::analyze ( const edm::Event evt,
const edm::EventSetup evtSetup 
)
virtual

Definition at line 48 of file SiStripDetVOffHandler.cc.

References SiStripDetVOffBuilder::BuildDetVOffObj(), cond::persistency::Transaction::commit(), cond::persistency::Session::createIov(), cond::persistency::ConnectionPool::createSession(), cond::persistency::Session::editIov(), cond::persistency::Session::existsDatabase(), cond::persistency::Session::existsIov(), cond::persistency::Session::fetchPayload(), cond::persistency::IOVEditor::flush(), cond::persistency::IOVProxy::getLast(), SiStripDetVOffBuilder::getModulesVOff(), cond::persistency::IOVEditor::insert(), m_condDb, m_connectionPool, m_localCondDbFile, m_targetTag, maxTimeBeforeNewIOV_, modHVBuilder, newPayloads, jetCorrFactors_cfi::payload, cond::Iov_t::payloadId, cond::persistency::Session::readIov(), edm::second(), cond::persistency::IOVEditor::setDescription(), SiStripDetVOffBuilder::setLastSiStripDetVOff(), cond::Iov_t::since, cond::persistency::Transaction::start(), cond::persistency::Session::storePayload(), cond::timestamp, cond::time::to_boost(), and cond::persistency::Session::transaction().

48  {
49  // get last payload from condDb
50  cond::Time_t lastIov = 0;
51  std::shared_ptr<SiStripDetVOff> lastPayload;
52 
53  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
54  << "Retrieve last IOV from " << m_condDb;
55  cond::persistency::Session condDbSession = m_connectionPool.createSession( m_condDb );
56  condDbSession.transaction().start( true );
57  if ( m_condDb.find("sqlite")==0 && (!condDbSession.existsDatabase()) ){
58  // Source of last IOV is empty
59  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
60  << "No information can be retrieved from " << m_condDb << " because the file is empty.\n"
61  << "Will assume all HV/LV's are off.";
62  }else{
63  cond::persistency::IOVProxy iovProxy = condDbSession.readIov( m_targetTag );
64  cond::Hash lastPayloadHash = iovProxy.getLast().payloadId;
65  if ( !lastPayloadHash.empty() ) {
66  lastPayload = condDbSession.fetchPayload<SiStripDetVOff>( lastPayloadHash );
67  lastIov = iovProxy.getLast().since; // move to LastValidatedTime?
68  }
69  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
70  << " ... last IOV: " << lastIov << " , " << "last Payload: " << lastPayloadHash;
71  }
72  condDbSession.transaction().commit();
73 
74  // build the object!
75  newPayloads.clear();
76  modHVBuilder->setLastSiStripDetVOff( lastPayload.get(), lastIov );
79  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
80  << "Finished building " << newPayloads.size() << " new payloads.";
81 
82  // write the payloads to sqlite file
83  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
84  << "Write new payloads to sqlite file " << m_localCondDbFile;
85  cond::persistency::Session localFileSession = m_connectionPool.createSession( m_localCondDbFile, true );
86  localFileSession.transaction().start( false );
87  if ( lastPayload && newPayloads.size() == 1 && *newPayloads[0].first == *lastPayload ){
88  // if no HV/LV transition was found in this period
89  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
90  << "No HV/LV transition was found from PVSS query.";
91  bool forceNewIOV = true;
92  if (maxTimeBeforeNewIOV_ < 0)
93  forceNewIOV = false;
94  else {
95  auto deltaT = cond::time::to_boost(newPayloads[0].second) - cond::time::to_boost(lastIov);
96  forceNewIOV = deltaT > boost::posix_time::hours(maxTimeBeforeNewIOV_);
97  }
98  if ( !forceNewIOV ){
99  newPayloads.erase(newPayloads.begin());
100  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
101  << " ... No payload transfered.";
102  }else {
103  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
104  << " ... The last IOV is too old. Will start a new IOV from " << newPayloads[0].second
105  << "(" << boost::posix_time::to_simple_string(cond::time::to_boost(newPayloads[0].second)) << ") with the same payload.";
106  }
107  }
108 
110  if (localFileSession.existsDatabase() && localFileSession.existsIov(m_targetTag)){
111  edm::LogWarning("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
112  << "IOV of tag " << m_targetTag << " already exists in sqlite file " << m_localCondDbFile;
113  iovEditor = localFileSession.editIov(m_targetTag);
114  }else {
115  iovEditor = localFileSession.createIov<SiStripDetVOff>( m_targetTag, cond::timestamp );
116  iovEditor.setDescription( "New IOV" );
117  }
118  for (const auto &payload : newPayloads){
119  cond::Hash thePayloadHash = localFileSession.storePayload<SiStripDetVOff>( *payload.first );
120  iovEditor.insert( payload.second, thePayloadHash );
121  }
122  iovEditor.flush();
123  localFileSession.transaction().commit();
124 
125  edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
126  << newPayloads.size() << " payloads written to sqlite file.";
127 
128 }
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > getModulesVOff()
void start(bool readOnly=true)
Definition: Session.cc:22
Time_t since
Definition: Types.h:55
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:180
void setDescription(const std::string &description)
Definition: IOVEditor.cc:128
Transaction & transaction()
Definition: Session.cc:66
U second(std::pair< T, U > const &p)
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > newPayloads
payload
payload postfix for testing
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
unsigned long long Time_t
Definition: Time.h:16
edm::Service< SiStripDetVOffBuilder > modHVBuilder
Hash payloadId
Definition: Types.h:57
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::string Hash
Definition: Types.h:45
cond::persistency::ConnectionPool m_connectionPool
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:141
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:152
bool existsIov(const std::string &tag)
Definition: Session.cc:97
void setLastSiStripDetVOff(SiStripDetVOff *lastPayload, cond::Time_t lastTimeStamp)
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:184
boost::posix_time::ptime to_boost(Time_t iValue)
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:197
void SiStripDetVOffHandler::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 130 of file SiStripDetVOffHandler.cc.

Referenced by o2olib.O2ORunMgr::executeJob().

130  {
131 }

Member Data Documentation

std::string SiStripDetVOffHandler::m_condDb
private

Definition at line 23 of file SiStripDetVOffHandler.cc.

Referenced by analyze(), and SiStripDetVOffHandler().

cond::persistency::ConnectionPool SiStripDetVOffHandler::m_connectionPool
private

Definition at line 22 of file SiStripDetVOffHandler.cc.

Referenced by analyze(), and SiStripDetVOffHandler().

std::string SiStripDetVOffHandler::m_localCondDbFile
private

Definition at line 24 of file SiStripDetVOffHandler.cc.

Referenced by analyze(), and SiStripDetVOffHandler().

std::string SiStripDetVOffHandler::m_targetTag
private

Definition at line 25 of file SiStripDetVOffHandler.cc.

Referenced by analyze().

int SiStripDetVOffHandler::maxTimeBeforeNewIOV_
private

Definition at line 27 of file SiStripDetVOffHandler.cc.

Referenced by analyze().

edm::Service<SiStripDetVOffBuilder> SiStripDetVOffHandler::modHVBuilder
private

Definition at line 30 of file SiStripDetVOffHandler.cc.

Referenced by analyze().

std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > SiStripDetVOffHandler::newPayloads
private

Definition at line 29 of file SiStripDetVOffHandler.cc.

Referenced by analyze().