ATLAS Offline Software
Loading...
Searching...
No Matches
MD::Formula Class Reference

#include <Formula.h>

Collaboration diagram for MD::Formula:

Public Member Functions

void testInvariant () const
 effects: test the invariant of this object guarantee: no-fail
 Formula ()
 effects: standard default constructor guarantee: no-fail
 Formula (const std::string &name, const std::string &formula, TTree *tree)
 effects: standard constructor guarantee: strong failures: out of memory II
 ~Formula ()
 effects: standard destructor guarantee: no-fail
void reset (TTree *tree)
 effects: reset this formula to a new tree guarantee: strong failures: out of memory II failures: TTreeFormula error requires: !formula().empty()
const std::string & formula () const
 description: the formula used guarantee: no-fail
bool valid () const
 returns: whether the formula is valid guarantee: no-fail
int ndim () const
 returns: the number of unspecified array dimensions for the given formula guarantee: no-fail requires: valid()
std::size_t ndata () const
 returns: the number of data entries for the formula with the given index guarantee: strong failures: TTreeFormula errors requires: valid()
Double_t value (std::size_t data) const
 returns: the result of evaluating the formula with the given index for the given data entry guarantee: strong failures: TTreeFormula errors requires: valid() requires: data < getNData()

Private Member Functions

 Formula (const Formula &that)
 rationale: to avoid broken objects
Formulaoperator= (const Formula &that)

Private Attributes

std::string m_formula
 description: members directly corresponding to accessors
std::string m_name
 description: the name we use for the formula
TTree * m_tree
 description: the tree we are connected to
TTreeFormula * m_form
 description the formula used
TTreeFormulaManager * m_manager
 description: the manager used
int m_ndim
 description: the number of array dimensions we need to loop over, or -1 if we are in error
Long64_t m_entry
 description: the last entry we read
Int_t m_ndata
 description: the number of data entries
std::vector< Double_t > m_cache
 description: the cache of data entries
std::vector< bool > m_read
 description: whether we read the given data entry

Detailed Description

Definition at line 26 of file Formula.h.

Constructor & Destructor Documentation

◆ Formula() [1/3]

MD::Formula::Formula ( )

effects: standard default constructor guarantee: no-fail

Definition at line 62 of file Formula.cxx.

