Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
caf::Proxy< T > Class Template Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-28/StandardRecord/Proxy/FwdDeclare.h"

Public Member Functions

 Proxy (TDirectory *d, TTree *tr, const std::string &name, const long &base, int offset)
 
 Proxy (const Proxy &)
 
 Proxy (const Proxy &&)
 
Proxyoperator= (const Proxy &)=delete
 
 Proxy (T v)=delete
 
 ~Proxy ()
 
 operator T () const
 
T GetValue () const
 
Proxy< T > & operator= (T x)
 
Proxy< T > & operator+= (T x)
 
Proxy< T > & operator*= (T x)
 
std::string Name () const
 
void CheckEquals (const T &x) const
 

Protected Types

typedef std::conditional_t< std::is_enum_v< T >, int, TU
 

Protected Member Functions

T GetValueNested () const
 
T GetValueFlatSingle () const
 
T GetValueFlatMulti () const
 
void SetShifted ()
 

Protected Attributes

std::string fName
 
CAFType fType
 
TLeaf * fLeaf
 
U fVal
 
TTree * fTree
 
TDirectory * fDir
 
const long & fBase
 
int fOffset
 
TFormLeafInfo * fLeafInfo
 
TBranch * fBranch
 
TTreeFormula * fTTF
 
long fEntry
 
int fSubIdx
 

Friends

class Restorer
 

Detailed Description

template<class T>
class caf::Proxy< T >

Definition at line 8 of file FwdDeclare.h.

Member Typedef Documentation

template<class T>
typedef std::conditional_t<std::is_enum_v<T>, int, T> caf::Proxy< T >::U
protected

Definition at line 91 of file BasicTypesProxy.h.

Constructor & Destructor Documentation

template<class T >
caf::Proxy< T >::Proxy ( TDirectory *  d,
TTree *  tr,
const std::string name,
const long &  base,
int  offset 
)

Definition at line 100 of file BasicTypesProxy.cxx.

101  : fName(name), fType(GetCAFType(d, tr)),
102  fLeaf(0), fTree(tr), fDir(d),
104  fLeafInfo(0), fBranch(0), fTTF(0), fEntry(-1), fSubIdx(0)
105  {
106  }
const XML_Char * name
Definition: expat.h:151
TDirectory * fDir
CAFType fType
const long & AdjustBase(const long &base, CAFType type, const std::string &name)
std::string fName
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
CAFType GetCAFType(const TDirectory *dir, TTree *tr)
TFormLeafInfo * fLeafInfo
const long & fBase
TLeaf * fLeaf
Float_t d
Definition: plot.C:236
TTreeFormula * fTTF
TTree * fTree
TBranch * fBranch
template<class T >
caf::Proxy< T >::Proxy ( const Proxy< T > &  p)

Definition at line 109 of file BasicTypesProxy.cxx.

References caf::Proxy< T >::fEntry, caf::Proxy< T >::fVal, and caf::Proxy< T >::GetValue().

110  : fName("copy of "+p.fName), fType(p.fType),
111  fLeaf(0), fTree(p.fDir ? 0 : p.fTree),
112  fDir(p.fDir), fBase(p.fBase), fOffset(p.fOffset),
113  fLeafInfo(0), fBranch(0), fTTF(0), fSubIdx(-1)
114  {
115  // Ensure that the value is evaluated and baked in in the parent object, so
116  // that fTTF et al aren't re-evaluated in every single copy.
117  fVal = p.GetValue();
118  fEntry = p.fEntry;
119  }
TDirectory * fDir
CAFType fType
const char * p
Definition: xmltok.h:285
std::string fName
TFormLeafInfo * fLeafInfo
const long & fBase
TLeaf * fLeaf
TTreeFormula * fTTF
TTree * fTree
TBranch * fBranch
template<class T >
caf::Proxy< T >::Proxy ( const Proxy< T > &&  p)

Definition at line 122 of file BasicTypesProxy.cxx.

References caf::Proxy< T >::fEntry, and caf::Proxy< T >::fVal.

