Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19: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 
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 RootDelayedReader: pretends to support file reading.
0031   //
0032 
0033   class RootDelayedReader : public DelayedReader {
0034   public:
0035     typedef roottree::BranchInfo BranchInfo;
0036     typedef roottree::BranchMap BranchMap;
0037     typedef roottree::EntryNumber EntryNumber;
0038     RootDelayedReader(RootTree const& tree, std::shared_ptr<InputFile> filePtr, InputType inputType);
0039 
0040     ~RootDelayedReader() override;
0041 
0042     RootDelayedReader(RootDelayedReader const&) = delete;             // Disallow copying and moving
0043     RootDelayedReader& operator=(RootDelayedReader const&) = delete;  // Disallow copying and moving
0044 
0045     signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadFromSourceSignal()
0046         const final {
0047       return preEventReadFromSourceSignal_;
0048     }
0049     signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadFromSourceSignal()
0050         const final {
0051       return postEventReadFromSourceSignal_;
0052     }
0053 
0054     void setSignals(
0055         signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadSource,
0056         signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource) {
0057       preEventReadFromSourceSignal_ = preEventReadSource;
0058       postEventReadFromSourceSignal_ = postEventReadSource;
0059     }
0060 
0061   private:
0062     std::shared_ptr<WrapperBase> getProduct_(BranchID const& k, EDProductGetter const* ep) override;
0063     void mergeReaders_(DelayedReader* other) override { nextReader_ = other; }
0064     void reset_() override { nextReader_ = nullptr; }
0065     std::pair<SharedResourcesAcquirer*, std::recursive_mutex*> sharedResources_() const override;
0066 
0067     BranchMap const& branches() const { return tree_.branches(); }
0068     BranchInfo const* getBranchInfo(BranchID const& k) const { return branches().find(k); }
0069     // NOTE: filePtr_ appears to be unused, but is needed to prevent
0070     // the file containing the branch from being reclaimed.
0071     RootTree const& tree_;
0072     edm::propagate_const<std::shared_ptr<InputFile>> filePtr_;
0073     edm::propagate_const<DelayedReader*> nextReader_;
0074     std::unique_ptr<SharedResourcesAcquirer>
0075         resourceAcquirer_;  // We do not use propagate_const because the acquirer is itself mutable.
0076     std::shared_ptr<std::recursive_mutex> mutex_;
0077     InputType inputType_;
0078     edm::propagate_const<TClass*> wrapperBaseTClass_;
0079 
0080     signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadFromSourceSignal_ =
0081         nullptr;
0082     signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadFromSourceSignal_ =
0083         nullptr;
0084 
0085     //If a fatal exception happens we need to make a copy so we can
0086     // rethrow that exception on other threads. This avoids TTree
0087     // non-exception safety problems on later calls to TTree.
0088     //All uses of the ROOT file are serialized
0089     CMS_SA_ALLOW mutable std::exception_ptr lastException_;
0090   };  // class RootDelayedReader
0091   //------------------------------------------------------------
0092 }  // namespace edm
0093 #endif