//////////////////////////////////////////////////////////////////////// /// \class RAT::DS::ClassifierResult /// /// \brief Container class for classification values /// /// \author Phil G Jones /// \author Matthew Mottram -- contact person /// /// REVISION HISTORY:\n /// 27/04/2012 : P G Jones - New file \n /// 2014-02-27 : P G Jones - refactor in line with the dsreview \n /// /// \details This class contains the classification values. /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// \class RAT::DS::ClassifierResult::NoClassifierResultError /// /// \brief An exception that is thrown when a user atempts to retrieve /// a classifier result that does not exist. /// /// \author Phil G Jones /// /// REVISION HISTORY:\n /// 29/05/2012 : P G Jones - New file \n /// 2014-02-27 : P G Jones - Inherit from DataNotFound \n /// /// \details This error is thrown when a classifier has not been executed or /// if the classifier fails /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// \class RAT::DS::ClassifierResult::NoClassificationError /// /// \brief An exception that is thrown when a user atempts to retrieve /// a classification that does not exist /// /// \author Phil G Jones /// /// REVISION HISTORY:\n /// 27/04/2012 : P G Jones - New file \n /// 2014-02-27 : P G Jones - Inherit from DataNotFound \n /// /// \details As brief /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_DS_ClassifierResult__ #define __RAT_DS_ClassifierResult__ #include #include #include #include #include #include namespace RAT { namespace DS { class ClassifierResult : public TObject { public: class NoClassifierResultError : public DataNotFound { public: /// Construct the error naming the variable that is problematic /// /// @param[in] className of class the variable is a member of /// @param[in] fieldName of the variable NoClassifierResultError( const std::string className, const std::string fieldName ) : DataNotFound(className, fieldName) { } }; class NoClassificationError : public DataNotFound { public: /// Construct the error naming the variable that is problematic /// /// @param[in] className of class the variable is a member of /// @param[in] fieldName of the variable NoClassificationError( const std::string className, const std::string fieldName ) : DataNotFound(className, fieldName) { } }; /// Constructs the classifier result ClassifierResult() : TObject(), executionTime(0.0), valid(false) { Reset(); } /// Reset this classifier result of data inline void Reset(); /// Set a classification by name /// /// @param[in] name of the classification /// @param[in] value of the classification void SetClassification( const std::string& name, const Double_t value ) { classifications[name] = value; }; /// Returns the Classification by name /// /// @param[in] name of the classification /// @return value of the classification /// @throws NoClassificationError if the no classification exists for the name inline Double_t GetClassification( const std::string& name ) const; /// Get the classification names /// /// @return list of classification names std::vector GetClassificationNames() const { return keys_in_map( classifications ); } /// Set the Classifier as Valid(true)/Invalid(false) /// /// @param[in] valid_ validity of the classifier void SetValid( const Bool_t valid_ ) { valid = valid_; } /// Returns classifier validity /// /// @return true if the classifier is valid Bool_t GetValid() const { return valid; } /// Sets the execution time /// /// @param[in] time of execution in seconds void SetExecutionTime( const Double_t time ) { executionTime = time; } /// Returns the execution time /// /// @return the execution time in seconds Double_t GetExecutionTime() const { return executionTime; } /// Set a figure of merit for the name /// /// @param[in] name of the fom /// @param[in] value of the fom void SetFOM( const std::string& name, const Double_t value ) { foms[name] = value; }; /// Returns the FOM for that named name /// /// @param[in] name of the fom /// @return value of the fom /// @throws out_of_range if there is no fom with the name Double_t GetFOM( const std::string& name ) const { return foms.at(name); }; /// Get the Figure of Merit names /// /// @return list of FOM names std::vector GetFOMNames() const { return keys_in_map( foms ); } // This ROOT macro adds dictionary methods to this class. // The number should be incremented whenever this class's members are changed. // It assumes this class has no virtual methods, use ClassDef if change this. ClassDefNV( ClassifierResult, 3 ); private: std::map classifications; ///< Map between classification name and value std::map foms; ///< Figure of merit mapping Double32_t executionTime; ///< Returns classifier execution time, for comparisons Bool_t valid; ///< Is the classifier valid }; inline void ClassifierResult::Reset() { classifications.clear(); foms.clear(); executionTime = 0.0; valid = false; } inline Double_t ClassifierResult::GetClassification( const std::string& name ) const { if( classifications.count( name ) == 0 ) throw NoClassificationError( "ClassifierResult", name ); return classifications.at( name ); } } //::DS } //::RAT #endif