Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-22 04:57:38

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