test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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
< SiStripDetInfoFileReader
detidReader
 
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 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().

62  :
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!="") fout = new TFile(m_outputRootFile.data(), "RECREATE");
76 }
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 78 of file SiStripDetVOffTrendPlotter.cc.

References fout.

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

Member Function Documentation

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

Implements edm::EDAnalyzer.

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

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

Definition at line 235 of file SiStripDetVOffTrendPlotter.cc.

References KineDebug3::count(), detidReader, SiStripDetInfoFileReader::getAllDetIds(), o2o::iov, 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().

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

Referenced by o2o.O2ORunMgr::executeJob().

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

Definition at line 209 of file SiStripDetVOffTrendPlotter.cc.

References cond::time::to_boost().

Referenced by analyze().

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

Referenced by analyze().

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

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().