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