CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
SiStripDetVOffPrinter Class Reference
Inheritance diagram for SiStripDetVOffPrinter:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup) override
 
void endJob () override
 
 SiStripDetVOffPrinter (const edm::ParameterSet &iConfig)
 
 ~SiStripDetVOffPrinter () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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 & itemsToGetFrom (BranchType iType) 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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Attributes

std::map< uint32_t, std::vector< cond::Time_t > > detidMap
 
edm::Service< SiStripDetInfoFileReaderdetidReader
 
std::map< cond::Time_t, std::set< uint32_t > > iovMap_HVOff
 
std::map< cond::Time_t, std::set< uint32_t > > iovMap_LVOff
 
std::string m_condDb
 
cond::persistency::ConnectionPool m_connectionPool
 
std::string m_endTime
 
std::string m_output
 
std::string m_startTime
 
std::string m_tagName
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 27 of file SiStripDetVOffPrinter.cc.

Constructor & Destructor Documentation

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

Definition at line 54 of file SiStripDetVOffPrinter.cc.

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

55  : m_connectionPool(),
56  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
57  m_tagName(iConfig.getParameter<std::string>("tagName")),
58  m_startTime(iConfig.getParameter<std::string>("startTime")),
59  m_endTime(iConfig.getParameter<std::string>("endTime")),
60  m_output(iConfig.getParameter<std::string>("output")) {
63 }
T getParameter(std::string const &) const
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool m_connectionPool
SiStripDetVOffPrinter::~SiStripDetVOffPrinter ( )
override

Definition at line 65 of file SiStripDetVOffPrinter.cc.

65 {}

Member Function Documentation

void SiStripDetVOffPrinter::analyze ( const edm::Event evt,
const edm::EventSetup evtSetup 
)
override

Definition at line 67 of file SiStripDetVOffPrinter.cc.

References cond::persistency::Transaction::commit(), cond::persistency::ConnectionPool::createSession(), detidMap, cond::persistency::IOVProxy::end(), Exception, cond::persistency::Session::fetchPayload(), spr::find(), cond::persistency::IOVProxy::find(), groupFilesInBlocks::fout, cond::time::from_boost(), iovMap_HVOff, iovMap_LVOff, m_condDb, m_connectionPool, m_endTime, m_output, m_startTime, m_tagName, jets_cff::payload, cond::persistency::Session::readIov(), cond::persistency::Transaction::start(), cond::time::to_boost(), and cond::persistency::Session::transaction().

