LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
EvtTimeShiftFactory.cxx
Go to the documentation of this file.
1 
12 #include "EvtTimeShiftFactory.h"
13 #include <iostream>
14 #include <iomanip>
15 
16 namespace evgb {
17 
18 // Define static variable which holds the one-and-only instance
19 EvtTimeShiftFactory* EvtTimeShiftFactory::fgTheInstance;
20 
22 {
23  fgTheInstance = this; // record created self in static pointer
24 }
25 
27 {
28  fgTheInstance = 0;
29 }
30 
32 {
33  // Cleaner dtor calls EvtTimeShiftFactory dtor at job end
34  static Cleaner cleaner;
35 
36  if ( ! fgTheInstance ) {
37  // need to create one
38  cleaner.UseMe(); // dummy call to quiet compiler warnings
40  }
41 
42  return *fgTheInstance;
43 }
44 
46 EvtTimeShiftFactory::GetEvtTimeShift(const std::string& name,
47  const std::string& config) const
48 {
49  evgb::EvtTimeShiftI* p = 0;
50 
51  // we don't want map creating an entry if it doesn't exist
52  // so use map::find() not map::operator[]
54  = fFunctionMap.find(name);
55  if ( fFunctionMap.end() != itr ) {
56  // found an appropriate entry in the list
57  EvtTimeShiftICtorFuncPtr_t foo = itr->second; // this is the function
58  p = (*foo)(config); // use function to create the EvtTimeShiftI
59  }
60  if ( ! p ) {
61  std::cerr << "### EvtTimeShiftFactory WARNING: "
62  << "EvtTimeShiftI \"" << name << "\" is not known" << std::endl;
63  }
64  return p;
65 }
66 
67 bool EvtTimeShiftFactory::IsKnownEvtTimeShift(const std::string& name)
68 {
69  // check if we know the name
70  bool res = false;
72  = fFunctionMap.find(name);
73  if ( fFunctionMap.end() != itr ) res = true;
74  return res;
75 }
76 
77 const std::vector<std::string>&
79 {
80  // list of names might be out of date due to new registrations
81  // rescan the std::map on each call (which won't be frequent)
82  listnames.clear();
83 
84  // scan map for registered names
86  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
87  listnames.push_back(itr->first);
88 
89  return listnames;
90 }
91 
93 {
94  const std::vector<std::string>& known = AvailableEvtTimeShift();
95  for (size_t i=0; i < known.size(); ++i) {
96  std::cout << " [" << std::setw(2) << i << "] " << known[i] << std::endl;
97  }
98 }
99 
102  bool* boolptr)
103 {
104  // record new functions for creating processes
105  fFunctionMap[name] = foo;
106  fBoolPtrMap[name] = boolptr;
107  return true;
108 }
109 
110 } // namespace evgb
111 
intermediate_table::iterator iterator
static EvtTimeShiftFactory * fgTheInstance
bool IsKnownEvtTimeShift(const std::string &)
const std::vector< std::string > & AvailableEvtTimeShift() const
interface for event time distribution
Definition: EvtTimeShiftI.h:29
intermediate_table::const_iterator const_iterator
std::map< std::string, EvtTimeShiftICtorFuncPtr_t > fFunctionMap
bool RegisterCreator(std::string name, EvtTimeShiftICtorFuncPtr_t ctorptr, bool *ptr)
std::map< std::string, bool * > fBoolPtrMap
std::vector< std::string > listnames
A class for generating concrete EvtTimeShiftI derived classes based on the factory pattern...
static EvtTimeShiftFactory & Instance()
evgb::EvtTimeShiftI *(* EvtTimeShiftICtorFuncPtr_t)(const std::string &)
Physics generators for neutrinos, cosmic rays, and others.
Definition: CRYHelper.cxx:33
evgb::EvtTimeShiftI * GetEvtTimeShift(const std::string &name, const std::string &config="") const