Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:35

0001 // Author: Ivan Kabadzhov CERN  10/2022
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT_RDF_RMETADATA
0012 #define ROOT_RDF_RMETADATA
0013 
0014 #include <string>
0015 #include <memory>
0016 
0017 namespace ROOT {
0018 
0019 namespace Internal {
0020 namespace RDF {
0021 // To avoid unnecessary dependence on nlohman json in the interface. Note that
0022 // we should not forward declare nlohmann::json directly, since its declaration
0023 // might change (it is currently a typedef). With this wrapper type, we are
0024 // completely decoupled on nlohmann::json in the RMetaData interface.
0025 struct RMetaDataJson;
0026 }
0027 }
0028 
0029 namespace RDF {
0030 namespace Experimental {
0031 
0032 /**
0033 \class ROOT::RDF::Experimental::RMetaData
0034 \ingroup dataframe
0035 \brief Class behaving as a heterogenuous dictionary to store the metadata of a dataset.
0036 
0037  The supported types of the metadata are: std::string, int and double. An example of creating the RMetaData object:
0038  ~~~{.cpp}
0039  ROOT::RDF::Experimental::RMetaData meta;
0040  meta.Add("sample_name", "name"");
0041  meta.Add("luminosity", 10064);
0042  meta.Add("xsecs", 1.0);
0043  ~~~
0044 
0045  The RMetaData object is passed to an RSample object which represents a single dataset sample.
0046 
0047  A dataframe built with the RMetaData object can be accessed with the \ref ROOT::RDF::RInterface< Proxied,
0048 DS_t>::DefinePerSample "DefinePerSample()" method.
0049 **/
0050 class RMetaData {
0051 public:
0052 
0053    RMetaData();
0054    // Note: each RMetaData instance should own its own fJson object, just as if
0055    // the underlying nlohmann::json object would be owned by value.
0056    RMetaData(RMetaData const&);
0057    RMetaData(RMetaData &&);
0058    RMetaData & operator=(RMetaData const&);
0059    RMetaData & operator=(RMetaData &&);
0060    ~RMetaData();
0061 
0062    void Add(const std::string &key, int val);
0063    void Add(const std::string &key, double val);
0064    void Add(const std::string &key, const std::string &val);
0065 
0066    std::string Dump(const std::string &key) const; // always returns a string
0067    int GetI(const std::string &key) const;
0068    double GetD(const std::string &key) const;
0069    std::string GetS(const std::string &key) const;
0070    int GetI(const std::string &key, int defaultVal) const;
0071    double GetD(const std::string &key, double defaultVal) const;
0072    const std::string GetS(const std::string &key, const std::string &defaultVal) const;
0073 
0074 private:
0075    std::unique_ptr<Internal::RDF::RMetaDataJson> fJson;
0076 };
0077 
0078 } // namespace Experimental
0079 } // namespace RDF
0080 } // namespace ROOT
0081 
0082 #endif // ROOT_RDF_RMETADATA