All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SystRegistry.cxx
Go to the documentation of this file.
2 
3 #include <cxxabi.h>
4 
5 #include <iostream>
6 
7 namespace ana
8 {
9  //----------------------------------------------------------------------
10  std::map<std::string, const ISyst*>& SystRegistry::Map()
11  {
12  // https://isocpp.org/wiki/faq/ctors#static-init-order
13  static auto m = new std::map<std::string, const ISyst*>;
14  return *m;
15  }
16 
17  //----------------------------------------------------------------------
19  {
20  const std::string name = s->ShortName();
21 
22  if(Map().count(name)){
23  std::cout << "SystRegistry: Warning: systematic '" << name
24  << "' registered multiple times." << std::endl
25  << "Check you declared it with 'extern' in the .h and "
26  << "instantiated it in the .cxx and check for other ISysts "
27  << "that happen to have the same name." << std::endl;
28  // Store an entry there, so we can detect further duplicates, but make it
29  // invalid.
30  Map()[name] = 0;
31  return;
32  }
33 
34  Map()[name] = s;
35  }
36 
37  //----------------------------------------------------------------------
39  {
40  auto it = Map().find(s->ShortName());
41 
42  if(it == Map().end()){
43  std::cout << "SystRegistry: Error: unregistering ISyst '"
44  << s->ShortName() << "' that was never registered!"
45  << std::endl;
46  return;
47  }
48 
49  // If was multiply registered, leave that signal
50  if(it->second) Map().erase(it);
51  }
52 
53  //----------------------------------------------------------------------
54  const ISyst* SystRegistry::ShortNameToSyst(const std::string& s,
55  bool allowFail)
56  {
57  auto it = Map().find(s);
58  if(it == Map().end()){
59  if(allowFail) return 0;
60  std::cout << "SystRegistry: Error: Syst '" << s << "' not found. "
61  << "Pass allowFail=true to return NULL in this case."
62  << std::endl;
63  abort();
64  }
65 
66  const ISyst* ret = it->second;
67 
68  if(!ret){
69  std::cout << "SystRegistry: Error: Syst '" << s
70  << "' was registered multiple times. Refusing to return a"
71  << " random instance. Go fix the syst registration."
72  << std::endl;
73  abort();
74  }
75 
76  return ret;
77  }
78 
79  //----------------------------------------------------------------------
81  {
82  std::cout << Map().size() << " ISysts:" << std::endl;
83  for(auto it: Map()){
84  std::cout << it.first << " :\t";
85 
86  if(it.second){
87  std::cout << abi::__cxa_demangle(typeid(*it.second).name(), 0, 0, 0)
88  << " at " << it.second << std::endl;
89  }
90  else{
91  std::cout << "MULTIPLY REGISTERED!" << std::endl;
92  }
93  }
94  }
95 }
process_name opflashCryoW ana
Encapsulate code to systematically shift a caf::StandardRecord.
Definition: ISyst.h:14
virtual std::string ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:30
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
static void UnRegister(const ISyst *s)
static void Print()
static std::map< std::string, const ISyst * > & Map()
static void Register(const ISyst *s)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
static const ISyst * ShortNameToSyst(const std::string &s, bool allowFail=false)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
then echo fcl name
std::size_t count(Cont const &cont)
BEGIN_PROLOG could also be cout