123  : fName("move of "+p.fName), fType(p.fType),
124  fLeaf(0), fTree(p.fDir ? 0 : p.fTree),
125  fDir(p.fDir), fBase(p.fBase), fOffset(p.fOffset),
126  fLeafInfo(0), fBranch(0), fTTF(0), fSubIdx(-1)
127  {
128  // Ensure that the value is evaluated and baked in in the parent object, so
129  // that fTTF et al aren't re-evaluated in every single copy.
130  fVal = p.GetValue();
131  fEntry = p.fEntry;
132  }
TDirectory * fDir
CAFType fType
const char * p
Definition: xmltok.h:285
std::string fName
TFormLeafInfo * fLeafInfo
const long & fBase
TLeaf * fLeaf
TTreeFormula * fTTF
TTree * fTree
TBranch * fBranch
template<class T>
caf::Proxy< T >::Proxy ( T  v)
delete
template<class T >
caf::Proxy< T >::~Proxy ( )

Definition at line 135 of file BasicTypesProxy.cxx.

References caf::Proxy< T >::fTTF.

136  {
137  // The other pointers aren't ours
138  delete fTTF;
139  }
TTreeFormula * fTTF

Member Function Documentation

template<class T>
void caf::Proxy< T >::CheckEquals ( const T x) const
template<class T >
T caf::Proxy< T >::GetValue ( ) const
template<class T >
T caf::Proxy< T >::GetValueFlatMulti ( ) const
protected

Definition at line 204 of file BasicTypesProxy.cxx.

References caf::SRBranchRegistry::AddBranch(), ana::assert(), om::cout, allTimeWatchdog::endl, caf::Proxy< T >::fBase, caf::Proxy< T >::fBranch, caf::Proxy< T >::fEntry, caf::Proxy< T >::fLeaf, caf::Proxy< T >::fName, caf::Proxy< T >::fOffset, caf::Proxy< T >::fTree, caf::Proxy< T >::fVal, caf::GetTypedValueWrapper(), string, caf::StripSubscripts(), and T.

Referenced by caf::Proxy< T >::GetValue().

205  {
206  // Valid cached or systematically-shifted value
207  if(fEntry == fBase+fOffset) return (T)fVal;
208  fEntry = fBase+fOffset;
209 
210  assert(fTree);
211 
212  if(!fLeaf){
213  const std::string sname = StripSubscripts(fName);
214  fLeaf = fTree->GetLeaf(sname.c_str());
215  if(!fLeaf){
216  std::cout << std::endl << "BasicTypeProxy: Branch '" << sname
217  << "' not found in tree '" << fTree->GetName() << "'."
218  << std::endl;
219  abort();
220  }
221 
222  fBranch = fLeaf->GetBranch();
223 
224  if(fName.find("_idx") == std::string::npos &&
225  fName.find("_length") == std::string::npos &&
226  fName.find(".size()") == std::string::npos){ // specific to "nested"
228  }
229  }
230 
231  fBranch->GetEntry(fBase+fOffset);
232 
234 
235  return (T)fVal;
236  }
std::string fName
void GetTypedValueWrapper(TLeaf *leaf, T &x, int subidx)
std::string StripSubscripts(const std::string &s)
const long & fBase
TLeaf * fLeaf
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
static void AddBranch(const std::string &b)
double T
Definition: Xdiff_gwt.C:5
TTree * fTree
TBranch * fBranch
enum BeamMode string
template<class T >
T caf::Proxy< T >::GetValueFlatSingle ( ) const
protected

Definition at line 164 of file BasicTypesProxy.cxx.

References caf::SRBranchRegistry::AddBranch(), ana::assert(), om::cout, allTimeWatchdog::endl, caf::Proxy< T >::fBase, caf::Proxy< T >::fBranch, caf::Proxy< T >::fEntry, caf::Proxy< T >::fLeaf, caf::Proxy< T >::fName, caf::Proxy< T >::fOffset, caf::Proxy< T >::fTree, caf::Proxy< T >::fVal, caf::GetTypedValueWrapper(), string, caf::StripSubscripts(), and T.

Referenced by caf::Proxy< T >::GetValue().

