 |
Belle II Software
release-05-02-19
|
12 #ifndef INCLUDE_GUARD_BELLE2_MVA_WEIGHTFILE_HEADER
13 #define INCLUDE_GUARD_BELLE2_MVA_WEIGHTFILE_HEADER
15 #include <mva/interface/Options.h>
17 #include <framework/database/IntervalOfValidity.h>
18 #include <framework/dataobjects/EventMetaData.h>
20 #include <boost/property_tree/ptree.hpp>
34 std::string makeSaveForDatabase(std::string str);
101 void addFile(
const std::string& identifier,
const std::string& custom_weightfile);
108 void addStream(
const std::string& identifier, std::istream& in);
116 void addElement(
const std::string& identifier,
const T& element)
118 m_pt.put(identifier, element);
127 void addVector(
const std::string& identifier,
const std::vector<T>& vector)
129 m_pt.put(identifier +
"_size", vector.size());
130 for (
unsigned int i = 0; i < vector.size(); ++i) {
131 m_pt.put(identifier + std::to_string(i), vector[i]);
140 void getFile(
const std::string& identifier,
const std::string& custom_weightfile);
146 std::string
getStream(
const std::string& identifier)
const;
155 return m_pt.get<T>(identifier);
164 return m_pt.count(identifier) > 0;
172 T
getElement(
const std::string& identifier,
const T& default_value)
const
174 return m_pt.get<T>(identifier, default_value);
182 std::vector<T>
getVector(
const std::string& identifier)
const
184 std::vector<T> vector;
185 vector.resize(
m_pt.get<T>(identifier +
"_size"));
186 for (
unsigned int i = 0; i < vector.size(); ++i) {
187 vector[i] =
m_pt.get<T>(identifier + std::to_string(i));
197 static void save(
Weightfile& weightfile,
const std::string& filename,
266 static void saveArrayToDatabase(std::vector<Weightfile>& weightfiles,
const std::string& identifier,
294 boost::property_tree::ptree
m_pt;
A class that describes the interval of experiments/runs for which an object in the database is valid.
std::vector< T > getVector(const std::string &identifier) const
Returns a stored vector from the xml tree.
void addSignalFraction(float signal_fraction)
Saves the signal fraction in the xml tree.
void getOptions(Options &options) const
Fills an Option object from the xml tree.
static void saveToDatabase(Weightfile &weightfile, const std::string &identifier, const Belle2::IntervalOfValidity &iov=Belle2::IntervalOfValidity(0, 0, -1, -1))
Static function which saves a Weightfile in the basf2 condition database.
boost::property_tree::ptree m_pt
xml tree containing all the saved information of this weightfile
void setTemporaryDirectory(const std::string &temporary_directory)
set temporary directory which is used to store temporary directories
bool containsElement(const std::string &identifier) const
Returns true if given element is stored in the property tree.
void addFile(const std::string &identifier, const std::string &custom_weightfile)
Add a file (mostly a weightfile from a MVA library) to our Weightfile.
The Weightfile class serializes all information about a training into an xml tree.
std::string m_temporary_directory
temporary directory which is used to store temporary directories
void addFeatureImportance(const std::map< std::string, float > &importance)
Add variable importance.
void addVector(const std::string &identifier, const std::vector< T > &vector)
Add a vector to the xml tree.
bool m_remove_temporary_directories
remove all temporary directories in the destructor of this class
void addStream(const std::string &identifier, std::istream &in)
Add a stream to our weightfile.
T getElement(const std::string &identifier) const
Returns a stored element from the xml tree.
const boost::property_tree::ptree & getXMLTree() const
Get xml tree.
std::string getStream(const std::string &identifier) const
Returns the content of a stored stream as string.
static Weightfile loadFromROOTFile(const std::string &filename)
Static function which loads a Weightfile from a ROOT file.
T getElement(const std::string &identifier, const T &default_value) const
Returns a stored element from the xml tree.
Abstract base class of all Options given to the MVA interface.
float getSignalFraction() const
Loads the signal fraction frm the xml tree.
static Weightfile load(const std::string &filename, const Belle2::EventMetaData &emd=Belle2::EventMetaData(0, 0, 0))
Static function which loads a Weightfile from a file or fomr the database.
Abstract base class for different kinds of events.
void addOptions(const Options &options)
Add an Option object to the xml tree.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from a XML file.
std::vector< std::string > m_filenames
generated temporary filenames, which will be removed in the destructor of this class
static void saveToStream(Weightfile &weightfile, std::ostream &stream)
Static function which serializes a Weightfile to a stream.
Weightfile()
Construct an empty weightfile.
void getFile(const std::string &identifier, const std::string &custom_weightfile)
Creates a file from our weightfile (mostly this will be a weightfile of an MVA library)
static void saveToXMLFile(Weightfile &weightfile, const std::string &filename)
Static function which saves a Weightfile to a XML file.
static void save(Weightfile &weightfile, const std::string &filename, const Belle2::IntervalOfValidity &iov=Belle2::IntervalOfValidity(0, 0, -1, -1))
Static function which saves a Weightfile to a file.
void addElement(const std::string &identifier, const T &element)
Add an element to the xml tree.
static Weightfile loadFromDatabase(const std::string &identifier, const Belle2::EventMetaData &emd=Belle2::EventMetaData(0, 0, 0))
Static function which loads a Weightfile from the basf2 condition database.
std::map< std::string, float > getFeatureImportance() const
Get feature importance.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
std::string generateFileName(const std::string &suffix="")
Returns a temporary filename with the given suffix.
void setRemoveTemporaryDirectories(bool remove_temporary_directories)
Set the deletion behaviour of the weightfile object for temporary directories For debugging it can be...
static void saveToROOTFile(Weightfile &weightfile, const std::string &filename)
Static function which saves a Weightfile to a ROOT file.
~Weightfile()
Destructor (removes temporary files associated with this weightfiles)
static void saveArrayToDatabase(std::vector< Weightfile > &weightfiles, const std::string &identifier, const Belle2::IntervalOfValidity &iov=Belle2::IntervalOfValidity(0, 0, -1, -1))
Static function which saves an array of Weightfile objects in the basf2 condition database.