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) {}
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
PhysicsTools::Variable::ValueList::end
iterator end()
Definition: Variable.h:114
PhysicsTools::AtomicId
Cheap generic unique keyword identifier class.
Definition: AtomicId.h:31
PhysicsTools::Variable::Flags
Flags
Definition: Variable.h:35
PhysicsTools::Variable::ValueList::back
const_reference back() const
Definition: Variable.h:122
PhysicsTools::Variable::Value::Value
Value(AtomicId name, double value)
Definition: Variable.h:50
PhysicsTools::Variable::isMultiple
bool isMultiple() const
Definition: Variable.h:140
PhysicsTools::Variable::ValueList::size_type
_Data::size_type size_type
Definition: Variable.h:87
PhysicsTools::Variable::getFlags
Flags getFlags() const
Definition: Variable.h:137
PhysicsTools::Variable::flags
Flags flags
Definition: Variable.h:144
PhysicsTools::Variable::ValueList::front
const_reference front() const
Definition: Variable.h:119
PhysicsTools::Variable::ValueList::values
_Data & values()
Definition: Variable.h:117
PhysicsTools::Variable::FLAG_OPTIONAL
Definition: Variable.h:35
PhysicsTools::Variable::ValueList::begin
const_iterator begin() const
Definition: Variable.h:110
PhysicsTools::Variable::ValueList::begin
iterator begin()
Definition: Variable.h:111
PhysicsTools::Variable::ValueList::back
reference back()
Definition: Variable.h:123
PhysicsTools::Variable::ValueList::data_
std::vector< Value > data_
Definition: Variable.h:129
PhysicsTools::Variable::ValueList::values
const _Data & values() const
Definition: Variable.h:116
PhysicsTools::Variable::FLAG_NONE
Definition: Variable.h:35
PhysicsTools::Variable::Value
Helper class that can contain an identifier-value pair.
Definition: Variable.h:46
PhysicsTools::Variable::ValueList::end
const_iterator end() const
Definition: Variable.h:113
PhysicsTools::Variable::ValueList::iterator
_Data::iterator iterator
Definition: Variable.h:85
PhysicsTools::Variable::ValueList
Helper class that can contain an list of identifier-value pairs.
Definition: Variable.h:77
PhysicsTools::Variable::name
AtomicId name
Definition: Variable.h:143
PhysicsTools::Variable::ValueList::clear
void clear()
Definition: Variable.h:101
PhysicsTools::Variable::ValueList::const_reference
_Data::const_reference const_reference
Definition: Variable.h:84
PhysicsTools::Variable::Value::value
double value
Definition: Variable.h:66
PhysicsTools::Variable::ValueList::const_pointer
_Data::const_pointer const_pointer
Definition: Variable.h:82
PhysicsTools::Variable::ValueList::pointer
_Data::pointer pointer
Definition: Variable.h:81
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
PhysicsTools::Variable::FLAG_ALL
Definition: Variable.h:35
PhysicsTools::Variable
Class describing an input variable.
Definition: Variable.h:33
PhysicsTools::Variable::ValueList::size
size_type size() const
Definition: Variable.h:107
PhysicsTools::Variable::Value::operator=
Value & operator=(const Value &orig)
Definition: Variable.h:52
AtomicId.h
PhysicsTools::Variable::ValueList::value_type
_Data::value_type value_type
Definition: Variable.h:80
PhysicsTools::Variable::ValueList::reference
_Data::reference reference
Definition: Variable.h:83
PhysicsTools::Variable::ValueList::operator=
ValueList & operator=(const ValueList &orig)
Definition: Variable.h:96
PhysicsTools::Variable::ValueList::add
void add(AtomicId id, double value)
Definition: Variable.h:103
PhysicsTools::Variable::ValueList::~ValueList
~ValueList()
Definition: Variable.h:94
PhysicsTools::Variable::ValueList::const_iterator
_Data::const_iterator const_iterator
Definition: Variable.h:86
PhysicsTools::Variable::ValueList::ValueList
ValueList(const _Data &orig)
Definition: Variable.h:93
PhysicsTools::Variable::ValueList::ValueList
ValueList()
Definition: Variable.h:91
PhysicsTools::Variable::FLAG_MULTIPLE
Definition: Variable.h:35
PhysicsTools::Variable::Value::setValue
void setValue(double value)
Definition: Variable.h:59
PhysicsTools::Variable::ValueList::data
pointer data()
Definition: Variable.h:126
PhysicsTools::Variable::Value::setName
void setName(AtomicId name)
Definition: Variable.h:58
PhysicsTools::Variable::Variable
Variable(const Variable &orig)
Definition: Variable.h:133
PhysicsTools::Variable::Value::Value
Value(const Value &orig)
Definition: Variable.h:49
PhysicsTools::Variable::isOptional
bool isOptional() const
Definition: Variable.h:139
PhysicsTools::Variable::Value::Value
Value()
Definition: Variable.h:48
PhysicsTools::Variable::ValueList::difference_type
_Data::difference_type difference_type
Definition: Variable.h:88
PhysicsTools::Variable::Value::getValue
double getValue() const
Definition: Variable.h:62
PhysicsTools::Variable::ValueList::data
const_pointer data() const
Definition: Variable.h:125
PhysicsTools
Definition: Histogram.h:13
RecoTauValidation_cfi.reference
reference
Definition: RecoTauValidation_cfi.py:233
value
Definition: value.py:1
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
PhysicsTools::Variable::Value::name
AtomicId name
Definition: Variable.h:65
PhysicsTools::Variable::Value::getName
AtomicId getName() const
Definition: Variable.h:61
PhysicsTools::Variable::ValueList::front
reference front()
Definition: Variable.h:120
PhysicsTools::Variable::ValueList::_Data
std::vector< Value > _Data
Definition: Variable.h:79
PhysicsTools::Variable::Variable
Variable()
Definition: Variable.h:132
PhysicsTools::Variable::getName
const AtomicId getName() const
Definition: Variable.h:136
PhysicsTools::Variable::ValueList::ValueList
ValueList(const ValueList &orig)
Definition: Variable.h:92
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition: JetExtendedAssociation.h:27
PhysicsTools::Variable::ValueList::allocator_type
_Data::allocator_type allocator_type
Definition: Variable.h:89
PhysicsTools::Variable::Variable
Variable(AtomicId name, Flags flags=FLAG_NONE)
Definition: Variable.h:134
PhysicsTools::Variable::ValueList::empty
bool empty() const
Definition: Variable.h:108
PhysicsTools::Variable::ValueList::add
void add(const Value &value)
Definition: Variable.h:105