Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
caf::Proxy< std::vector< T > > Class Template Reference

#include "SRProxy/BasicTypesProxy.h"

Inheritance diagram for caf::Proxy< std::vector< T > >:
caf::VectorProxyBase caf::ArrayVectorProxyBase

Classes

class  iterator
 

Public Member Functions

 Proxy (TDirectory *d, TTree *tr, const std::string &name, const long &base, int offset)
 
 ~Proxy ()
 
Proxyoperator= (const Proxy< std::vector< T >> &)=delete
 
 Proxy (const Proxy< std::vector< T >> &v)=delete
 
Proxy< T > & at (size_t i) const
 
Proxy< T > & at (size_t i)
 
Proxy< T > & operator[] (size_t i) const
 
Proxy< T > & operator[] (size_t i)
 
template<class U >
Proxy< std::vector< T > > & operator= (const std::vector< U > &x)
 
template<class U >
void CheckEquals (const std::vector< U > &x) const
 
iterator< const Tbegin () const
 
iterator< Tbegin ()
 
iterator< const Tend () const
 
iterator< Tend ()
 
size_t size () const
 
bool empty () const
 
void resize (size_t i)
 
std::string Name () const
 

Protected Member Functions

void EnsureSize (size_t i) const
 Implies CheckIndex() More...
 
std::string LengthField () const
 
std::string NName () const
 Helper for LengthField() More...
 
void CheckIndex (size_t i, size_t size) const
 
TTree * GetTreeForName () const
 
std::string IndexField () const
 
std::string Subscript (int i) const
 add [i], or something more complex for nested CAFs More...
 

Protected Attributes

std::vector< Proxy< T > * > fElems
 
Proxy< intfSize
 
bool fWarn
 
TDirectory * fDir
 
TTree * fTree
 
std::string fName
 
CAFType fType
 
const long & fBase
 
int fOffset
 
Proxy< long long > * fIdxP
 
long fIdx
 

Detailed Description

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

Definition at line 164 of file BasicTypesProxy.h.

Constructor & Destructor Documentation

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

Definition at line 167 of file BasicTypesProxy.h.

169  {
170  }
const XML_Char * name
Definition: expat.h:151
VectorProxyBase(TDirectory *d, TTree *tr, const std::string &name, const long &base, int offset)
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
Float_t d
Definition: plot.C:236
template<class T >
caf::Proxy< std::vector< T > >::~Proxy ( )
inline

Definition at line 172 of file BasicTypesProxy.h.

References e, and registry_explorer::v.

172 {for(Proxy<T>* e: fElems) delete e;}
std::vector< Proxy< T > * > fElems
Float_t e
Definition: plot.C:35
template<class T >
caf::Proxy< std::vector< T > >::Proxy ( const Proxy< std::vector< T >> &  v)
delete

Member Function Documentation

template<class T >
Proxy<T>& caf::Proxy< std::vector< T > >::at ( size_t  i) const
inline

Definition at line 177 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i.

177 {EnsureSize(i); return *fElems[i];}
void EnsureSize(size_t i) const
Implies CheckIndex()
std::vector< Proxy< T > * > fElems
template<class T >
Proxy<T>& caf::Proxy< std::vector< T > >::at ( size_t  i)
inline

Definition at line 178 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i.

178 {EnsureSize(i); return *fElems[i];}
void EnsureSize(size_t i) const
Implies CheckIndex()
std::vector< Proxy< T > * > fElems
template<class T >
iterator<const T> caf::Proxy< std::vector< T > >::begin ( ) const
inline

Definition at line 214 of file BasicTypesProxy.h.

214 {return iterator<const T>(this, 0 );}
template<class T >
iterator< T> caf::Proxy< std::vector< T > >::begin ( )
inline

Definition at line 215 of file BasicTypesProxy.h.

215 {return iterator< T>(this, 0 );}
template<class T >
template<class U >
void caf::Proxy< std::vector< T > >::CheckEquals ( const std::vector< U > &  x) const
inline

Definition at line 191 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i, std::min(), and gen_hdf5record::size.

192  {
193  fSize.CheckEquals(x.size());
194  for(unsigned int i = 0; i < std::min(size(), x.size()); ++i) at(i).CheckEquals(x[i]);
195  }
Proxy< T > & at(size_t i) const
T min(const caf::Proxy< T > &a, T b)
void CheckEquals(const T &x) const
void caf::ArrayVectorProxyBase::CheckIndex ( size_t  i,
size_t  size 
) const
protectedinherited

Definition at line 399 of file BasicTypesProxy.cxx.

References om::cout, allTimeWatchdog::endl, and caf::ArrayVectorProxyBase::fName.

400  {
401  // This is the only way to get good error messages. But it also seems like
402  // the call to size() here is necessary in Nested mode to trigger some
403  // side-effect within ROOT, otherwise we get some bogus index out-of-range
404  // crashes.
405  if(i >= size){
406  std::cout << std::endl << fName << "[" << (signed)i << "] out of range (size() == " << size << "). Aborting." << std::endl;
407  abort();
408  }
409  }
OStream cout
Definition: OStream.cxx:6
bool caf::VectorProxyBase::empty ( ) const
inherited

