CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripDetVOffTkMapPlotter.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 #include <sstream>
8 
10 
15 
18 
19 
21 public:
22  explicit SiStripDetVOffTkMapPlotter(const edm::ParameterSet& iConfig );
24  virtual void analyze( const edm::Event& evt, const edm::EventSetup& evtSetup);
25  virtual void endJob();
26 
27 private:
28  std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S");
29 
33 
34  // IOV of plotting.
36  // Or use datatime string. Format: "2002-01-20 23:59:59.000". Set IOV to 0 to use this.
38  // Set the plot format. Default: png.
40  // Specify output root file name. Leave empty if do not want to save plots in a root file.
42 
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 }
60 
62 
63  cond::Time_t theIov = 0;
64  if (m_IOV != 0){
65  theIov = m_IOV;
66  }else if (!m_Time.empty()){
67  theIov = cond::time::from_boost( boost::posix_time::time_from_string(m_Time) );
68  }else{
69  // Use the current time if no input. Will get the last IOV.
70  theIov = cond::time::from_boost( boost::posix_time::second_clock::universal_time() );
71  }
72 
73  // open db session
74  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
75  << "Query the condition database " << m_condDb << " for tag " << m_plotTag;
77  condDbSession.transaction().start( true );
78  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag, true);
79  auto iiov = iovProxy.find(theIov);
80  if (iiov==iovProxy.end())
81  throw cms::Exception("Input IOV "+std::to_string(m_IOV)+"/"+m_Time+" is invalid!");
82 
83  theIov = (*iiov).since;
84  edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
85  << "Make tkMap for IOV " << theIov << " (" << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
86  auto payload = condDbSession.fetchPayload<SiStripDetVOff>( (*iiov).payloadId );
87 
88  TrackerMap lvmap,hvmap;
89  TkHistoMap lvhisto("LV_Status","LV_Status",-1);
90  TkHistoMap hvhisto("HV_Status","HV_Status",-1);
91 
92  auto detids = detidReader->getAllDetIds();
93  for (auto id : detids){
94  if (payload->IsModuleLVOff(id))
95  lvhisto.fill(id, 1); // RED
96  else
97  lvhisto.fill(id, 0.5);
98 
99  if (payload->IsModuleHVOff(id))
100  hvhisto.fill(id, 1); // RED
101  else
102  hvhisto.fill(id, 0.5);
103  }
104 
105  lvhisto.dumpInTkMap(&lvmap);
106  hvhisto.dumpInTkMap(&hvmap);
107  lvmap.setPalette(1);
108  hvmap.setPalette(1);
109  lvmap.save(true,0,0,"LV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);
110  hvmap.save(true,0,0,"HV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);
111 
112  if (!m_outputFile.empty()){
113  lvhisto.save(m_outputFile);
114  hvhisto.save(m_outputFile);
115  }
116 
117 }
118 
120 }
121 
123  auto facet = new boost::posix_time::time_facet(format.c_str());
124  std::ostringstream stream;
125  stream.imbue(std::locale(stream.getloc(), facet));
126  stream << cond::time::to_boost(iov);
127  return stream.str();
128 }
129 
131 
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:190
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)
edm::Service< SiStripDetInfoFileReader > detidReader
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
void save(std::string filename)
Definition: TkHistoMap.cc:57
unsigned long long Time_t
Definition: Time.h:16
const std::vector< uint32_t > & getAllDetIds() const
tuple iov
Definition: o2o.py:307
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:180
virtual void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup)
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:288
Session createSession(const std::string &connectionString, bool writeCapable=false)
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:234
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")
cond::Time_t Time_t
Definition: Time.h:17
boost::posix_time::ptime to_boost(Time_t iValue)
Iterator end() const
Definition: IOVProxy.cc:265