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"
4 #include "InputFile.h"
20 
21 #include <set>
22 
23 namespace edm {
24 
25  class LuminosityBlockID;
26  class EventID;
27 
28  namespace {
29  void checkHistoryConsistency(Principal const& primary, Principal const& secondary) {
30  ProcessHistory const& ph1 = primary.processHistory();
31  ProcessHistory const& ph2 = secondary.processHistory();
32  if(ph1 != ph2 && !isAncestor(ph2, ph1)) {
33  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
34  "The secondary file is not an ancestor of the primary file\n";
35  }
36  }
37  void checkConsistency(EventPrincipal const& primary, EventPrincipal const& secondary) {
38  if(!isSameEvent(primary, secondary)) {
39  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
40  primary.id() << " has inconsistent EventAuxiliary data in the primary and secondary file\n";
41  }
42  }
43  void checkConsistency(LuminosityBlockAuxiliary const& primary, LuminosityBlockAuxiliary const& secondary) {
44  if(primary.id() != secondary.id()) {
45  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
46  primary.id() << " has inconsistent LuminosityBlockAuxiliary data in the primary and secondary file\n";
47  }
48  }
49  void checkConsistency(RunAuxiliary const& primary, RunAuxiliary const& secondary) {
50  if(primary.id() != secondary.id()) {
51  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
52  primary.id() << " has inconsistent RunAuxiliary data in the primary and secondary file\n";
53  }
54  }
55  }
56 
58  VectorInputSource(pset, desc),
59  rootServiceChecker_(),
60  primaryFileSequence_(new RootInputFileSequence(pset, *this, catalog(), desc.allocations_->numberOfStreams(),
61  primary() ? InputType::Primary : InputType::SecondarySource)),
62  secondaryFileSequence_(catalog(1).empty() ? nullptr :
63  new RootInputFileSequence(pset, *this, catalog(1), desc.allocations_->numberOfStreams(),
65  secondaryRunPrincipal_(),
66  secondaryLumiPrincipal_(),
67  secondaryEventPrincipals_(),
68  branchIDsToReplace_(),
69  resourceSharedWithDelayedReaderPtr_(primary()?
71  static_cast<SharedResourcesAcquirer*>(nullptr))
72  {
74  unsigned int nStreams = desc.allocations_->numberOfStreams();
75  assert(primary());
76  secondaryEventPrincipals_.reserve(nStreams);
77  for(unsigned int index = 0; index < nStreams; ++index) {
78  secondaryEventPrincipals_.emplace_back(new EventPrincipal(secondaryFileSequence_->fileProductRegistry(),
79  secondaryFileSequence_->fileBranchIDListHelper(),
81  nullptr,
82  index));
83  }
84  std::array<std::set<BranchID>, NumBranchTypes> idsToReplace;
85  ProductRegistry::ProductList const& secondary = secondaryFileSequence_->fileProductRegistry()->productList();
86  ProductRegistry::ProductList const& primary = primaryFileSequence_->fileProductRegistry()->productList();
87  typedef ProductRegistry::ProductList::const_iterator const_iterator;
88  typedef ProductRegistry::ProductList::iterator iterator;
89  //this is the registry used by the 'outside' world and only has the primary file information in it at present
91  for(const_iterator it = secondary.begin(), itEnd = secondary.end(); it != itEnd; ++it) {
92  if(it->second.present()) {
93  idsToReplace[it->second.branchType()].insert(it->second.branchID());
94  //now make sure this is marked as not dropped else the product will not be 'get'table from the Event
95  iterator itFound = fullList.find(it->first);
96  if(itFound != fullList.end()) {
97  itFound->second.setDropped(false);
98  }
99  }
100  }
101  for(const_iterator it = primary.begin(), itEnd = primary.end(); it != itEnd; ++it) {
102  if(it->second.present()) idsToReplace[it->second.branchType()].erase(it->second.branchID());
103  }
104  if(idsToReplace[InEvent].empty() && idsToReplace[InLumi].empty() && idsToReplace[InRun].empty()) {
105  secondaryFileSequence_.reset();
106  } else {
107  for(int i = InEvent; i < NumBranchTypes; ++i) {
108  branchIDsToReplace_[i].reserve(idsToReplace[i].size());
109  for(std::set<BranchID>::const_iterator it = idsToReplace[i].begin(), itEnd = idsToReplace[i].end();
110  it != itEnd; ++it) {
111  branchIDsToReplace_[i].push_back(*it);
112  }
113  }
114  }
115  }
116  }
117 
119 
120  void
123  primaryFileSequence_->endJob();
125  }
126 
127  std::unique_ptr<FileBlock>
129  std::unique_ptr<FileBlock> fb = primaryFileSequence_->readFile_();
131  fb->setNotFastClonable(FileBlock::HasSecondaryFileSequence);
132  }
133  return std::move(fb);
134  }
135 
137  primaryFileSequence_->closeFile_();
138  }
139 
140  boost::shared_ptr<RunAuxiliary>
142  return primaryFileSequence_->readRunAuxiliary_();
143  }
144 
145  boost::shared_ptr<LuminosityBlockAuxiliary>
147  return primaryFileSequence_->readLuminosityBlockAuxiliary_();
148  }
149 
150  void
152  primaryFileSequence_->readRun_(runPrincipal);
154  bool found = secondaryFileSequence_->skipToItem(runPrincipal.run(), 0U, 0U);
155  if(found) {
156  boost::shared_ptr<RunAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readRunAuxiliary_();
157  checkConsistency(runPrincipal.aux(), *secondaryAuxiliary);
158  secondaryRunPrincipal_.reset(new RunPrincipal(secondaryAuxiliary,
159  secondaryFileSequence_->fileProductRegistry(),
161  nullptr,
162  runPrincipal.index()));
164  checkHistoryConsistency(runPrincipal, *secondaryRunPrincipal_);
166  } else {
167  throw Exception(errors::MismatchedInputFiles, "PoolSource::readRun_")
168  << " Run " << runPrincipal.run()
169  << " is not found in the secondary input files\n";
170  }
171  }
172  }
173 
174  void
176  primaryFileSequence_->readLuminosityBlock_(lumiPrincipal);
178  bool found = secondaryFileSequence_->skipToItem(lumiPrincipal.run(), lumiPrincipal.luminosityBlock(), 0U);
179  if(found) {
180  boost::shared_ptr<LuminosityBlockAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readLuminosityBlockAuxiliary_();
181  checkConsistency(lumiPrincipal.aux(), *secondaryAuxiliary);
182  secondaryLumiPrincipal_.reset(new LuminosityBlockPrincipal(secondaryAuxiliary,
183  secondaryFileSequence_->fileProductRegistry(),
185  nullptr,
186  lumiPrincipal.index()));
187  secondaryFileSequence_->readLuminosityBlock_(*secondaryLumiPrincipal_);
188  checkHistoryConsistency(lumiPrincipal, *secondaryLumiPrincipal_);
190  } else {
191  throw Exception(errors::MismatchedInputFiles, "PoolSource::readLuminosityBlock_")
192  << " Run " << lumiPrincipal.run()
193  << " LuminosityBlock " << lumiPrincipal.luminosityBlock()
194  << " is not found in the secondary input files\n";
195  }
196  }
197  }
198 
199  void
201  primaryFileSequence_->readEvent(eventPrincipal);
203  bool found = secondaryFileSequence_->skipToItem(eventPrincipal.run(),
204  eventPrincipal.luminosityBlock(),
205  eventPrincipal.id().event());
206  if(found) {
207  EventPrincipal& secondaryEventPrincipal = *secondaryEventPrincipals_[eventPrincipal.streamID().value()];
208  secondaryFileSequence_->readEvent(secondaryEventPrincipal);
209  checkConsistency(eventPrincipal, secondaryEventPrincipal);
210  checkHistoryConsistency(eventPrincipal, secondaryEventPrincipal);
211  eventPrincipal.recombine(secondaryEventPrincipal, branchIDsToReplace_[InEvent]);
212  eventPrincipal.mergeProvenanceRetrievers(secondaryEventPrincipal);
213  secondaryEventPrincipal.clearPrincipal();
214  } else {
215  throw Exception(errors::MismatchedInputFiles, "PoolSource::readEvent_") <<
216  eventPrincipal.id() << " is not found in the secondary input files\n";
217  }
218  }
219  }
220 
221  bool
222  PoolSource::readIt(EventID const& id, EventPrincipal& eventPrincipal, StreamContext& streamContext) {
223  bool found = primaryFileSequence_->skipToItem(id.run(), id.luminosityBlock(), id.event());
224  if(!found) return false;
225  EventSourceSentry sentry(*this, streamContext);
226  readEvent_(eventPrincipal);
227  return true;
228  }
229 
235  InputSource::ItemType itemType = primaryFileSequence_->getNextItemType(run, lumi, event);
237  if(itemType == IsRun || itemType == IsLumi || itemType == IsEvent) {
238  if(!secondaryFileSequence_->containedInCurrentFile(run, lumi, event)) {
239  return IsSynchronize;
240  }
241  }
242  }
243  return itemType;
244  }
245 
246  void
248  primaryFileSequence_->closeFile_();
249  }
250 
254  }
255 
256  // Rewind to before the first event that was read.
257  void
259  primaryFileSequence_->rewind_();
260  }
261 
262  // Advance "offset" events. Offset can be positive or negative (or zero).
263  void
265  primaryFileSequence_->skipEvents(offset);
266  }
267 
268  bool
269  PoolSource::goToEvent_(EventID const& eventID) {
270  return primaryFileSequence_->goToEvent(eventID);
271  }
272 
273  void
274  PoolSource::readOneRandom(EventPrincipal& cache, CLHEP::HepRandomEngine* engine) {
275  assert(!secondaryFileSequence_);
276  primaryFileSequence_->readOneRandom(cache, engine);
277  }
278 
279  bool
280  PoolSource::readOneRandomWithID(EventPrincipal& cache, LuminosityBlockID const& lumiID, CLHEP::HepRandomEngine* engine) {
281  assert(!secondaryFileSequence_);
282  return primaryFileSequence_->readOneRandomWithID(cache, lumiID, engine);
283  }
284 
285  bool
287  assert(!secondaryFileSequence_);
288  return primaryFileSequence_->readOneSequential(cache);
289  }
290 
291  bool
293  assert(!secondaryFileSequence_);
294  return primaryFileSequence_->readOneSequentialWithID(cache, lumiID);
295  }
296 
297  void
299  assert(!secondaryFileSequence_);
300  primaryFileSequence_->readOneSpecified(cache, id);
301  }
302 
303  void
304  PoolSource::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) {
305  assert(!secondaryFileSequence_);
306  primaryFileSequence_->dropUnwantedBranches_(wantedBranches);
307  }
308 
309  void
311 
313 
314  desc.setComment("Reads EDM/Root files.");
317 
318  descriptions.add("source", desc);
319  }
320 
321  bool
323  return true;
324  }
325 
328  return primaryFileSequence_->forwardState();
329  }
330 
333  return primaryFileSequence_->reverseState();
334  }
335 }
virtual boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: PoolSource.cc:141
PoolSource(ParameterSet const &pset, InputSourceDescription const &desc)
Definition: PoolSource.cc:57
EventNumber_t event() const
Definition: EventID.h:44
void clearPrincipal()
Definition: Principal.cc:304
int i
Definition: DBlmapReader.cc:9
SharedResourcesAcquirer createAcquirerForSourceDelayedReader()
bool isSameEvent(EventAuxiliary const &a, EventAuxiliary const &b)
InputType
Definition: InputType.h:5
std::unique_ptr< SharedResourcesAcquirer > resourceSharedWithDelayedReaderPtr_
Definition: PoolSource.h:78
virtual std::unique_ptr< FileBlock > readFile_()
Definition: PoolSource.cc:128
RunNumber_t run() const
virtual ProcessingController::ForwardState forwardState_() const
Definition: PoolSource.cc:327
unsigned int EventNumber_t
Definition: EventID.h:30
virtual bool goToEvent_(EventID const &eventID)
Definition: PoolSource.cc:269
tuple lumi
Definition: fjr2json.py:35
virtual void readOneRandom(EventPrincipal &cache, CLHEP::HepRandomEngine *) override
Definition: PoolSource.cc:274
std::map< BranchKey, BranchDescription > ProductList
EventID const & id() const
static void fillDescription(ParameterSetDescription &desc)
std::unique_ptr< RootInputFileSequence > secondaryFileSequence_
Definition: PoolSource.h:72
LuminosityBlockAuxiliary const & aux() const
void mergeProvenanceRetrievers(EventPrincipal const &other)
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:595
LuminosityBlockIndex index() const
LuminosityBlockNumber_t luminosityBlock() const
RunNumber_t run() const
Definition: RunPrincipal.h:61
#define nullptr
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
static void fillDescription(ParameterSetDescription &desc)
static EventNumber_t const invalidEvent
virtual void dropUnwantedBranches_(std::vector< std::string > const &wantedBranches)
Definition: PoolSource.cc:304
void setComment(std::string const &value)
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
LuminosityBlockNumber_t luminosityBlock() const
virtual bool randomAccess_() const
Definition: PoolSource.cc:322
static RunNumber_t const invalidRun
virtual ProcessingController::ReverseState reverseState_() const
Definition: PoolSource.cc:332
boost::shared_ptr< RunPrincipal > secondaryRunPrincipal_
Definition: PoolSource.h:73
static SharedResourcesRegistry * instance()
static void reportReadBranches()
Definition: InputFile.cc:106
StreamID streamID() const
RunAuxiliary const & aux() const
Definition: RunPrincipal.h:57
virtual ~PoolSource()
Definition: PoolSource.cc:118
#define end
Definition: vmac.h:37
SharedResourcesAcquirer * resourceSharedWithDelayedReader_() const override
Definition: PoolSource.cc:252
unsigned int offset(bool)
virtual void readRun_(RunPrincipal &runPrincipal)
Definition: PoolSource.cc:151
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
ItemType state() const
Definition: InputSource.h:349
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:601
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: PoolSource.cc:310
unsigned int value() const
Definition: StreamID.h:46
virtual void rewind_()
Definition: PoolSource.cc:258
virtual void readOneSpecified(EventPrincipal &cache, EventID const &id)
Definition: PoolSource.cc:298
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:347
static LuminosityBlockNumber_t const invalidLumi
virtual bool readIt(EventID const &id, EventPrincipal &eventPrincipal, StreamContext &streamContext) override
Definition: PoolSource.cc:222
virtual void readEvent_(EventPrincipal &eventPrincipal)
Definition: PoolSource.cc:200
std::array< std::vector< BranchID >, NumBranchTypes > branchIDsToReplace_
Definition: PoolSource.h:76
virtual void endJob()
Definition: PoolSource.cc:121
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ProductList & productListUpdator()
bool primary() const
Accessor for primary input source flag.
Definition: InputSource.h:211
virtual void closeFile_()
Definition: PoolSource.cc:136
std::unique_ptr< RootInputFileSequence > primaryFileSequence_
Definition: PoolSource.h:71
RunIndex index() const
Definition: RunPrincipal.h:53
#define begin
Definition: vmac.h:30
virtual ItemType getNextItemType()
Definition: PoolSource.cc:231
virtual void skip(int offset)
Definition: PoolSource.cc:264
virtual bool readOneSequentialWithID(EventPrincipal &cache, LuminosityBlockID const &lumiID)
Definition: PoolSource.cc:292
boost::shared_ptr< LuminosityBlockPrincipal > secondaryLumiPrincipal_
Definition: PoolSource.h:74
virtual void preForkReleaseResources()
Definition: PoolSource.cc:247
unsigned int RunNumber_t
Definition: EventRange.h:32
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:208
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:773
virtual bool readOneSequential(EventPrincipal &cache)
Definition: PoolSource.cc:286
virtual bool readOneRandomWithID(EventPrincipal &cache, LuminosityBlockID const &lumiID, CLHEP::HepRandomEngine *) override
Definition: PoolSource.cc:280
std::vector< std::unique_ptr< EventPrincipal > > secondaryEventPrincipals_
Definition: PoolSource.h:75
tuple size
Write out results.
virtual boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: PoolSource.cc:146
virtual void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: PoolSource.cc:175