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