test
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"
7 #include "RunHelper.h"
26 
27 #include <set>
28 
29 namespace edm {
30 
31  class BranchID;
32  class LuminosityBlockID;
33  class EventID;
34  class ThinnedAssociationsHelper;
35 
36  namespace {
37  void checkHistoryConsistency(Principal const& primary, Principal const& secondary) {
38  ProcessHistory const& ph1 = primary.processHistory();
39  ProcessHistory const& ph2 = secondary.processHistory();
40  if(ph1 != ph2 && !isAncestor(ph2, ph1)) {
41  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
42  "The secondary file is not an ancestor of the primary file\n";
43  }
44  }
45  void checkConsistency(EventPrincipal const& primary, EventPrincipal const& secondary) {
46  if(!isSameEvent(primary, secondary)) {
47  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
48  primary.id() << " has inconsistent EventAuxiliary data in the primary and secondary file\n";
49  }
50  }
51  void checkConsistency(LuminosityBlockAuxiliary const& primary, LuminosityBlockAuxiliary const& secondary) {
52  if(primary.id() != secondary.id()) {
53  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
54  primary.id() << " has inconsistent LuminosityBlockAuxiliary data in the primary and secondary file\n";
55  }
56  }
57  void checkConsistency(RunAuxiliary const& primary, RunAuxiliary const& secondary) {
58  if(primary.id() != secondary.id()) {
59  throw Exception(errors::MismatchedInputFiles, "PoolSource::checkConsistency") <<
60  primary.id() << " has inconsistent RunAuxiliary data in the primary and secondary file\n";
61  }
62  }
63  }
64 
66  InputSource(pset, desc),
67  rootServiceChecker_(),
68  catalog_(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"),
69  pset.getUntrackedParameter<std::string>("overrideCatalog", std::string())),
70  secondaryCatalog_(pset.getUntrackedParameter<std::vector<std::string> >("secondaryFileNames", std::vector<std::string>()),
71  pset.getUntrackedParameter<std::string>("overrideCatalog", std::string())),
72  secondaryRunPrincipal_(),
73  secondaryLumiPrincipal_(),
74  secondaryEventPrincipals_(),
75  branchIDsToReplace_(),
76  nStreams_(desc.allocations_->numberOfStreams()),
77  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles")),
78  bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck")),
79  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize")),
80  productSelectorRules_(pset, "inputCommands", "InputSource"),
81  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches")),
82  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC")),
83  runHelper_(makeRunHelper(pset)),
85  // Note: primaryFileSequence_ and secondaryFileSequence_ need to be initialized last, because they use data members
86  // initialized previously in their own initialization.
87  primaryFileSequence_(new RootPrimaryFileSequence(pset, *this, catalog_)),
88  secondaryFileSequence_(secondaryCatalog_.empty() ? nullptr :
89  new RootSecondaryFileSequence(pset, *this, secondaryCatalog_))
90  {
91  if (secondaryCatalog_.empty() && pset.getUntrackedParameter<bool>("needSecondaryFileNames", false)) {
92  throw Exception(errors::Configuration, "PoolSource") << "'secondaryFileNames' must be specified\n";
93  }
94  if(secondaryFileSequence_) {
95  secondaryEventPrincipals_.reserve(nStreams_);
96  for(unsigned int index = 0; index < nStreams_; ++index) {
97  secondaryEventPrincipals_.emplace_back(new EventPrincipal(secondaryFileSequence_->fileProductRegistry(),
98  secondaryFileSequence_->fileBranchIDListHelper(),
99  std::make_shared<ThinnedAssociationsHelper const>(),
101  nullptr,
102  index));
103  }
104  std::array<std::set<BranchID>, NumBranchTypes> idsToReplace;
105  ProductRegistry::ProductList const& secondary = secondaryFileSequence_->fileProductRegistry()->productList();
106  ProductRegistry::ProductList const& primary = primaryFileSequence_->fileProductRegistry()->productList();
107  std::set<BranchID> associationsFromSecondary;
108  //this is the registry used by the 'outside' world and only has the primary file information in it at present
109  ProductRegistry::ProductList& fullList = productRegistryUpdate().productListUpdator();
110  for(auto const& item : secondary) {
111  if(item.second.present()) {
112  idsToReplace[item.second.branchType()].insert(item.second.branchID());
113  if(item.second.branchType() == InEvent &&
114  item.second.unwrappedType() == typeid(ThinnedAssociation)) {
115  associationsFromSecondary.insert(item.second.branchID());
116  }
117  //now make sure this is marked as not dropped else the product will not be 'get'table from the Event
118  auto itFound = fullList.find(item.first);
119  if(itFound != fullList.end()) {
120  itFound->second.setDropped(false);
121  }
122  }
123  }
124  for(auto const& item : primary) {
125  if(item.second.present()) {
126  idsToReplace[item.second.branchType()].erase(item.second.branchID());
127  associationsFromSecondary.erase(item.second.branchID());
128  }
129  }
130  if(idsToReplace[InEvent].empty() && idsToReplace[InLumi].empty() && idsToReplace[InRun].empty()) {
131  secondaryFileSequence_ = nullptr; // propagate_const<T> has no reset() function
132  } else {
133  for(int i = InEvent; i < NumBranchTypes; ++i) {
134  branchIDsToReplace_[i].reserve(idsToReplace[i].size());
135  for(auto const& id : idsToReplace[i]) {
136  branchIDsToReplace_[i].push_back(id);
137  }
138  }
139  secondaryFileSequence_->initAssociationsFromSecondary(associationsFromSecondary);
140  }
141  }
142  }
143 
145 
146  void
149  primaryFileSequence_->endJob();
151  }
152 
153  std::unique_ptr<FileBlock>
155  std::unique_ptr<FileBlock> fb = primaryFileSequence_->readFile_();
157  fb->setNotFastClonable(FileBlock::HasSecondaryFileSequence);
158  }
159  return std::move(fb);
160  }
161 
163  primaryFileSequence_->closeFile_();
164  }
165 
166  std::shared_ptr<RunAuxiliary>
168  return primaryFileSequence_->readRunAuxiliary_();
169  }
170 
171  std::shared_ptr<LuminosityBlockAuxiliary>
173  return primaryFileSequence_->readLuminosityBlockAuxiliary_();
174  }
175 
176  void
178  primaryFileSequence_->readRun_(runPrincipal);
180  bool found = secondaryFileSequence_->skipToItem(runPrincipal.run(), 0U, 0U);
181  if(found) {
182  std::shared_ptr<RunAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readRunAuxiliary_();
183  checkConsistency(runPrincipal.aux(), *secondaryAuxiliary);
184  secondaryRunPrincipal_ = std::make_shared<RunPrincipal>(secondaryAuxiliary,
185  secondaryFileSequence_->fileProductRegistry(),
187  nullptr,
188  runPrincipal.index());
189  secondaryFileSequence_->readRun_(*secondaryRunPrincipal_);
190  checkHistoryConsistency(runPrincipal, *secondaryRunPrincipal_);
191  runPrincipal.recombine(*secondaryRunPrincipal_, branchIDsToReplace_[InRun]);
192  } else {
193  throw Exception(errors::MismatchedInputFiles, "PoolSource::readRun_")
194  << " Run " << runPrincipal.run()
195  << " is not found in the secondary input files\n";
196  }
197  }
198  }
199 
200  void
202  primaryFileSequence_->readLuminosityBlock_(lumiPrincipal);
204  bool found = secondaryFileSequence_->skipToItem(lumiPrincipal.run(), lumiPrincipal.luminosityBlock(), 0U);
205  if(found) {
206  std::shared_ptr<LuminosityBlockAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readLuminosityBlockAuxiliary_();
207  checkConsistency(lumiPrincipal.aux(), *secondaryAuxiliary);
208  secondaryLumiPrincipal_ = std::make_shared<LuminosityBlockPrincipal>(secondaryAuxiliary,
209  secondaryFileSequence_->fileProductRegistry(),
211  nullptr,
212  lumiPrincipal.index());
213  secondaryFileSequence_->readLuminosityBlock_(*secondaryLumiPrincipal_);
214  checkHistoryConsistency(lumiPrincipal, *secondaryLumiPrincipal_);
215  lumiPrincipal.recombine(*secondaryLumiPrincipal_, branchIDsToReplace_[InLumi]);
216  } else {
217  throw Exception(errors::MismatchedInputFiles, "PoolSource::readLuminosityBlock_")
218  << " Run " << lumiPrincipal.run()
219  << " LuminosityBlock " << lumiPrincipal.luminosityBlock()
220  << " is not found in the secondary input files\n";
221  }
222  }
223  }
224 
225  void
227  primaryFileSequence_->readEvent(eventPrincipal);
229  bool found = secondaryFileSequence_->skipToItem(eventPrincipal.run(),
230  eventPrincipal.luminosityBlock(),
231  eventPrincipal.id().event());
232  if(found) {
233  EventPrincipal& secondaryEventPrincipal = *secondaryEventPrincipals_[eventPrincipal.streamID().value()];
234  secondaryFileSequence_->readEvent(secondaryEventPrincipal);
235  checkConsistency(eventPrincipal, secondaryEventPrincipal);
236  checkHistoryConsistency(eventPrincipal, secondaryEventPrincipal);
237  eventPrincipal.recombine(secondaryEventPrincipal, branchIDsToReplace_[InEvent]);
238  eventPrincipal.mergeProvenanceRetrievers(secondaryEventPrincipal);
239  secondaryEventPrincipal.clearPrincipal();
240  } else {
241  throw Exception(errors::MismatchedInputFiles, "PoolSource::readEvent_") <<
242  eventPrincipal.id() << " is not found in the secondary input files\n";
243  }
244  }
245  }
246 
247  bool
248  PoolSource::readIt(EventID const& id, EventPrincipal& eventPrincipal, StreamContext& streamContext) {
249  bool found = primaryFileSequence_->skipToItem(id.run(), id.luminosityBlock(), id.event());
250  if(!found) return false;
251  EventSourceSentry sentry(*this, streamContext);
252  readEvent_(eventPrincipal);
253  return true;
254  }
255 
261  InputSource::ItemType itemType = primaryFileSequence_->getNextItemType(run, lumi, event);
263  if(itemType == IsRun || itemType == IsLumi || itemType == IsEvent) {
264  if(!secondaryFileSequence_->containedInCurrentFile(run, lumi, event)) {
265  return IsSynchronize;
266  }
267  }
268  }
269  return runHelper_->nextItemType(state(), itemType);
270  }
271 
272  void
274  primaryFileSequence_->closeFile_();
275  }
276 
280  }
281 
282  // Rewind to before the first event that was read.
283  void
285  primaryFileSequence_->rewind_();
286  }
287 
288  // Advance "offset" events. Offset can be positive or negative (or zero).
289  void
291  primaryFileSequence_->skipEvents(offset);
292  }
293 
294  bool
295  PoolSource::goToEvent_(EventID const& eventID) {
296  return primaryFileSequence_->goToEvent(eventID);
297  }
298 
299  void
301 
303 
304  std::vector<std::string> defaultStrings;
305  desc.setComment("Reads EDM/Root files.");
306  desc.addUntracked<std::vector<std::string> >("fileNames")
307  ->setComment("Names of files to be processed.");
308  desc.addUntracked<std::vector<std::string> >("secondaryFileNames", defaultStrings)
309  ->setComment("Names of secondary files to be processed.");
310  desc.addUntracked<bool>("needSecondaryFileNames", false)
311  ->setComment("If True, 'secondaryFileNames' must be specified and be non-empty.");
312  desc.addUntracked<std::string>("overrideCatalog", std::string());
313  desc.addUntracked<bool>("skipBadFiles", false)
314  ->setComment("True: Ignore any missing or unopenable input file.\n"
315  "False: Throw exception if missing or unopenable input file.");
316  desc.addUntracked<bool>("bypassVersionCheck", false)
317  ->setComment("True: Bypass release version check.\n"
318  "False: Throw exception if reading file in a release prior to the release in which the file was written.");
319  desc.addUntracked<int>("treeMaxVirtualSize", -1)
320  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
321  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
322  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
323  desc.addUntracked<bool>("labelRawDataLikeMC", true)
324  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
325  ProductSelectorRules::fillDescription(desc, "inputCommands");
329 
330  descriptions.add("source", desc);
331  }
332 
333  bool
335  return true;
336  }
337 
340  return primaryFileSequence_->forwardState();
341  }
342 
345  return primaryFileSequence_->reverseState();
346  }
347 }
virtual void preForkReleaseResources() override
Definition: PoolSource.cc:273
edm::propagate_const< std::unique_ptr< RootSecondaryFileSequence > > secondaryFileSequence_
Definition: PoolSource.h:91
PoolSource(ParameterSet const &pset, InputSourceDescription const &desc)
Definition: PoolSource.cc:65
EventNumber_t event() const
Definition: EventID.h:41
void clearPrincipal()
Definition: Principal.cc:321
int i
Definition: DBlmapReader.cc:9
SharedResourcesAcquirer createAcquirerForSourceDelayedReader()
virtual bool goToEvent_(EventID const &eventID) override
Definition: PoolSource.cc:295
bool isSameEvent(EventAuxiliary const &a, EventAuxiliary const &b)
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
std::unique_ptr< SharedResourcesAcquirer > resourceSharedWithDelayedReaderPtr_
Definition: PoolSource.h:89
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
RunNumber_t run() const
tuple lumi
Definition: fjr2json.py:35
edm::propagate_const< std::unique_ptr< RunHelperBase > > runHelper_
Definition: PoolSource.h:88
std::map< BranchKey, BranchDescription > ProductList
static void fillDescription(ParameterSetDescription &desc)
Definition: RunHelper.cc:174
edm::propagate_const< std::shared_ptr< RunPrincipal > > secondaryRunPrincipal_
Definition: PoolSource.h:75
EventID const & id() const
unsigned long long EventNumber_t
processConfiguration
Definition: Schedule.cc:374
LuminosityBlockAuxiliary const & aux() const
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:590
virtual void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal) override
Definition: PoolSource.cc:201
LuminosityBlockIndex index() const
LuminosityBlockNumber_t luminosityBlock() const
RunNumber_t run() const
Definition: RunPrincipal.h:61
static void fillDescription(ParameterSetDescription &desc)
unsigned int LuminosityBlockNumber_t
static EventNumber_t const invalidEvent
virtual std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: PoolSource.cc:172
virtual bool randomAccess_() const override
Definition: PoolSource.cc:334
void mergeProvenanceRetrievers(EventPrincipal &other)
virtual ProcessingController::ReverseState reverseState_() const override
Definition: PoolSource.cc:344
SharedResourcesAcquirer * resourceSharedWithDelayedReader_() override
Definition: PoolSource.cc:278
void setComment(std::string const &value)
virtual void readRun_(RunPrincipal &runPrincipal) override
Definition: PoolSource.cc:177
std::vector< edm::propagate_const< std::unique_ptr< EventPrincipal > > > secondaryEventPrincipals_
Definition: PoolSource.h:77
bool isAncestor(ProcessHistory const &a, ProcessHistory const &b)
LuminosityBlockNumber_t luminosityBlock() const
virtual void readEvent_(EventPrincipal &eventPrincipal) override
Definition: PoolSource.cc:226
static RunNumber_t const invalidRun
static SharedResourcesRegistry * instance()
static void reportReadBranches()
Definition: InputFile.cc:113
def move
Definition: eostools.py:510
StreamID streamID() const
virtual std::shared_ptr< RunAuxiliary > readRunAuxiliary_() override
Definition: PoolSource.cc:167
RunAuxiliary const & aux() const
Definition: RunPrincipal.h:57
virtual ~PoolSource()
Definition: PoolSource.cc:144
virtual ItemType getNextItemType() override
Definition: PoolSource.cc:257
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:352
std::unique_ptr< RunHelperBase > makeRunHelper(ParameterSet const &pset)
Definition: RunHelper.cc:13
LuminosityBlockNumber_t luminosityBlock() const
Accessor for current luminosity block number.
Definition: InputSource.cc:596
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: PoolSource.cc:300
unsigned int value() const
Definition: StreamID.h:46
virtual ProcessingController::ForwardState forwardState_() const override
Definition: PoolSource.cc:339
static LuminosityBlockNumber_t const invalidLumi
virtual bool readIt(EventID const &id, EventPrincipal &eventPrincipal, StreamContext &streamContext) override
Definition: PoolSource.cc:248
std::array< std::vector< BranchID >, NumBranchTypes > branchIDsToReplace_
Definition: PoolSource.h:78
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual void endJob() override
Definition: PoolSource.cc:147
RunIndex index() const
Definition: RunPrincipal.h:53
virtual void skip(int offset) override
Definition: PoolSource.cc:290
virtual std::unique_ptr< FileBlock > readFile_() override
Definition: PoolSource.cc:154
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:127
unsigned int RunNumber_t
virtual void rewind_() override
Definition: PoolSource.cc:284
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:214
edm::propagate_const< std::shared_ptr< LuminosityBlockPrincipal > > secondaryLumiPrincipal_
Definition: PoolSource.h:76
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:812
tuple size
Write out results.
edm::propagate_const< std::unique_ptr< RootPrimaryFileSequence > > primaryFileSequence_
Definition: PoolSource.h:90
virtual void closeFile_() override
Definition: PoolSource.cc:162