10 #ifndef INCLUDE_GUARD_BELLE2_MVA_WEIGHTFILE_HEADER 
   11 #define INCLUDE_GUARD_BELLE2_MVA_WEIGHTFILE_HEADER 
   13 #include <mva/interface/Options.h> 
   15 #include <framework/database/IntervalOfValidity.h> 
   16 #include <framework/dataobjects/EventMetaData.h> 
   18 #include <boost/property_tree/ptree.hpp> 
   32     std::string makeSaveForDatabase(std::string str);
 
   99       void addFile(
const std::string& identifier, 
const std::string& custom_weightfile);
 
  106       void addStream(
const std::string& identifier, std::istream& in);
 
  114       void addElement(
const std::string& identifier, 
const T& element)
 
  116         m_pt.put(identifier, element);
 
  125       void addVector(
const std::string& identifier, 
const std::vector<T>& vector)
 
  127         m_pt.put(identifier + 
"_size", vector.size());
 
  128         for (
unsigned int i = 0; i < vector.size(); ++i) {
 
  129           m_pt.put(identifier + std::to_string(i), vector[i]);
 
  138       void getFile(
const std::string& identifier, 
const std::string& custom_weightfile);
 
  144       std::string 
getStream(
const std::string& identifier) 
const;
 
  153         return m_pt.get<T>(identifier);
 
  162         return m_pt.count(identifier) > 0;
 
  171       T 
getElement(
const std::string& identifier, 
const T& default_value)
 const 
  173         return m_pt.get<T>(identifier, default_value);
 
  181       std::vector<T> 
getVector(
const std::string& identifier)
 const 
  183         std::vector<T> vector;
 
  184         vector.resize(
m_pt.get<
size_t>(identifier + 
"_size"));
 
  185         for (
unsigned int i = 0; i < vector.size(); ++i) {
 
  186           vector[i] = 
m_pt.get<T>(identifier + std::to_string(i));
 
  197       static void save(
Weightfile& weightfile, 
const std::string& filename,
 
  267       static void saveArrayToDatabase(
const std::vector<Weightfile>& weightfiles, 
const std::string& identifier,
 
  295       boost::property_tree::ptree 
m_pt; 
 
A class that describes the interval of experiments/runs for which an object in the database is valid.
Abstract base class of all Options given to the MVA interface.
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 addStream(const std::string &identifier, std::istream &in)
Add a stream to our weightfile.
void addElement(const std::string &identifier, const T &element)
Add an element to the xml tree.
Weightfile()
Construct an empty weightfile.
T getElement(const std::string &identifier) const
Returns a stored element from the xml 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.
std::map< std::string, float > getFeatureImportance() const
Get feature importance.
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from 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.
~Weightfile()
Destructor (removes temporary files associated with this weightfiles)
void setRemoveTemporaryDirectories(bool remove_temporary_directories)
Set the deletion behaviour of the weightfile object for temporary directories For debugging it can be...
bool m_remove_temporary_directories
remove all temporary directories in the destructor of this class
static void saveToXMLFile(Weightfile &weightfile, const std::string &filename)
Static function which saves a Weightfile to a XML file.
static Weightfile loadFromStream(std::istream &stream)
Static function which deserializes a Weightfile from a stream.
bool containsElement(const std::string &identifier) const
Returns true if given element is stored in the property tree.
const boost::property_tree::ptree & getXMLTree() const
Get xml tree.
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
void addOptions(const Options &options)
Add an Option object to the xml tree.
static Weightfile loadFromROOTFile(const std::string &filename)
Static function which loads a Weightfile from a ROOT file.
std::vector< T > getVector(const std::string &identifier) const
Returns a stored vector from the xml tree.
void getOptions(Options &options) const
Fills an Option object from 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 from the database.
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.
static void saveToStream(Weightfile &weightfile, std::ostream &stream)
Static function which serializes a Weightfile to a stream.
static Weightfile loadFromFile(const std::string &filename)
Static function which loads a Weightfile from a file.
void addSignalFraction(float signal_fraction)
Saves the signal fraction in the xml tree.
std::vector< std::string > m_filenames
generated temporary filenames, which will be removed in the destructor of this class
void addFeatureImportance(const std::map< std::string, float > &importance)
Add variable importance.
static void saveToROOTFile(Weightfile &weightfile, const std::string &filename)
Static function which saves a Weightfile to a ROOT file.
void addVector(const std::string &identifier, const std::vector< T > &vector)
Add a vector to the xml tree.
T getElement(const std::string &identifier, const T &default_value) const
Returns a stored element from the xml tree.
float getSignalFraction() const
Loads the signal fraction frm the xml tree.
static void saveArrayToDatabase(const 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.
std::string generateFileName(const std::string &suffix="")
Returns a temporary filename with the given suffix.
std::string getStream(const std::string &identifier) const
Returns the content of a stored stream as string.
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.
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)
Abstract base class for different kinds of events.