Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-23 02:05:08

0001 /*----------------------------------------------------------------------
0002 ----------------------------------------------------------------------*/
0003 #include "DuplicateChecker.h"
0004 #include "PoolSource.h"
0005 #include "InputFile.h"
0006 #include "RootFile.h"
0007 #include "RootSecondaryFileSequence.h"
0008 #include "RootTree.h"
0009 
0010 #include "DataFormats/Provenance/interface/BranchID.h"
0011 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0012 #include "FWCore/Catalog/interface/InputFileCatalog.h"
0013 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 #include "Utilities/StorageFactory/interface/StorageFactory.h"
0019 
0020 namespace edm {
0021   RootSecondaryFileSequence::RootSecondaryFileSequence(ParameterSet const& pset,
0022                                                        PoolSource& input,
0023                                                        InputFileCatalog const& catalog)
0024       : RootInputFileSequence(pset, catalog),
0025         input_(input),
0026         orderedProcessHistoryIDs_(),
0027         enablePrefetching_(false),
0028         enforceGUIDInFileName_(pset.getUntrackedParameter<bool>("enforceGUIDInFileName")) {
0029     // The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
0030     Service<SiteLocalConfig> pSLC;
0031     if (pSLC.isAvailable()) {
0032       enablePrefetching_ = pSLC->enablePrefetching();
0033     }
0034 
0035     // Prestage the files
0036     //NOTE: we do not want to stage in all secondary files since we can be given a list of
0037     // thousands of files and prestaging all those files can cause a site to fail.
0038     // So, we stage in the first secondary file only.
0039     setAtFirstFile();
0040     storage::StorageFactory::get()->stagein(fileNames()[0]);
0041 
0042     // Open the first file.
0043     for (setAtFirstFile(); !noMoreFiles(); setAtNextFile()) {
0044       initFile(input_.skipBadFiles());
0045       if (rootFile())
0046         break;
0047     }
0048     if (rootFile()) {
0049       input_.productRegistryUpdate().updateFromInput(rootFile()->productRegistry()->productList());
0050     }
0051   }
0052 
0053   RootSecondaryFileSequence::~RootSecondaryFileSequence() {}
0054 
0055   void RootSecondaryFileSequence::endJob() { closeFile(); }
0056 
0057   void RootSecondaryFileSequence::closeFile_() {
0058     // close the currently open file, if any, and delete the RootFile object.
0059     if (rootFile()) {
0060       rootFile()->close();
0061       rootFile().reset();
0062     }
0063   }
0064 
0065   void RootSecondaryFileSequence::initFile_(bool skipBadFiles) {
0066     initTheFile(skipBadFiles, false, nullptr, "secondaryFiles", InputType::SecondaryFile);
0067   }
0068 
0069   RootSecondaryFileSequence::RootFileSharedPtr RootSecondaryFileSequence::makeRootFile(
0070       std::shared_ptr<InputFile> filePtr) {
0071     size_t currentIndexIntoFile = sequenceNumberOfFile();
0072     return std::make_shared<RootFile>(
0073         RootFile::FileOptions{.fileName = fileNames()[0],
0074                               .logicalFileName = logicalFileName(),
0075                               .filePtr = filePtr,
0076                               .bypassVersionCheck = input_.bypassVersionCheck(),
0077                               .enforceGUIDInFileName = enforceGUIDInFileName_},
0078         InputType::SecondaryFile,
0079         RootFile::ProcessingOptions{
0080             .processingMode = input_.processingMode(),
0081         },
0082         RootFile::TTreeOptions{.treeMaxVirtualSize = input_.treeMaxVirtualSize(),
0083                                .enablePrefetching = enablePrefetching_,
0084                                .promptReading = not input_.delayReadingEventProducts()},
0085         RootFile::ProductChoices{.productSelectorRules = input_.productSelectorRules(),
0086                                  .associationsFromSecondary = &associationsFromSecondary_,
0087                                  .dropDescendantsOfDroppedProducts = input_.dropDescendants(),
0088                                  .labelRawDataLikeMC = input_.labelRawDataLikeMC()},
0089         RootFile::CrossFileInfo{.runHelper = input_.runHelper(),
0090                                 .branchIDListHelper = input_.branchIDListHelper(),
0091                                 .thinnedAssociationsHelper = input_.thinnedAssociationsHelper(),
0092                                 .indexesIntoFiles = indexesIntoFiles(),
0093                                 .currentIndexIntoFile = currentIndexIntoFile},
0094         input_.nStreams(),
0095         input_.processHistoryRegistryForUpdate(),
0096         orderedProcessHistoryIDs_);
0097   }
0098 
0099   void RootSecondaryFileSequence::initAssociationsFromSecondary(std::set<BranchID> const& associationsFromSecondary) {
0100     for (auto const& branchID : associationsFromSecondary) {
0101       associationsFromSecondary_.push_back(branchID);
0102     }
0103     rootFile()->initAssociationsFromSecondary(associationsFromSecondary_);
0104   }
0105 }  // namespace edm