Definition at line 525 of file BasicTypesProxy.cxx.

References caf::VectorProxyBase::size().

526  {
527  return size() == 0;
528  }
template<class T >
iterator<const T> caf::Proxy< std::vector< T > >::end ( ) const
inline

Definition at line 216 of file BasicTypesProxy.h.

References gen_hdf5record::size.

216 {return iterator<const T>(this, size());}
template<class T >
iterator< T> caf::Proxy< std::vector< T > >::end ( )
inline

Definition at line 217 of file BasicTypesProxy.h.

References gen_hdf5record::size.

217 {return iterator< T>(this, size());}
template<class T >
void caf::Proxy< std::vector< T > >::EnsureSize ( size_t  i) const
inlineprotected

Implies CheckIndex()

Definition at line 221 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i, and gen_hdf5record::size.

222  {
223  CheckIndex(i, size());
224  if(i >= fElems.size()) fElems.resize(i+1);
225 
226  if(fIdxP) fIdx = *fIdxP; // store into an actual value we can point to
227 
228  if(!fElems[i]) fElems[i] = new Proxy<T>(fDir, GetTreeForName(), Subscript(i), fIdx, i);
229  }
Proxy< long long > * fIdxP
std::vector< Proxy< T > * > fElems
std::string Subscript(int i) const
add [i], or something more complex for nested CAFs
TTree * GetTreeForName() const
void CheckIndex(size_t i, size_t size) const
TTree * caf::ArrayVectorProxyBase::GetTreeForName ( ) const
protectedinherited

Definition at line 477 of file BasicTypesProxy.cxx.

References om::cout, allTimeWatchdog::endl, caf::ArrayVectorProxyBase::fDir, caf::ArrayVectorProxyBase::fName, caf::ArrayVectorProxyBase::fTree, caf::ArrayVectorProxyBase::fType, caf::kFlatMultiTree, string, caf::StripSubscripts(), and make_root_from_grid_output::tr.

478  {
479  if(fType != kFlatMultiTree) return fTree; // all in the same tree
480 
481  const std::string sname = StripSubscripts(fName);
482  TTree* tr = (TTree*)fDir->Get(sname.c_str());
483  if(!tr){
484  std::cout << "Couldn't find TTree " << sname
485  << " in " << fDir->GetName() << std::endl;
486  abort();
487  }
488  return tr;
489  }
std::string StripSubscripts(const std::string &s)
OStream cout
Definition: OStream.cxx:6
enum BeamMode string
std::string caf::ArrayVectorProxyBase::IndexField ( ) const
protectedinherited
std::string caf::VectorProxyBase::LengthField ( ) const
protectedinherited

Definition at line 420 of file BasicTypesProxy.cxx.

References caf::ArrayVectorProxyBase::fName, caf::ArrayVectorProxyBase::fTree, caf::ArrayVectorProxyBase::fType, runNovaSAM::gErrorIgnoreLevel, compare_h5_caf::idx, caf::kFlatMultiTree, caf::kFlatSingleTree, and string.

421  {
422  if(fType == kFlatMultiTree) return fName+"_length";
423  if(fType == kFlatSingleTree) return fName+"..length";
424 
425  // Counts exist, but with non-systematic names
426  if(fName == "rec.me.trkkalman" ) return "rec.me.nkalman";
427  if(fName == "rec.me.trkdiscrete") return "rec.me.ndiscrete";
428  if(fName == "rec.me.trkcosmic" ) return "rec.me.ncosmic";
429  if(fName == "rec.me.trkbpf" ) return "rec.me.nbpf";
430 
431  const int idx = fName.find_last_of('.');
432  // foo.bar.baz -> foo.bar.nbaz
433  const std::string nname = NName();
434 
435  if(!fTree) return nname; // doesn't matter if leaf exists or not
436 
437  int olderr = gErrorIgnoreLevel;
438  gErrorIgnoreLevel = 99999999;
439  TTreeFormula ttf(("TTFProxySize-"+fName).c_str(), nname.c_str(), fTree);
440  TString junks = nname.c_str();
441  int junki;
442  const int def = ttf.DefinedVariable(junks, junki);
443  gErrorIgnoreLevel = olderr;
444 
445  if(def >= 0) return nname;
446 
447  // Otherwise fallback and make a note to warn the first time we're accessed
448  fWarn = true;
449 
450  // foo.bar.baz -> foo.bar.@baz.size()
451  return fName.substr(0, idx+1)+"@"+fName.substr(idx+1)+".size()";
452  }
std::string NName() const
Helper for LengthField()
enum BeamMode string
std::string caf::ArrayVectorProxyBase::Name ( void  ) const
inlineinherited
std::string caf::VectorProxyBase::NName ( ) const
protectedinherited

Helper for LengthField()

Definition at line 412 of file BasicTypesProxy.cxx.

References caf::ArrayVectorProxyBase::fName, and compare_h5_caf::idx.

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

