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 {kBlack, kRed, kBlue, kOrange, kMagenta}
 

Private Member Functions

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::string m_condDb
 
cond::persistency::ConnectionPool m_connectionPool
 
std::string m_endTime
 
int m_interval
 
std::string m_outputFile
 
std::string m_plotFormat
 
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 25 of file SiStripDetVOffTrendPlotter.cc.

Constructor & Destructor Documentation

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

Definition at line 55 of file SiStripDetVOffTrendPlotter.cc.

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

55  :
57  m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
58  m_plotTags( iConfig.getParameter< std::vector<std::string> >("plotTags") ),
59  m_interval( iConfig.getParameter< int >("timeInterval") ),
60  m_startTime( iConfig.getUntrackedParameter< std::string >("startTime", "") ),
61  m_endTime( iConfig.getUntrackedParameter< std::string >("endTime", "") ),
62  m_plotFormat( iConfig.getUntrackedParameter< std::string >("plotFormat", "png") ),
63  m_outputFile( iConfig.getUntrackedParameter< std::string >("outputFile", "") ),
64  fout(nullptr){
67  if (m_outputFile!="") fout = new TFile(m_outputFile.data(), "RECREATE");
68 }
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 70 of file SiStripDetVOffTrendPlotter.cc.

References fout.

70  {
71  if (fout) fout->Close();
72 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 74 of file SiStripDetVOffTrendPlotter.cc.

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

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

Reimplemented from edm::EDAnalyzer.

Definition at line 188 of file SiStripDetVOffTrendPlotter.cc.

Referenced by o2o.O2ORunMgr::executeJob().

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

Definition at line 191 of file SiStripDetVOffTrendPlotter.cc.

References cond::time::to_boost().

Referenced by analyze().

191  {
192  auto facet = new boost::posix_time::time_facet(format.c_str());
193  std::ostringstream stream;
194  stream.imbue(std::locale(stream.getloc(), facet));
195  stream << cond::time::to_boost(iov);
196  return stream.str();
197 }
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 199 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

199  {
200  gr->SetName(name);
201  gr->SetTitle(title);
202  gr->SetLineColor(color);
203  gr->SetMarkerStyle(20);
204  gr->SetMarkerColor(color);
205  gr->GetXaxis()->SetTimeDisplay(1);
206  gr->GetXaxis()->SetTimeOffset(0, "gmt");
207  gr->GetYaxis()->SetRangeUser(0, 1.01);
208 }

Member Data Documentation

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

Definition at line 52 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

TFile* SiStripDetVOffTrendPlotter::fout
private
std::string SiStripDetVOffTrendPlotter::m_condDb
private

Definition at line 39 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

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

Definition at line 38 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze(), and SiStripDetVOffTrendPlotter().

std::string SiStripDetVOffTrendPlotter::m_endTime
private

Definition at line 46 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

int SiStripDetVOffTrendPlotter::m_interval
private

Definition at line 43 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_outputFile
private

Definition at line 50 of file SiStripDetVOffTrendPlotter.cc.

Referenced by SiStripDetVOffTrendPlotter().

std::string SiStripDetVOffTrendPlotter::m_plotFormat
private

Definition at line 48 of file SiStripDetVOffTrendPlotter.cc.

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

Definition at line 40 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

std::string SiStripDetVOffTrendPlotter::m_startTime
private

Definition at line 45 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().

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

Definition at line 27 of file SiStripDetVOffTrendPlotter.cc.

Referenced by analyze().