Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::DepMan< T > Class Template Reference

Deep magic to fix static initialization order. Here Be Dragons! More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.11/src/CAFAna/Core/DepMan.h"

Classes

struct  ParentKids
 

Public Member Functions

void RegisterConstruction (T *x)
 Call from constructor (in the success case) More...
 
void RegisterDestruction (T *x)
 Call from destructor. More...
 
void RegisterDependency (const T *parent, T *child)
 Call from copy constructor and assignment operator. More...
 
void Print ()
 Prints some stats. More...
 
void Disable ()
 
void Enable ()
 

Static Public Member Functions

static DepManInstance ()
 

Protected Member Functions

 DepMan ()
 

Protected Attributes

std::unordered_map< const T *, ParentKidsfNodes
 
bool fDisabled
 
int fNOps
 

Detailed Description

template<class T>
class ana::DepMan< T >

Deep magic to fix static initialization order. Here Be Dragons!

Intended for internal use by Cut and Var only.

Definition at line 12 of file DepMan.h.

Constructor & Destructor Documentation

template<class T>
ana::DepMan< T >::DepMan ( )
inlineprotected

Definition at line 30 of file DepMan.h.

30 : fDisabled(false), fNOps(0) {}
bool fDisabled
Definition: DepMan.h:35
int fNOps
Definition: DepMan.h:37

Member Function Documentation

template<class T >
void ana::DepMan< T >::Disable ( )

Definition at line 131 of file DepMan.cxx.

132  {
133  if(!gDuringShutdown) fDisabled = true;
134  }
bool fDisabled
Definition: DepMan.h:35
template<class T >
void ana::DepMan< T >::Enable ( )

Definition at line 137 of file DepMan.cxx.

138  {
139  if(!gDuringShutdown) fDisabled = false;
140  }
bool fDisabled
Definition: DepMan.h:35
template<class T >
DepMan< T > & ana::DepMan< T >::Instance ( void  )
static

Definition at line 51 of file DepMan.cxx.

Referenced by ana::Binning::Binning(), ana::Binning::Custom(), ana::Binning::operator=(), ana::Binning::Simple(), test_depman(), and ana::Binning::~Binning().

52  {
53  // Avoid static order problems for the manager itself
54  static DepMan<T> dm;
55  return dm;
56  }
template<class T >
void ana::DepMan< T >::Print ( )

Prints some stats.

Definition at line 59 of file DepMan.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by test_depman().

60  {
61  std::cout << "DepMan for "<< DemangledTypeName<T>() << " :\n";
62  if(gDuringShutdown){
63  std::cout << " Unable to print during shutdown" << std::endl;
64  }
65  else{
66  std::cout << " assisted construction of " << fNOps << " objects. "
67  << fNodes.size() << " still awaiting construction."
68  << std::endl;
69  }
70  }
std::unordered_map< const T *, ParentKids > fNodes
Definition: DepMan.h:33
OStream cout
Definition: OStream.cxx:6
int fNOps
Definition: DepMan.h:37
template<class T >
void ana::DepMan< T >::RegisterConstruction ( T x)

Call from constructor (in the success case)

Definition at line 73 of file DepMan.cxx.

References ana::DepMan< T >::ParentKids::kids, ana::DepMan< T >::ParentKids::parent, T, and submit_syst::x.

Referenced by ana::_Cut< T >::_Cut(), ana::_Var< T >::_Var(), ana::Binning::Binning(), ana::Binning::Custom(), ana::_Var< T >::operator=(), ana::Binning::operator=(), ana::_Cut< T >::operator=(), and ana::Binning::Simple().

74  {
75  if(fDisabled || gDuringShutdown) return;
76 
77  ParentKids* xnode = maybe_find(fNodes, x);
78  if(!xnode) return; // No record of us, nothing to do
79 
80  std::unordered_set<T*> kids = xnode->kids;
81 
82  // We have been constructed, so parent doesn't need to remember us
83  // anymore
84  ParentKids* pnode = maybe_find(fNodes, xnode->parent);
85  if(pnode) maybe_erase(pnode->kids, x);
86  // Nor do we need to remember anything about this node anymore
87  maybe_erase(fNodes, x);
88 
89  // Assign into all the kids that were depending on us. They in turn will
90  // register their construction and so recurse into any grandkids.
91  for(T* kid: kids) *kid = *x;
92 
93  fNOps += kids.size();
94  }
std::unordered_map< const T *, ParentKids > fNodes
Definition: DepMan.h:33
bool fDisabled
Definition: DepMan.h:35
int fNOps
Definition: DepMan.h:37
double T
Definition: Xdiff_gwt.C:5
template<class T >
void ana::DepMan< T >::RegisterDependency ( const T parent,
T child 
)

Call from copy constructor and assignment operator.

Definition at line 122 of file DepMan.cxx.

References file_size_ana::parent.

Referenced by ana::_Cut< T >::_Cut(), ana::_Var< T >::_Var(), ana::Binning::Binning(), ana::_Var< T >::operator=(), ana::Binning::operator=(), and ana::_Cut< T >::operator=().

123  {
124  if(fDisabled || gDuringShutdown) return;
125 
126  fNodes[child].parent = parent;
127  fNodes[parent].kids.insert(child);
128  }
std::unordered_map< const T *, ParentKids > fNodes
Definition: DepMan.h:33
bool fDisabled
Definition: DepMan.h:35
template<class T >
void ana::DepMan< T >::RegisterDestruction ( T x)

Call from destructor.

Definition at line 97 of file DepMan.cxx.

References ana::DepMan< T >::ParentKids::kids, ana::DepMan< T >::ParentKids::parent, and T.

Referenced by ana::_Cut< T >::~_Cut(), ana::_Var< T >::~_Var(), and ana::Binning::~Binning().

98  {
99  if(fDisabled || gDuringShutdown) return;
100 
101  ParentKids* xnode = maybe_find(fNodes, x);
102  if(!xnode) return; // No record of us, nothing to do
103 
104  // Make the parent forget about us
105  ParentKids* pnode = maybe_find(fNodes, xnode->parent);
106  if(pnode) pnode->kids.erase(x);
107 
108  // Kids need to forget about us, but get hooked up to their grandparent
109  // instead.
110  for(T* kid: xnode->kids){
111  ParentKids* knode = maybe_find(fNodes, kid);
112 
113  if(knode) knode->parent = xnode->parent;
114  if(pnode) pnode->kids.insert(kid);
115  }
116 
117  fNodes.erase(x); // And finally forget this node in particular
118  }
std::unordered_map< const T *, ParentKids > fNodes
Definition: DepMan.h:33
bool fDisabled
Definition: DepMan.h:35
double T
Definition: Xdiff_gwt.C:5

Member Data Documentation

template<class T>
bool ana::DepMan< T >::fDisabled
protected

Definition at line 35 of file DepMan.h.

template<class T>
std::unordered_map<const T*, ParentKids> ana::DepMan< T >::fNodes
protected

Definition at line 33 of file DepMan.h.

template<class T>
int ana::DepMan< T >::fNOps
protected

Definition at line 37 of file DepMan.h.


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