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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CAFAna/Core/Registry.h"

Static Public Member Functions

static void Register (const T *s)
 
static void UnRegister (const T *s)
 
static const TShortNameToPtr (const std::string &s, bool allowFail=false)
 
static void Print ()
 

Static Protected Member Functions

static std::map< std::string, const T * > & Map ()
 

Detailed Description

template<class T>
class ana::Registry< T >

Definition at line 8 of file Registry.h.

Member Function Documentation

template<class T >
std::map< std::string, const T * > & ana::Registry< T >::Map ( )
staticprotected

Definition at line 12 of file Registry.cxx.

References m.

13  {
14  // https://isocpp.org/wiki/faq/ctors#static-init-order
15  static auto m = new std::map<std::string, const T*>;
16  return *m;
17  }
template<class T >
void ana::Registry< T >::Print ( )
static

Definition at line 91 of file Registry.cxx.

References om::cout, ana::DemangledTypeName(), allTimeWatchdog::endl, and it.

92  {
93  std::cout << Map().size() << " Registry contains pointers:" << std::endl;
94  for (auto it: Map())
95  {
96  std::cout << it.first << " :\t";
97 
98  if (it.second)
99  {
100  std::cout << DemangledTypeName(it.second)
101  << " at " << &it.second << std::endl;
102  } else
103  {
104  std::cout << "MULTIPLY REGISTERED!" << std::endl;
105  }
106  }
107  }
set< int >::iterator it
std::string DemangledTypeName(T *obj)
utility method to figure out exactly what kind of object I am
Definition: UtilsExt.h:114
OStream cout
Definition: OStream.cxx:6
static std::map< std::string, const T * > & Map()
Definition: Registry.cxx:12
template<class T >
void ana::Registry< T >::Register ( const T s)
static

Definition at line 20 of file Registry.cxx.

References confusionMatrixTree::count, om::cout, ana::DemangledTypeName(), allTimeWatchdog::endl, and string.

Referenced by ana::IFitVar::IFitVar(), and ana::ISyst::ISyst().

21  {
22  const std::string name = s->ShortName();
23 
24  // uncomment if you need to work out what's going on under the hood
25  // std::cout << "Registering " << DemangledTypeName<T>() << " named " << s->ShortName() << std::endl;
26 
27  if (Map().count(name)){
28  std::cout << "Registry: Warning: " << DemangledTypeName(s)
29  << " '" << name << "' registered multiple times." << std::endl
30  << "Check you declared it with 'extern' in the .h and "
31  << "instantiated it in the .cxx and check for other "
33  << "s that happen to have the same name." << std::endl;
34  // Store an entry there, so we can detect further duplicates, but make it
35  // invalid.
36  Map()[name] = 0;
37  return;
38  }
39 
40  Map()[name] = s;
41  }
const XML_Char * name
Definition: expat.h:151
std::string DemangledTypeName(T *obj)
utility method to figure out exactly what kind of object I am
Definition: UtilsExt.h:114
const XML_Char * s
Definition: expat.h:262
OStream cout
Definition: OStream.cxx:6
static std::map< std::string, const T * > & Map()
Definition: Registry.cxx:12
enum BeamMode string
template<class T >
const T * ana::Registry< T >::ShortNameToPtr ( const std::string s,
bool  allowFail = false 
)
static

Definition at line 60 of file Registry.cxx.

References om::cout, febshutoff_auto::end, allTimeWatchdog::endl, it, msf_helper::o, runNovaSAM::ret, and T.

Referenced by GetKeySysts(), ana::PredictionInterp::LoadFromBody(), LoadSystsFromFile(), MakeSysts(), SetSystAlias(), and test_stanfit_systpulls().

62  {
63  auto it = Map().find(s);
64  if (it == Map().end()){
65  if (allowFail) return 0;
66  std::cout << "Registry: Error: "
67  << "Object with short name '" << s << "' not found. "
68  << "Pass allowFail=true to return NULL in this case."
69  << std::endl;
70 
71 // std::cout << "I know about the following " << DemangledTypeName<T>() << "s:" << std::endl;
72  for (const auto &o : Map())
73  std::cout << " " << o.first << std::endl;
74  abort();
75  }
76 
77  const T* ret = it->second;
78 
79  if (!ret){
80  std::cout << "Registry: Error: object '" << s
81  << "' was registered multiple times. Refusing to return a"
82  << " random instance. Go fix the syst registration."
83  << std::endl;
84  abort();
85  }
86 
87  return ret;
88  }
set< int >::iterator it
const XML_Char * s
Definition: expat.h:262
OStream cout
Definition: OStream.cxx:6
static std::map< std::string, const T * > & Map()
Definition: Registry.cxx:12
double T
Definition: Xdiff_gwt.C:5
template<class T >
void ana::Registry< T >::UnRegister ( const T s)
static

Definition at line 44 of file Registry.cxx.

References om::cout, ana::DemangledTypeName(), allTimeWatchdog::endl, and it.

Referenced by ana::IFitVar::~IFitVar(), and ana::ISyst::~ISyst().

45  {
46  auto it = Map().find(s->ShortName());
47 
48  if(it == Map().end()){
49  std::cout << "Registry: Error: unregistering " << DemangledTypeName(s)
50  << " '" << s->ShortName() << "' that was never registered!"
51  << std::endl;
52  return;
53  }
54 
55  // If was multiply registered, leave that signal
56  if(it->second) Map().erase(it);
57  }
set< int >::iterator it
std::string DemangledTypeName(T *obj)
utility method to figure out exactly what kind of object I am
Definition: UtilsExt.h:114
const XML_Char * s
Definition: expat.h:262
OStream cout
Definition: OStream.cxx:6
static std::map< std::string, const T * > & Map()
Definition: Registry.cxx:12

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