Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef IOPool_Input_RootPromptReadDelayedReader_h
0002 #define IOPool_Input_RootPromptReadDelayedReader_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 RootPromptReadDelayedReader.h // used by ROOT input sources
0007 
0008 ----------------------------------------------------------------------*/
0009 
0010 #include "DataFormats/Provenance/interface/BranchID.h"
0011 #include "FWCore/Utilities/interface/InputType.h"
0012 #include "FWCore/Utilities/interface/propagate_const.h"
0013 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0014 #include "RootTree.h"
0015 #include "RootDelayedReaderBase.h"
0016 
0017 #include <map>
0018 #include <memory>
0019 #include <string>
0020 #include <exception>
0021 
0022 class TClass;
0023 namespace edm {
0024   class InputFile;
0025   class RootTree;
0026   class SharedResourcesAcquirer;
0027   class Exception;
0028 
0029   //------------------------------------------------------------
0030   // Class RootPromptReadDelayedReader: pretends to support file reading.
0031   //
0032 
0033   class RootPromptReadDelayedReader : public RootDelayedReaderBase {
0034   public:
0035     typedef roottree::BranchInfo BranchInfo;
0036     typedef roottree::BranchMap BranchMap;
0037     typedef roottree::EntryNumber EntryNumber;
0038     RootPromptReadDelayedReader(RootTree const& tree,
0039                                 std::shared_ptr<InputFile> filePtr,
0040                                 InputType inputType,
0041                                 unsigned int iNIndexes);
0042 
0043     ~RootPromptReadDelayedReader() override;
0044 
0045     RootPromptReadDelayedReader(RootPromptReadDelayedReader const&) = delete;
0046     RootPromptReadDelayedReader& operator=(RootPromptReadDelayedReader const&) = delete;
0047     RootPromptReadDelayedReader(RootPromptReadDelayedReader&&) = delete;
0048     RootPromptReadDelayedReader& operator=(RootPromptReadDelayedReader&&) = delete;
0049 
0050     struct Cache {
0051       std::unique_ptr<edm::WrapperBase> wrapperBase_;
0052       edm::WrapperBase* wrapperBasePtr_ = nullptr;  // TBranch::SetAddress() needs a long live pointer to reference.
0053     };
0054 
0055     void readAllProductsNow(EDProductGetter const* ep) override;
0056 
0057   private:
0058     std::shared_ptr<WrapperBase> getProduct_(BranchID const& k, EDProductGetter const* ep) override;
0059     void mergeReaders_(DelayedReader* other) override { nextReader_ = other; }
0060     void reset_() override { nextReader_ = nullptr; }
0061     std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> sharedResources_() const override;
0062 
0063     BranchMap const& branches() const { return tree_.branches(); }
0064     BranchInfo const* getBranchInfo(unsigned int k) const { return branches().find(k); }
0065     std::vector<std::unordered_map<unsigned int, Cache>> cacheMaps_;
0066     // NOTE: filePtr_ appears to be unused, but is needed to prevent
0067     // the file containing the branch from being reclaimed.
0068     RootTree const& tree_;
0069     edm::propagate_const<std::shared_ptr<InputFile>> filePtr_;
0070     edm::propagate_const<DelayedReader*> nextReader_;
0071     // We do not use propagate_const because the acquirer is itself mutable.
0072     std::unique_ptr<SharedResourcesAcquirer> resourceAcquirer_;
0073     std::shared_ptr<std::recursive_mutex> mutex_;
0074     InputType inputType_;
0075 
0076     //If a fatal exception happens we need to make a copy so we can
0077     // rethrow that exception on other threads. This avoids TTree
0078     // non-exception safety problems on later calls to TTree.
0079     //All uses of the ROOT file are serialized
0080     CMS_SA_ALLOW mutable std::exception_ptr lastException_;
0081   };  // class RootPromptReadDelayedReader
0082   //------------------------------------------------------------
0083 }  // namespace edm
0084 #endif