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 35 of file Formula.h.

Constructor & Destructor Documentation

◆ Formula() [1/3]

MD::Formula::Formula ( )

effects: standard default constructor guarantee: no-fail

Definition at line 68 of file Formula.cxx.

70 : m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
71 m_entry (-1), m_ndata (0)
72 {
73 RCU_NEW_INVARIANT (this);
74 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
Long64_t m_entry
description: the last entry we read
Definition Formula.h:146
TTreeFormulaManager * m_manager
description: the manager used
Definition Formula.h:137
TTreeFormula * m_form
description the formula used
Definition Formula.h:133
TTree * m_tree
description: the tree we are connected to
Definition Formula.h:129
int m_ndim
description: the number of array dimensions we need to loop over, or -1 if we are in error
Definition Formula.h:142
Int_t m_ndata
description: the number of data entries
Definition Formula.h:150

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

80 : m_formula (formula), m_name (name),
81 m_tree (0), m_form (0), m_manager (0), m_ndim (-1),
82 m_entry (-1), m_ndata (0)
83 {
84 RCU_NEW_INVARIANT (this);
85
86 reset (tree);
87 }
const std::string & formula() const
description: the formula used guarantee: no-fail
Definition Formula.cxx:140
std::string m_name
description: the name we use for the formula
Definition Formula.h:125
std::string m_formula
description: members directly corresponding to accessors
Definition Formula.h:121
void reset(TTree *tree)
effects: reset this formula to a new tree guarantee: strong failures: out of memory II failures: TTre...
Definition Formula.cxx:103
TChain * tree

◆ ~Formula()

MD::Formula::~Formula ( )

effects: standard destructor guarantee: no-fail

Definition at line 91 of file Formula.cxx.

93 {
95
96 delete m_form;
97 m_form = 0;
98 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235

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

141 {
142 RCU_READ_INVARIANT (this);
143 return m_formula;
144 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229

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

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

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

159 {
160 RCU_READ_INVARIANT (this);
162 return m_ndim;
163 }

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

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

◆ testInvariant()

void MD::Formula::testInvariant ( ) const

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

Definition at line 36 of file Formula.cxx.

38 {
39 RCU_INVARIANT (this != 0);
40 if (!m_formula.empty())
41 {
42 RCU_INVARIANT (!m_name.empty());
43
44 if (m_tree != 0)
45 {
47 if (m_ndata > 0)
48 {
49 RCU_INVARIANT (m_cache.size() >= std::size_t (m_ndata));
50 RCU_INVARIANT (m_read.size() >= std::size_t (m_ndata));
51 }
52 } else
53 {
54 RCU_INVARIANT (m_form == 0);
56 }
57 } else
58 {
59 RCU_INVARIANT (m_name.empty());
60 RCU_INVARIANT (m_tree == 0);
61 RCU_INVARIANT (m_form == 0);
63 }
64 }
#define RCU_INVARIANT(x)
Definition Assert.h:201

◆ valid()

bool MD::Formula::valid ( ) const

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

Definition at line 148 of file Formula.cxx.

150 {
151 RCU_READ_INVARIANT (this);
152 return !m_formula.empty() && m_ndim >= 0;
153 }

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

202 {
203 RCU_READ_INVARIANT (this);
206
207 if (!m_read[data])
208 {
209 m_cache[data] = m_form->EvalInstance (data);
210 m_read[data] = true;
211 }
212 return m_cache[data];
213 }
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::size_t ndata() const
returns: the number of data entries for the formula with the given index guarantee: strong failures: ...
Definition Formula.cxx:168

Member Data Documentation

◆ m_cache

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

description: the cache of data entries

Definition at line 154 of file Formula.h.

◆ m_entry

Long64_t MD::Formula::m_entry
mutableprivate

description: the last entry we read

Definition at line 146 of file Formula.h.

◆ m_form

TTreeFormula* MD::Formula::m_form
private

description the formula used

Definition at line 133 of file Formula.h.

◆ m_formula

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

description: members directly corresponding to accessors

Definition at line 121 of file Formula.h.

◆ m_manager

TTreeFormulaManager* MD::Formula::m_manager
private

description: the manager used

Definition at line 137 of file Formula.h.

◆ m_name

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

description: the name we use for the formula

Definition at line 125 of file Formula.h.

◆ m_ndata

Int_t MD::Formula::m_ndata
mutableprivate

description: the number of data entries

Definition at line 150 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 142 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 158 of file Formula.h.

◆ m_tree

TTree* MD::Formula::m_tree
private

description: the tree we are connected to

Definition at line 129 of file Formula.h.


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