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

virtual void analyze (const edm::Event &evt, const edm::EventSetup &evtSetup)
 
virtual void endJob ()
 
 SiStripDetVOffTrendPlotter (const edm::ParameterSet &iConfig)
 
virtual ~SiStripDetVOffTrendPlotter ()
 
- 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
 
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
 
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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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 &)
 
- 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 27 of file SiStripDetVOffTrendPlotter.cc.

Constructor & Destructor Documentation

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

Definition at line 63 of file SiStripDetVOffTrendPlotter.cc.

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

63  :
65  m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
66  m_plotTags( iConfig.getParameter< std::vector<std::string> >("plotTags") ),
67  m_interval( iConfig.getParameter< int >("timeInterval") ),
68  m_startTime( iConfig.getUntrackedParameter< std::string >("startTime", "") ),
69  m_endTime( iConfig.getUntrackedParameter< std::string >("endTime", "") ),
70  m_outputPlot( iConfig.getUntrackedParameter< std::string >("outputPlot", "") ),
71  m_outputRootFile( iConfig.getUntrackedParameter< std::string >("outputRootFile", "") ),
72  m_outputCSV( iConfig.getUntrackedParameter< std::string >("outputCSV", "") ),
73  fout(nullptr){
76  if (m_outputRootFile!="") 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 ( )
virtual

Definition at line 79 of file SiStripDetVOffTrendPlotter.cc.

References fout.

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

Member Function Documentation

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

Definition at line 83 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, jetCorrFactors_cfi::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().

83  {
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") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
104  << "Set start IOV " << startIov << " (" << boost::posix_time::to_simple_string(p_start) << ")"
105  << "\n ... Set end IOV " << endIov << " (" << boost::posix_time::to_simple_string(p_end) << ")" ;
106 
107  // open db session
108  edm::LogInfo("SiStripDetVOffTrendPlotter") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
109  << "Query the condition database " << m_condDb;
110  cond::persistency::Session condDbSession = m_connectionPool.createSession( m_condDb );
111  condDbSession.transaction().start( true );
112 
113  // loop over all tags to plot
114  std::vector<TGraph*> hvgraphs, lvgraphs;
115  TLegend *leg_hv = new TLegend(0.6, 0.87, 0.99, 0.99);
116  TLegend *leg_lv = new TLegend(0.6, 0.87, 0.99, 0.99);
117  for (unsigned itag=0; itag<m_plotTags.size(); ++itag){
118  auto tag = m_plotTags.at(itag);
119  auto color = itag<PLOT_COLORS.size() ? PLOT_COLORS.at(itag) : kGreen+itag;
120 
121  std::vector<double> vTime;
122  std::vector<double> vHVOffPercent, vLVOffPercent;
123 
124  // query the database
125  edm::LogInfo("SiStripDetVOffTrendPlotter") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
126  << "Reading IOVs from tag " << tag;
127  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(tag, true); // load all?
128  auto iiov = iovProxy.find(startIov);
129  auto eiov = iovProxy.find(endIov);
130  int niov = 0;
131  while (iiov != iovProxy.end() && (*iiov).since <= (*eiov).since){
132  // convert cond::Time_t to seconds since epoch
133  if ((*iiov).since<startIov)
134  vTime.push_back(cond::time::unpack(startIov).first);
135  else
136  vTime.push_back(cond::time::unpack((*iiov).since).first);
137  auto payload = condDbSession.fetchPayload<SiStripDetVOff>( (*iiov).payloadId );
138  vHVOffPercent.push_back( 1.0*payload->getHVoffCounts()/num_modules );
139  vLVOffPercent.push_back( 1.0*payload->getLVoffCounts()/num_modules );
140  iovMap[(*iiov).since][tag] = {payload->getHVoffCounts(), payload->getLVoffCounts()};
141  // debug
142  std::cout << boost::posix_time::to_simple_string(cond::time::to_boost((*iiov).since))
143  << " (" << (*iiov).since << ")"
144  << ", # HV Off=" << std::setw(6) << payload->getHVoffCounts()
145  << ", # LV Off=" << std::setw(6) << payload->getLVoffCounts() << std::endl;
146  ++iiov;
147  ++niov;
148  }
149  edm::LogInfo("SiStripDetVOffTrendPlotter") << "[SiStripDetVOffTrendPlotter::" << __func__ << "] "
150  << "Read " << niov << " IOVs from tag " << tag << " in the specified interval.";
151 
152  TGraph *hv = new TGraph(vTime.size(), vTime.data(), vHVOffPercent.data());
153  prepGraph(hv, TString("HVOff_")+tag, ";UTC;Fraction of HV off", color);
154  leg_hv->AddEntry(hv, tag.data(), "LP");
155 
156  TGraph *lv = new TGraph(vTime.size(), vTime.data(), vLVOffPercent.data());
157  prepGraph(lv, TString("LVOff_")+tag, ";UTC;Fraction of LV off", color);
158  leg_lv->AddEntry(lv, tag.data(), "LP");
159 
160  hvgraphs.push_back(hv);
161  lvgraphs.push_back(lv);
162  }
163 
164  condDbSession.transaction().commit();
165 
166  // Make plots
167  TCanvas c("c", "c", 1800, 1200);
168  c.SetTopMargin(0.12);
169  c.SetBottomMargin(0.08);
170  c.SetGridx();
171  c.SetGridy();
172  for (const auto hv : hvgraphs){
173  if (hv==hvgraphs.front())
174  hv->Draw("ALP");
175  else
176  hv->Draw("LPsame");
177  if (fout){
178  fout->cd();
179  hv->Write();
180  }
181  }
182  leg_hv->Draw();
183  std::string plot_postfix = m_outputPlot!="" ? m_outputPlot : "from_" + formatIOV(startIov) + "_to_" + formatIOV(endIov) + ".png";
184  c.Print( ("HVOff_" + plot_postfix).data() );
185 
186  c.Clear();
187  for (const auto lv : lvgraphs){
188  if (lv==lvgraphs.front())
189  lv->Draw("ALP");
190  else
191  lv->Draw("LPsame");
192  if (fout){
193  fout->cd();
194  lv->Write();
195  }
196  }
197  leg_lv->Draw();
198  c.Print( ("LVOff_" + plot_postfix).data() );
199 
200  if (m_outputCSV!="") {
201  dumpCSV(true);
202  dumpCSV(false);
203  }
204 
205 }
void start(bool readOnly=true)
Definition: Session.cc:22
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
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
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)
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215
void SiStripDetVOffTrendPlotter::dumpCSV ( bool  isHV)
private

