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 63 of file Formula.cxx.

65 : m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
66 m_entry (-1), m_ndata (0)
67 {
68 RCU_NEW_INVARIANT (this);
69 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
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 73 of file Formula.cxx.

75 : m_formula (formula), m_name (name),
76 m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
77 m_entry (-1), m_ndata (0)
78 {
79 RCU_NEW_INVARIANT (this);
80
81 reset (tree);
82 }
const std::string & formula() const
description: the formula used guarantee: no-fail
Definition Formula.cxx:135
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:98
TChain * tree

◆ ~Formula()

MD::Formula::~Formula ( )

effects: standard destructor guarantee: no-fail

Definition at line 86 of file Formula.cxx.

88 {
90
91 delete m_form;
92 m_form = 0;
93 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:223

◆ 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 134 of file Formula.cxx.

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

◆ 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 162 of file Formula.cxx.

164 {
165 RCU_READ_INVARIANT (this);
167
168 if (m_ndim < 0)
169 throw std::runtime_error ("invalid formula: " + m_formula);
170 if (m_tree->GetReadEntry() != m_entry)
171 {
172 m_entry = -1;
173 m_ndata = m_manager->GetNdata();
174 if (m_ndata > 0)
175 {
176 if (m_read.size() < std::size_t (m_ndata))
177 m_read.resize (m_ndata);
178 for (std::size_t iter = 0, end = m_ndata; iter != end; ++ iter)
179 m_read[iter] = false;
180
181 if (m_cache.size() < std::size_t (m_ndata))
182 m_cache.resize (m_ndata);
183 m_cache[0] = m_form->EvalInstance (0);
184 m_read[0] = true;
185 m_entry = m_tree->GetReadEntry();
186 }
187 }
188 if (m_ndata < 0)
189 throw std::runtime_error ("failed to read formula: " + m_formula);
190 return m_ndata;
191 }
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:141
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:144
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 152 of file Formula.cxx.

154 {
155 RCU_READ_INVARIANT (this);
157 return m_ndim;
158 }

◆ 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 97 of file Formula.cxx.

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

◆ testInvariant()

void MD::Formula::testInvariant ( ) const

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

Definition at line 31 of file Formula.cxx.

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

◆ valid()

bool MD::Formula::valid ( ) const

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

Definition at line 143 of file Formula.cxx.

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

◆ 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 195 of file Formula.cxx.

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

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: