Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-02 04:38:20

0001 #ifndef DataFormats_FWLite_DataGetterHelper_h
0002 #define DataFormats_FWLite_DataGetterHelper_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     DataFormats/FWLite
0006 // Class  :     DataGetterHelper
0007 //
0008 /**\class DataGetterHelper DataGetterHelper.h src/DataFormats/FWLite/interface/DataGetterHelper.h
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author: Eric Vaandering
0018 //         Created:  Fri Jan 29 12:45:17 CST 2010
0019 //
0020 
0021 // user include files
0022 #include "DataFormats/Common/interface/EDProductGetter.h"
0023 #include "DataFormats/FWLite/interface/HistoryGetterBase.h"
0024 #include "DataFormats/FWLite/interface/InternalDataKey.h"
0025 #include "FWCore/FWLite/interface/BranchMapReader.h"
0026 #include "FWCore/Utilities/interface/propagate_const.h"
0027 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0028 
0029 #include "Rtypes.h"
0030 
0031 // system include files
0032 #include <cstring>
0033 #include <map>
0034 #include <memory>
0035 #include <typeinfo>
0036 #include <vector>
0037 #include <functional>
0038 
0039 // forward declarations
0040 class TTreeCache;
0041 class TTree;
0042 
0043 namespace edm {
0044   class BranchDescription;
0045   class BranchID;
0046   class ObjectWithDict;
0047   class ProductID;
0048   class ThinnedAssociation;
0049   class WrapperBase;
0050 }  // namespace edm
0051 
0052 namespace fwlite {
0053   class DataGetterHelper {
0054   public:
0055     //            DataGetterHelper() {};
0056     DataGetterHelper(
0057         TTree* tree,
0058         std::shared_ptr<HistoryGetterBase> historyGetter,
0059         std::shared_ptr<BranchMapReader> branchMap = std::shared_ptr<BranchMapReader>(),
0060         std::shared_ptr<edm::EDProductGetter> getter = std::shared_ptr<edm::EDProductGetter>(),
0061         bool useCache = false,
0062         std::function<void(TBranch const&)> baFunc = [](TBranch const&) {});
0063     virtual ~DataGetterHelper();
0064 
0065     // ---------- const member functions ---------------------
0066     virtual std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const;
0067 
0068     // This function should only be called by fwlite::Handle<>
0069     virtual bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*, Long_t) const;
0070 
0071     edm::WrapperBase const* getByProductID(edm::ProductID const& pid, Long_t eventEntry) const;
0072     std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
0073                                                                                        unsigned int key,
0074                                                                                        Long_t eventEntry) const;
0075     void getThinnedProducts(edm::ProductID const& pid,
0076                             std::vector<edm::WrapperBase const*>& foundContainers,
0077                             std::vector<unsigned int>& keys,
0078                             Long_t eventEntry) const;
0079     edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0080                                               unsigned int key,
0081                                               edm::ProductID const& thinned,
0082                                               Long_t eventEntry) const;
0083 
0084     // ---------- static member functions --------------------
0085 
0086     // ---------- member functions ---------------------------
0087 
0088     void setGetter(std::shared_ptr<edm::EDProductGetter const> getter) { getter_ = getter; }
0089 
0090     edm::EDProductGetter const* getter() const { return getter_.get(); }
0091 
0092     DataGetterHelper(const DataGetterHelper&) = delete;                   // stop default
0093     const DataGetterHelper& operator=(const DataGetterHelper&) = delete;  // stop default
0094 
0095   private:
0096     typedef std::map<internal::DataKey, std::shared_ptr<internal::Data>> KeyToDataMap;
0097 
0098     internal::Data& getBranchDataFor(std::type_info const&, char const*, char const*, char const*) const;
0099     void getBranchData(edm::EDProductGetter const*, Long64_t, internal::Data&) const;
0100     bool getByBranchDescription(edm::BranchDescription const&, Long_t eventEntry, KeyToDataMap::iterator&) const;
0101     edm::WrapperBase const* getByBranchID(edm::BranchID const& bid, Long_t eventEntry) const;
0102     edm::WrapperBase const* wrapperBasePtr(edm::ObjectWithDict const&) const;
0103     edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID, Long_t eventEntry) const;
0104 
0105     // ---------- member data --------------------------------
0106     TTree* tree_;
0107     //This class is not inteded to be used across different threads
0108     CMS_SA_ALLOW mutable std::shared_ptr<BranchMapReader> branchMap_;
0109     CMS_SA_ALLOW mutable KeyToDataMap data_;
0110     CMS_SA_ALLOW mutable std::vector<char const*> labels_;
0111     const edm::ProcessHistory& history() const;
0112 
0113     CMS_SA_ALLOW mutable std::map<std::pair<edm::ProductID, edm::BranchListIndex>, std::shared_ptr<internal::Data>>
0114         idToData_;
0115     CMS_SA_ALLOW mutable std::map<edm::BranchID, std::shared_ptr<internal::Data>> bidToData_;
0116     edm::propagate_const<std::shared_ptr<fwlite::HistoryGetterBase>> historyGetter_;
0117     std::shared_ptr<edm::EDProductGetter const> getter_;
0118     CMS_SA_ALLOW mutable bool tcTrained_;
0119     /// Use internal TTreeCache.
0120     const bool tcUse_;
0121     /// Branch-access-function gets called whenever a branch data is accessed.
0122     /// This can be used for management of TTreeCache on the user side.
0123     std::function<void(TBranch const&)> branchAccessFunc_;
0124   };
0125 
0126 }  // namespace fwlite
0127 
0128 #endif