Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:07

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>(fileNames()[0],
0073                                       input_.processConfiguration(),
0074                                       logicalFileName(),
0075                                       filePtr,
0076                                       input_.nStreams(),
0077                                       input_.treeMaxVirtualSize(),
0078                                       input_.processingMode(),
0079                                       input_.runHelper(),
0080                                       input_.productSelectorRules(),
0081                                       InputType::SecondaryFile,
0082                                       input_.branchIDListHelper(),
0083                                       input_.thinnedAssociationsHelper(),
0084                                       &associationsFromSecondary_,
0085                                       input_.dropDescendants(),
0086                                       input_.processHistoryRegistryForUpdate(),
0087                                       indexesIntoFiles(),
0088                                       currentIndexIntoFile,
0089                                       orderedProcessHistoryIDs_,
0090                                       input_.bypassVersionCheck(),
0091                                       input_.labelRawDataLikeMC(),
0092                                       enablePrefetching_,
0093                                       enforceGUIDInFileName_);
0094   }
0095 
0096   void RootSecondaryFileSequence::initAssociationsFromSecondary(std::set<BranchID> const& associationsFromSecondary) {
0097     for (auto const& branchID : associationsFromSecondary) {
0098       associationsFromSecondary_.push_back(branchID);
0099     }
0100     rootFile()->initAssociationsFromSecondary(associationsFromSecondary_);
0101   }
0102 }  // namespace edm