Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-18 10:42:34

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