CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConfigurableInputSource.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 
4 #include <errno.h>
5 
14 
15 namespace edm {
16  //used for defaults
17  static unsigned long long const kNanoSecPerSec = 1000000000ULL;
18  static unsigned long long const kAveEventPerSec = 200ULL;
19 
21  InputSourceDescription const& desc, bool realData) :
22  InputSource(pset, desc),
23  numberEventsInRun_(pset.getUntrackedParameter<unsigned int>("numberEventsInRun", remainingEvents())),
24  numberEventsInLumi_(pset.getUntrackedParameter<unsigned int>("numberEventsInLuminosityBlock", remainingEvents())),
25  presentTime_(pset.getUntrackedParameter<unsigned long long>("firstTime", 1ULL)), //time in ns
26  origTime_(presentTime_),
27  timeBetweenEvents_(pset.getUntrackedParameter<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)),
28  eventCreationDelay_(pset.getUntrackedParameter<unsigned int>("eventCreationDelay", 0)),
29  numberEventsInThisRun_(0),
30  numberEventsInThisLumi_(0),
31  zerothEvent_(pset.getUntrackedParameter<unsigned int>("firstEvent", 1) - 1),
32  eventID_(pset.getUntrackedParameter<unsigned int>("firstRun", 1), pset.getUntrackedParameter<unsigned int>("firstLuminosityBlock", 1), zerothEvent_),
33  origEventID_(eventID_),
34  newRun_(true),
35  newLumi_(true),
36  eventCached_(false),
37  lumiSet_(false),
38  eventSet_(false),
39  isRealData_(realData),
40  eType_(EventAuxiliary::Undefined),
41  numberOfEventsBeforeBigSkip_(0),
42  numberOfSequentialEvents_(0)
43  {
44 
46  // We need to map this string to the EventAuxiliary::ExperimentType enumeration
47  // std::string eType = pset.getUntrackedParameter<std::string>("experimentType", std::string("Any"))),
48  }
49 
51  }
52 
53  boost::shared_ptr<RunAuxiliary>
56  newRun_ = false;
57  return boost::shared_ptr<RunAuxiliary>(new RunAuxiliary(eventID_.run(), ts, Timestamp::invalidTimestamp()));
58  }
59 
60  boost::shared_ptr<LuminosityBlockAuxiliary>
62  if (processingMode() == Runs) return boost::shared_ptr<LuminosityBlockAuxiliary>();
64  newLumi_ = false;
65  return boost::shared_ptr<LuminosityBlockAuxiliary>(new LuminosityBlockAuxiliary(eventID_.run(), eventID_.luminosityBlock(), ts, Timestamp::invalidTimestamp()));
66  }
67 
71  eventCached_ = false;
72  return eventPrincipalCache();
73  }
74 
75  void
77  if (processingMode() != RunsLumisAndEvents) return;
78  EventSourceSentry sentry(*this);
82  if (!produce(e)) {
83  eventCached_ = false;
84  return;
85  }
86  e.commit_();
87  eventCached_ = true;
88  }
89 
90  void
92  for (; offset < 0; ++offset) {
94  }
95  for (; offset > 0; --offset) {
96  advanceToNext();
97  }
98  }
99 
100 
101  void
103  // No need to check for invalid (zero) run number,
104  // as this is a legitimate way of stopping the job.
105  // Do nothing if the run is not changed.
106  if (r != eventID_.run()) {
110  newRun_ = newLumi_ = true;
111  }
112  }
113 
114  void
116  }
117 
118  void
120  }
121 
122  void
124  }
125 
126  void
128  }
129 
130  void
132  // Protect against invalid lumi.
133  if (lb == LuminosityBlockNumber_t()) {
135  }
136  // Do nothing if the lumi block is not changed.
137  if (lb != eventID_.luminosityBlock()) {
140  newLumi_ = true;
141  }
142  lumiSet_ = true;
143  }
144 
145  void
146  ConfigurableInputSource::postForkReacquireResources(boost::shared_ptr<edm::multicore::MessageReceiverForSource> iReceiver) {
147  receiver_ = iReceiver;
148  receiver_->receive();
149  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices() + 1;
150  numberOfSequentialEvents_ = receiver_->numberOfConsecutiveIndices();
151  repeat();
152  rewind();
153  }
154 
155  void
161 
162  if(receiver_) {
163  unsigned int numberToSkip = receiver_->numberToSkip();
164  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices() + 1;
165  //NOTE: skip() will decrease numberOfEventsBeforeBigSkip_ and therefore we need
166  // to be sure it is large enough so that it never goes to 0 during the skipping
167  if(numberOfEventsBeforeBigSkip_ < numberToSkip) {
168  numberOfEventsBeforeBigSkip_ = numberToSkip+1;
169  }
170  skip(numberToSkip);
171  decreaseRemainingEventsBy(numberToSkip);
172  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices() + 1;
173  }
174  newRun_ = newLumi_ = true;
175  }
176 
179  if (newRun_) {
180  if (eventID_.run() == RunNumber_t()) {
181  eventCached_ = false;
182  return IsStop;
183  }
184  return IsRun;
185  }
186  if (newLumi_) {
187  return IsLumi;
188  }
189  if(eventCached_) {
190  return IsEvent;
191  }
192  EventID oldEventID = eventID_;
194  size_t index = fileIndex();
195  if (!eventSet_) {
196  lumiSet_ = false;
198  eventSet_ = true;
199  nextEvent();
200  }
201  if (eventID_.run() == RunNumber_t()) {
202  eventCached_ = false;
203  return IsStop;
204  }
205  bool newFile = (fileIndex() > index);
206  if (oldEventID.run() != eventID_.run()) {
207  // New Run
208  // If the user did not explicitly set the luminosity block number,
209  // reset it back to the beginning.
210  if (!lumiSet_) {
212  }
213  newRun_ = newLumi_ = true;
214  return newFile ? IsFile : IsRun;
215  }
216  // Same Run
217  if (oldLumi != eventID_.luminosityBlock()) {
218  // New Lumi
219  newLumi_ = true;
220  if (processingMode() != Runs) {
221  return newFile ? IsFile : IsLumi;
222  }
223  }
224  reallyReadEvent();
225  if(!eventCached_) {
226  return IsStop;
227  }
228  eventSet_ = false;
229  return IsEvent;
230  }
231 
232  void
235  // same run
238  // new lumi
241  } else {
244  }
245  } else {
246  // new run
250  }
252  }
253 
254  void
256  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
257  // same run
260  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
261  // new lumi
264  } else {
266  }
267  } else {
268  // new run
273  }
275  }
276 
277  void
280  receiver_->receive();
281  unsigned long numberOfEventsToSkip = receiver_->numberToSkip();
282  if (numberOfEventsToSkip !=0) {
283  skip(numberOfEventsToSkip);
284  decreaseRemainingEventsBy(numberOfEventsToSkip);
285  }
286  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices();
287  //Since we decrease 'remaining events' count we need to see if we reached 0 and therefore are at the end
289  //this means we are to stop
290  eventID_ = EventID();
291  return;
292  }
293  }
294  advanceToNext();
295  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
296  }
297 
298  void
300  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")->setComment("Number of events to generate in each run.");
301  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")->setComment("Number of events to generate in each lumi.");
302  desc.addUntracked<unsigned long long>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
303  desc.addUntracked<unsigned long long>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)->setComment("Time between consecutive events (ns) (for timestamp).");
304  desc.addUntracked<unsigned int>("eventCreationDelay", 0)->setComment("Real time delay between generation of consecutive events (ms).");
305  desc.addUntracked<unsigned int>("firstEvent", 1)->setComment("Event number of first event to generate.");
306  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
307  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
309  }
310 
311 }
RunNumber_t run() const
Definition: EventID.h:42
EventAuxiliary::ExperimentType eType_
static unsigned long long const kNanoSecPerSec
void decreaseRemainingEventsBy(int iSkipped)
Definition: InputSource.cc:482
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescription(ParameterSetDescription &desc)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
virtual void setRun(RunNumber_t r)
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:229
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:293
virtual bool produce(Event &e)=0
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
boost::shared_ptr< LuminosityBlockPrincipal > const luminosityBlockPrincipal() const
Definition: InputSource.cc:281
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:190
boost::shared_ptr< edm::multicore::MessageReceiverForSource > receiver_
EventID previous(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:66
EventID next(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:47
int remainingEvents() const
Definition: InputSource.h:170
virtual void endLuminosityBlock(LuminosityBlock &)
void setLuminosityBlockNumber(LuminosityBlockNumber_t const &lb)
Definition: EventID.h:115
virtual size_t fileIndex() const
unsigned int offset(bool)
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
static unsigned long long const kAveEventPerSec
ConfigurableInputSource(ParameterSet const &pset, InputSourceDescription const &desc, bool realData=true)
void commit_(std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:103
virtual void postForkReacquireResources(boost::shared_ptr< edm::multicore::MessageReceiverForSource >)
void repeat()
Reset the remaining number of events/lumis to the maximum number.
Definition: InputSource.h:158
virtual void beginLuminosityBlock(LuminosityBlock &)
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:56
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:129
void rewind()
Begin again at the first event.
Definition: InputSource.cc:407
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
int remainingLuminosityBlocks() const
Definition: InputSource.h:178
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:181
unsigned int RunNumber_t
Definition: EventRange.h:32
virtual void setLumi(LuminosityBlockNumber_t lb)
EventPrincipal * eventPrincipalCache()
Definition: InputSource.cc:139
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:59
virtual EventPrincipal * readEvent_()
Definition: Run.h:33