![]() |
Belle II Software light-2609-luna
|
The Weightfile class serializes all information about a training into an xml tree. More...
#include <Weightfile.h>

Public Member Functions | |
| Weightfile () | |
| Construct an empty weightfile. | |
| ~Weightfile () | |
| Destructor (removes temporary files associated with this weightfiles) | |
| void | addFeatureImportance (const std::map< std::string, float > &importance) |
| Add variable importance. | |
| std::map< std::string, float > | getFeatureImportance () const |
| Get feature importance. | |
| void | addOptions (const Options &options) |
| Add an Option object to the xml tree. | |
| void | getOptions (Options &options) const |
| Fills an Option object from the xml tree. | |
| void | addSignalFraction (float signal_fraction) |
| Saves the signal fraction in the xml tree. | |
| float | getSignalFraction () const |
| Loads the signal fraction frm the xml tree. | |
| std::string | generateFileName (const std::string &suffix="") |
| Returns a temporary filename with the given suffix. | |
| void | addFile (const std::string &identifier, const std::string &custom_weightfile) |
| Add a file (mostly a weightfile from a MVA library) to our Weightfile. | |
| void | addStream (const std::string &identifier, std::istream &in) |
| Add a stream to our weightfile. | |
| template<class T> | |
| void | addElement (const std::string &identifier, const T &element) |
| Add an element to the xml tree. | |
| template<class T> | |
| void | addVector (const std::string &identifier, const std::vector< T > &vector) |
| Add a vector to the xml tree. | |
| void | addContractVersion (int version) |
| Store the version of the contract between this weightfile and the code applying it. | |
| bool | hasContractVersion () const |
| Returns true if this weightfile records a contract version. | |
| int | getContractVersion (int default_value=-1) const |
| Returns the contract version of this weightfile, or the default value. | |
| 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) | |
| std::string | getStream (const std::string &identifier) const |
| Returns the content of a stored stream as string. | |
| template<class T> | |
| T | getElement (const std::string &identifier) const |
| Returns a stored element from the xml tree. | |
| bool | containsElement (const std::string &identifier) const |
| Returns true if given element is stored in the property tree. | |
| template<class T> | |
| T | getElement (const std::string &identifier, const T &default_value) const |
| Returns a stored element from the xml tree. | |
| template<class T> | |
| std::vector< T > | getVector (const std::string &identifier) const |
| Returns a stored vector from the xml tree. | |
| void | setRemoveTemporaryDirectories (bool remove_temporary_directories) |
| Set the deletion behaviour of the weightfile object for temporary directories For debugging it can be useful to not delete temporary directories. | |
| const boost::property_tree::ptree & | getXMLTree () const |
| Get xml tree. | |
Static Public Member Functions | |
| 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. | |
| static void | saveToROOTFile (Weightfile &weightfile, const std::string &filename) |
| Static function which saves a Weightfile to a ROOT file. | |
| static void | saveToXMLFile (Weightfile &weightfile, const std::string &filename) |
| Static function which saves a Weightfile to a XML file. | |
| static void | saveToStream (Weightfile &weightfile, std::ostream &stream) |
| Static function which serializes a Weightfile to a stream. | |
| 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 | loadFromFile (const std::string &filename) |
| Static function which loads a Weightfile from a file. | |
| static Weightfile | loadFromROOTFile (const std::string &filename) |
| Static function which loads a Weightfile from a ROOT file. | |
| static Weightfile | loadFromXMLFile (const std::string &filename) |
| Static function which loads a Weightfile from a XML file. | |
| static Weightfile | loadFromStream (std::istream &stream) |
| Static function which deserializes a Weightfile from a stream. | |
| 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. | |
| 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. | |
| 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. | |
Private Attributes | |
| boost::property_tree::ptree | m_pt |
| xml tree containing all the saved information of this weightfile | |
| std::vector< std::string > | m_filenames |
| generated temporary filenames, which will be removed in the destructor of this class | |
| bool | m_remove_temporary_directories = true |
| remove all temporary directories in the destructor of this class | |
Static Private Attributes | |
| static constexpr const char * | c_contractVersion = "contract_version" |
| identifier of the element holding the contract version, shared by all weightfiles | |
The Weightfile class serializes all information about a training into an xml tree.
It can save and load this information from: a stream, a file, the database
Definition at line 38 of file Weightfile.h.
|
inline |
| ~Weightfile | ( | ) |
Destructor (removes temporary files associated with this weightfiles)
Definition at line 51 of file Weightfile.cc.
|
inline |
Store the version of the contract between this weightfile and the code applying it.
The contract version says which code can use this weightfile: how the inputs are built and how the outputs are interpreted. It is bumped by hand whenever such a change makes earlier weightfiles unusable. The applying code has to decide whether it implements that version, provides an older code path for it, or refuses to run. It is therefore meant for weightfiles whose payload names carry no version, where the file itself has to say which code it fits.
| version | contract version of the code that created this weightfile |
Definition at line 144 of file Weightfile.h.
|
inline |
Add an element to the xml tree.
| identifier | identifier of the element |
| element | the value |
Definition at line 114 of file Weightfile.h.
| void addFeatureImportance | ( | const std::map< std::string, float > & | importance | ) |
Add variable importance.
| importance |
Definition at line 71 of file Weightfile.cc.
| void addFile | ( | const std::string & | identifier, |
| const std::string & | custom_weightfile ) |
Add a file (mostly a weightfile from a MVA library) to our Weightfile.
| identifier | of this weightfile |
| custom_weightfile | the filename |
Definition at line 114 of file Weightfile.cc.
| void addOptions | ( | const Options & | options | ) |
Add an Option object to the xml tree.
| options | to add |
Definition at line 61 of file Weightfile.cc.
| void addSignalFraction | ( | float | signal_fraction | ) |
Saves the signal fraction in the xml tree.
| signal_fraction |
Definition at line 94 of file Weightfile.cc.
| void addStream | ( | const std::string & | identifier, |
| std::istream & | in ) |
Add a stream to our weightfile.
| identifier | of the stream |
| in | the stream |
Definition at line 122 of file Weightfile.cc.
|
inline |
Add a vector to the xml tree.
| identifier | identifier of the vector |
| vector | the std::vector |
Definition at line 125 of file Weightfile.h.
|
inline |
Returns true if given element is stored in the property tree.
| identifier | of the stored element |
Definition at line 200 of file Weightfile.h.
| std::string generateFileName | ( | const std::string & | suffix = "" | ) |
Returns a temporary filename with the given suffix.
All temporary files are removed when the Weightfile class is destroyed
| suffix | of the temporary filename |
Definition at line 104 of file Weightfile.cc.
|
inline |
Returns the contract version of this weightfile, or the default value.
The default is returned if no contract version is stored, and also if the stored value is not an integer. Use hasContractVersion() to tell the two apart.
| default_value | returned if no usable contract version is stored |
Definition at line 167 of file Weightfile.h.
|
inline |
Returns a stored element from the xml tree.
| identifier | of the stored element |
Definition at line 191 of file Weightfile.h.
|
inline |
Returns a stored element from the xml tree.
| identifier | of the stored element |
| default_value | default value of the stored element |
Definition at line 211 of file Weightfile.h.
| std::map< std::string, float > getFeatureImportance | ( | ) | const |
Get feature importance.
Definition at line 82 of file Weightfile.cc.
| 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)
| identifier | of the file |
| custom_weightfile | the filename which is created |
Definition at line 137 of file Weightfile.cc.
| void getOptions | ( | Options & | options | ) | const |
Fills an Option object from the xml tree.
| options |
Definition at line 66 of file Weightfile.cc.
| float getSignalFraction | ( | ) | const |
Loads the signal fraction frm the xml tree.
Definition at line 99 of file Weightfile.cc.
| std::string getStream | ( | const std::string & | identifier | ) | const |
Returns the content of a stored stream as string.
| identifier | of the stored stream |
Definition at line 143 of file Weightfile.cc.
|
inline |
Returns a stored vector from the xml tree.
| identifier | of the stored std::vector |
Definition at line 221 of file Weightfile.h.
|
inline |
|
inline |
Returns true if this weightfile records a contract version.
False for weightfiles written before the contract version was introduced, which the applying code has to treat as the oldest version it knows.
Definition at line 155 of file Weightfile.h.
|
static |
Static function which loads a Weightfile from a file or from the database.
| filename | of the file containing our serialized Weightfile |
| emd | EventMetaData |
Definition at line 194 of file Weightfile.cc.
|
static |
Static function which loads a Weightfile from the basf2 condition database.
| identifier | in the database |
| emd | event meta data containing the current valid event which is checked against the interval of validity of the stored weightfiles. |
Definition at line 280 of file Weightfile.cc.
|
static |
Static function which loads a Weightfile from a file.
| filename | of the file containing our serialized Weightfile |
Definition at line 205 of file Weightfile.cc.
|
static |
Static function which loads a Weightfile from a ROOT file.
| filename | of the file containing our serialized Weightfile |
Definition at line 216 of file Weightfile.cc.
|
static |
Static function which deserializes a Weightfile from a stream.
| stream | containing our serialized Weightfile |
Definition at line 250 of file Weightfile.cc.
|
static |
Static function which loads a Weightfile from a XML file.
| filename | of the file containing our serialized Weightfile |
Definition at line 239 of file Weightfile.cc.
|
static |
Static function which saves a Weightfile to a file.
| weightfile | to store |
| filename | of the file or identifier of the database |
| iov | IntervalOfValidity of the Weightfile |
Definition at line 153 of file Weightfile.cc.
|
static |
Static function which saves an array of Weightfile objects in the basf2 condition database.
| weightfiles | vector of weightfiles to save |
| identifier | in the database |
| iov | interval of validity of this weightfile |
Definition at line 266 of file Weightfile.cc.
|
static |
Static function which saves a Weightfile in the basf2 condition database.
| weightfile | to save |
| identifier | in the database |
| iov | interval of validity of this weightfile |
Definition at line 257 of file Weightfile.cc.
|
static |
Static function which saves a Weightfile to a ROOT file.
| weightfile | to store |
| filename | of the file |
Definition at line 164 of file Weightfile.cc.
|
static |
Static function which serializes a Weightfile to a stream.
| weightfile | to serialize |
| stream |
Definition at line 184 of file Weightfile.cc.
|
static |
Static function which saves a Weightfile to a XML file.
| weightfile | to store |
| filename | of the file |
Definition at line 174 of file Weightfile.cc.
|
inline |
Set the deletion behaviour of the weightfile object for temporary directories For debugging it can be useful to not delete temporary directories.
Definition at line 322 of file Weightfile.h.
|
staticconstexprprivate |
identifier of the element holding the contract version, shared by all weightfiles
Definition at line 331 of file Weightfile.h.
|
private |
generated temporary filenames, which will be removed in the destructor of this class
Definition at line 334 of file Weightfile.h.
|
private |
xml tree containing all the saved information of this weightfile
Definition at line 333 of file Weightfile.h.
|
private |
remove all temporary directories in the destructor of this class
Definition at line 335 of file Weightfile.h.