CMS 3D CMS Logo

Variable.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVAComputer_Variable_h
2 #define PhysicsTools_MVAComputer_Variable_h
3 // -*- C++ -*-
4 //
5 // Package: MVAComputer
6 // Class : Variable
7 //
8 
9 //
10 // Author: Christophe Saout <christophe.saout@cern.ch>
11 // Created: Sat Apr 24 15:18 CEST 2007
12 //
13 
14 #include <vector>
15 #include <string>
16 
18 
19 namespace PhysicsTools {
20 
33  class Variable {
34  public:
35  enum Flags { FLAG_NONE = 0, FLAG_OPTIONAL = 1 << 0, FLAG_MULTIPLE = 1 << 1, FLAG_ALL = (1 << 2) - 1 };
36 
46  class Value {
47  public:
48  inline Value() {}
49  inline Value(const Value &orig) : name(orig.name), value(orig.value) {}
50  inline Value(AtomicId name, double value) : name(name), value(value) {}
51 
52  inline Value &operator=(const Value &orig) {
53  name = orig.name;
54  value = orig.value;
55  return *this;
56  }
57 
58  inline void setName(AtomicId name) { this->name = name; }
59  inline void setValue(double value) { this->value = value; }
60 
61  inline AtomicId getName() const { return name; }
62  inline double getValue() const { return value; }
63 
64  private:
66  double value;
67  };
68 
77  class ValueList {
78  public:
79  typedef std::vector<Value> _Data;
81  typedef _Data::pointer pointer;
82  typedef _Data::const_pointer const_pointer;
84  typedef _Data::const_reference const_reference;
85  typedef _Data::iterator iterator;
86  typedef _Data::const_iterator const_iterator;
88  typedef _Data::difference_type difference_type;
89  typedef _Data::allocator_type allocator_type;
90 
91  inline ValueList() {}
92  inline ValueList(const ValueList &orig) : data_(orig.data_) {}
93  inline ValueList(const _Data &orig) : data_(orig) {}
94  inline ~ValueList() {}
95 
96  inline ValueList &operator=(const ValueList &orig) {
97  data_ = orig.data_;
98  return *this;
99  }
100 
101  inline void clear() { data_.clear(); }
102 
103  inline void add(AtomicId id, double value) { data_.push_back(Value(id, value)); }
104 
105  inline void add(const Value &value) { data_.push_back(value); }
106 
107  inline size_type size() const { return data_.size(); }
108  bool empty() const { return data_.empty(); }
109 
110  inline const_iterator begin() const { return data_.begin(); }
111  iterator begin() { return data_.begin(); }
112 
113  inline const_iterator end() const { return data_.end(); }
114  iterator end() { return data_.end(); }
115 
116  inline const _Data &values() const { return data_; }
117  _Data &values() { return data_; }
118 
119  inline const_reference front() const { return *data_.begin(); }
120  reference front() { return *data_.begin(); }
121 
122  inline const_reference back() const { return *data_.rbegin(); }
123  reference back() { return *data_.rbegin(); }
124 
125  inline const_pointer data() const { return &front(); }
126  pointer data() { return &front(); }
127 
128  private:
129  std::vector<Value> data_;
130  };
131 
132  inline Variable() {}
133  inline Variable(const Variable &orig) : name(orig.name), flags(orig.flags) {}
134  inline Variable(AtomicId name, Flags flags = FLAG_NONE) : name(name), flags(flags) {}
135 
136  const AtomicId getName() const { return name; }
137  Flags getFlags() const { return flags; }
138 
139  bool isOptional() const { return flags & FLAG_OPTIONAL; }
140  bool isMultiple() const { return flags & FLAG_MULTIPLE; }
141 
142  private:
145  };
146 
147 } // namespace PhysicsTools
148 
149 #endif // PhysicsTools_MVAComputer_Variable_h
bool isOptional() const
Definition: Variable.h:139
bool isMultiple() const
Definition: Variable.h:140
double getValue() const
Definition: Variable.h:62
Class describing an input variable.
Definition: Variable.h:33
_Data::const_pointer const_pointer
Definition: Variable.h:82
void setName(AtomicId name)
Definition: Variable.h:58
_Data::size_type size_type
Definition: Variable.h:87
std::vector< Value > data_
Definition: Variable.h:129
const_iterator end() const
Definition: Variable.h:113
uint16_t size_type
const_iterator begin() const
Definition: Variable.h:110
ValueList & operator=(const ValueList &orig)
Definition: Variable.h:96
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
const AtomicId getName() const
Definition: Variable.h:136
Variable(AtomicId name, Flags flags=FLAG_NONE)
Definition: Variable.h:134
Flags getFlags() const
Definition: Variable.h:137
Value & operator=(const Value &orig)
Definition: Variable.h:52
Value(AtomicId name, double value)
Definition: Variable.h:50
void add(const Value &value)
Definition: Variable.h:105
const_pointer data() const
Definition: Variable.h:125
_Data::const_reference const_reference
Definition: Variable.h:84
Definition: value.py:1
std::vector< Value > _Data
Definition: Variable.h:79
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:77
Value(const Value &orig)
Definition: Variable.h:49
ValueList(const _Data &orig)
Definition: Variable.h:93
Helper class that can contain an identifier-value pair.
Definition: Variable.h:46
const_reference front() const
Definition: Variable.h:119
const _Data & values() const
Definition: Variable.h:116
const_reference back() const
Definition: Variable.h:122
_Data::allocator_type allocator_type
Definition: Variable.h:89
AtomicId getName() const
Definition: Variable.h:61
ValueList(const ValueList &orig)
Definition: Variable.h:92
_Data::const_iterator const_iterator
Definition: Variable.h:86
_Data::difference_type difference_type
Definition: Variable.h:88
void add(AtomicId id, double value)
Definition: Variable.h:103
_Data::reference reference
Definition: Variable.h:83
Variable(const Variable &orig)
Definition: Variable.h:133
_Data::value_type value_type
Definition: Variable.h:80
void setValue(double value)
Definition: Variable.h:59