67  {
68  // get total number of modules
69  //auto num_modules = detidReader->getAllDetIds().size();
70 
71  // use start and end time from config file
72  boost::posix_time::ptime p_start, p_end;
73  p_start = boost::posix_time::time_from_string(m_startTime);
74  p_end = boost::posix_time::time_from_string(m_endTime);
75  cond::Time_t startIov = cond::time::from_boost(p_start);
76  cond::Time_t endIov = cond::time::from_boost(p_end);
77  if (startIov > endIov)
78  throw cms::Exception("endTime must be greater than startTime!");
79  edm::LogInfo("SiStripDetVOffPrinter") << "[SiStripDetVOffPrinter::" << __func__ << "] "
80  << "Set start time " << startIov << " ("
81  << boost::posix_time::to_simple_string(p_start) << ")"
82  << "\n ... Set end time " << endIov << " ("
83  << boost::posix_time::to_simple_string(p_end) << ")";
84 
85  // open db session
86  edm::LogInfo("SiStripDetVOffPrinter") << "[SiStripDetVOffPrinter::" << __func__ << "] "
87  << "Query the condition database " << m_condDb;
89  condDbSession.transaction().start(true);
90 
91  std::stringstream ss;
92  // list of times with new IOVs within the time range
93  std::vector<cond::Time_t> vTime;
94 
95  // query the database
96  edm::LogInfo("SiStripDetVOffPrinter") << "[SiStripDetVOffPrinter::" << __func__ << "] "
97  << "Reading IOVs from tag " << m_tagName;
98  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_tagName, true); // load all?
99  auto iiov = iovProxy.find(startIov);
100  auto eiov = iovProxy.find(endIov);
101  int niov = 0;
102  while (iiov != iovProxy.end() && (*iiov).since <= (*eiov).since) {
103  // convert cond::Time_t to seconds since epoch
104  if ((*iiov).since < startIov) {
105  vTime.push_back(startIov);
106  } else {
107  vTime.push_back((*iiov).since);
108  }
109  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
110  // print IOVs summary
111  ss << boost::posix_time::to_simple_string(cond::time::to_boost((*iiov).since)) << " (" << (*iiov).since << ")"
112  << ", # HV Off=" << std::setw(6) << payload->getHVoffCounts() << ", # LV Off=" << std::setw(6)
113  << payload->getLVoffCounts() << std::endl;
114 
115  // list of detids with HV/LV Off
116  std::vector<uint32_t> detIds;
117  payload->getDetIds(detIds);
118  std::set<uint32_t> detIds_HVOff;
119  std::set<uint32_t> detIds_LVOff;
120  std::vector<uint32_t>::const_iterator it = detIds.begin();
121  for (; it != detIds.end(); ++it) {
122  if (payload->IsModuleHVOff(*it))
123  detIds_HVOff.insert(*it);
124  if (payload->IsModuleLVOff(*it))
125  detIds_LVOff.insert(*it);
126 
127  if (detidMap.find(*it) == detidMap.end()) {
128  std::vector<cond::Time_t> vec;
129  detidMap[*it] = vec;
130  }
131 
132  // for each module concerned by the IOV, add the time in an history vector
133  detidMap[*it].push_back(vTime.back());
134  }
135 
136  // fill list of channels Off at a given time
137  iovMap_HVOff[vTime.back()] = detIds_HVOff;
138  iovMap_LVOff[vTime.back()] = detIds_LVOff;
139 
140  /*std::vector<uint32_t>::const_iterator it = detIds.begin();
141  for( ; it!=detIds.end(); ++it ) {
142  std::cout << *it << std::endl;
143  }*/
144 
145  ++iiov;
146  ++niov;
147  }
148  vTime.push_back(endIov); // used to compute last IOV duration
149 
150  edm::LogInfo("SiStripDetVOffPrinter") << "[SiStripDetVOffPrinter::" << __func__ << "] "
151  << "Read " << niov << " IOVs from tag " << m_tagName
152  << " corresponding to the specified time interval.\n"
153  << ss.str();
154 
155  // Create a map of IOVs time_duration
156  std::map<cond::Time_t, boost::posix_time::time_duration> mIOVsDuration;
157  std::vector<cond::Time_t>::const_iterator itTime = ++vTime.begin();
158  std::vector<cond::Time_t>::const_iterator itPreviousTime = vTime.begin();
159  //std::vector< cond::Time_t >::const_iterator itLastTime = --vTime.end();
160  for (; itTime != vTime.end(); ++itTime) {
161  mIOVsDuration[*itPreviousTime] = cond::time::to_boost(*itTime) - cond::time::to_boost(*itPreviousTime);
162  itPreviousTime = itTime;
163  }
164  boost::posix_time::time_duration time_period =
165  cond::time::to_boost(*(--vTime.end())) - cond::time::to_boost(*(vTime.begin()));
166 
167  // debug
168  /*for( itTime=vTime.begin(); itTime!=itLastTime; ++itTime ) {
169  std::cout<<boost::posix_time::to_simple_string( cond::time::to_boost(*itTime) ) << " " <<boost::posix_time::to_simple_string(mIOVsDuration[ *itTime ])<<std::endl;
170  }*/
171 
172  // Print summary per module
173  edm::LogInfo("SiStripDetVOffPrinter") << "[SiStripDetVOffPrinter::" << __func__ << "] " << detidMap.size()
174  << " modules were Off at some point during the time interval";
175  ss.str("");
176 
177  // Loop over detIds
178  std::map<uint32_t, std::vector<cond::Time_t> >::const_iterator itMap = detidMap.begin();
179  for (; itMap != detidMap.end(); ++itMap) {
180  std::vector<cond::Time_t> vecTime = itMap->second;
181 
182  boost::posix_time::time_duration cumul_time_HVOff(0, 0, 0, 0);
183  boost::posix_time::time_duration cumul_time_LVOff(0, 0, 0, 0);
184  // Loop over IOVs
185  std::vector<cond::Time_t>::const_iterator itTime = vecTime.begin();
186  for (; itTime != vecTime.end(); ++itTime) {
187  if (iovMap_HVOff[*itTime].find(itMap->first) != iovMap_HVOff[*itTime].end())
188  cumul_time_HVOff += mIOVsDuration[*itTime];
189  if (iovMap_LVOff[*itTime].find(itMap->first) != iovMap_LVOff[*itTime].end())
190  cumul_time_LVOff += mIOVsDuration[*itTime];
191  }
192  ss << "detId " << itMap->first << " #IOVs: " << vecTime.size() << " HVOff: " << cumul_time_HVOff << " "
193  << cumul_time_HVOff.total_milliseconds() * 100.0 / time_period.total_milliseconds() << "% "
194  << " LVOff: " << cumul_time_LVOff << " "
195  << cumul_time_LVOff.total_milliseconds() * 100.0 / time_period.total_milliseconds() << "%" << std::endl;
196  }
197 
198  condDbSession.transaction().commit();
199 
200  if (!m_output.empty()) {
201  std::ofstream fout;
202  fout.open(m_output);
203  fout << ss.str();
204  fout.close();
205  }
206 }
std::map< cond::Time_t, std::set< uint32_t > > iovMap_LVOff
std::map< uint32_t, std::vector< cond::Time_t > > detidMap
void start(bool readOnly=true)
Definition: Session.cc:22
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:218
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
Transaction & transaction()
Definition: Session.cc:66
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
unsigned long long Time_t
Definition: Time.h:16
std::map< cond::Time_t, std::set< uint32_t > > iovMap_HVOff
cond::persistency::ConnectionPool m_connectionPool
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
Session createSession(const std::string &connectionString, bool writeCapable=false)
Time_t from_boost(boost::posix_time::ptime bt)
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:297
void SiStripDetVOffPrinter::endJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 227 of file SiStripDetVOffPrinter.cc.

