CMS 3D CMS Logo

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