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);
77  auto iovs = iovProxy.selectAll();
78  auto iiov = iovs.find(theIov);
79  if (iiov == iovs.end())
80  throw cms::Exception("Input IOV " + std::to_string(m_IOV) + "/" + m_Time + " is invalid!");
81 
82  theIov = (*iiov).since;
83  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
84  << "Make tkMap for IOV " << theIov << " ("
85  << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
86  auto payload = condDbSession.fetchPayload<SiStripDetVOff>((*iiov).payloadId);
87 
88  edm::ESHandle<TkDetMap> tkDetMapHandle;
89  evtSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
90  const TkDetMap* tkDetMap = tkDetMapHandle.product();
91  TrackerMap lvmap, hvmap;
92  TkHistoMap lvhisto(tkDetMap, "LV_Status", "LV_Status", -1);
93  TkHistoMap hvhisto(tkDetMap, "HV_Status", "HV_Status", -1);
94 
95  edm::ESHandle<GeometricDet> geomDetHandle;
96  evtSetup.get<IdealGeometryRecord>().get(geomDetHandle);
97 
98  const auto detids = TrackerGeometryUtils::getSiStripDetIds(*geomDetHandle);
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:60
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
edm::LogInfo
Definition: MessageLogger.h:254
EDAnalyzer.h
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:158
SiStripDetVOffTkMapPlotter::m_connectionPool
cond::persistency::ConnectionPool m_connectionPool
Definition: SiStripDetVOffTkMapPlotter.cc:32
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:171
TrackerGeometryUtils::getSiStripDetIds
std::vector< uint32_t > getSiStripDetIds(const GeometricDet &geomDet)
Definition: utils.cc:4
SiStripDetVOffTkMapPlotter::m_IOV
cond::Time_t m_IOV
Definition: SiStripDetVOffTkMapPlotter.cc:37
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
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:93
TkHistoMap::fill
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:176
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
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
edm::ESHandle
Definition: DTSurvey.h:22
TkDetMap
Definition: TkDetMap.h:175
jets_cff.payload
payload
Definition: jets_cff.py:34
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:36
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:39
utils.h
edm::EventSetup
Definition: EventSetup.h:57
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:125
get
#define get
SiStripDetVOffTkMapPlotter::m_plotFormat
std::string m_plotFormat
Definition: SiStripDetVOffTkMapPlotter.cc:41
TrackerMap.h
TkHistoMap
Definition: TkHistoMap.h:12
SiStripDetVOffTkMapPlotter::m_condDb
std::string m_condDb
Definition: SiStripDetVOffTkMapPlotter.cc:33
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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
cms::Exception
Definition: Exception.h:70
TimeConversions.h
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
SiStripDetVOff.h
edm::Event
Definition: Event.h:73
IdealGeometryRecord
Definition: IdealGeometryRecord.h:27
SiStripDetVOffTkMapPlotter::m_Time
std::string m_Time
Definition: SiStripDetVOffTkMapPlotter.cc:39
SiStripDetVOffTkMapPlotter::~SiStripDetVOffTkMapPlotter
~SiStripDetVOffTkMapPlotter() override
Definition: SiStripDetVOffTkMapPlotter.cc:58
SiStripDetVOffTkMapPlotter::formatIOV
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S")
Definition: SiStripDetVOffTkMapPlotter.cc:126
SiStripDetVOffTkMapPlotter::SiStripDetVOffTkMapPlotter
SiStripDetVOffTkMapPlotter(const edm::ParameterSet &iConfig)
Definition: SiStripDetVOffTkMapPlotter.cc:46