CMS 3D CMS Logo

FileBasedEmptySource.cc
Go to the documentation of this file.
5 #include <string>
6 #include <fstream>
7 #include <unistd.h>
8 namespace cond {
10  public:
12  ~FileBasedEmptySource() override;
13  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
14 
15  private:
16  void produce(edm::Event& e) override;
19  edm::EventAuxiliary::ExperimentType& eType) override;
21 
22  private:
23  unsigned int m_interval;
24  unsigned long long m_eventId;
25  unsigned int m_eventsPerLumi;
27  unsigned int m_currentRun;
28  unsigned int m_currentLumi;
29  boost::posix_time::ptime m_currentLumiTime;
30  };
31 } // namespace cond
32 
36 //#include "DataFormats/Provenance/interface/EventID.h"
37 
38 namespace cond {
39  //allowed parameters: firstRun, firstTime, lastRun, lastTime,
40  //common paras: timetype,interval
42  : edm::ProducerSourceBase(pset, desc, true),
43  m_interval(pset.getParameter<unsigned int>("interval")),
44  m_eventId(0),
45  m_eventsPerLumi(pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock")),
46  m_pathForLastLumiFile(pset.getParameter<std::string>("pathForLastLumiFile")),
47  m_currentRun(0),
48  m_currentLumi(0),
49  m_currentLumiTime() {}
50 
52 
54 
59  {
60  std::ifstream lastLumiFile(m_pathForLastLumiFile);
61  if (lastLumiFile) {
63  } else {
64  std::cout << "Error: last lumi file can't be read." << std::endl;
65  return false;
66  }
67  }
69  unsigned int runId = t.first;
70  unsigned int lumiId = t.second;
71  //std::cout <<"###### setRunAndEventInfo Run: "<<runId<<" lumi: "<<lumiId<<std::endl;
72  boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
73  if (runId == m_currentRun && lumiId == m_currentLumi) {
74  m_eventId += 1;
75  if (m_eventId >= m_eventsPerLumi) {
76  return false;
77  }
78  } else {
79  m_currentRun = runId;
80  m_currentLumi = lumiId;
82  m_eventId = 1;
83  }
84  std::cout << "###### setRunAndEventInfo Run: " << runId << " lumi: " << lumiId << " event id: " << m_eventId
85  << " time:" << boost::posix_time::to_simple_string(now) << std::endl;
87  id = edm::EventID(runId, lumiId, m_eventId);
88  usleep(20000);
89  return true;
90  }
91 
94  {
95  std::ifstream lastLumiFile(m_pathForLastLumiFile);
96  if (lastLumiFile) {
98  } else {
99  std::cout << "Error: last lumi file can't be read." << std::endl;
100  return;
101  }
102  }
103  m_eventId = 0;
104  auto t = cond::time::unpack(lastLumi);
105  unsigned int runId = t.first;
106  unsigned int lumiId = t.second;
107  std::cout << "###### initialize Run: " << runId << " lumi: " << lumiId << std::endl;
108  m_currentRun = runId;
109  m_currentLumi = lumiId;
110  boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
113  id = edm::EventID(runId, lumiId, m_eventId);
115  }
116 
119  desc.setComment("Creates runs, lumis and events containing no products.");
120  ProducerSourceBase::fillDescription(desc);
121 
122  //desc.add<unsigned int>("firstRunnumber")->setComment("The first run number to use");
123  //desc.add<unsigned int>("lastRunnumber")->setComment("The last run number to use");
124  //desc.add<unsigned int>("firstLumi")->setComment("The first lumi id to use");
125  //desc.add<unsigned int>("lastLumi")->setComment("The last lumi id to use");
126  //desc.add<unsigned int>("maxLumiInRun");
127  //desc.add<std::string>("startTime");
128  //desc.add<std::string>("endTime");
129  desc.add<unsigned int>("interval");
130  desc.add<unsigned int>("maxEvents");
131  desc.add<std::string>("pathForLastLumiFile");
132  descriptions.add("source", desc);
133  }
134 
135 } // namespace cond
136 
139 
boost::posix_time::ptime m_currentLumiTime
const Time_t MIN_VAL(0)
unsigned long long Time_t
Definition: Time.h:14
#define DEFINE_FWK_INPUT_SOURCE(type)
unsigned long long TimeValue_t
Definition: Timestamp.h:21
Time_t from_boost(boost::posix_time::ptime bt)
FileBasedEmptySource(edm::ParameterSet const &, edm::InputSourceDescription const &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: plugin.cc:23
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void initialize(edm::EventID &id, edm::TimeValue_t &time, edm::TimeValue_t &interval) override
bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &eType) override
void produce(edm::Event &e) override
cond::UnpackedTime unpack(cond::Time_t iValue)