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 
47 };
48 
50  : m_connectionPool(),
51  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
52  m_plotTag(iConfig.getParameter<std::string>("Tag")),
53  m_IOV(iConfig.getUntrackedParameter<cond::Time_t>("IOV", 0)),
54  m_Time(iConfig.getUntrackedParameter<std::string>("Time", "")),
55  m_plotFormat(iConfig.getUntrackedParameter<std::string>("plotFormat", "png")),
56  m_outputFile(iConfig.getUntrackedParameter<std::string>("outputFile", "")),
57  tkDetMapToken_(esConsumes()),
58  geomDetToken_(esConsumes()) {
61 }
62 
64 
66  cond::Time_t theIov = 0;
67  if (m_IOV != 0) {
68  theIov = m_IOV;
69  } else if (!m_Time.empty()) {
70  theIov = cond::time::from_boost(boost::posix_time::time_from_string(m_Time));
71  } else {
72  // Use the current time if no input. Will get the last IOV.
73  theIov = cond::time::from_boost(boost::posix_time::second_clock::universal_time());
74  }
75 
76  // open db session
77  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
78  << "Query the condition database " << m_condDb << " for tag " << m_plotTag;
80  condDbSession.transaction().start(true);
81  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag);
82  auto iovs = iovProxy.selectAll();
83  auto iiov = iovs.find(theIov);
84  if (iiov == iovs.end())
85  throw cms::Exception("Input IOV " + std::to_string(m_IOV) + "/" + m_Time + " is invalid!");
86 
87  theIov = (*iiov).since;
88  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
89  << "Make tkMap for IOV " << theIov << " ("
90  << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
91  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
92 
93  const TkDetMap* tkDetMap = &evtSetup.getData(tkDetMapToken_);
94  TrackerMap lvmap, hvmap;
95  TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
96  TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);
97 
98  const auto detids = TrackerGeometryUtils::getSiStripDetIds(evtSetup.getData(geomDetToken_));
99  for (auto id : detids) {
100  if (payload->IsModuleLVOff(id))
101  lvhisto.fill(id, 1); // RED
102  else
103  lvhisto.fill(id, 0.5);
104 
105  if (payload->IsModuleHVOff(id))
106  hvhisto.fill(id, 1); // RED
107  else
108  hvhisto.fill(id, 0.5);
109  }
110 
111  lvhisto.dumpInTkMap(&lvmap);
112  hvhisto.dumpInTkMap(&hvmap);
113  lvmap.setPalette(1);
114  hvmap.setPalette(1);
115  lvmap.save(true, 0, 0, "LV_tkMap_" + formatIOV(theIov) + "." + m_plotFormat);
116  hvmap.save(true, 0, 0, "HV_tkMap_" + formatIOV(theIov) + "." + m_plotFormat);
117 
118  if (!m_outputFile.empty()) {
119  lvhisto.save(m_outputFile);
120  hvhisto.save(m_outputFile);
121  }
122 }
123 
125 
127  auto facet = new boost::posix_time::time_facet(format.c_str());
128  std::ostringstream stream;
129  stream.imbue(std::locale(stream.getloc(), facet));
131  return stream.str();
132 }
133 
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
SiStripDetVOffTkMapPlotter::analyze
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: SiStripDetVOffTkMapPlotter.cc:65
ConnectionPool.h
cond::time::to_boost
boost::posix_time::ptime to_boost(Time_t iValue)
Definition: TimeConversions.h:39
TrackerMap::setPalette
void setPalette(int numpalette)
Definition: TrackerMap.h:155
SiStripDetVOffTkMapPlotter
Definition: SiStripDetVOffTkMapPlotter.cc:22
Time.h
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
EDAnalyzer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SiStripDetVOffTkMapPlotter::geomDetToken_
edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
Definition: SiStripDetVOffTkMapPlotter.cc:46
TkHistoMap::save
void save(const std::string &filename)
Definition: TkHistoMap.cc:71
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:172
SiStripDetVOffTkMapPlotter::m_connectionPool
cond::persistency::ConnectionPool m_connectionPool
Definition: SiStripDetVOffTkMapPlotter.cc:32
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:175
TrackerGeometryUtils::getSiStripDetIds
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:5
SiStripDetVOffTkMapPlotter::m_IOV
cond::Time_t m_IOV
Definition: SiStripDetVOffTkMapPlotter.cc:37
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
MakerMacros.h
cond::persistency::IOVArray::find
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:95
TkHistoMap::fill
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:176
TrackerTopologyRcd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
SiStripDetVOffTkMapPlotter::m_plotTag
std::string m_plotTag
Definition: SiStripDetVOffTkMapPlotter.cc:34
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
TkDetMap
Definition: TkDetMap.h:175
jets_cff.payload
payload
Definition: jets_cff.py:32
TrackerMap
Definition: TrackerMap.h:76
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
TkHistoMap.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond
Definition: plugin.cc:23
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
TkHistoMap::dumpInTkMap
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:270
cond::time::from_boost
Time_t from_boost(boost::posix_time::ptime bt)
Definition: TimeConversions.h:43
SiStripDetVOffTkMapPlotter::endJob
void endJob() override
Definition: SiStripDetVOffTkMapPlotter.cc:124
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
SiStripDetVOff
Definition: SiStripDetVOff.h:31
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
utils.h
edm::EventSetup
Definition: EventSetup.h:57
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
edm::ESGetToken< TkDetMap, TrackerTopologyRcd >
SiStripDetVOffTkMapPlotter::m_plotFormat
std::string m_plotFormat
Definition: SiStripDetVOffTkMapPlotter.cc:41
TrackerMap.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
TkHistoMap
Definition: TkHistoMap.h:12
SiStripDetVOffTkMapPlotter::m_condDb
std::string m_condDb
Definition: SiStripDetVOffTkMapPlotter.cc:33
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
TrackerMap::save
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:810
std
Definition: JetResolutionObject.h:76
SiStripDetVOffTkMapPlotter::m_outputFile
std::string m_outputFile
Definition: SiStripDetVOffTkMapPlotter.cc:43
format
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cms::Exception
Definition: Exception.h:70
TimeConversions.h
ParameterSet.h
SiStripDetVOff.h
edm::Event
Definition: Event.h:73
SiStripDetVOffTkMapPlotter::m_Time
std::string m_Time
Definition: SiStripDetVOffTkMapPlotter.cc:39
SiStripDetVOffTkMapPlotter::~SiStripDetVOffTkMapPlotter
~SiStripDetVOffTkMapPlotter() override
Definition: SiStripDetVOffTkMapPlotter.cc:63
SiStripDetVOffTkMapPlotter::formatIOV
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
Definition: SiStripDetVOffTkMapPlotter.cc:126
SiStripDetVOffTkMapPlotter::tkDetMapToken_
edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
Definition: SiStripDetVOffTkMapPlotter.cc:45
SiStripDetVOffTkMapPlotter::SiStripDetVOffTkMapPlotter
SiStripDetVOffTkMapPlotter(const edm::ParameterSet &iConfig)
Definition: SiStripDetVOffTkMapPlotter.cc:49