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 
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 
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", "")),
56  tkDetMapToken_(esConsumes()),
57  geomDetToken_(esConsumes()) {
60 }
61 
63 
65  cond::Time_t theIov = 0;
66  if (m_IOV != 0) {
67  theIov = m_IOV;
68  } else if (!m_Time.empty()) {
69  theIov = cond::time::from_boost(boost::posix_time::time_from_string(m_Time));
70  } else {
71  // Use the current time if no input. Will get the last IOV.
72  theIov = cond::time::from_boost(boost::posix_time::second_clock::universal_time());
73  }
74 
75  // open db session
76  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
77  << "Query the condition database " << m_condDb << " for tag " << m_plotTag;
79  condDbSession.transaction().start(true);
80  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag);
81  auto iovs = iovProxy.selectAll();
82  auto iiov = iovs.find(theIov);
83  if (iiov == iovs.end())
84  throw cms::Exception("Input IOV " + std::to_string(m_IOV) + "/" + m_Time + " is invalid!");
85 
86  theIov = (*iiov).since;
87  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
88  << "Make tkMap for IOV " << theIov << " ("
89  << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
90  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
91 
92  const TkDetMap* tkDetMap = &evtSetup.getData(tkDetMapToken_);
93  TrackerMap lvmap, hvmap;
94  TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
95  TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);
96 
97  const auto detids = TrackerGeometryUtils::getSiStripDetIds(evtSetup.getData(geomDetToken_));
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  auto facet = new boost::posix_time::time_facet(format.c_str());
125  std::ostringstream stream;
126  stream.imbue(std::locale(stream.getloc(), facet));
128  return stream.str();
129 }
130 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void start(bool readOnly=true)
Definition: Session.cc:18
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Transaction & transaction()
Definition: Session.cc:52
SiStripDetVOffTkMapPlotter(const edm::ParameterSet &iConfig)
void setParameters(const edm::ParameterSet &connectionPset)
~SiStripDetVOffTkMapPlotter() override
void save(const std::string &filename)
Definition: TkHistoMap.cc:72
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:5
Session createSession(const std::string &connectionString, bool writeCapable=false)
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:101
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:271
Time_t from_boost(boost::posix_time::ptime bt)
cond::persistency::ConnectionPool m_connectionPool
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
Log< level::Info, false > LogInfo
edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:177
cond::Time_t Time_t
Definition: Time.h:18
Definition: plugin.cc:23
boost::posix_time::ptime to_boost(Time_t iValue)