CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/PhysicsTools/MVAComputer/interface/Variable.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_MVAComputer_Variable_h
00002 #define PhysicsTools_MVAComputer_Variable_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     MVAComputer
00006 // Class  :     Variable
00007 //
00008 
00009 //
00010 // Author:      Christophe Saout <christophe.saout@cern.ch>
00011 // Created:     Sat Apr 24 15:18 CEST 2007
00012 // $Id: Variable.h,v 1.8 2009/03/27 14:33:38 saout Exp $
00013 //
00014 
00015 #include <vector>
00016 #include <string>
00017 
00018 #include "PhysicsTools/MVAComputer/interface/AtomicId.h"
00019 
00020 namespace PhysicsTools {
00021 
00034 class Variable {
00035     public:
00036         enum Flags {
00037                 FLAG_NONE       = 0,
00038                 FLAG_OPTIONAL   = 1 << 0,
00039                 FLAG_MULTIPLE   = 1 << 1,
00040                 FLAG_ALL        = (1 << 2) - 1
00041         };
00042 
00052         class Value {
00053             public:
00054                 inline Value() {}
00055                 inline Value(const Value &orig) :
00056                         name(orig.name), value(orig.value) {}
00057                 inline Value(AtomicId name, double value) :
00058                         name(name), value(value) {}
00059 
00060                 inline Value &operator = (const Value &orig)
00061                 { name = orig.name; value = orig.value; return *this; }
00062 
00063                 inline void setName(AtomicId name) { this->name = name; }
00064                 inline void setValue(double value) { this->value = value; }
00065 
00066                 inline AtomicId getName() const { return name; }
00067                 inline double getValue() const { return value; }
00068 
00069             private:
00070                 AtomicId        name;
00071                 double          value;
00072         };
00073 
00082         class ValueList {
00083             public:
00084                 typedef std::vector<Value>      _Data;
00085                 typedef _Data::value_type       value_type;
00086                 typedef _Data::pointer          pointer;
00087                 typedef _Data::const_pointer    const_pointer;
00088                 typedef _Data::reference        reference;
00089                 typedef _Data::const_reference  const_reference;
00090                 typedef _Data::iterator         iterator;
00091                 typedef _Data::const_iterator   const_iterator;
00092                 typedef _Data::size_type        size_type;
00093                 typedef _Data::difference_type  difference_type;
00094                 typedef _Data::allocator_type   allocator_type;
00095 
00096                 inline ValueList() {}
00097                 inline ValueList(const ValueList &orig) : data_(orig.data_) {}
00098                 inline ValueList(const _Data &orig) : data_(orig) {}
00099                 inline ~ValueList() {}
00100 
00101                 inline ValueList &operator = (const ValueList &orig)
00102                 { data_ = orig.data_; return *this; }
00103 
00104                 inline void clear()
00105                 { data_.clear(); }
00106 
00107                 inline void add(AtomicId id, double value)
00108                 { data_.push_back(Value(id, value)); }
00109 
00110                 inline void add(const Value &value)
00111                 { data_.push_back(value); }
00112 
00113                 inline size_type size() const { return data_.size(); }
00114                 bool empty() const { return data_.empty(); }
00115 
00116                 inline const_iterator begin() const { return data_.begin(); }
00117                 iterator begin() { return data_.begin(); }
00118 
00119                 inline const_iterator end() const { return data_.end(); }
00120                 iterator end() { return data_.end(); }
00121 
00122                 inline const _Data &values() const { return data_; }
00123                 _Data &values() { return data_; }
00124 
00125                 inline const_reference front() const { return *data_.begin(); }
00126                 reference front() { return *data_.begin(); }
00127 
00128                 inline const_reference back() const { return *data_.rbegin(); }
00129                 reference back() { return *data_.rbegin(); }
00130 
00131                 inline const_pointer data() const { return &front(); }
00132                 pointer data() { return &front(); }
00133 
00134             private:
00135                 std::vector<Value>      data_;
00136         };
00137 
00138         inline Variable() {}
00139         inline Variable(const Variable &orig) :
00140                 name(orig.name), flags(orig.flags) {}
00141         inline Variable(AtomicId name, Flags flags = FLAG_NONE) :
00142                 name(name), flags(flags) {}
00143 
00144         const AtomicId getName() const { return name; }
00145         Flags getFlags() const { return flags;}
00146 
00147         bool isOptional() const { return flags & FLAG_OPTIONAL; }
00148         bool isMultiple() const { return flags & FLAG_MULTIPLE; }
00149 
00150     private:
00151         AtomicId        name;
00152         Flags           flags;
00153 };
00154 
00155 } // namespace PhysicsTools
00156 
00157 #endif // PhysicsTools_MVAComputer_Variable_h