CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PoolSource.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "PoolSource.h"
15 #include "TTreeCache.h"
16 
17 #include <set>
18 
19 namespace edm {
20 
21  class LuminosityBlockID;
22  class EventID;
23 
24  namespace {
25  void checkHistoryConsistency(Principal const& primary, Principal const& secondary) {
26  ProcessHistory const& ph1 = primary.processHistory();
27  ProcessHistory const& ph2 = secondary.processHistory();
28  if (ph1 != ph2 && !isAncestor(ph2, ph1)) {
29  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
30  "The secondary file is not an ancestor of the primary file\n";
31  }
32  }
33  void checkConsistency(EventPrincipal const& primary, EventPrincipal const& secondary) {
34  if (!isSameEvent(primary, secondary)) {
35  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
36  primary.id() << " has inconsistent EventAuxiliary data in the primary and secondary file\n";
37  }
38  }
39  void checkConsistency(LuminosityBlockAuxiliary const& primary, LuminosityBlockAuxiliary const& secondary) {
40  if (primary.id() != secondary.id()) {
41  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
42  primary.id() << " has inconsistent LuminosityBlockAuxiliary data in the primary and secondary file\n";
43  }
44  }
45  void checkConsistency(RunAuxiliary const& primary, RunAuxiliary const& secondary) {
46  if (primary.id() != secondary.id()) {
47  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
48  primary.id() << " has inconsistent RunAuxiliary data in the primary and secondary file\n";
49  }
50  }
51  }
52 
54  VectorInputSource(pset, desc),
55  rootServiceChecker_(),
56  primaryFileSequence_(new RootInputFileSequence(pset, *this, catalog(), principalCache(), primary())),
57  secondaryFileSequence_(catalog(1).empty() ? 0 :
58  new RootInputFileSequence(pset, *this, catalog(1), principalCache(), false)),
59  secondaryRunPrincipal_(),
60  secondaryLumiPrincipal_(),
61  secondaryEventPrincipal_(secondaryFileSequence_ ? new EventPrincipal(secondaryFileSequence_->fileProductRegistry(), processConfiguration()) : 0),
62  branchIDsToReplace_(),
63  numberOfEventsBeforeBigSkip_(0)
64  {
66  boost::array<std::set<BranchID>, NumBranchTypes> idsToReplace;
67  ProductRegistry::ProductList const& secondary = secondaryFileSequence_->fileProductRegistry()->productList();
68  ProductRegistry::ProductList const& primary = primaryFileSequence_->fileProductRegistry()->productList();
69  typedef ProductRegistry::ProductList::const_iterator const_iterator;
70  typedef ProductRegistry::ProductList::iterator iterator;
71  //this is the registry used by the 'outside' world and only has the primary file information in it at present
73  for (const_iterator it = secondary.begin(), itEnd = secondary.end(); it != itEnd; ++it) {
74  if (it->second.present()) {
75  idsToReplace[it->second.branchType()].insert(it->second.branchID());
76  //now make sure this is marked as not dropped else the product will not be 'get'table from the Event
77  iterator itFound = fullList.find(it->first);
78  if(itFound != fullList.end()) {
79  itFound->second.dropped()=false;
80  }
81  }
82  }
83  for (const_iterator it = primary.begin(), itEnd = primary.end(); it != itEnd; ++it) {
84  if (it->second.present()) idsToReplace[it->second.branchType()].erase(it->second.branchID());
85  }
86  if (idsToReplace[InEvent].empty() && idsToReplace[InLumi].empty() && idsToReplace[InRun].empty()) {
87  secondaryFileSequence_.reset();
88  }
89  else {
90  for (int i = InEvent; i < NumBranchTypes; ++i) {
91  branchIDsToReplace_[i].reserve(idsToReplace[i].size());
92  for (std::set<BranchID>::const_iterator it = idsToReplace[i].begin(), itEnd = idsToReplace[i].end();
93  it != itEnd; ++it) {
94  branchIDsToReplace_[i].push_back(*it);
95  }
96  }
97  }
98  }
99  }
100 
102 
103  void
106  primaryFileSequence_->endJob();
107  }
108 
109  boost::shared_ptr<FileBlock>
111  boost::shared_ptr<FileBlock> fb = primaryFileSequence_->readFile_(principalCache());
113  fb->setNotFastClonable(FileBlock::HasSecondaryFileSequence);
114  }
115  return fb;
116  }
117 
119  primaryFileSequence_->closeFile_();
120  }
121 
122  boost::shared_ptr<RunAuxiliary>
124  return primaryFileSequence_->readRunAuxiliary_();
125  }
126 
127  boost::shared_ptr<LuminosityBlockAuxiliary>
129  return primaryFileSequence_->readLuminosityBlockAuxiliary_();
130  }
131 
132  boost::shared_ptr<RunPrincipal>
133  PoolSource::readRun_(boost::shared_ptr<RunPrincipal> rpCache) {
135  boost::shared_ptr<RunPrincipal> primaryPrincipal = primaryFileSequence_->readRun_(rpCache);
136  bool found = secondaryFileSequence_->skipToItem(primaryPrincipal->run(), 0U, 0U);
137  if (found) {
138  boost::shared_ptr<RunAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readRunAuxiliary_();
139  checkConsistency(primaryPrincipal->aux(), *secondaryAuxiliary);
140  boost::shared_ptr<RunPrincipal> rp(new RunPrincipal(secondaryAuxiliary, secondaryFileSequence_->fileProductRegistry(), processConfiguration()));
142  checkHistoryConsistency(*primaryPrincipal, *secondaryRunPrincipal_);
143  primaryPrincipal->recombine(*secondaryRunPrincipal_, branchIDsToReplace_[InRun]);
144  } else {
145  throw Exception(errors::MismatchedInputFiles, "PoolSource::readRun_")
146  << " Run " << primaryPrincipal->run()
147  << " is not found in the secondary input files\n";
148  }
149  return primaryPrincipal;
150  }
151  return primaryFileSequence_->readRun_(rpCache);
152  }
153 
154  boost::shared_ptr<LuminosityBlockPrincipal>
155  PoolSource::readLuminosityBlock_(boost::shared_ptr<LuminosityBlockPrincipal> lbCache) {
157  boost::shared_ptr<LuminosityBlockPrincipal> primaryPrincipal = primaryFileSequence_->readLuminosityBlock_(lbCache);
158  bool found = secondaryFileSequence_->skipToItem(primaryPrincipal->run(), primaryPrincipal->luminosityBlock(), 0U);
159  if (found) {
160  boost::shared_ptr<LuminosityBlockAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readLuminosityBlockAuxiliary_();
161  checkConsistency(primaryPrincipal->aux(), *secondaryAuxiliary);
162  boost::shared_ptr<LuminosityBlockPrincipal> lbp(new LuminosityBlockPrincipal(secondaryAuxiliary, secondaryFileSequence_->fileProductRegistry(), processConfiguration(), secondaryRunPrincipal_));
163  secondaryLumiPrincipal_ = secondaryFileSequence_->readLuminosityBlock_(lbp);
164  checkHistoryConsistency(*primaryPrincipal, *secondaryLumiPrincipal_);
165  primaryPrincipal->recombine(*secondaryLumiPrincipal_, branchIDsToReplace_[InLumi]);
166  } else {
167  throw Exception(errors::MismatchedInputFiles, "PoolSource::readLuminosityBlock_")
168  << " Run " << primaryPrincipal->run()
169  << " LuminosityBlock " << primaryPrincipal->luminosityBlock()
170  << " is not found in the secondary input files\n";
171  }
172  return primaryPrincipal;
173  }
174  return primaryFileSequence_->readLuminosityBlock_(lbCache);
175  }
176 
179  EventSourceSentry(*this);
182  bool found = secondaryFileSequence_->skipToItem(primaryPrincipal->run(),
183  primaryPrincipal->luminosityBlock(),
184  primaryPrincipal->id().event());
185  if (found) {
187  checkConsistency(*primaryPrincipal, *secondaryPrincipal);
188  checkHistoryConsistency(*primaryPrincipal, *secondaryPrincipal);
189  primaryPrincipal->recombine(*secondaryPrincipal, branchIDsToReplace_[InEvent]);
190  secondaryEventPrincipal_->clearPrincipal();
191  } else {
192  throw Exception(errors::MismatchedInputFiles, "PoolSource::readEvent_") <<
193  primaryPrincipal->id() << " is not found in the secondary input files\n";
194  }
195  }
196  if(receiver_) {
198  }
199  return primaryPrincipal;
200  }
201 
204  bool found = primaryFileSequence_->skipToItem(id.run(), id.luminosityBlock(), id.event());
205  if (!found) return 0;
206  return readEvent_();
207  }
208 
211  if(receiver_ &&
213  receiver_->receive();
214  unsigned long toSkip = receiver_->numberToSkip();
215  if (0 != toSkip) {
216  primaryFileSequence_->skipEvents(toSkip, principalCache());
218  }
219  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices();
221  return IsStop;
222  }
223  }
224  return primaryFileSequence_->getNextItemType();;
225  }
226 
227  void
229  primaryFileSequence_->closeFile_();
230  }
231 
232  void
233  PoolSource::postForkReacquireResources(boost::shared_ptr<edm::multicore::MessageReceiverForSource> iReceiver) {
234  receiver_ = iReceiver;
235  receiver_->receive();
237  rewind();
238  decreaseRemainingEventsBy(receiver_->numberToSkip());
239  }
240 
241  // Rewind to before the first event that was read.
242  void
244  primaryFileSequence_->rewind_();
245  if (receiver_) {
246  unsigned int numberToSkip = receiver_->numberToSkip();
247  if(0 != numberToSkip) {
248  primaryFileSequence_->skipEvents(numberToSkip, principalCache());
249  }
250  numberOfEventsBeforeBigSkip_ = receiver_->numberOfConsecutiveIndices();
251  }
252 
253  }
254 
255  // Advance "offset" events. Offset can be positive or negative (or zero).
256  void
258  primaryFileSequence_->skipEvents(offset, principalCache());
259  }
260 
261  bool
262  PoolSource::goToEvent_(EventID const& eventID) {
263  return primaryFileSequence_->goToEvent(eventID, principalCache());
264  }
265 
266  void
268  assert (!secondaryFileSequence_);
269  primaryFileSequence_->readMany(number, result);
270  }
271 
272  void
273  PoolSource::readManyRandom_(int number, EventPrincipalVector& result, unsigned int& fileSeqNumber) {
274  assert (!secondaryFileSequence_);
275  primaryFileSequence_->readManyRandom(number, result, fileSeqNumber);
276  }
277 
278  void
279  PoolSource::readManySequential_(int number, EventPrincipalVector& result, unsigned int& fileSeqNumber) {
280  assert (!secondaryFileSequence_);
281  primaryFileSequence_->readManySequential(number, result, fileSeqNumber);
282  }
283 
284  void
286  assert (!secondaryFileSequence_);
287  primaryFileSequence_->readManySpecified(events, result);
288  }
289 
290  void
291  PoolSource::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
292  assert (!secondaryFileSequence_);
293  primaryFileSequence_->dropUnwantedBranches_(wantedBranches);
294  }
295 
296  void
298 
300 
301  desc.setComment("Reads EDM/Root files.");
304 
305  descriptions.add("source", desc);
306  }
307 
308  bool
310  return true;
311  }
312 
315  return primaryFileSequence_->forwardState();
316  }
317 
320  return primaryFileSequence_->reverseState();
321  }
322 }
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: PoolSource.cc:123
PoolSource(ParameterSet const &pset, InputSourceDescription const &desc)
Definition: PoolSource.cc:53
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
bool isSameEvent(EventAuxiliary const &a, EventAuxiliary const &b)
void decreaseRemainingEventsBy(int iSkipped)
Definition: InputSource.cc:472
virtual void readMany_(int number, EventPrincipalVector &result)
Definition: PoolSource.cc:267
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
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:588
RunNumber_t run() const
virtual ProcessingController::ForwardState forwardState_() const
Definition: PoolSource.cc:314
virtual boost::shared_ptr< LuminosityBlockPrincipal > readLuminosityBlock_(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
Definition: PoolSource.cc:155
virtual void readManySpecified_(std::vector< EventID > const &events, EventPrincipalVector &result)
Definition: PoolSource.cc:285
virtual bool goToEvent_(EventID const &eventID)
Definition: PoolSource.cc:262
virtual boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
Definition: PoolSource.cc:133
std::map< BranchKey, BranchDescription > ProductList
EventID const & id() const
EventPrincipal *const eventPrincipalCache()
Definition: InputSource.cc:156
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
virtual void readManyRandom_(int number, EventPrincipalVector &result, unsigned int &fileSeqNumber)
Definition: PoolSource.cc:273
boost::scoped_ptr< EventPrincipal > secondaryEventPrincipal_
Definition: PoolSource.h:71
static void fillDescription(ParameterSetDescription &desc)
virtual void dropUnwantedBranches_(std::vector< std::string > const &wantedBranches)
Definition: PoolSource.cc:291
void setComment(std::string const &value)
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
int remainingEvents() const
Definition: InputSource.h:176
virtual bool randomAccess_() const
Definition: PoolSource.cc:309
virtual ProcessingController::ReverseState reverseState_() const
Definition: PoolSource.cc:319
boost::shared_ptr< RunPrincipal > secondaryRunPrincipal_
Definition: PoolSource.h:69
void rewind()
Begin again at the first event.
Definition: InputSource.h:138
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:582
tuple result
Definition: query.py:137
std::vector< EventPrincipalVectorElement > EventPrincipalVector
unsigned int numberOfEventsBeforeBigSkip_
Definition: PoolSource.h:76
virtual EventPrincipal * readEvent_()
Definition: PoolSource.cc:178
tuple pset
Definition: CrabTask.py:85
virtual ~PoolSource()
Definition: PoolSource.cc:101
#define end
Definition: vmac.h:38
unsigned int offset(bool)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
PrincipalCache const & principalCache() const
Definition: InputSource.h:316
virtual void readManySequential_(int number, EventPrincipalVector &result, unsigned int &fileSeqNumber)
Definition: PoolSource.cc:279
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: PoolSource.cc:297
virtual void postForkReacquireResources(boost::shared_ptr< edm::multicore::MessageReceiverForSource >)
Definition: PoolSource.cc:233
virtual void rewind_()
Definition: PoolSource.cc:243
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:299
virtual void endJob()
Definition: PoolSource.cc:104
void add(std::string const &label, ParameterSetDescription const &psetDescription)
boost::array< std::vector< BranchID >, NumBranchTypes > branchIDsToReplace_
Definition: PoolSource.h:72
ProductList & productListUpdator()
boost::scoped_ptr< RootInputFileSequence > primaryFileSequence_
Definition: PoolSource.h:67
virtual void closeFile_()
Definition: PoolSource.cc:118
boost::shared_ptr< edm::multicore::MessageReceiverForSource > receiver_
Definition: PoolSource.h:75
#define begin
Definition: vmac.h:31
tuple events
Definition: patZpeak.py:19
virtual ItemType getNextItemType()
Definition: PoolSource.cc:210
virtual void skip(int offset)
Definition: PoolSource.cc:257
boost::shared_ptr< LuminosityBlockPrincipal > secondaryLumiPrincipal_
Definition: PoolSource.h:70
boost::scoped_ptr< RootInputFileSequence > secondaryFileSequence_
Definition: PoolSource.h:68
virtual void preForkReleaseResources()
Definition: PoolSource.cc:228
virtual boost::shared_ptr< FileBlock > readFile_()
Definition: PoolSource.cc:110
boost::shared_ptr< LuminosityBlockPrincipal > const luminosityBlockPrincipal() const
Definition: InputSource.cc:280
virtual EventPrincipal * readIt(EventID const &id)
Definition: PoolSource.cc:203
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:190
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:576
tuple size
Write out results.
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: PoolSource.cc:128