Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-06 00:35:40

0001 #ifndef IOPool_Input_RootInputFileSequence_h
0002 #define IOPool_Input_RootInputFileSequence_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 RootInputFileSequence: This is an InputSource. initTheFile tries to open
0007 a file using a list of PFN names constructed from multiple data catalogs
0008 in site-local-config.xml. These are accessed via FileCatalogItem iterator
0009 fileIter_.
0010 
0011 ----------------------------------------------------------------------*/
0012 
0013 #include "InputFile.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Catalog/interface/InputFileCatalog.h"
0016 #include "FWCore/Utilities/interface/InputType.h"
0017 #include "FWCore/Utilities/interface/get_underlying_safe.h"
0018 
0019 #include <memory>
0020 #include <string>
0021 #include <unordered_map>
0022 #include <vector>
0023 
0024 namespace edm {
0025 
0026   class FileCatalogItem;
0027   class IndexIntoFile;
0028   class InputFileCatalog;
0029   class ParameterSetDescription;
0030   class RootFile;
0031 
0032   class RootInputFileSequence {
0033   public:
0034     explicit RootInputFileSequence(ParameterSet const& pset, InputFileCatalog const& catalog);
0035     virtual ~RootInputFileSequence();
0036 
0037     RootInputFileSequence(RootInputFileSequence const&) = delete;             // Disallow copying and moving
0038     RootInputFileSequence& operator=(RootInputFileSequence const&) = delete;  // Disallow copying and moving
0039 
0040     bool containedInCurrentFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
0041     bool readEvent(EventPrincipal& cache);
0042     std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
0043     bool readLuminosityBlock_(LuminosityBlockPrincipal& lumiPrincipal);
0044     std::shared_ptr<RunAuxiliary> readRunAuxiliary_();
0045     bool readRun_(RunPrincipal& runPrincipal);
0046     void fillProcessBlockHelper_();
0047     bool nextProcessBlock_(ProcessBlockPrincipal&);
0048     void readProcessBlock_(ProcessBlockPrincipal&);
0049     bool skipToItem(RunNumber_t run,
0050                     LuminosityBlockNumber_t lumi,
0051                     EventNumber_t event,
0052                     size_t fileNameHash = 0U,
0053                     bool currentFileFirst = true);
0054     std::shared_ptr<ProductRegistry const> fileProductRegistry() const;
0055     std::shared_ptr<BranchIDListHelper const> fileBranchIDListHelper() const;
0056 
0057     void closeFile();
0058 
0059   protected:
0060     typedef std::shared_ptr<RootFile> RootFileSharedPtr;
0061     void initFile(bool skipBadFiles) { initFile_(skipBadFiles); }
0062     void initTheFile(bool skipBadFiles,
0063                      bool deleteIndexIntoFile,
0064                      InputSource* input,
0065                      char const* inputTypeName,
0066                      InputType inputType);
0067 
0068     bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event);
0069     bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash);
0070 
0071     bool atFirstFile() const { return fileIter_ == fileIterBegin_; }
0072     bool atLastFile() const { return fileIter_ + 1 == fileIterEnd_; }
0073     bool noMoreFiles() const { return fileIter_ == fileIterEnd_; }
0074     bool noFiles() const { return fileIterBegin_ == fileIterEnd_; }
0075     size_t sequenceNumberOfFile() const { return fileIter_ - fileIterBegin_; }
0076     size_t numberOfFiles() const { return fileIterEnd_ - fileIterBegin_; }
0077 
0078     void setAtFirstFile() { fileIter_ = fileIterBegin_; }
0079     void setAtFileSequenceNumber(size_t offset) { fileIter_ = fileIterBegin_ + offset; }
0080     void setNoMoreFiles() { fileIter_ = fileIterEnd_; }
0081     void setAtNextFile() { ++fileIter_; }
0082     void setAtPreviousFile() { --fileIter_; }
0083 
0084     std::vector<std::string> const& fileNames() const { return fileIter_->fileNames(); }
0085 
0086     std::string const& logicalFileName() const { return fileIter_->logicalFileName(); }
0087     std::string const& lfn() const { return lfn_; }
0088     std::vector<FileCatalogItem> const& fileCatalogItems() const;
0089 
0090     std::vector<std::shared_ptr<IndexIntoFile>> const& indexesIntoFiles() const { return indexesIntoFiles_; }
0091     void setIndexIntoFile(size_t index);
0092     size_t lfnHash() const { return lfnHash_; }
0093     bool usedFallback() const { return usedFallback_; }
0094 
0095     std::shared_ptr<RootFile const> rootFile() const { return get_underlying_safe(rootFile_); }
0096     std::shared_ptr<RootFile>& rootFile() { return get_underlying_safe(rootFile_); }
0097 
0098   private:
0099     InputFileCatalog const& catalog_;
0100     std::string lfn_;
0101     size_t lfnHash_;
0102     bool usedFallback_;
0103     edm::propagate_const<std::unique_ptr<std::unordered_multimap<size_t, size_t>>> findFileForSpecifiedID_;
0104     std::vector<FileCatalogItem>::const_iterator const fileIterBegin_;
0105     std::vector<FileCatalogItem>::const_iterator const fileIterEnd_;
0106     std::vector<FileCatalogItem>::const_iterator fileIter_;
0107     std::vector<FileCatalogItem>::const_iterator fileIterLastOpened_;
0108     edm::propagate_const<RootFileSharedPtr> rootFile_;
0109     std::vector<std::shared_ptr<IndexIntoFile>> indexesIntoFiles_;
0110 
0111   private:
0112     virtual RootFileSharedPtr makeRootFile(std::shared_ptr<InputFile> filePtr) = 0;
0113     virtual void initFile_(bool skipBadFiles) = 0;
0114     virtual void closeFile_() = 0;
0115 
0116   };  // class RootInputFileSequence
0117 }  // namespace edm
0118 #endif