413  {
414  const int idx = fName.find_last_of('.');
415  // foo.bar.baz -> foo.bar.nbaz
416  return fName.substr(0, idx)+".n"+fName.substr(idx+1);
417  }
template<class T >
Proxy& caf::Proxy< std::vector< T > >::operator= ( const Proxy< std::vector< T >> &  )
delete
template<class T >
template<class U >
Proxy<std::vector<T> >& caf::Proxy< std::vector< T > >::operator= ( const std::vector< U > &  x)
inline

Definition at line 183 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i, and stan::math::resize().

184  {
185  resize(x.size());
186  for(unsigned int i = 0; i < x.size(); ++i) at(i) = x[i];
187  return *this;
188  }
Proxy< T > & at(size_t i) const
template<class T >
Proxy<T>& caf::Proxy< std::vector< T > >::operator[] ( size_t  i) const
inline

Definition at line 180 of file BasicTypesProxy.h.

180 {return at(i);}
Proxy< T > & at(size_t i) const
template<class T >
Proxy<T>& caf::Proxy< std::vector< T > >::operator[] ( size_t  i)
inline

Definition at line 181 of file BasicTypesProxy.h.

181 {return at(i);}
Proxy< T > & at(size_t i) const
void caf::VectorProxyBase::resize ( size_t  i)
inherited

Definition at line 531 of file BasicTypesProxy.cxx.

References caf::VectorProxyBase::fSize, and MECModelEnuComparisons::i.

532  {
533  fSize = i;
534  }
size_t caf::VectorProxyBase::size ( void  ) const
inherited

Definition at line 502 of file BasicTypesProxy.cxx.

References om::cout, allTimeWatchdog::endl, caf::VectorProxyBase::fSize, caf::VectorProxyBase::fWarn, findDuplicateFiles::key, caf::Proxy< T >::Name(), caf::VectorProxyBase::NName(), string, and caf::StripSubscripts().

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

503  {
504  if(fWarn){
505  fWarn = false;
506 
507  // Don't emit the same warning more than once
508  static std::set<std::string> already;
509 
511  if(already.count(key) == 0){
512  already.insert(key);
513  std::cout << std::endl;
514  std::cout << "Warning: field '" << key << "' does not exist in file. "
515  << "Falling back to '" << StripSubscripts(fSize.Name()) << "' which is less efficient. "
516  << "Consider updating StandardRecord to include '" << key << "'." << std::endl;
517  std::cout << std::endl;
518  }
519  }
520 
521  return fSize;
522  }
std::string StripSubscripts(const std::string &s)
std::string Name() const
OStream cout
Definition: OStream.cxx:6
std::string NName() const
Helper for LengthField()
enum BeamMode string
std::string caf::ArrayVectorProxyBase::Subscript ( int  i) const
protectedinherited

add [i], or something more complex for nested CAFs

Definition at line 463 of file BasicTypesProxy.cxx.

References caf::ArrayVectorProxyBase::fName, caf::ArrayVectorProxyBase::fType, compare_h5_caf::idx, caf::kNested, caf::NSubscripts(), and art::to_string().

464  {
465  // Only have to do the at() business for the nested case for subscripts
466  // from the 3rd one on
467  if(fType != kNested || NSubscripts(fName) < 2){
468  return fName+"["+std::to_string(i)+"]";
469  }
470 
471  const int idx = fName.find_last_of('.');
472 
473  return fName.substr(0, idx)+".@"+fName.substr(idx+1)+".at("+std::to_string(i)+")";
474  }
int NSubscripts(const std::string &name)
Count the subscripts in the name.
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32

Member Data Documentation

const long& caf::ArrayVectorProxyBase::fBase
protectedinherited

Definition at line 138 of file BasicTypesProxy.h.

TDirectory* caf::ArrayVectorProxyBase::fDir
protectedinherited

Definition at line 134 of file BasicTypesProxy.h.

Referenced by caf::ArrayVectorProxyBase::GetTreeForName().

template<class T >
std::vector<Proxy<T>*> caf::Proxy< std::vector< T > >::fElems
mutableprotected

Definition at line 231 of file BasicTypesProxy.h.

long caf::ArrayVectorProxyBase::fIdx
mutableprotectedinherited

Definition at line 141 of file BasicTypesProxy.h.

Proxy<long long>* caf::ArrayVectorProxyBase::fIdxP
protectedinherited
std::string caf::ArrayVectorProxyBase::fName
protectedinherited
int caf::ArrayVectorProxyBase::fOffset
protectedinherited

Definition at line 139 of file BasicTypesProxy.h.

Proxy<int> caf::VectorProxyBase::fSize
protectedinherited

Definition at line 159 of file BasicTypesProxy.h.

Referenced by caf::VectorProxyBase::resize(), and caf::VectorProxyBase::size().

TTree* caf::ArrayVectorProxyBase::fTree
protectedinherited
CAFType caf::ArrayVectorProxyBase::fType
protectedinherited
bool caf::VectorProxyBase::fWarn
mutableprotectedinherited

Definition at line 161 of file BasicTypesProxy.h.

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


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