165  {
166  // Magic value indicating the value has been set even in the absence of a
167  // tree
168  if(!fTree && fEntry == -100) return (T)fVal;
169 
170  assert(fTree);
171 
172  // Valid cached or systematically-shifted value
173  if(fEntry == fTree->GetReadEntry()) return (T)fVal;
174  fEntry = fTree->GetReadEntry();
175 
176  assert(fTree);
177 
178  if(!fLeaf){
179  const std::string sname = StripSubscripts(fName);
180  fLeaf = fTree->GetLeaf(sname.c_str());
181  if(!fLeaf){
182  std::cout << std::endl << "BasicTypeProxy: Branch '" << sname
183  << "' not found in tree '" << fTree->GetName() << "'."
184  << std::endl;
185  abort();
186  }
187 
188  fBranch = fLeaf->GetBranch();
189 
190  if(fName.find("..idx") == std::string::npos &&
191  fName.find("..length") == std::string::npos){
193  }
194  }
195 
196  fBranch->GetEntry(fEntry);
197 
199 
200  return (T)fVal;
201  }
std::string fName
void GetTypedValueWrapper(TLeaf *leaf, T &x, int subidx)
std::string StripSubscripts(const std::string &s)
const long & fBase
TLeaf * fLeaf
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
static void AddBranch(const std::string &b)
double T
Definition: Xdiff_gwt.C:5
TTree * fTree
TBranch * fBranch
enum BeamMode string
template<class T >
T caf::Proxy< T >::GetValueNested ( ) const
protected

Definition at line 250 of file BasicTypesProxy.cxx.

References caf::SRBranchRegistry::AddBranch(), ana::assert(), om::cout, allTimeWatchdog::endl, caf::EvalInstanceWrapper(), caf::Proxy< T >::fBranch, caf::Proxy< T >::fEntry, caf::Proxy< T >::fLeaf, caf::Proxy< T >::fLeafInfo, caf::Proxy< T >::fName, caf::Proxy< T >::fSubIdx, caf::Proxy< T >::fTree, caf::Proxy< T >::fTTF, caf::Proxy< T >::fVal, caf::GetTypedValueWrapper(), string, and T.

Referenced by caf::Proxy< T >::GetValue().

251  {
252  // Magic value indicating the value has been set even in the absence of a
253  // tree
254  if(!fTree && fEntry == -100) return (T)fVal;
255 
256  assert(fTree);
257 
258  // Valid cached or systematically-shifted value
259  if(fEntry == fTree->GetReadEntry()) return (T)fVal;
260  fEntry = fTree->GetReadEntry();
261 
262  // First time calling, set up the branches etc
263  if(!fTTF){
265 
266  // Leaves are attached to the TTF, must keep it
267  fTTF = new TTreeFormula(("TTFProxy-"+fName).c_str(), fName.c_str(), fTree);
268  fLeafInfo = fTTF->GetLeafInfo(0); // Can fail (for a regular branch?)
269  fLeaf = fTTF->GetLeaf(0);
270  fBranch = fLeaf->GetBranch();
271 
272  if(!fLeaf || !fBranch){
273  std::cout << "Couldn't find " << fName << " in tree. Abort."
274  << std::endl;
275 
276  abort();
277  }
278 
279  // TODO - parsing the array indices out sucks - pass in as an int somehow
280  const size_t open_idx = fName.find_first_of('[');
281  // Do we have exactly one set of [] in the name?
282  if(open_idx != std::string::npos && open_idx == fName.find_last_of('[')){
283  const size_t close_idx = fName.find_first_of(']');
284 
285  std::string numPart = fName.substr(open_idx+1, close_idx-open_idx-1);
286  fSubIdx = atoi(numPart.c_str());
287  }
288  }
289 
290  if(fLeafInfo){
291  // Using TTreeFormula always works, and is sometimes necessary
292 
293  fTTF->GetNdata(); // for some reason this is necessary for fTTF to work
294  // in all cases.
295 
297  }
298  else{
299  // But when this is possible the hope is it might be faster
300 
301  if(fBranch->GetReadEntry() != fEntry){
302  fBranch->GetEntry(fEntry);
303  }
304 
305  // This check is much quicker than what CheckIndex() does, which winds up
306  // calling a TTF, but I can't figure out a safe way to automatically
307  // elide that check.
308  if(fSubIdx > fLeaf->GetLen()){
309  std::cout << std::endl << fName << " out of range (size() == " << fLeaf->GetLen() << "). Aborting." << std::endl;
310  abort();
311  }
312 
314  }
315 
316  return (T)fVal;
317  }
std::string fName
void GetTypedValueWrapper(TLeaf *leaf, T &x, int subidx)
TFormLeafInfo * fLeafInfo
TLeaf * fLeaf
TTreeFormula * fTTF
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
static void AddBranch(const std::string &b)
double T
Definition: Xdiff_gwt.C:5
TTree * fTree
void EvalInstanceWrapper(TTreeFormula *ttf, T &x)
TBranch * fBranch
enum BeamMode string
template<class T>
std::string caf::Proxy< T >::Name ( void  ) const
inline

