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