64 : m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
65 m_entry (-1), m_ndata (0)
66 {
67 RCU_NEW_INVARIANT (this);
68 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
Long64_t m_entry
description: the last entry we read
Definition Formula.h:137
TTreeFormulaManager * m_manager
description: the manager used
Definition Formula.h:128
TTreeFormula * m_form
description the formula used
Definition Formula.h:124
TTree * m_tree
description: the tree we are connected to
Definition Formula.h:120
int m_ndim
description: the number of array dimensions we need to loop over, or -1 if we are in error
Definition Formula.h:133
Int_t m_ndata
description: the number of data entries
Definition Formula.h:141

◆ Formula() [2/3]

MD::Formula::Formula ( const std::string & name,
const std::string & formula,
TTree * tree )

effects: standard constructor guarantee: strong failures: out of memory II

Definition at line 72 of file Formula.cxx.

74 : m_formula (formula), m_name (name),
75 m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
76 m_entry (-1), m_ndata (0)
77 {
78 RCU_NEW_INVARIANT (this);
79
80 reset (tree);
81 }
const std::string & formula() const
description: the formula used guarantee: no-fail
Definition Formula.cxx:134
std::string m_name
description: the name we use for the formula
Definition Formula.h:116
std::string m_formula
description: members directly corresponding to accessors
Definition Formula.h:112
void reset(TTree *tree)
effects: reset this formula to a new tree guarantee: strong failures: out of memory II failures: TTre...
Definition Formula.cxx:97
TChain * tree

◆ ~Formula()

MD::Formula::~Formula ( )

effects: standard destructor guarantee: no-fail

Definition at line 85 of file Formula.cxx.

87 {
89
90 delete m_form;
91 m_form = 0;
92 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:230

◆ Formula() [3/3]

MD::Formula::Formula ( const Formula & that)
private

rationale: to avoid broken objects

Member Function Documentation

◆ formula()

const std::string & MD::Formula::formula ( ) const

description: the formula used guarantee: no-fail

Definition at line 133 of file Formula.cxx.

135 {
136 RCU_READ_INVARIANT (this);
137 return m_formula;
138 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224

◆ ndata()

std::size_t MD::Formula::ndata ( ) const

returns: the number of data entries for the formula with the given index guarantee: strong failures: TTreeFormula errors requires: valid()

Definition at line 161 of file Formula.cxx.

163 {
164 RCU_READ_INVARIANT (this);
166
167 if (m_ndim < 0)
168 RCU_THROW_MSG ("invalid formula: " + m_formula);
169 if (m_tree->GetReadEntry() != m_entry)
170 {
171 m_entry = -1;
172 m_ndata = m_manager->GetNdata();
173 if (m_ndata > 0)
174 {
175 if (m_read.size() < std::size_t (m_ndata))
176 m_read.resize (m_ndata);
177 for (std::size_t iter = 0, end = m_ndata; iter != end; ++ iter)
178 m_read[iter] = false;
179
180 if (m_cache.size() < std::size_t (m_ndata))
181 m_cache.resize (m_ndata);
182 m_cache[0] = m_form->EvalInstance (0);
183 m_read[0] = true;
184 m_entry = m_tree->GetReadEntry();
185 }
186 }
187 if (m_ndata < 0)
188 RCU_THROW_MSG ("failed to read formula: " + m_formula);
189 return m_ndata;
190 }
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:148
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
std::vector< Double_t > m_cache
description: the cache of data entries
Definition Formula.h:145
bool valid() const
returns: whether the formula is valid guarantee: no-fail
Definition Formula.cxx:143
std::vector< bool > m_read
description: whether we read the given data entry
Definition Formula.h:149

◆ ndim()

int MD::Formula::ndim ( ) const

returns: the number of unspecified array dimensions for the given formula guarantee: no-fail requires: valid()

Definition at line 151 of file Formula.cxx.

153 {
154 RCU_READ_INVARIANT (this);
156 return m_ndim;
157 }

◆ operator=()

Formula & MD::Formula::operator= ( const Formula & that)
private

◆ reset()

void MD::Formula::reset ( TTree * tree)

effects: reset this formula to a new tree guarantee: strong failures: out of memory II failures: TTreeFormula error requires: !formula().empty()

Definition at line 96 of file Formula.cxx.

98 {
101
102 delete m_form;
103 m_form = 0;
104 m_manager = 0;
105 m_ndim = -1;
106 m_entry = -1;
107 m_ndata = 0;
108 m_tree = 0;
109
110 m_tree = tree;
111 m_form = new TTreeFormula (m_name.c_str(), m_formula.c_str(), tree);
112
113 m_form->SetQuickLoad (kTRUE);
114 m_manager = new TTreeFormulaManager;
115 m_manager->Add (m_form);
116 m_manager->Sync ();
117 if (m_manager->GetMultiplicity () == -1)
118 tree->SetBit (TTree::kForceRead);
119 if (m_form->GetNdim() <= 0)
120 m_ndim = -1;
121 else if (m_form->GetMultiplicity() == 0)
122 m_ndim = 0;
123 else if (m_manager->GetMultiplicity() == 1 && m_form->GetMultiplicity() == 1)
124 m_ndim = 1;
125 else if (m_manager->GetMultiplicity() == -1 && m_form->GetMultiplicity() == 1)
126 m_ndim = 0;
127
128
129 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_REQUIRE(x)
Definition Assert.h:203
static const Attributes_t empty

◆ testInvariant()

void MD::Formula::testInvariant ( ) const

effects: test the invariant of this object guarantee: no-fail

Definition at line 30 of file Formula.cxx.

32 {
33 RCU_INVARIANT (this != 0);
34 if (!m_formula.empty())
35 {
36 RCU_INVARIANT (!m_name.empty());
37
38 if (m_tree != 0)
39 {
41 if (m_ndata > 0)
42 {
43 RCU_INVARIANT (m_cache.size() >= std::size_t (m_ndata));
44 RCU_INVARIANT (m_read.size() >= std::size_t (m_ndata));
45 }
46 } else
47 {
48 RCU_INVARIANT (m_form == 0);
50 }
51 } else
52 {
53 RCU_INVARIANT (m_name.empty());
54 RCU_INVARIANT (m_tree == 0);
55 RCU_INVARIANT (m_form == 0);
57 }
58 }
#define RCU_INVARIANT(x)
Definition Assert.h:196

◆ valid()

bool MD::Formula::valid ( ) const

returns: whether the formula is valid guarantee: no-fail

Definition at line 142 of file Formula.cxx.

144 {
145 RCU_READ_INVARIANT (this);
146 return !m_formula.empty() && m_ndim >= 0;
147 }

◆ value()

Double_t MD::Formula::value ( std::size_t data) const

returns: the result of evaluating the formula with the given index for the given data entry guarantee: strong failures: TTreeFormula errors requires: valid() requires: data < getNData()

Definition at line 194 of file Formula.cxx.

196 {
197 RCU_READ_INVARIANT (this);
199 RCU_REQUIRE_SOFT (data < ndata ());
200
201 if (!m_read[data])
202 {
203 m_cache[data] = m_form->EvalInstance (data);
204 m_read[data] = true;
205 }
206 return m_cache[data];
207 }
std::size_t ndata() const
returns: the number of data entries for the formula with the given index guarantee: strong failures: ...
Definition Formula.cxx:162

Member Data Documentation

◆ m_cache

std::vector<Double_t> MD::Formula::m_cache
mutableprivate

description: the cache of data entries

Definition at line 145 of file Formula.h.

◆ m_entry

Long64_t MD::Formula::m_entry
mutableprivate

description: the last entry we read

Definition at line 137 of file Formula.h.

◆ m_form

TTreeFormula* MD::Formula::m_form
private

description the formula used

Definition at line 124 of file Formula.h.

◆ m_formula

std::string MD::Formula::m_formula
private

description: members directly corresponding to accessors

Definition at line 112 of file Formula.h.

◆ m_manager

TTreeFormulaManager* MD::Formula::m_manager
private

description: the manager used

Definition at line 128 of file Formula.h.

◆ m_name

std::string MD::Formula::m_name
private

description: the name we use for the formula

Definition at line 116 of file Formula.h.

◆ m_ndata

Int_t MD::Formula::m_ndata
mutableprivate

description: the number of data entries

Definition at line 141 of file Formula.h.

◆ m_ndim

int MD::Formula::m_ndim
private

description: the number of array dimensions we need to loop over, or -1 if we are in error

Definition at line 133 of file Formula.h.

◆ m_read

std::vector<bool> MD::Formula::m_read
mutableprivate

description: whether we read the given data entry

Definition at line 149 of file Formula.h.

◆ m_tree

TTree* MD::Formula::m_tree
private

description: the tree we are connected to

Definition at line 120 of file Formula.h.


The documentation for this class was generated from the following files: