Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:31:58

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 namespace RDF {
0019 namespace Experimental {
0020 class RMetaData;
0021 }
0022 } // namespace RDF
0023 
0024 namespace Internal {
0025 namespace RDF {
0026 // To avoid unnecessary dependence on nlohman json in the interface. Note that
0027 // we should not forward declare nlohmann::json directly, since its declaration
0028 // might change (it is currently a typedef). With this wrapper type, we are
0029 // completely decoupled on nlohmann::json in the RMetaData interface.
0030 void ImportJSON(ROOT::RDF::Experimental::RMetaData &metadata, const std::string &jsonString);
0031 std::string ExportJSON(ROOT::RDF::Experimental::RMetaData &metadata);
0032 struct RMetaDataJson;
0033 }
0034 }
0035 
0036 namespace RDF {
0037 namespace Experimental {
0038 
0039 /**
0040 \class ROOT::RDF::Experimental::RMetaData
0041 \ingroup dataframe
0042 \brief Class behaving as a heterogenuous dictionary to store the metadata of a dataset.
0043 
0044  The supported types of the metadata are: std::string, int and double. An example of creating the RMetaData object:
0045  ~~~{.cpp}
0046  ROOT::RDF::Experimental::RMetaData meta;
0047  meta.Add("sample_name", "name"");
0048  meta.Add("luminosity", 10064);
0049  meta.Add("xsecs", 1.0);
0050  ~~~
0051 
0052  The RMetaData object is passed to an RSample object which represents a single dataset sample.
0053 
0054  A dataframe built with the RMetaData object can be accessed with the \ref ROOT::RDF::RInterface< Proxied,
0055 DS_t>::DefinePerSample "DefinePerSample()" method.
0056 **/
0057 class RMetaData {
0058    friend void ROOT::Internal::RDF::ImportJSON(ROOT::RDF::Experimental::RMetaData &, const std::string &jsonString);
0059    friend std::string ROOT::Internal::RDF::ExportJSON(ROOT::RDF::Experimental::RMetaData &);
0060 
0061 public:
0062 
0063    RMetaData();
0064    // Note: each RMetaData instance should own its own fJson object, just as if
0065    // the underlying nlohmann::json object would be owned by value.
0066    RMetaData(RMetaData const&);
0067    RMetaData(RMetaData &&);
0068    RMetaData & operator=(RMetaData const&);
0069    RMetaData & operator=(RMetaData &&);
0070    ~RMetaData();
0071 
0072    void Add(const std::string &key, int val);
0073    void Add(const std::string &key, double val);
0074    void Add(const std::string &key, const std::string &val);
0075 
0076    std::string Dump(const std::string &key) const; // always returns a string
0077    int GetI(const std::string &key) const;
0078    double GetD(const std::string &key) const;
0079    std::string GetS(const std::string &key) const;
0080    int GetI(const std::string &key, int defaultVal) const;
0081    double GetD(const std::string &key, double defaultVal) const;
0082    const std::string GetS(const std::string &key, const std::string &defaultVal) const;
0083 
0084 private:
0085    std::unique_ptr<Internal::RDF::RMetaDataJson> fJson;
0086 };
0087 
0088 } // namespace Experimental
0089 } // namespace RDF
0090 } // namespace ROOT
0091 
0092 #endif // ROOT_RDF_RMETADATA