CMS 3D CMS Logo

SiStripDetVOffTkMapPlotter.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 #include <sstream>
9 
11 
14 
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 };
45 
47  : m_connectionPool(),
48  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
49  m_plotTag(iConfig.getParameter<std::string>("Tag")),
50  m_IOV(iConfig.getUntrackedParameter<cond::Time_t>("IOV", 0)),
51  m_Time(iConfig.getUntrackedParameter<std::string>("Time", "")),
52  m_plotFormat(iConfig.getUntrackedParameter<std::string>("plotFormat", "png")),
53  m_outputFile(iConfig.getUntrackedParameter<std::string>("outputFile", "")) {
56 }
57 
59 
61  cond::Time_t theIov = 0;
62  if (m_IOV != 0) {
63  theIov = m_IOV;
64  } else if (!m_Time.empty()) {
65  theIov = cond::time::from_boost(boost::posix_time::time_from_string(m_Time));
66  } else {
67  // Use the current time if no input. Will get the last IOV.
68  theIov = cond::time::from_boost(boost::posix_time::second_clock::universal_time());
69  }
70 
71  // open db session
72  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
73  << "Query the condition database " << m_condDb << " for tag " << m_plotTag;
75  condDbSession.transaction().start(true);
76  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag, true);
77  auto iiov = iovProxy.find(theIov);
78  if (iiov == iovProxy.end())
79  throw cms::Exception("Input IOV " + std::to_string(m_IOV) + "/" + m_Time + " is invalid!");
80 
81  theIov = (*iiov).since;
82  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
83  << "Make tkMap for IOV " << theIov << " ("
84  << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
85  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
86 
87  edm::ESHandle<TkDetMap> tkDetMapHandle;
88  evtSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
89  const TkDetMap* tkDetMap = tkDetMapHandle.product();
90  TrackerMap lvmap, hvmap;
91  TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
92  TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);
93 
94  edm::ESHandle<GeometricDet> geomDetHandle;
95  evtSetup.get<IdealGeometryRecord>().get(geomDetHandle);
96 
97  const auto detids = TrackerGeometryUtils::getSiStripDetIds(*geomDetHandle);
98  for (auto id : detids) {
99  if (payload->IsModuleLVOff(id))
100  lvhisto.fill(id, 1); // RED
101  else
102  lvhisto.fill(id, 0.5);
103 
104  if (payload->IsModuleHVOff(id))
105  hvhisto.fill(id, 1); // RED
106  else
107  hvhisto.fill(id, 0.5);
108  }
109 
110  lvhisto.dumpInTkMap(&lvmap);
111  hvhisto.dumpInTkMap(&hvmap);
112  lvmap.setPalette(1);
113  hvmap.setPalette(1);
114  lvmap.save(true, 0, 0, "LV_tkMap_" + formatIOV(theIov) + "." + m_plotFormat);
115  hvmap.save(true, 0, 0, "HV_tkMap_" + formatIOV(theIov) + "." + m_plotFormat);
116 
117  if (!m_outputFile.empty()) {
118  lvhisto.save(m_outputFile);
119  hvhisto.save(m_outputFile);
120  }
121 }
122 
124 
126  auto facet = new boost::posix_time::time_facet(format.c_str());
127  std::ostringstream stream;
128  stream.imbue(std::locale(stream.getloc(), facet));
129  stream << cond::time::to_boost(iov);
130  return stream.str();
131 }
132 
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:18
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:224
Transaction & transaction()
Definition: Session.cc:43
SiStripDetVOffTkMapPlotter(const edm::ParameterSet &iConfig)
void setParameters(const edm::ParameterSet &connectionPset)
void save(const std::string &filename)
Definition: TkHistoMap.cc:71
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:54
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned long long Time_t
Definition: Time.h:14
void setPalette(int numpalette)
Definition: TrackerMap.h:155
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:811
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:4
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:322
Session createSession(const std::string &connectionString, bool writeCapable=false)
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:270
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:176
cond::Time_t Time_t
Definition: Time.h:18
Definition: plugin.cc:23
T get() const
Definition: EventSetup.h:73
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:293