Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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