CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
36  FLAG_NONE = 0,
37  FLAG_OPTIONAL = 1 << 0,
38  FLAG_MULTIPLE = 1 << 1,
39  FLAG_ALL = (1 << 2) - 1
40  };
41 
51  class Value {
52  public:
53  inline Value() {}
54  inline Value(const Value &orig) :
55  name(orig.name), value(orig.value) {}
56  inline Value(AtomicId name, double value) :
57  name(name), value(value) {}
58 
59  inline Value &operator = (const Value &orig)
60  { name = orig.name; value = orig.value; return *this; }
61 
62  inline void setName(AtomicId name) { this->name = name; }
63  inline void setValue(double value) { this->value = value; }
64 
65  inline AtomicId getName() const { return name; }
66  inline double getValue() const { return value; }
67 
68  private:
70  double value;
71  };
72 
81  class ValueList {
82  public:
83  typedef std::vector<Value> _Data;
85  typedef _Data::pointer pointer;
86  typedef _Data::const_pointer const_pointer;
88  typedef _Data::const_reference const_reference;
89  typedef _Data::iterator iterator;
90  typedef _Data::const_iterator const_iterator;
92  typedef _Data::difference_type difference_type;
93  typedef _Data::allocator_type allocator_type;
94 
95  inline ValueList() {}
96  inline ValueList(const ValueList &orig) : data_(orig.data_) {}
97  inline ValueList(const _Data &orig) : data_(orig) {}
98  inline ~ValueList() {}
99 
100  inline ValueList &operator = (const ValueList &orig)
101  { data_ = orig.data_; return *this; }
102 
103  inline void clear()
104  { data_.clear(); }
105 
106  inline void add(AtomicId id, double value)
107  { data_.push_back(Value(id, value)); }
108 
109  inline void add(const Value &value)
110  { data_.push_back(value); }
111 
112  inline size_type size() const { return data_.size(); }
113  bool empty() const { return data_.empty(); }
114 
115  inline const_iterator begin() const { return data_.begin(); }
116  iterator begin() { return data_.begin(); }
117 
118  inline const_iterator end() const { return data_.end(); }
119  iterator end() { return data_.end(); }
120 
121  inline const _Data &values() const { return data_; }
122  _Data &values() { return data_; }
123 
124  inline const_reference front() const { return *data_.begin(); }
125  reference front() { return *data_.begin(); }
126 
127  inline const_reference back() const { return *data_.rbegin(); }
128  reference back() { return *data_.rbegin(); }
129 
130  inline const_pointer data() const { return &front(); }
131  pointer data() { return &front(); }
132 
133  private:
134  std::vector<Value> data_;
135  };
136 
137  inline Variable() {}
138  inline Variable(const Variable &orig) :
139  name(orig.name), flags(orig.flags) {}
141  name(name), flags(flags) {}
142 
143  const AtomicId getName() const { return name; }
144  Flags getFlags() const { return flags;}
145 
146  bool isOptional() const { return flags & FLAG_OPTIONAL; }
147  bool isMultiple() const { return flags & FLAG_MULTIPLE; }
148 
149  private:
152 };
153 
154 } // namespace PhysicsTools
155 
156 #endif // PhysicsTools_MVAComputer_Variable_h
bool isOptional() const
Definition: Variable.h:146
bool isMultiple() const
Definition: Variable.h:147
double getValue() const
Definition: Variable.h:66
Class describing an input variable.
Definition: Variable.h:33
_Data::const_pointer const_pointer
Definition: Variable.h:86
void setName(AtomicId name)
Definition: Variable.h:62
_Data::size_type size_type
Definition: Variable.h:91
std::vector< Value > data_
Definition: Variable.h:134
const_iterator end() const
Definition: Variable.h:118
uint16_t size_type
const_iterator begin() const
Definition: Variable.h:115
ValueList & operator=(const ValueList &orig)
Definition: Variable.h:100
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
const AtomicId getName() const
Definition: Variable.h:143
Variable(AtomicId name, Flags flags=FLAG_NONE)
Definition: Variable.h:140
Flags getFlags() const
Definition: Variable.h:144
Value & operator=(const Value &orig)
Definition: Variable.h:59
Value(AtomicId name, double value)
Definition: Variable.h:56
void add(const Value &value)
Definition: Variable.h:109
const_pointer data() const
Definition: Variable.h:130
reco::JetExtendedAssociation::JetExtendedData Value
_Data::const_reference const_reference
Definition: Variable.h:88
std::vector< Value > _Data
Definition: Variable.h:83
Container::value_type value_type
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:81
Value(const Value &orig)
Definition: Variable.h:54
ValueList(const _Data &orig)
Definition: Variable.h:97
Helper class that can contain an identifier-value pair.
Definition: Variable.h:51
const_reference front() const
Definition: Variable.h:124
const _Data & values() const
Definition: Variable.h:121
const_reference back() const
Definition: Variable.h:127
_Data::allocator_type allocator_type
Definition: Variable.h:93
AtomicId getName() const
Definition: Variable.h:65
ValueList(const ValueList &orig)
Definition: Variable.h:96
_Data::const_iterator const_iterator
Definition: Variable.h:90
_Data::difference_type difference_type
Definition: Variable.h:92
void add(AtomicId id, double value)
Definition: Variable.h:106
_Data::reference reference
Definition: Variable.h:87
Variable(const Variable &orig)
Definition: Variable.h:138
_Data::value_type value_type
Definition: Variable.h:84
void setValue(double value)
Definition: Variable.h:63