Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:09

0001 #ifndef PODIO_UTILITIES_ROOTHELPERS_H
0002 #define PODIO_UTILITIES_ROOTHELPERS_H
0003 
0004 #include "podio/GenericParameters.h"
0005 
0006 #include "ROOT/RVec.hxx"
0007 #include "TBranch.h"
0008 
0009 #include <string>
0010 #include <tuple>
0011 #include <vector>
0012 
0013 namespace podio {
0014 class CollectionBase;
0015 
0016 namespace root_utils {
0017 
0018   // A collection of additional information that describes the collection: the
0019   // collectionID, the collection (data) type, whether it is a subset
0020   // collection, and its schema version
0021   using CollectionWriteInfoT = std::tuple<uint32_t, std::string, bool, unsigned int>;
0022   // for backwards compatibility
0023   using CollectionInfoWithoutSchemaT = std::tuple<int, std::string, bool>;
0024 
0025   /// A collection name and a base pointer grouped together for writing
0026   using StoreCollection = std::tuple<const std::string&, podio::CollectionBase*>;
0027 
0028   /// Small helper struct to collect all branches that are necessary to read or
0029   /// write a collection. Needed to cache the branch pointers and avoid having to
0030   /// get them from a TTree/TChain for every event.
0031   struct CollectionBranches {
0032     CollectionBranches() = default;
0033     ~CollectionBranches() = default;
0034     CollectionBranches(const CollectionBranches&) = delete;
0035     CollectionBranches& operator=(const CollectionBranches&) = delete;
0036     CollectionBranches(CollectionBranches&&) = default;
0037     CollectionBranches& operator=(CollectionBranches&&) = default;
0038 
0039     CollectionBranches(TBranch* dataBranch) : data(dataBranch) {
0040     }
0041 
0042     TBranch* data{nullptr};
0043     std::vector<TBranch*> refs{};
0044     std::vector<TBranch*> vecs{};
0045     std::vector<std::string> refNames{}; ///< The names of the relation branches
0046     std::vector<std::string> vecNames{}; ///< The names of the vector member branches
0047   };
0048 
0049   /// Pair of keys and values for one type of the ones that can be stored in
0050   /// GenericParameters
0051   template <typename T>
0052   struct ParamStorage {
0053     ParamStorage() = default;
0054     ~ParamStorage() = default;
0055     ParamStorage(const ParamStorage&) = delete;
0056     ParamStorage& operator=(const ParamStorage&) = delete;
0057     ParamStorage(ParamStorage&&) = default;
0058     ParamStorage& operator=(ParamStorage&&) = default;
0059 
0060     ParamStorage(std::tuple<std::vector<std::string>, std::vector<std::vector<T>>> keysValues) :
0061         keys(std::move(std::get<0>(keysValues))), values(std::move(std::get<1>(keysValues))) {
0062     }
0063 
0064     /// Get a pointer to the stored keys for binding it to a TBranch
0065     auto keysPtr() {
0066       m_keysPtr = &keys;
0067       return &m_keysPtr;
0068     }
0069 
0070     /// Get a pointer to the stored vectors for binding it to a TBranch
0071     auto valuesPtr() {
0072       m_valuesPtr = &values;
0073       return &m_valuesPtr;
0074     }
0075 
0076     std::vector<std::string> keys{};      ///< The keys for this type
0077     std::vector<std::vector<T>> values{}; ///< The values for this type
0078 
0079   private:
0080     std::vector<std::string>* m_keysPtr{nullptr};
0081     std::vector<std::vector<T>>* m_valuesPtr{nullptr};
0082   };
0083 
0084   GenericParameters
0085   loadParamsFrom(ROOT::VecOps::RVec<std::string> intKeys, ROOT::VecOps::RVec<std::vector<int>> intValues,
0086                  ROOT::VecOps::RVec<std::string> floatKeys, ROOT::VecOps::RVec<std::vector<float>> floatValues,
0087                  ROOT::VecOps::RVec<std::string> doubleKeys, ROOT::VecOps::RVec<std::vector<double>> doubleValues,
0088                  ROOT::VecOps::RVec<std::string> stringKeys, ROOT::VecOps::RVec<std::vector<std::string>> stringValues);
0089 
0090 } // namespace root_utils
0091 } // namespace podio
0092 
0093 #endif // PODIO_UTILITIES_ROOTHELPERS_H