CMS 3D CMS Logo

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