References DEFINE_FWK_MODULE.

Referenced by o2olib.O2ORunMgr::executeJob().

227 {}
void SiStripDetVOffPrinter::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 208 of file SiStripDetVOffPrinter.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

208  {
210  desc.add<std::string>("conditionDatabase", "frontier://FrontierProd/CMS_CONDITIONS");
211  desc.add<std::string>("tagName", "SiStripDetVOff_1hourDelay_v1_Validation");
212  desc.add<std::string>("startTime", "2002-01-20 23:59:59.000");
213  desc.add<std::string>("endTime", "2002-01-20 23:59:59.000");
214  desc.add<std::string>("output", "PerModuleSummary.txt");
215  desc.add<std::string>("connect", "");
216 
217  edm::ParameterSetDescription descDBParameters;
218  descDBParameters.addUntracked<std::string>("authenticationPath", "");
219  descDBParameters.addUntracked<int>("authenticationSystem", 0);
220  descDBParameters.addUntracked<std::string>("security", "");
221  descDBParameters.addUntracked<int>("messageLevel", 0);
222 
223  desc.add<edm::ParameterSetDescription>("DBParameters", descDBParameters);
224  descriptions.add("siStripDetVOffPrinter", desc);
225 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

Member Data Documentation

std::map<uint32_t, std::vector<cond::Time_t> > SiStripDetVOffPrinter::detidMap
private

Definition at line 51 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

edm::Service<SiStripDetInfoFileReader> SiStripDetVOffPrinter::detidReader
private

Definition at line 45 of file SiStripDetVOffPrinter.cc.

std::map<cond::Time_t, std::set<uint32_t> > SiStripDetVOffPrinter::iovMap_HVOff
private

Definition at line 48 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

std::map<cond::Time_t, std::set<uint32_t> > SiStripDetVOffPrinter::iovMap_LVOff
private

Definition at line 49 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

std::string SiStripDetVOffPrinter::m_condDb
private

Definition at line 37 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

cond::persistency::ConnectionPool SiStripDetVOffPrinter::m_connectionPool
private

Definition at line 36 of file SiStripDetVOffPrinter.cc.

Referenced by analyze(), and SiStripDetVOffPrinter().

std::string SiStripDetVOffPrinter::m_endTime
private

Definition at line 42 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

std::string SiStripDetVOffPrinter::m_output
private

Definition at line 44 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

std::string SiStripDetVOffPrinter::m_startTime
private

Definition at line 41 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().

std::string SiStripDetVOffPrinter::m_tagName
private

Definition at line 38 of file SiStripDetVOffPrinter.cc.

Referenced by analyze().