CMS 3D CMS Logo

BeamSpotRcdPrinter.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 
15 
16 #include <TROOT.h>
17 #include <TSystem.h>
18 #include <TCanvas.h>
19 #include <TFile.h>
20 #include <TLegend.h>
21 #include <TGraph.h>
22 #include <TH1.h>
23 
24 namespace BSPrintUtils {
25  std::pair<unsigned int, unsigned int> unpack(cond::Time_t since) {
26  auto kLowMask = 0XFFFFFFFF;
27  auto run = (since >> 32);
28  auto lumi = (since & kLowMask);
29  return std::make_pair(run, lumi);
30  }
31 } // namespace BSPrintUtils
32 
34 public:
35  explicit BeamSpotRcdPrinter(const edm::ParameterSet& iConfig);
36  ~BeamSpotRcdPrinter() override = default;
37  void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) override;
38  void endJob() override;
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
45 
46  // Manually specify the start/end time.
47  unsigned long long m_startTime;
48  unsigned long long m_endTime;
49  // Specify output text file name. Leave empty if do not want to dump beamspots in a file.
51  // decide if to print to screen the dump
52  bool m_verbose;
53 };
54 
56  : m_connectionPool(),
57  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
58  m_tagName(iConfig.getParameter<std::string>("tagName")),
59  m_startTime(iConfig.getParameter<unsigned long long>("startIOV")),
60  m_endTime(iConfig.getParameter<unsigned long long>("endIOV")),
61  m_output(iConfig.getParameter<std::string>("output")),
62  m_verbose(iConfig.getParameter<bool>("verbose")) {
65 }
66 
67 void BeamSpotRcdPrinter::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
68  cond::Time_t startIov = m_startTime;
69  cond::Time_t endIov = m_endTime;
70  if (startIov > endIov)
71  throw cms::Exception("endTime must be greater than startTime!");
72  edm::LogInfo("BeamSpotRcdPrinter") << "[BeamSpotRcdPrinter::" << __func__ << "] "
73  << "Set start time " << startIov << "\n ... Set end time " << endIov;
74 
75  // open db session
76  edm::LogInfo("BeamSpotRcdPrinter") << "[BeamSpotRcdPrinter::" << __func__ << "] "
77  << "Query the condition database " << m_condDb;
79  condDbSession.transaction().start(true);
80 
81  std::stringstream ss;
82  // list of times with new IOVs within the time range
83  std::vector<cond::Time_t> vTime;
84 
85  // query the database
86  edm::LogInfo("BeamSpotRcdPrinter") << "[BeamSpotRcdPrinter::" << __func__ << "] "
87  << "Reading IOVs from tag " << m_tagName;
88  cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_tagName); // load all?
89  auto iovs = iovProxy.selectAll();
90  auto iiov = iovs.find(startIov);
91  auto eiov = iovs.find(endIov);
92  int niov = 0;
93  while (iiov != iovs.end() && (*iiov).since <= (*eiov).since) {
94  // convert cond::Time_t to seconds since epoch
95  if ((*iiov).since < startIov) {
96  vTime.push_back(startIov);
97  } else {
98  vTime.push_back((*iiov).since);
99  }
100  auto payload = condDbSession.fetchPayload<BeamSpotObjects>((*iiov).payloadId);
101  auto runLS = BSPrintUtils::unpack((*iiov).since);
102  // print IOVs summary
103  ss << runLS.first << "," << runLS.second << " (" << (*iiov).since << ")"
104  << " [hash: " << (*iiov).payloadId << "] \n"
105  << *payload << std::endl;
106 
107  ++iiov;
108  ++niov;
109  }
110 
111  vTime.push_back(endIov); // used to compute last IOV duration
112 
113  edm::LogInfo("BeamSpotRcdPrinter") << "[BeamSpotRcdPrinter::" << __func__ << "] "
114  << "Read " << niov << " IOVs from tag " << m_tagName
115  << " corresponding to the specified time interval.\n\n"
116  << (m_verbose ? ss.str() : std::string{});
117 
118  condDbSession.transaction().commit();
119 
120  if (!m_output.empty()) {
121  std::ofstream fout;
122  fout.open(m_output);
123  fout << ss.str();
124  fout.close();
125  }
126 }
127 
130  desc.add<std::string>("conditionDatabase", "frontier://FrontierProd/CMS_CONDITIONS");
131  desc.add<std::string>("tagName", "BeamSpotObjects_PCL_byLumi_v0_prompt");
132  desc.add<unsigned long long>("startIOV", 1406859487478481);
133  desc.add<unsigned long long>("endIOV", 1406876667347162);
134  desc.add<std::string>("output", "summary.txt")->setComment("ASCII file with the full tag dump information");
135  desc.add<bool>("verbose", true)->setComment("print to screen the dump of all the payloads");
136  desc.add<std::string>("connect", "");
137 
138  edm::ParameterSetDescription descDBParameters;
139  descDBParameters.addUntracked<std::string>("authenticationPath", "");
140  descDBParameters.addUntracked<int>("authenticationSystem", 0);
141  descDBParameters.addUntracked<std::string>("security", "");
142  descDBParameters.addUntracked<int>("messageLevel", 0);
143 
144  desc.add<edm::ParameterSetDescription>("DBParameters", descDBParameters);
145  descriptions.add("BeamSpotRcdPrinter", desc);
146 }
147 
149 
~BeamSpotRcdPrinter() override=default
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
BeamSpotRcdPrinter(const edm::ParameterSet &iConfig)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void start(bool readOnly=true)
Definition: Session.cc:18
const Time_t kLowMask(0xFFFFFFFF)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
cond::persistency::ConnectionPool m_connectionPool
Transaction & transaction()
Definition: Session.cc:52
void setParameters(const edm::ParameterSet &connectionPset)
unsigned long long Time_t
Definition: Time.h:14
unsigned long long m_startTime
Session createSession(const std::string &connectionString, bool writeCapable=false)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:102
unsigned long long m_endTime
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
Log< level::Info, false > LogInfo
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void endJob() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)