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 
22 
24 public:
25  explicit SiStripDetVOffTkMapPlotter(const edm::ParameterSet& iConfig );
26  ~SiStripDetVOffTkMapPlotter() override;
27  void analyze( const edm::Event& evt, const edm::EventSetup& evtSetup) override;
28  void endJob() override;
29 
30 private:
31  std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S");
32 
36 
37  // IOV of plotting.
39  // Or use datatime string. Format: "2002-01-20 23:59:59.000". Set IOV to 0 to use this.
41  // Set the plot format. Default: png.
43  // Specify output root file name. Leave empty if do not want to save plots in a root file.
45 
47 };
48 
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", "") ){
59 }
60 
62 }
63 
65 
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, true);
82  auto iiov = iovProxy.find(theIov);
83  if (iiov==iovProxy.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 << " (" << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
89  auto payload = condDbSession.fetchPayload<SiStripDetVOff>( (*iiov).payloadId );
90 
91  edm::ESHandle<TkDetMap> tkDetMapHandle;
92  evtSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
93  const TkDetMap* tkDetMap = tkDetMapHandle.product();
94  TrackerMap lvmap,hvmap;
95  TkHistoMap lvhisto(tkDetMap, "LV_Status","LV_Status",-1);
96  TkHistoMap hvhisto(tkDetMap, "HV_Status","HV_Status",-1);
97 
98  auto detids = detidReader->getAllDetIds();
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 }
124 
126 }
127 
129  auto facet = new boost::posix_time::time_facet(format.c_str());
130  std::ostringstream stream;
131  stream.imbue(std::locale(stream.getloc(), facet));
132  stream << cond::time::to_boost(iov);
133  return stream.str();
134 }
135 
137 
T getParameter(std::string const &) const
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void start(bool readOnly=true)
Definition: Session.cc:22
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:62
edm::Service< SiStripDetInfoFileReader > detidReader
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
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:237
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")
const T & get() const
Definition: EventSetup.h:59
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:162
cond::Time_t Time_t
Definition: Time.h:17
Definition: plugin.cc:24
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:297
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215