Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:33:05

0001 #ifndef FWLite_BareRootProductGetter_h
0002 #define FWLite_BareRootProductGetter_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     BareRootProductGetter
0007 //
0008 /**\class BareRootProductGetter BareRootProductGetter.h FWCore/FWLite/interface/BareRootProductGetter.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Tue May 23 11:03:27 EDT 2006
0019 //
0020 
0021 // user include files
0022 #include "DataFormats/Common/interface/WrapperBase.h"
0023 #include "DataFormats/Common/interface/EDProductGetter.h"
0024 #include "FWCore/FWLite/interface/BranchMapReader.h"
0025 #include "FWCore/Utilities/interface/propagate_const.h"
0026 
0027 // system include files
0028 #include "Rtypes.h"
0029 #include <map>
0030 #include <memory>
0031 #include <vector>
0032 
0033 // forward declarations
0034 class TBranch;
0035 class TClass;
0036 
0037 namespace edm {
0038   class BranchID;
0039   class ProductID;
0040   class ThinnedAssociation;
0041 }  // namespace edm
0042 
0043 class BareRootProductGetter : public edm::EDProductGetter {
0044 public:
0045   BareRootProductGetter();
0046   ~BareRootProductGetter() override;
0047   BareRootProductGetter(BareRootProductGetter const&) = delete;                   // stop default
0048   BareRootProductGetter const& operator=(BareRootProductGetter const&) = delete;  // stop default
0049 
0050   // ---------- const member functions ---------------------
0051   edm::WrapperBase const* getIt(edm::ProductID const&) const override;
0052 
0053   // getThinnedProduct assumes getIt was already called and failed to find
0054   // the product. The input key is the index of the desired element in the
0055   // container identified by ProductID (which cannot be found).
0056   // If the return value is not null, then the desired element was
0057   // found in a thinned container. If the desired element is not
0058   // found, then an optional without a value is returned.
0059   std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const&,
0060                                                                                      unsigned int key) const override;
0061 
0062   // getThinnedProducts assumes getIt was already called and failed to find
0063   // the product. The input keys are the indexes into the container identified
0064   // by ProductID (which cannot be found). On input the WrapperBase pointers
0065   // must all be set to nullptr (except when the function calls itself
0066   // recursively where non-null pointers mark already found elements).
0067   // Thinned containers derived from the product are searched to see
0068   // if they contain the desired elements. For each that is
0069   // found, the corresponding WrapperBase pointer is set and the key
0070   // is modified to be the key into the container where the element
0071   // was found. The WrapperBase pointers might or might not all point
0072   // to the same thinned container.
0073   void getThinnedProducts(edm::ProductID const&,
0074                           std::vector<edm::WrapperBase const*>& foundContainers,
0075                           std::vector<unsigned int>& keys) const override;
0076 
0077   // This overload is allowed to be called also without getIt()
0078   // being called first, but the thinned ProductID must come from an
0079   // existing RefCore. The input key is the index of the desired
0080   // element in the container identified by the parent ProductID.
0081   // If the return value is not null, then the desired element was found
0082   // in a thinned container. If the desired element is not found, then
0083   // an optional without a value is returned.
0084   edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0085                                             unsigned int key,
0086                                             edm::ProductID const& thinned) const override;
0087 
0088 private:
0089   // ---------- static member functions --------------------
0090 
0091   // ---------- member functions ---------------------------
0092   unsigned int transitionIndex_() const override { return 0u; }
0093 
0094   edm::WrapperBase const* getIt(edm::BranchID const&, Long_t eventEntry) const;
0095 
0096   struct Buffer {
0097     Buffer(edm::WrapperBase const* iProd, TBranch* iBranch, void* iAddress, TClass* iClass)
0098         : product_(iProd), branch_(iBranch), address_(iAddress), eventEntry_(-1), class_(iClass) {}
0099     Buffer() : product_(), branch_(), address_(), eventEntry_(-1), class_(nullptr) {}
0100 
0101     std::shared_ptr<edm::WrapperBase const> product_;
0102     edm::propagate_const<TBranch*> branch_;
0103     void* address_;      //the address to pass to Root since as of 5.13 they cache that info
0104     Long_t eventEntry_;  //the event Entry used with the last GetEntry call
0105     edm::propagate_const<TClass*> class_;
0106   };
0107 
0108   Buffer* createNewBuffer(edm::BranchID const&) const;
0109   edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID, Long_t eventEntry) const;
0110 
0111   // ---------- member data --------------------------------
0112 
0113   typedef std::map<edm::BranchID, Buffer> IdToBuffers;
0114   mutable IdToBuffers idToBuffers_;
0115   mutable fwlite::BranchMapReader branchMap_;
0116 };
0117 #endif