|
| 1 | +/*---------------------------------------------------------------------- |
| 2 | +----------------------------------------------------------------------*/ |
| 3 | +#include "EmbeddedRNTupleTempSource.h" |
| 4 | +#include "InputFile.h" |
| 5 | +#include "RootEmbeddedFileSequence.h" |
| 6 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 7 | +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" |
| 8 | +#include "FWCore/Sources/interface/VectorInputSourceDescription.h" |
| 9 | +#include "FWCore/Sources/interface/InputSourceRunHelper.h" |
| 10 | + |
| 11 | +namespace edm { |
| 12 | + |
| 13 | + class EventID; |
| 14 | + class EventPrincipal; |
| 15 | +} // namespace edm |
| 16 | +namespace edm::rntuple_temp { |
| 17 | + |
| 18 | + EmbeddedRNTupleTempSource::EmbeddedRNTupleTempSource(ParameterSet const& pset, |
| 19 | + VectorInputSourceDescription const& desc) |
| 20 | + : VectorInputSource(pset, desc), |
| 21 | + rootServiceChecker_(), |
| 22 | + nStreams_(desc.allocations_->numberOfStreams()), |
| 23 | + // The default value provided as the second argument to the getUntrackedParameter function call |
| 24 | + // is not used when the ParameterSet has been validated and the parameters are not optional |
| 25 | + // in the description. This is currently true when RNTupleTempSource is the primary input source. |
| 26 | + // The modules that use RNTupleTempSource as a SecSource have not defined their fillDescriptions function |
| 27 | + // yet, so the ParameterSet does not get validated yet. As soon as all the modules with a SecSource |
| 28 | + // have defined descriptions, the defaults in the getUntrackedParameterSet function calls can |
| 29 | + // and should be deleted from the code. |
| 30 | + // |
| 31 | + skipBadFiles_(pset.getUntrackedParameter<bool>("skipBadFiles", false)), |
| 32 | + bypassVersionCheck_(pset.getUntrackedParameter<bool>("bypassVersionCheck", false)), |
| 33 | + treeMaxVirtualSize_(pset.getUntrackedParameter<int>("treeMaxVirtualSize", -1)), |
| 34 | + productSelectorRules_(pset, "inputCommands", "InputSource"), |
| 35 | + runHelper_(new DefaultInputSourceRunHelper()), |
| 36 | + catalog_(pset.getUntrackedParameter<std::vector<std::string> >("fileNames"), |
| 37 | + pset.getUntrackedParameter<std::string>("overrideCatalog", std::string())), |
| 38 | + // Note: fileSequence_ needs to be initialized last, because it uses data members |
| 39 | + // initialized previously in its own initialization. |
| 40 | + fileSequence_(new RootEmbeddedFileSequence(pset, *this, catalog_)) {} |
| 41 | + |
| 42 | + EmbeddedRNTupleTempSource::~EmbeddedRNTupleTempSource() {} |
| 43 | + |
| 44 | + void EmbeddedRNTupleTempSource::beginJob() {} |
| 45 | + |
| 46 | + void EmbeddedRNTupleTempSource::endJob() { |
| 47 | + fileSequence_->endJob(); |
| 48 | + InputFile::reportReadBranches(); |
| 49 | + } |
| 50 | + |
| 51 | + void EmbeddedRNTupleTempSource::closeFile_() { fileSequence_->closeFile(); } |
| 52 | + |
| 53 | + bool EmbeddedRNTupleTempSource::readOneEvent(EventPrincipal& cache, |
| 54 | + size_t& fileNameHash, |
| 55 | + CLHEP::HepRandomEngine* engine, |
| 56 | + EventID const* id, |
| 57 | + bool recycleFiles) { |
| 58 | + return fileSequence_->readOneEvent(cache, fileNameHash, engine, id, recycleFiles); |
| 59 | + } |
| 60 | + |
| 61 | + void EmbeddedRNTupleTempSource::readOneSpecified(EventPrincipal& cache, |
| 62 | + size_t& fileNameHash, |
| 63 | + SecondaryEventIDAndFileInfo const& id) { |
| 64 | + fileSequence_->readOneSpecified(cache, fileNameHash, id); |
| 65 | + } |
| 66 | + |
| 67 | + void EmbeddedRNTupleTempSource::dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) { |
| 68 | + std::vector<std::string> rules; |
| 69 | + rules.reserve(wantedBranches.size() + 1); |
| 70 | + rules.emplace_back("drop *"); |
| 71 | + for (std::string const& branch : wantedBranches) { |
| 72 | + rules.push_back("keep " + branch + "_*"); |
| 73 | + } |
| 74 | + ParameterSet pset; |
| 75 | + pset.addUntrackedParameter("inputCommands", rules); |
| 76 | + productSelectorRules_ = ProductSelectorRules(pset, "inputCommands", "InputSource"); |
| 77 | + } |
| 78 | + |
| 79 | + void EmbeddedRNTupleTempSource::fillDescriptions(ConfigurationDescriptions& descriptions) { |
| 80 | + ParameterSetDescription desc; |
| 81 | + |
| 82 | + std::vector<std::string> defaultStrings; |
| 83 | + desc.setComment("Reads EDM/Root files for mixing."); |
| 84 | + desc.addUntracked<std::vector<std::string> >("fileNames")->setComment("Names of files to be processed."); |
| 85 | + desc.addUntracked<std::string>("overrideCatalog", std::string()); |
| 86 | + desc.addUntracked<bool>("skipBadFiles", false) |
| 87 | + ->setComment( |
| 88 | + "True: Ignore any missing or unopenable input file.\n" |
| 89 | + "False: Throw exception if missing or unopenable input file."); |
| 90 | + desc.addUntracked<bool>("bypassVersionCheck", false) |
| 91 | + ->setComment( |
| 92 | + "True: Bypass release version check.\n" |
| 93 | + "False: Throw exception if reading file in a release prior to the release in which the file was written."); |
| 94 | + desc.addUntracked<int>("treeMaxVirtualSize", -1) |
| 95 | + ->setComment("Size of ROOT TTree TBasket cache. Affects performance."); |
| 96 | + |
| 97 | + ProductSelectorRules::fillDescription(desc, "inputCommands"); |
| 98 | + RootEmbeddedFileSequence::fillDescription(desc); |
| 99 | + |
| 100 | + descriptions.add("source", desc); |
| 101 | + } |
| 102 | +} // namespace edm::rntuple_temp |
0 commit comments