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 int const kNanoSecPerSec = 1000000000U;
18  static unsigned int const kAveEventPerSec = 200U;
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 int>("firstTime", 1)), //time in ns
26  origTime_(presentTime_),
27  timeBetweenEvents_(pset.getUntrackedParameter<unsigned int>("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);
79  std::auto_ptr<EventAuxiliary> aux(new EventAuxiliary(eventID_, processGUID(), Timestamp(presentTime_), isRealData_, eType_));
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  if (!eventSet_) {
195  lumiSet_ = false;
197  eventSet_ = true;
198  }
199  if (eventID_.run() == RunNumber_t()) {
200  eventCached_ = false;
201  return IsStop;
202  }
203  if (oldEventID.run() != eventID_.run()) {
204  // New Run
205  // If the user did not explicitly set the luminosity block number,
206  // reset it back to the beginning.
207  if (!lumiSet_) {
209  }
210  newRun_ = newLumi_ = true;
211  return IsRun;
212  }
213  // Same Run
214  if (oldLumi != eventID_.luminosityBlock()) {
215  // New Lumi
216  newLumi_ = true;
217  if (processingMode() != Runs) {
218  return IsLumi;
219  }
220  }
221  reallyReadEvent();
222  if(!eventCached_) {
223  return IsStop;
224  }
225  eventSet_ = false;
226  return IsEvent;
227  }
228 
229  void
232  // same run
235  // new lumi
238  } else {
241  }
242  } else {
243  // new run
247  }
249  }
250 
251  void
253  if (numberEventsInRun_ < 1 || numberEventsInThisRun_ > 0) {
254  // same run
257  if (!(numberEventsInLumi_ < 1 || numberEventsInThisLumi_ > 0)) {
258  // new lumi
261  } else {
263  }
264  } else {
265  // new run
270  }
272  }
273 
274  void
277  receiver_->receive();
278  unsigned long numberOfEventsToSkip = receiver_->numberToSkip();
279  if (numberOfEventsToSkip !=0) {
280  skip(numberOfEventsToSkip);
281  decreaseRemainingEventsBy(numberOfEventsToSkip);
282  }
283  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices();
284  //Since we decrease 'remaining events' count we need to see if we reached 0 and therefore are at the end
286  //this means we are to stop
287  eventID_ = EventID();
288  return;
289  }
290  }
291  advanceToNext();
292  if (eventCreationDelay_ > 0) {usleep(eventCreationDelay_);}
293  }
294 
295  void
297  desc.addOptionalUntracked<unsigned int>("numberEventsInRun")->setComment("Number of events to generate in each run.");
298  desc.addOptionalUntracked<unsigned int>("numberEventsInLuminosityBlock")->setComment("Number of events to generate in each lumi.");
299  desc.addUntracked<unsigned int>("firstTime", 1)->setComment("Time before first event (ns) (for timestamp).");
300  desc.addUntracked<unsigned int>("timeBetweenEvents", kNanoSecPerSec/kAveEventPerSec)->setComment("Time between consecutive events (ns) (for timestamp).");
301  desc.addUntracked<unsigned int>("eventCreationDelay", 0)->setComment("Real time delay between generation of consecutive events (ms).");
302  desc.addUntracked<unsigned int>("firstEvent", 1)->setComment("Event number of first event to generate.");
303  desc.addUntracked<unsigned int>("firstLuminosityBlock", 1)->setComment("Luminosity block number of first lumi to generate.");
304  desc.addUntracked<unsigned int>("firstRun", 1)->setComment("Run number of first run to generate.");
306  }
307 
308 }
RunNumber_t run() const
Definition: EventID.h:42
EventAuxiliary::ExperimentType eType_
EventPrincipal *const eventPrincipalCache()
Definition: InputSource.cc:156
void decreaseRemainingEventsBy(int iSkipped)
Definition: InputSource.cc:472
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescription(ParameterSetDescription &desc)
static unsigned int const kAveEventPerSec
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:233
void setTimestamp(Timestamp const &theTime)
To set the current time, as seen by the input source.
Definition: InputSource.h:297
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:280
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:196
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:176
void rewind()
Begin again at the first event.
Definition: InputSource.h:138
virtual void endLuminosityBlock(LuminosityBlock &)
void setLuminosityBlockNumber(LuminosityBlockNumber_t const &lb)
Definition: EventID.h:115
unsigned int offset(bool)
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
void fillEventPrincipal(std::auto_ptr< EventAuxiliary > aux, boost::shared_ptr< LuminosityBlockPrincipal > lbp, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(new EventSelectionIDVector), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(new BranchListIndexes), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), boost::shared_ptr< DelayedReader > rtrv=boost::shared_ptr< DelayedReader >(new NoDelayedReader))
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
ConfigurableInputSource(ParameterSet const &pset, InputSourceDescription const &desc, bool realData=true)
static unsigned int const kNanoSecPerSec
void commit_(std::vector< BranchID > *previousParentage=0, ParentageID *previousParentageId=0)
Definition: Event.cc:105
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:164
virtual void beginLuminosityBlock(LuminosityBlock &)
EventID nextRunFirstEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:56
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:146
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
int remainingLuminosityBlocks() const
Definition: InputSource.h:184
ModuleDescription const & moduleDescription() const
Accessor for &#39;module&#39; description.
Definition: InputSource.h:187
unsigned int RunNumber_t
Definition: EventRange.h:32
virtual void setLumi(LuminosityBlockNumber_t lb)
EventID previousRunLastEvent(LuminosityBlockNumber_t const &lumi) const
Definition: EventID.h:59
virtual EventPrincipal * readEvent_()
Definition: Run.h:32