CMS 3D CMS Logo

SiStripDetVOffTkMapPlotter.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 #include <sstream>
9 
11 
16 
19 
20 
22 public:
23  explicit SiStripDetVOffTkMapPlotter(const edm::ParameterSet& iConfig );
24  ~SiStripDetVOffTkMapPlotter() override;
25  void analyze( const edm::Event& evt, const edm::EventSetup& evtSetup) override;
26  void endJob() override;
27 
28 private:
29  std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S");
30 
34 
35  // IOV of plotting.
37  // Or use datatime string. Format: "2002-01-20 23:59:59.000". Set IOV to 0 to use this.
39  // Set the plot format. Default: png.
41  // Specify output root file name. Leave empty if do not want to save plots in a root file.
43 
45 };
46 
49  m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
50  m_plotTag( iConfig.getParameter< std::string >("Tag") ),
51  m_IOV( iConfig.getUntrackedParameter< cond::Time_t >("IOV", 0) ),
52  m_Time( iConfig.getUntrackedParameter< std::string >("Time", "") ),
53  m_plotFormat( iConfig.getUntrackedParameter< std::string >("plotFormat", "png") ),
54  m_outputFile( iConfig.getUntrackedParameter< std::string >("outputFile", "") ){
57 }
58 
60 }
61 
63 
64  cond::Time_t theIov = 0;
65  if (m_IOV != 0){
66  theIov = m_IOV;
67  }else if (!m_Time.empty()){
68  theIov = cond::time::from_boost( boost::posix_time::time_from_string(m_Time) );
69  }else{
70  // Use the current time if no input. Will get the last IOV.
71  theIov = cond::time::from_boost( boost::posix_time::second_clock::universal_time() );
72  }
73 
74  // open db session
75  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
76  << "Query the condition database " << m_condDb << " for tag " << m_plotTag;
78  condDbSession.transaction().start( true );
79  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag, true);
80  auto iiov = iovProxy.find(theIov);
81  if (iiov==iovProxy.end())
82  throw cms::Exception("Input IOV "+std::to_string(m_IOV)+"/"+m_Time+" is invalid!");
83 
84  theIov = (*iiov).since;
85  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
86  << "Make tkMap for IOV " << theIov << " (" << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
87  auto payload = condDbSession.fetchPayload<SiStripDetVOff>( (*iiov).payloadId );
88 
89  TrackerMap lvmap,hvmap;
90  TkHistoMap lvhisto("LV_Status","LV_Status",-1);
91  TkHistoMap hvhisto("HV_Status","HV_Status",-1);
92 
93  auto detids = detidReader->getAllDetIds();
94  for (auto id : detids){
95  if (payload->IsModuleLVOff(id))
96  lvhisto.fill(id, 1); // RED
97  else
98  lvhisto.fill(id, 0.5);
99 
100  if (payload->IsModuleHVOff(id))
101  hvhisto.fill(id, 1); // RED
102  else
103  hvhisto.fill(id, 0.5);
104  }
105 
106  lvhisto.dumpInTkMap(&lvmap);
107  hvhisto.dumpInTkMap(&hvmap);
108  lvmap.setPalette(1);
109  hvmap.setPalette(1);
110  lvmap.save(true,0,0,"LV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);
111  hvmap.save(true,0,0,"HV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);
112 
113  if (!m_outputFile.empty()){
114  lvhisto.save(m_outputFile);
115  hvhisto.save(m_outputFile);
116  }
117 
118 }
119 
121 }
122 
124  auto facet = new boost::posix_time::time_facet(format.c_str());
125  std::ostringstream stream;
126  stream.imbue(std::locale(stream.getloc(), facet));
127  stream << cond::time::to_boost(iov);
128  return stream.str();
129 }
130 
132 
T getParameter(std::string const &) const
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void start(bool readOnly=true)
Definition: Session.cc:22
Transaction & transaction()
Definition: Session.cc:66
SiStripDetVOffTkMapPlotter(const edm::ParameterSet &iConfig)
void setParameters(const edm::ParameterSet &connectionPset)
edm::Service< SiStripDetInfoFileReader > detidReader
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
void save(std::string filename)
Definition: TkHistoMap.cc:57
unsigned long long Time_t
Definition: Time.h:16
const std::vector< uint32_t > & getAllDetIds() const
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:180
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
Session createSession(const std::string &connectionString, bool writeCapable=false)
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:234
Time_t from_boost(boost::posix_time::ptime bt)
cond::persistency::ConnectionPool m_connectionPool
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
cond::Time_t Time_t
Definition: Time.h:17
Definition: plugin.cc:24
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:297
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215