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 } // namespace BSPrintUtils
33 
35 public:
36  explicit BeamSpotRcdPrinter(const edm::ParameterSet& iConfig);
37  ~BeamSpotRcdPrinter() override;
38  void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) override;
39  void endJob() override;
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42 private:
46 
47  // Manually specify the start/end time.
48  unsigned long long m_startTime;
49  unsigned long long m_endTime;
50  // Specify output text file name. Leave empty if do not want to dump beamspots in a file.
52 };
53 
55  : m_connectionPool(),
56  m_condDb(iConfig.getParameter<std::string>("conditionDatabase")),
57  m_tagName(iConfig.getParameter<std::string>("tagName")),
58  m_startTime(iConfig.getParameter<unsigned long long>("startIOV")),
59  m_endTime(iConfig.getParameter<unsigned long long>("endIOV")),
60  m_output(iConfig.getParameter<std::string>("output")) {
63 }
64 
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  << ss.str();
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");
135  desc.add<std::string>("connect", "");
136 
137  edm::ParameterSetDescription descDBParameters;
138  descDBParameters.addUntracked<std::string>("authenticationPath", "");
139  descDBParameters.addUntracked<int>("authenticationSystem", 0);
140  descDBParameters.addUntracked<std::string>("security", "");
141  descDBParameters.addUntracked<int>("messageLevel", 0);
142 
143  desc.add<edm::ParameterSetDescription>("DBParameters", descDBParameters);
144  descriptions.add("BeamSpotRcdPrinter", desc);
145 }
146 
148 
EDAnalyzer.h
ConnectionPool.h
Time.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BeamSpotRcdPrinter::m_connectionPool
cond::persistency::ConnectionPool m_connectionPool
Definition: BeamSpotRcdPrinter.cc:43
BeamSpotRcdPrinter::BeamSpotRcdPrinter
BeamSpotRcdPrinter(const edm::ParameterSet &iConfig)
Definition: BeamSpotRcdPrinter.cc:54
EDAnalyzer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
cond::persistency::ConnectionPool::createSession
Session createSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:172
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:175
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MakerMacros.h
cond::persistency::IOVArray::find
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:95
BeamSpotObjects.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
writeEcalDQMStatus.since
since
Definition: writeEcalDQMStatus.py:53
jets_cff.payload
payload
Definition: jets_cff.py:32
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
cond::time::kLowMask
const Time_t kLowMask(0xFFFFFFFF)
BeamSpotRcdPrinter::m_tagName
std::string m_tagName
Definition: BeamSpotRcdPrinter.cc:45
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
BeamSpotRcdPrinter::analyze
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: BeamSpotRcdPrinter.cc:67
cond::persistency::ConnectionPool::setParameters
void setParameters(const edm::ParameterSet &connectionPset)
Definition: ConnectionPool.cc:43
BeamSpotObjects
Definition: BeamSpotObjects.h:20
edm::EventSetup
Definition: EventSetup.h:58
cond::persistency::ConnectionPool::configure
void configure()
Definition: ConnectionPool.cc:127
BeamSpotRcdPrinter::m_condDb
std::string m_condDb
Definition: BeamSpotRcdPrinter.cc:44
BeamSpotRcdPrinter::m_endTime
unsigned long long m_endTime
Definition: BeamSpotRcdPrinter.cc:49
BSPrintUtils::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: BeamSpotRcdPrinter.cc:26
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
BeamSpotRcdPrinter::m_output
std::string m_output
Definition: BeamSpotRcdPrinter.cc:51
BeamSpotRcdPrinter::~BeamSpotRcdPrinter
~BeamSpotRcdPrinter() override
Definition: BeamSpotRcdPrinter.cc:65
Exception
Definition: hltDiff.cc:245
BSPrintUtils
Definition: BeamSpotRcdPrinter.cc:25
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
BeamSpotRcdPrinter::endJob
void endJob() override
Definition: BeamSpotRcdPrinter.cc:147
TimeConversions.h
ParameterSet.h
BeamSpotRcdPrinter::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: BeamSpotRcdPrinter.cc:128
edm::Event
Definition: Event.h:73
BeamSpotRcdPrinter
Definition: BeamSpotRcdPrinter.cc:34
lumi
Definition: LumiSectionData.h:20
BeamSpotRcdPrinter::m_startTime
unsigned long long m_startTime
Definition: BeamSpotRcdPrinter.cc:48