Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:37

0001 #ifndef PhysicsTools_MVAComputer_Variable_h
0002 #define PhysicsTools_MVAComputer_Variable_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     MVAComputer
0006 // Class  :     Variable
0007 //
0008 
0009 //
0010 // Author:  Christophe Saout <christophe.saout@cern.ch>
0011 // Created:     Sat Apr 24 15:18 CEST 2007
0012 //
0013 
0014 #include <vector>
0015 #include <string>
0016 
0017 #include "PhysicsTools/MVAComputer/interface/AtomicId.h"
0018 
0019 namespace PhysicsTools {
0020 
0021   /** \class Variable
0022  *
0023  * \short Class describing an input variable.
0024  *
0025  * The class Variable describes an input variable by its name and properties.
0026  * The name is represented by an atomic identifier (an alphanumerical value).
0027  * The properties consists of flags. Currently the two flags describe
0028  * the allowed number of times a variable can appear in the input, whether
0029  * a variable is allowed to be omitted and whether a variable can have
0030  * multiple values.
0031  *
0032  ************************************************************/
0033   class Variable {
0034   public:
0035     enum Flags { FLAG_NONE = 0, FLAG_OPTIONAL = 1 << 0, FLAG_MULTIPLE = 1 << 1, FLAG_ALL = (1 << 2) - 1 };
0036 
0037     /** \class Value
0038      *
0039      * \short Helper class that can contain an identifier-value pair
0040      *
0041      * Variable::Value contains an instance of an input variable that
0042      * is identified by the atomic identifer of the variable and carries
0043      * an associated double value.
0044      *
0045      ************************************************************/
0046     class Value {
0047     public:
0048       inline Value() {}
0049       inline Value(const Value &orig) : name(orig.name), value(orig.value) {}
0050       inline Value(AtomicId name, double value) : name(name), value(value) {}
0051 
0052       inline Value &operator=(const Value &orig) {
0053         name = orig.name;
0054         value = orig.value;
0055         return *this;
0056       }
0057 
0058       inline void setName(AtomicId name) { this->name = name; }
0059       inline void setValue(double value) { this->value = value; }
0060 
0061       inline AtomicId getName() const { return name; }
0062       inline double getValue() const { return value; }
0063 
0064     private:
0065       AtomicId name;
0066       double value;
0067     };
0068 
0069     /** \class ValueList
0070      *
0071      * \short Helper class that can contain an list of identifier-value pairs
0072      *
0073      * Variable::ValueList contains a vector of Variable::Value with
0074      * additional convenience methods.
0075      *
0076      ************************************************************/
0077     class ValueList {
0078     public:
0079       typedef std::vector<Value> _Data;
0080       typedef _Data::value_type value_type;
0081       typedef _Data::pointer pointer;
0082       typedef _Data::const_pointer const_pointer;
0083       typedef _Data::reference reference;
0084       typedef _Data::const_reference const_reference;
0085       typedef _Data::iterator iterator;
0086       typedef _Data::const_iterator const_iterator;
0087       typedef _Data::size_type size_type;
0088       typedef _Data::difference_type difference_type;
0089       typedef _Data::allocator_type allocator_type;
0090 
0091       inline ValueList() {}
0092       inline ValueList(const ValueList &orig) : data_(orig.data_) {}
0093       inline ValueList(const _Data &orig) : data_(orig) {}
0094       inline ~ValueList() {}
0095 
0096       inline ValueList &operator=(const ValueList &orig) {
0097         data_ = orig.data_;
0098         return *this;
0099       }
0100 
0101       inline void clear() { data_.clear(); }
0102 
0103       inline void add(AtomicId id, double value) { data_.push_back(Value(id, value)); }
0104 
0105       inline void add(const Value &value) { data_.push_back(value); }
0106 
0107       inline size_type size() const { return data_.size(); }
0108       bool empty() const { return data_.empty(); }
0109 
0110       inline const_iterator begin() const { return data_.begin(); }
0111       iterator begin() { return data_.begin(); }
0112 
0113       inline const_iterator end() const { return data_.end(); }
0114       iterator end() { return data_.end(); }
0115 
0116       inline const _Data &values() const { return data_; }
0117       _Data &values() { return data_; }
0118 
0119       inline const_reference front() const { return *data_.begin(); }
0120       reference front() { return *data_.begin(); }
0121 
0122       inline const_reference back() const { return *data_.rbegin(); }
0123       reference back() { return *data_.rbegin(); }
0124 
0125       inline const_pointer data() const { return &front(); }
0126       pointer data() { return &front(); }
0127 
0128     private:
0129       std::vector<Value> data_;
0130     };
0131 
0132     inline Variable() {}
0133     inline Variable(const Variable &orig) : name(orig.name), flags(orig.flags) {}
0134     inline Variable(AtomicId name, Flags flags = FLAG_NONE) : name(name), flags(flags) {}
0135     Variable &operator=(const Variable &other) = default;
0136 
0137     const AtomicId getName() const { return name; }
0138     Flags getFlags() const { return flags; }
0139 
0140     bool isOptional() const { return flags & FLAG_OPTIONAL; }
0141     bool isMultiple() const { return flags & FLAG_MULTIPLE; }
0142 
0143   private:
0144     AtomicId name;
0145     Flags flags;
0146   };
0147 
0148 }  // namespace PhysicsTools
0149 
0150 #endif  // PhysicsTools_MVAComputer_Variable_h