ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 
 Formula ()
 effects: standard default constructor guarantee: no-fail More...
 
 Formula (const std::string &name, const std::string &formula, TTree *tree)
 effects: standard constructor guarantee: strong failures: out of memory II More...
 
 ~Formula ()
 effects: standard destructor guarantee: no-fail More...
 
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() More...
 
const std::string & formula () const
 description: the formula used guarantee: no-fail More...
 
bool valid () const
 returns: whether the formula is valid guarantee: no-fail More...
 
int ndim () const
 returns: the number of unspecified array dimensions for the given formula guarantee: no-fail requires: valid() More...
 
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() More...
 
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() More...
 

Private Member Functions

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

Private Attributes

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

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  }

◆ 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.

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  }

◆ ~Formula()

MD::Formula::~Formula ( )

effects: standard destructor guarantee: no-fail

Definition at line 91 of file Formula.cxx.

93  {
94  RCU_DESTROY_INVARIANT (this);
95 
96  delete m_form;
97  m_form = 0;
98  }

◆ 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  }

◆ 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);
171  RCU_REQUIRE_SOFT (valid ());
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  }

◆ 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);
161  RCU_REQUIRE_SOFT (valid ());
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  {
105  RCU_CHANGE_INVARIANT (this);
106  RCU_REQUIRE (!formula().empty());
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  }

◆ 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  {
46  RCU_INVARIANT (m_manager != 0);
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);
55  RCU_INVARIANT (m_manager == 0);
56  }
57  } else
58  {
59  RCU_INVARIANT (m_name.empty());
60  RCU_INVARIANT (m_tree == 0);
61  RCU_INVARIANT (m_form == 0);
62  RCU_INVARIANT (m_manager == 0);
63  }
64  }

◆ 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);
204  RCU_REQUIRE_SOFT (valid ());
205  RCU_REQUIRE_SOFT (data < ndata ());
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  }

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:
MD::Formula::formula
const std::string & formula() const
description: the formula used guarantee: no-fail
Definition: Formula.cxx:140
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MD::Formula::m_form
TTreeFormula * m_form
description the formula used
Definition: Formula.h:133
MD::Formula::m_name
std::string m_name
description: the name we use for the formula
Definition: Formula.h:125
MD::Formula::m_ndim
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
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
tree
TChain * tree
Definition: tile_monitor.h:30
MD::Formula::valid
bool valid() const
returns: whether the formula is valid guarantee: no-fail
Definition: Formula.cxx:149
MD::Formula::ndata
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
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MD::Formula::m_cache
std::vector< Double_t > m_cache
description: the cache of data entries
Definition: Formula.h:154
MD::Formula::m_formula
std::string m_formula
description: members directly corresponding to accessors
Definition: Formula.h:121
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
MD::Formula::m_entry
Long64_t m_entry
description: the last entry we read
Definition: Formula.h:146
MD::Formula::m_manager
TTreeFormulaManager * m_manager
description: the manager used
Definition: Formula.h:137
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
MD::Formula::m_read
std::vector< bool > m_read
description: whether we read the given data entry
Definition: Formula.h:158
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MD::Formula::m_tree
TTree * m_tree
description: the tree we are connected to
Definition: Formula.h:129
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
MD::Formula::reset
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
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
MD::Formula::m_ndata
Int_t m_ndata
description: the number of data entries
Definition: Formula.h:150
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233