Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:09

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     ~DataGetterHelper();
0064 
0065     // ---------- const member functions ---------------------
0066     std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const;
0067     std::optional<edm::BranchID> getBranchIDFor(std::type_info const&, char const*, char const*, char const*) const;
0068 
0069     // This function should only be called by fwlite::Handle<>
0070     bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*, Long_t) const;
0071 
0072     edm::WrapperBase const* getByProductID(edm::ProductID const& pid, Long_t eventEntry) const;
0073     edm::WrapperBase const* getByBranchID(edm::BranchID const& bid, Long_t eventEntry) const;
0074     std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
0075                                                                                        unsigned int key,
0076                                                                                        Long_t eventEntry) const;
0077     void getThinnedProducts(edm::ProductID const& pid,
0078                             std::vector<edm::WrapperBase const*>& foundContainers,
0079                             std::vector<unsigned int>& keys,
0080                             Long_t eventEntry) const;
0081     edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0082                                               unsigned int key,
0083                                               edm::ProductID const& thinned,
0084                                               Long_t eventEntry) const;
0085 
0086     // ---------- static member functions --------------------
0087 
0088     // ---------- member functions ---------------------------
0089 
0090     void setGetter(std::shared_ptr<edm::EDProductGetter const> getter) { getter_ = getter; }
0091 
0092     edm::EDProductGetter const* getter() const { return getter_.get(); }
0093 
0094     DataGetterHelper(const DataGetterHelper&) = delete;                   // stop default
0095     const DataGetterHelper& operator=(const DataGetterHelper&) = delete;  // stop default
0096 
0097   private:
0098     typedef std::map<internal::DataKey, std::shared_ptr<internal::Data>> KeyToDataMap;
0099 
0100     internal::Data& getBranchDataFor(std::type_info const&, char const*, char const*, char const*) const;
0101     void getBranchData(edm::EDProductGetter const*, Long64_t, internal::Data&) const;
0102     bool getByBranchDescription(edm::BranchDescription const&, Long_t eventEntry, KeyToDataMap::iterator&) const;
0103     edm::WrapperBase const* wrapperBasePtr(edm::ObjectWithDict const&) const;
0104     edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID, Long_t eventEntry) const;
0105 
0106     // ---------- member data --------------------------------
0107     TTree* tree_;
0108     //This class is not inteded to be used across different threads
0109     CMS_SA_ALLOW mutable std::shared_ptr<BranchMapReader> branchMap_;
0110     CMS_SA_ALLOW mutable KeyToDataMap data_;
0111     CMS_SA_ALLOW mutable std::vector<char const*> labels_;
0112     const edm::ProcessHistory& history() const;
0113 
0114     CMS_SA_ALLOW mutable std::map<std::pair<edm::ProductID, edm::BranchListIndex>, std::shared_ptr<internal::Data>>
0115         idToData_;
0116     CMS_SA_ALLOW mutable std::map<edm::BranchID, std::shared_ptr<internal::Data>> bidToData_;
0117     edm::propagate_const<std::shared_ptr<fwlite::HistoryGetterBase>> historyGetter_;
0118     std::shared_ptr<edm::EDProductGetter const> getter_;
0119     CMS_SA_ALLOW mutable bool tcTrained_;
0120     /// Use internal TTreeCache.
0121     const bool tcUse_;
0122     /// Branch-access-function gets called whenever a branch data is accessed.
0123     /// This can be used for management of TTreeCache on the user side.
0124     std::function<void(TBranch const&)> branchAccessFunc_;
0125   };
0126 
0127 }  // namespace fwlite
0128 
0129 #endif