Definition at line 78 of file BasicTypesProxy.h.

Referenced by caf::VectorProxyBase::size().

78 {return fName;}
std::string fName
template<class T>
caf::Proxy< T >::operator T ( ) const
inline

Definition at line 69 of file BasicTypesProxy.h.

69 {return GetValue();}
T GetValue() const
template<class T>
Proxy< T > & caf::Proxy< T >::operator*= ( T  x)

Definition at line 352 of file BasicTypesProxy.cxx.

References om::cout, allTimeWatchdog::endl, caf::Proxy< T >::GetValue(), T, and void().

353  {
354  if constexpr(std::is_same_v<T, std::string>){
355  std::cout << "Proxy<std::string>::operator*=() is meaningless" << std::endl;
356  (void)x;
357  abort();
358  }
359  else if constexpr(std::is_same_v<T, bool>){
360  std::cout << "Proxy<bool>::operator*=() is meaningless" << std::endl;
361  (void)x;
362  abort();
363  }
364  else{
365  // Do it this way to re-use the systematics logic in operator=
366  *this = T(GetValue() * x);
367  }
368 
369  return *this;
370  }
T GetValue() const
OStream cout
Definition: OStream.cxx:6
double T
Definition: Xdiff_gwt.C:5
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
template<class T>
Proxy< T > & caf::Proxy< T >::operator+= ( T  x)

Definition at line 336 of file BasicTypesProxy.cxx.

References om::cout, allTimeWatchdog::endl, caf::Proxy< T >::GetValue(), T, and void().

337  {
338  if constexpr(!std::is_same_v<T, bool>){
339  // Do it this way to re-use the systematics logic in operator=
340  *this = T(GetValue() + x);
341  }
342  else{
343  std::cout << "Proxy<bool>::operator+=() is meaningless" << std::endl;
344  (void)x;
345  abort();
346  }
347 
348  return *this;
349  }
T GetValue() const
OStream cout
Definition: OStream.cxx:6
double T
Definition: Xdiff_gwt.C:5
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
template<class T>
Proxy& caf::Proxy< T >::operator= ( const Proxy< T > &  )
delete
template<class T>
Proxy< T > & caf::Proxy< T >::operator= ( T  x)
template<class T>
void caf::Proxy< T >::SetShifted ( )
protected

Friends And Related Function Documentation

template<class T>
friend class Restorer
friend

Definition at line 50 of file BasicTypesProxy.h.

Member Data Documentation

template<class T>
const long& caf::Proxy< T >::fBase
protected
template<class T>
TBranch* caf::Proxy< T >::fBranch
mutableprotected
template<class T>
TDirectory* caf::Proxy< T >::fDir
protected

Definition at line 101 of file BasicTypesProxy.h.

template<class T>
long caf::Proxy< T >::fEntry
mutableprotected
template<class T>
TLeaf* caf::Proxy< T >::fLeaf
mutableprotected
template<class T>
TFormLeafInfo* caf::Proxy< T >::fLeafInfo
mutableprotected

Definition at line 106 of file BasicTypesProxy.h.

Referenced by caf::Proxy< T >::GetValueNested().

template<class T>
std::string caf::Proxy< T >::fName
protected
template<class T>
int caf::Proxy< T >::fOffset
protected
template<class T>
int caf::Proxy< T >::fSubIdx
mutableprotected

Definition at line 110 of file BasicTypesProxy.h.

Referenced by caf::Proxy< T >::GetValueNested().

template<class T>
TTree* caf::Proxy< T >::fTree
protected
template<class T>
TTreeFormula* caf::Proxy< T >::fTTF
mutableprotected

Definition at line 108 of file BasicTypesProxy.h.

Referenced by caf::Proxy< T >::GetValueNested(), and caf::Proxy< T >::~Proxy().

template<class T>
CAFType caf::Proxy< T >::fType
protected

Definition at line 95 of file BasicTypesProxy.h.

Referenced by caf::Proxy< T >::GetValue(), and caf::Proxy< T >::operator=().

template<class T>
U caf::Proxy< T >::fVal
mutableprotected

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