CMS 3D CMS Logo

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

Public Member Functions

void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup) override
 
void endJob () override
 
 SiStripDetVOffTrendPlotter (const edm::ParameterSet &iConfig)
 
 ~SiStripDetVOffTrendPlotter () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () 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)
 

Public Attributes

const std::vector< Color_t > PLOT_COLORS {kRed, kBlue, kBlack, kOrange, kMagenta}
 

Private Member Functions

void dumpCSV (bool isHV)
 
std::string formatIOV (cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
 
void prepGraph (TGraph *gr, TString name, TString title, Color_t color)
 

Private Attributes

edm::Service< SiStripDetInfoFileReaderdetidReader
 
TFile * fout
 
std::map< cond::Time_t, std::map< std::string, std::pair< int, int > > > iovMap
 
std::string m_condDb
 
cond::persistency::ConnectionPool m_connectionPool
 
std::string m_endTime
 
int m_interval
 
std::string m_outputCSV
 
std::string m_outputPlot
 
std::string m_outputRootFile
 
std::vector< std::string > m_plotTags
 
std::string m_startTime
 

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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 26 of file SiStripDetVOffTrendPlotter.cc.

Constructor & Destructor Documentation

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

Definition at line 62 of file SiStripDetVOffTrendPlotter.cc.

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

63  : m_connectionPool(),
64  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
65  m_plotTags(iConfig.getParameter<std::vector<std::string>>("plotTags")),
66  m_interval(iConfig.getParameter<int>("timeInterval")),
67  m_startTime(iConfig.getUntrackedParameter<std::string>("startTime", "")),
68  m_endTime(iConfig.getUntrackedParameter<std::string>("endTime", "")),
69  m_outputPlot(iConfig.getUntrackedParameter<std::string>("outputPlot", "")),
70  m_outputRootFile(iConfig.getUntrackedParameter<std::string>("outputRootFile", "")),
71  m_outputCSV(iConfig.getUntrackedParameter<std::string>("outputCSV", "")),
72  fout(nullptr) {
75  if (!m_outputRootFile.empty())
76  fout = new TFile(m_outputRootFile.data(), "RECREATE");
77 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > m_plotTags
void setParameters(const edm::ParameterSet &connectionPset)
cond::persistency::ConnectionPool m_connectionPool
SiStripDetVOffTrendPlotter::~SiStripDetVOffTrendPlotter ( )
override

Definition at line 79 of file SiStripDetVOffTrendPlotter.cc.

References fout.

79  {
80  if (fout)
81  fout->Close();
82 }

Member Function Documentation

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

Definition at line 84 of file SiStripDetVOffTrendPlotter.cc.

References EnergyCorrector::c, create_public_lumi_plots::color, cond::persistency::Transaction::commit(), gather_cfg::cout, cond::persistency::ConnectionPool::createSession(), data, detidReader, dumpCSV(), cond::persistency::IOVProxy::end(), Exception, cond::persistency::Session::fetchPayload(), cond::persistency::IOVProxy::find(), plotBeamSpotDB::first, formatIOV(), fout, cond::time::from_boost(), SiStripDetInfoFileReader::getAllDetIds(), AnalysisDataFormats_SUSYBSMObjects::hv, iovMap, m_condDb, m_connectionPool, m_endTime, m_interval, m_outputCSV, m_outputPlot, m_plotTags, m_startTime, jets_cff::payload, PLOT_COLORS, prepGraph(), cond::persistency::Session::readIov(), cond::persistency::Transaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, cond::time::to_boost(), cond::persistency::Session::transaction(), and cond::time::unpack().

84  {
85  // get total number of modules
86  auto num_modules = detidReader->getAllDetIds().size();
87 
88  // get start and end time for DB query
89  boost::posix_time::ptime p_start, p_end;
90  if (m_interval > 0) {
91  // from m_interval hours ago to now
92  p_end = boost::posix_time::second_clock::universal_time();
93  p_start = p_end - boost::posix_time::hours(m_interval);
94  } else {
95  // use start and end time from config file
96  p_start = boost::posix_time::time_from_string(m_startTime);
97  p_end = boost::posix_time::time_from_string(m_endTime);
98  }
99  cond::Time_t startIov = cond::time::from_boost(p_start);
100  cond::Time_t endIov = cond::time::from_boost(p_end);
101  if (startIov > endIov)
102  throw cms::Exception("endTime must be greater than startTime!");
103  edm::LogInfo("SiStripDetVOffTrendPlotter")
104  << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
105  << "Set start IOV " << startIov << " (" << boost::posix_time::to_simple_string(p_start) << ")"
106  << "\n ... Set end IOV " << endIov << " (" << boost::posix_time::to_simple_string(p_end) << ")";
107 
108  // open db session
109  edm::LogInfo("SiStripDetVOffTrendPlotter") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
110  << "Query the condition database " << m_condDb;
112  condDbSession.transaction().start(true);
113 
114  // loop over all tags to plot
115  std::vector<TGraph *> hvgraphs, lvgraphs;
116  TLegend *leg_hv = new TLegend(0.6, 0.87, 0.99, 0.99);
117  TLegend *leg_lv = new TLegend(0.6, 0.87, 0.99, 0.99);
118  for (unsigned itag = 0; itag < m_plotTags.size(); ++itag) {
119  auto tag = m_plotTags.at(itag);
120  auto color = itag < PLOT_COLORS.size() ? PLOT_COLORS.at(itag) : kGreen + itag;
121 
122  std::vector<double> vTime;
123  std::vector<double> vHVOffPercent, vLVOffPercent;
124 
125  // query the database
126  edm::LogInfo("SiStripDetVOffTrendPlotter") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
127  << "Reading IOVs from tag " << tag;
128  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(tag, true); // load all?
129  auto iiov = iovProxy.find(startIov);
130  auto eiov = iovProxy.find(endIov);
131  int niov = 0;
132  while (iiov != iovProxy.end() && (*iiov).since <= (*eiov).since) {
133  // convert cond::Time_t to seconds since epoch
134  if ((*iiov).since < startIov)
135  vTime.push_back(cond::time::unpack(startIov).first);
136  else
137  vTime.push_back(cond::time::unpack((*iiov).since).first);
138  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
139  vHVOffPercent.push_back(1.0 * payload->getHVoffCounts() / num_modules);
140  vLVOffPercent.push_back(1.0 * payload->getLVoffCounts() / num_modules);
141  iovMap[(*iiov).since][tag] = {payload->getHVoffCounts(), payload->getLVoffCounts()};
142  // debug
143  std::cout << boost::posix_time::to_simple_string(cond::time::to_boost((*iiov).since)) << " (" << (*iiov).since
144  << ")"
145  << ", # HV Off=" << std::setw(6) << payload->getHVoffCounts() << ", # LV Off=" << std::setw(6)
146  << payload->getLVoffCounts() << std::endl;
147  ++iiov;
148  ++niov;
149  }
150  edm::LogInfo("SiStripDetVOffTrendPlotter")
151  << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
152  << "Read " << niov << " IOVs from tag " << tag << " in the specified interval.";
153 
154  TGraph *hv = new TGraph(vTime.size(), vTime.data(), vHVOffPercent.data());
155  prepGraph(hv, TString("HVOff_") + tag, ";UTC;Fraction of HV off", color);
156  leg_hv->AddEntry(hv, tag.data(), "LP");
157 
158  TGraph *lv = new TGraph(vTime.size(), vTime.data(), vLVOffPercent.data());
159  prepGraph(lv, TString("LVOff_") + tag, ";UTC;Fraction of LV off", color);
160  leg_lv->AddEntry(lv, tag.data(), "LP");
161 
162  hvgraphs.push_back(hv);
163  lvgraphs.push_back(lv);
164  }
165 
166  condDbSession.transaction().commit();
167 
168  // Make plots
169  TCanvas c("c", "c", 1800, 1200);
170  c.SetTopMargin(0.12);
171  c.SetBottomMargin(0.08);
172  c.SetGridx();
173  c.SetGridy();
174  for (const auto hv : hvgraphs) {
175  if (hv == hvgraphs.front())
176  hv->Draw("ALP");
177  else
178  hv->Draw("LPsame");
179  if (fout) {
180  fout->cd();
181  hv->Write();
182  }
183  }
184  leg_hv->Draw();
185  std::string plot_postfix =
186  !m_outputPlot.empty() ? m_outputPlot : "from_" + formatIOV(startIov) + "_to_" + formatIOV(endIov) + ".png";
187  c.Print(("HVOff_" + plot_postfix).data());
188 
189  c.Clear();
190  for (const auto lv : lvgraphs) {
191  if (lv == lvgraphs.front())
192  lv->Draw("ALP");
193  else
194  lv->Draw("LPsame");
195  if (fout) {
196  fout->cd();
197  lv->Write();
198  }
199  }
200  leg_lv->Draw();
201  c.Print(("LVOff_" + plot_postfix).data());
202 
203  if (!m_outputCSV.empty()) {
204  dumpCSV(true);
205  dumpCSV(false);
206  }
207 }
void start(bool readOnly=true)
Definition: Session.cc:22
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:218
susybsm::HSCParticleRefVector hv
Definition: classes.h:28
std::vector< std::string > m_plotTags
Transaction & transaction()
Definition: Session.cc:66
void prepGraph(TGraph *gr, TString name, TString title, Color_t color)
edm::Service< SiStripDetInfoFileReader > detidReader
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
unsigned long long Time_t
Definition: Time.h:16
const std::vector< uint32_t > & getAllDetIds() const
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
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)
std::map< cond::Time_t, std::map< std::string, std::pair< int, int > > > iovMap
cond::persistency::ConnectionPool m_connectionPool
const std::vector< Color_t > PLOT_COLORS
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:297
cond::UnpackedTime unpack(cond::Time_t iValue)
void SiStripDetVOffTrendPlotter::dumpCSV ( bool  isHV)
private

Definition at line 237 of file SiStripDetVOffTrendPlotter.cc.

References KineDebug3::count(), DEFINE_FWK_MODULE, detidReader, alignBH_cfg::fixed, SiStripDetInfoFileReader::getAllDetIds(), iovMap, m_outputCSV, m_plotTags, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, cond::timestamp, cond::time::to_boost(), and findQualityFiles::v.

Referenced by analyze().

237  {
238  // get total number of modules
239  auto num_modules = detidReader->getAllDetIds().size();
240 
241  std::string outCSV = isHV ? "HVOff_table_" + m_outputCSV : "LVOff_table_" + m_outputCSV;
242  std::ofstream csv;
243  csv.open(outCSV);
244  csv << "IOV,Timestamp(UTC),";
245  for (const auto &tag : m_plotTags)
246  csv << tag << ",";
247  csv << std::endl;
248 
249  csv << std::fixed << std::setprecision(1);
250 
251  for (const auto &v : iovMap) {
252  auto iov = v.first;
253  auto timestamp = boost::posix_time::to_simple_string(cond::time::to_boost(iov));
254  csv << iov << "," << timestamp << ",";
255  for (const auto &tag : m_plotTags) {
256  if (v.second.find(tag) != v.second.end()) {
257  int count = isHV ? v.second.at(tag).first : v.second.at(tag).second;
258  csv << count << " (" << 100. * count / num_modules << "%)";
259  }
260  csv << ",";
261  }
262  csv << std::endl;
263  }
264 
265  csv.close();
266 }
std::vector< std::string > m_plotTags
edm::Service< SiStripDetInfoFileReader > detidReader
const std::vector< uint32_t > & getAllDetIds() const
std::map< cond::Time_t, std::map< std::string, std::pair< int, int > > > iovMap
boost::posix_time::ptime to_boost(Time_t iValue)
void SiStripDetVOffTrendPlotter::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 209 of file SiStripDetVOffTrendPlotter.cc.

Referenced by o2olib.O2ORunMgr::executeJob().

209 {}
std::string SiStripDetVOffTrendPlotter::formatIOV ( cond::Time_t  iov,
std::string  format = "%Y-%m-%d__%H_%M_%S" 
)
private

Definition at line 211 of file SiStripDetVOffTrendPlotter.cc.

References cond::time::to_boost().

Referenced by analyze().

211  {
212  auto facet = new boost::posix_time::time_facet(format.c_str());
213  std::ostringstream stream;
214  stream.imbue(std::locale(stream.getloc(), facet));
215  stream << cond::time::to_boost(iov);
216  return stream.str();
217 }
boost::posix_time::ptime to_boost(Time_t iValue)
void SiStripDetVOffTrendPlotter::prepGraph ( TGraph *  gr,
TString  name,
TString  title,
Color_t  color 
)
private

Definition at line 219 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

219  {
220  gr->SetName(name);
221  gr->SetTitle(title);
222  gr->SetLineColor(color);
223  gr->SetLineWidth(2);
224  gr->SetMarkerStyle(20);
225  gr->SetMarkerSize(1.5);
226  gr->SetMarkerColor(color);
227  gr->GetXaxis()->SetTimeDisplay(1);
228  gr->GetXaxis()->SetLabelOffset(0.02);
229  gr->GetXaxis()->SetTimeFormat("#splitline{%b %d}{%H:%M}");
230  gr->GetXaxis()->SetTimeOffset(0, "gmt");
231  gr->GetXaxis()->SetLabelSize(0.025);
232  gr->GetXaxis()->SetTitleSize(0.025);
233  gr->GetXaxis()->SetTitleOffset(1.6);
234  gr->GetYaxis()->SetRangeUser(0, 1.05);
235 }

Member Data Documentation

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

Definition at line 56 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

TFile* SiStripDetVOffTrendPlotter::fout
private
std::map<cond::Time_t, std::map<std::string, std::pair<int, int> > > SiStripDetVOffTrendPlotter::iovMap
private

Definition at line 59 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_condDb
private

Definition at line 41 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

cond::persistency::ConnectionPool SiStripDetVOffTrendPlotter::m_connectionPool
private

Definition at line 40 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and SiStripDetVOffTrendPlotter().

std::string SiStripDetVOffTrendPlotter::m_endTime
private

Definition at line 48 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

int SiStripDetVOffTrendPlotter::m_interval
private

Definition at line 45 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_outputCSV
private

Definition at line 54 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_outputPlot
private

Definition at line 50 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_outputRootFile
private

Definition at line 52 of file SiStripDetVOffTrendPlotter.cc.

Referenced by SiStripDetVOffTrendPlotter().

std::vector<std::string> SiStripDetVOffTrendPlotter::m_plotTags
private

Definition at line 42 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_startTime
private

Definition at line 47 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

const std::vector<Color_t> SiStripDetVOffTrendPlotter::PLOT_COLORS {kRed, kBlue, kBlack, kOrange, kMagenta}

Definition at line 28 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().