Definition at line 236 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().

236  {
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) csv << tag << ",";
246  csv << std::endl;
247 
248  csv << std::fixed << std::setprecision(1);
249 
250  for (const auto &v : iovMap){
251  auto iov = v.first;
252  auto timestamp = boost::posix_time::to_simple_string(cond::time::to_boost(iov));
253  csv << iov << "," << timestamp << ",";
254  for (const auto &tag : m_plotTags){
255  if (v.second.find(tag)!=v.second.end()){
256  int count = isHV ? v.second.at(tag).first : v.second.at(tag).second;
257  csv << count << " (" << 100.*count/num_modules << "%)";
258  }
259  csv << ",";
260  }
261  csv << std::endl;
262  }
263 
264  csv.close();
265 }
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  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 207 of file SiStripDetVOffTrendPlotter.cc.

Referenced by o2olib.O2ORunMgr::executeJob().

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

Definition at line 210 of file SiStripDetVOffTrendPlotter.cc.

References cond::time::to_boost().

Referenced by analyze().

210  {
211  auto facet = new boost::posix_time::time_facet(format.c_str());
212  std::ostringstream stream;
213  stream.imbue(std::locale(stream.getloc(), facet));
214  stream << cond::time::to_boost(iov);
215  return stream.str();
216 }
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 218 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

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

Member Data Documentation

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

Definition at line 57 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 60 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_condDb
private

Definition at line 42 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

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

Definition at line 41 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and SiStripDetVOffTrendPlotter().

std::string SiStripDetVOffTrendPlotter::m_endTime
private

Definition at line 49 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

int SiStripDetVOffTrendPlotter::m_interval
private

Definition at line 46 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_outputCSV
private

Definition at line 55 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_outputPlot
private

Definition at line 51 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_outputRootFile
private

Definition at line 53 of file SiStripDetVOffTrendPlotter.cc.

Referenced by SiStripDetVOffTrendPlotter().

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

Definition at line 43 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and dumpCSV().

std::string SiStripDetVOffTrendPlotter::m_startTime
private

Definition at line 48 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

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

Definition at line 29 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().