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 163 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 166 of file BasicTypesProxy.h.

168  {
169  }
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 171 of file BasicTypesProxy.h.

References e, and registry_explorer::v.

171 {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 176 of file BasicTypesProxy.h.

References MECModelEnuComparisons::i.

176 {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 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 >
iterator<const T> caf::Proxy< std::vector< T > >::begin ( ) const
inline

Definition at line 213 of file BasicTypesProxy.h.

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

Definition at line 214 of file BasicTypesProxy.h.

214 {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 190 of file BasicTypesProxy.h.

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

191  {
192  fSize.CheckEquals(x.size());
193  for(unsigned int i = 0; i < std::min(size(), x.size()); ++i) at(i).CheckEquals(x[i]);
194  }
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 404 of file BasicTypesProxy.cxx.

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

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

Definition at line 530 of file BasicTypesProxy.cxx.

References caf::VectorProxyBase::size().

531  {
532  return size() == 0;
533  }
template<class T >
iterator<const T> caf::Proxy< std::vector< T > >::end ( ) const
inline

Definition at line 215 of file BasicTypesProxy.h.

References gen_flatrecord::size.

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

Definition at line 216 of file BasicTypesProxy.h.

References gen_flatrecord::size.

216 {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 220 of file BasicTypesProxy.h.

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

221  {
222  CheckIndex(i, size());
223  if(i >= fElems.size()) fElems.resize(i+1);
224 
225  if(fIdxP) fIdx = *fIdxP; // store into an actual value we can point to
226 
227  if(!fElems[i]) fElems[i] = new Proxy<T>(fDir, GetTreeForName(), Subscript(i), fIdx, i);
228  }
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 482 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.

483  {
484  if(fType != kFlatMultiTree) return fTree; // all in the same tree
485 
486  const std::string sname = StripSubscripts(fName);
487  TTree* tr = (TTree*)fDir->Get(sname.c_str());
488  if(!tr){
489  std::cout << "Couldn't find TTree " << sname
490  << " in " << fDir->GetName() << std::endl;
491  abort();
492  }
493  return tr;
494  }
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 425 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.

426  {
427  if(fType == kFlatMultiTree) return fName+"_length";
428  if(fType == kFlatSingleTree) return fName+"..length";
429 
430  // Counts exist, but with non-systematic names
431  if(fName == "rec.me.trkkalman" ) return "rec.me.nkalman";
432  if(fName == "rec.me.trkdiscrete") return "rec.me.ndiscrete";
433  if(fName == "rec.me.trkcosmic" ) return "rec.me.ncosmic";
434  if(fName == "rec.me.trkbpf" ) return "rec.me.nbpf";
435 
436  const int idx = fName.find_last_of('.');
437  // foo.bar.baz -> foo.bar.nbaz
438  const std::string nname = NName();
439 
440  if(!fTree) return nname; // doesn't matter if leaf exists or not
441 
442  int olderr = gErrorIgnoreLevel;
443  gErrorIgnoreLevel = 99999999;
444  TTreeFormula ttf(("TTFProxySize-"+fName).c_str(), nname.c_str(), fTree);
445  TString junks = nname.c_str();
446  int junki;
447  const int def = ttf.DefinedVariable(junks, junki);
448  gErrorIgnoreLevel = olderr;
449 
450  if(def >= 0) return nname;
451 
452  // Otherwise fallback and make a note to warn the first time we're accessed
453  fWarn = true;
454 
455  // foo.bar.baz -> foo.bar.@baz.size()
456  return fName.substr(0, idx+1)+"@"+fName.substr(idx+1)+".size()";
457  }
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 417 of file BasicTypesProxy.cxx.

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

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

418  {
419  const int idx = fName.find_last_of('.');
420  // foo.bar.baz -> foo.bar.nbaz
421  return fName.substr(0, idx)+".n"+fName.substr(idx+1);
422  }
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 182 of file BasicTypesProxy.h.

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

183  {
184  resize(x.size());
185  for(unsigned int i = 0; i < x.size(); ++i) at(i) = x[i];
186  return *this;
187  }
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 179 of file BasicTypesProxy.h.

179 {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 180 of file BasicTypesProxy.h.

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

Definition at line 536 of file BasicTypesProxy.cxx.

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

537  {
538  fSize = i;
539  }
size_t caf::VectorProxyBase::size ( void  ) const
inherited

Definition at line 507 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().

508  {
509  if(fWarn){
510  fWarn = false;
511 
512  // Don't emit the same warning more than once
513  static std::set<std::string> already;
514 
516  if(already.count(key) == 0){
517  already.insert(key);
518  std::cout << std::endl;
519  std::cout << "Warning: field '" << key << "' does not exist in file. "
520  << "Falling back to '" << StripSubscripts(fSize.Name()) << "' which is less efficient. "
521  << "Consider updating StandardRecord to include '" << key << "'." << std::endl;
522  std::cout << std::endl;
523  }
524  }
525 
526  return fSize;
527  }
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 468 of file BasicTypesProxy.cxx.

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

469  {
470  // Only have to do the at() business for the nested case for subscripts
471  // from the 3rd one on
472  if(fType != kNested || NSubscripts(fName) < 2){
473  return fName+"["+std::to_string(i)+"]";
474  }
475 
476  const int idx = fName.find_last_of('.');
477 
478  return fName.substr(0, idx)+".@"+fName.substr(idx+1)+".at("+std::to_string(i)+")";
479  }
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 137 of file BasicTypesProxy.h.

TDirectory* caf::ArrayVectorProxyBase::fDir
protectedinherited

Definition at line 133 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 230 of file BasicTypesProxy.h.

long caf::ArrayVectorProxyBase::fIdx
mutableprotectedinherited

Definition at line 140 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 138 of file BasicTypesProxy.h.

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

Definition at line 158 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 160 of file BasicTypesProxy.h.

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


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