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