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  } // namespace
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_(
71  pset.getUntrackedParameter<std::vector<std::string> >("secondaryFileNames", std::vector<std::string>()),
72  pset.getUntrackedParameter<std::string>("overrideCatalog", std::string())),
73  secondaryRunPrincipal_(),
74  secondaryLumiPrincipal_(),
75  secondaryEventPrincipals_(),
76  branchIDsToReplace_(),
77  nStreams_(desc.allocations_->numberOfStreams()),
78  skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles")),
79  bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck")),
80  treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize")),
81  productSelectorRules_(pset, "inputCommands", "InputSource"),
82  dropDescendants_(pset.getUntrackedParameter<bool>("dropDescendantsOfDroppedBranches")),
83  labelRawDataLikeMC_(pset.getUntrackedParameter<bool>("labelRawDataLikeMC")),
84  runHelper_(makeRunHelper(pset)),
86  // Note: primaryFileSequence_ and secondaryFileSequence_ need to be initialized last, because they use data members
87  // initialized previously in their own initialization.
88  primaryFileSequence_(new RootPrimaryFileSequence(pset, *this, catalog_)),
89  secondaryFileSequence_(
90  secondaryCatalog_.empty() ? nullptr : new RootSecondaryFileSequence(pset, *this, secondaryCatalog_)) {
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 && item.second.unwrappedType() == typeid(ThinnedAssociation)) {
114  associationsFromSecondary.insert(item.second.branchID());
115  }
116  //now make sure this is marked as not dropped else the product will not be 'get'table from the Event
117  auto itFound = fullList.find(item.first);
118  if (itFound != fullList.end()) {
119  itFound->second.setDropped(false);
120  }
121  }
122  }
123  for (auto const& item : primary) {
124  if (item.second.present()) {
125  idsToReplace[item.second.branchType()].erase(item.second.branchID());
126  associationsFromSecondary.erase(item.second.branchID());
127  }
128  }
129  if (idsToReplace[InEvent].empty() && idsToReplace[InLumi].empty() && idsToReplace[InRun].empty()) {
130  secondaryFileSequence_ = nullptr; // propagate_const<T> has no reset() function
131  } else {
132  for (int i = InEvent; i < NumBranchTypes; ++i) {
133  branchIDsToReplace_[i].reserve(idsToReplace[i].size());
134  for (auto const& id : idsToReplace[i]) {
135  branchIDsToReplace_[i].push_back(id);
136  }
137  }
138  secondaryFileSequence_->initAssociationsFromSecondary(associationsFromSecondary);
139  }
140  }
141  }
142 
144 
147  secondaryFileSequence_->endJob();
148  primaryFileSequence_->endJob();
150  }
151 
152  std::unique_ptr<FileBlock> PoolSource::readFile_() {
153  std::unique_ptr<FileBlock> fb = primaryFileSequence_->readFile_();
155  fb->setNotFastClonable(FileBlock::HasSecondaryFileSequence);
156  }
157  return std::move(fb);
158  }
159 
161 
162  std::shared_ptr<RunAuxiliary> PoolSource::readRunAuxiliary_() { return primaryFileSequence_->readRunAuxiliary_(); }
163 
164  std::shared_ptr<LuminosityBlockAuxiliary> PoolSource::readLuminosityBlockAuxiliary_() {
165  return primaryFileSequence_->readLuminosityBlockAuxiliary_();
166  }
167 
168  void PoolSource::readRun_(RunPrincipal& runPrincipal) {
169  primaryFileSequence_->readRun_(runPrincipal);
171  bool found = secondaryFileSequence_->skipToItem(runPrincipal.run(), 0U, 0U);
172  if (found) {
173  std::shared_ptr<RunAuxiliary> secondaryAuxiliary = secondaryFileSequence_->readRunAuxiliary_();
174  checkConsistency(runPrincipal.aux(), *secondaryAuxiliary);
175  secondaryRunPrincipal_ = std::make_shared<RunPrincipal>(secondaryAuxiliary,
176  secondaryFileSequence_->fileProductRegistry(),
178  nullptr,
179  runPrincipal.index());
180  secondaryFileSequence_->readRun_(*secondaryRunPrincipal_);
181  checkHistoryConsistency(runPrincipal, *secondaryRunPrincipal_);
182  runPrincipal.recombine(*secondaryRunPrincipal_, branchIDsToReplace_[InRun]);
183  } else {
184  throw Exception(errors::MismatchedInputFiles, "PoolSource::readRun_")
185  << " Run " << runPrincipal.run() << " is not found in the secondary input files\n";
186  }
187  }
188  }
189 
191  primaryFileSequence_->readLuminosityBlock_(lumiPrincipal);
193  bool found = secondaryFileSequence_->skipToItem(lumiPrincipal.run(), lumiPrincipal.luminosityBlock(), 0U);
194  if (found) {
195  std::shared_ptr<LuminosityBlockAuxiliary> secondaryAuxiliary =
196  secondaryFileSequence_->readLuminosityBlockAuxiliary_();
197  checkConsistency(lumiPrincipal.aux(), *secondaryAuxiliary);
198  secondaryLumiPrincipal_ = std::make_shared<LuminosityBlockPrincipal>(secondaryAuxiliary,
199  secondaryFileSequence_->fileProductRegistry(), processConfiguration(), nullptr, lumiPrincipal.index());
200  secondaryFileSequence_->readLuminosityBlock_(*secondaryLumiPrincipal_);
201  checkHistoryConsistency(lumiPrincipal, *secondaryLumiPrincipal_);
202  lumiPrincipal.recombine(*secondaryLumiPrincipal_, branchIDsToReplace_[InLumi]);
203  } else {
204  throw Exception(errors::MismatchedInputFiles, "PoolSource::readLuminosityBlock_")
205  << " Run " << lumiPrincipal.run() << " LuminosityBlock " << lumiPrincipal.luminosityBlock()
206  << " is not found in the secondary input files\n";
207  }
208  }
209  }
210 
211  void PoolSource::readEvent_(EventPrincipal& eventPrincipal) {
212  primaryFileSequence_->readEvent(eventPrincipal);
214  bool found = secondaryFileSequence_->skipToItem(
215  eventPrincipal.run(), eventPrincipal.luminosityBlock(), eventPrincipal.id().event());
216  if (found) {
217  EventPrincipal& secondaryEventPrincipal = *secondaryEventPrincipals_[eventPrincipal.streamID().value()];
218  secondaryFileSequence_->readEvent(secondaryEventPrincipal);
219  checkConsistency(eventPrincipal, secondaryEventPrincipal);
220  checkHistoryConsistency(eventPrincipal, secondaryEventPrincipal);
221  eventPrincipal.recombine(secondaryEventPrincipal, branchIDsToReplace_[InEvent]);
222  eventPrincipal.mergeProvenanceRetrievers(secondaryEventPrincipal);
223  secondaryEventPrincipal.clearPrincipal();
224  } else {
225  throw Exception(errors::MismatchedInputFiles, "PoolSource::readEvent_")
226  << eventPrincipal.id() << " is not found in the secondary input files\n";
227  }
228  }
229  }
230 
231  bool PoolSource::readIt(EventID const& id, EventPrincipal& eventPrincipal, StreamContext& streamContext) {
232  bool found = primaryFileSequence_->skipToItem(id.run(), id.luminosityBlock(), id.event());
233  if (!found)
234  return false;
235  EventSourceSentry sentry(*this, streamContext);
236  readEvent_(eventPrincipal);
237  return true;
238  }
239 
244  InputSource::ItemType itemType = primaryFileSequence_->getNextItemType(run, lumi, event);
246  if (itemType == IsRun || itemType == IsLumi || itemType == IsEvent) {
247  if (!secondaryFileSequence_->containedInCurrentFile(run, lumi, event)) {
248  return IsSynchronize;
249  }
250  }
251  }
252  return runHelper_->nextItemType(state(), itemType);
253  }
254 
255  void
257  primaryFileSequence_->closeFile();
258  }
259 
263  }
264 
265  // Rewind to before the first event that was read.
267 
268  // Advance "offset" events. Offset can be positive or negative (or zero).
269  void PoolSource::skip(int offset) { primaryFileSequence_->skipEvents(offset); }
270 
271  bool PoolSource::goToEvent_(EventID const& eventID) { return primaryFileSequence_->goToEvent(eventID); }
272 
275 
276  std::vector<std::string> defaultStrings;
277  desc.setComment("Reads EDM/Root files.");
278  desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed.");
279  desc.addUntracked<std::vector<std::string> >("secondaryFileNames", defaultStrings)
280  ->setComment("Names of secondary files to be processed.");
281  desc.addUntracked<bool>("needSecondaryFileNames", false)
282  ->setComment("If True, 'secondaryFileNames' must be specified and be non-empty.");
283  desc.addUntracked<std::string>("overrideCatalog", std::string());
284  desc.addUntracked<bool>("skipBadFiles", false)
285  ->setComment(
286  "True: Ignore any missing or unopenable input file.\n"
287  "False: Throw exception if missing or unopenable input file.");
288  desc.addUntracked<bool>("bypassVersionCheck", false)
289  ->setComment(
290  "True: Bypass release version check.\n"
291  "False: Throw exception if reading file in a release prior to the release in which the file was written.");
292  desc.addUntracked<int>("treeMaxVirtualSize", -1)
293  ->setComment("Size of ROOT TTree TBasket cache. Affects performance.");
294  desc.addUntracked<bool>("dropDescendantsOfDroppedBranches", true)
295  ->setComment("If True, also drop on input any descendent of any branch dropped on input.");
296  desc.addUntracked<bool>("labelRawDataLikeMC", true)
297  ->setComment("If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
298  ProductSelectorRules::fillDescription(desc, "inputCommands");
302 
303  descriptions.add("source", desc);
304  }
305 
306  bool PoolSource::randomAccess_() const { return true; }
307 
309 
311 } // namespace edm
virtual void preForkReleaseResources() override
Definition: PoolSource.cc:256
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:271
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:190
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:164
virtual bool randomAccess_() const override
Definition: PoolSource.cc:306
void mergeProvenanceRetrievers(EventPrincipal &other)
virtual ProcessingController::ReverseState reverseState_() const override
Definition: PoolSource.cc:310
SharedResourcesAcquirer * resourceSharedWithDelayedReader_() override
Definition: PoolSource.cc:261
void setComment(std::string const &value)
virtual void readRun_(RunPrincipal &runPrincipal) override
Definition: PoolSource.cc:168
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:211
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:162
RunAuxiliary const & aux() const
Definition: RunPrincipal.h:57
virtual ~PoolSource()
Definition: PoolSource.cc:143
virtual ItemType getNextItemType() override
Definition: PoolSource.cc:240
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:273
unsigned int value() const
Definition: StreamID.h:46
virtual ProcessingController::ForwardState forwardState_() const override
Definition: PoolSource.cc:308
static LuminosityBlockNumber_t const invalidLumi
virtual bool readIt(EventID const &id, EventPrincipal &eventPrincipal, StreamContext &streamContext) override
Definition: PoolSource.cc:231
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:145
RunIndex index() const
Definition: RunPrincipal.h:53
virtual void skip(int offset) override
Definition: PoolSource.cc:269
virtual std::unique_ptr< FileBlock > readFile_() override
Definition: PoolSource.cc:152
static void fillDescription(ParameterSetDescription &desc)
Definition: InputSource.cc:127
unsigned int RunNumber_t
virtual void rewind_() override
Definition: PoolSource.cc:266
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:160