GFlavorMixerFactory.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Robert Hatcher <rhatcher@fnal.gov>
7  Fermi National Accelerator Laboratory
8 */
9 //____________________________________________________________________________
10 
13 
14 namespace genie {
15 namespace flux {
16 
17 // Define static variable which holds the one-and-only instance
18 GFlavorMixerFactory* GFlavorMixerFactory::fgTheInstance;
19 
21 {
22  fgTheInstance = this; // record created self in static pointer
23 }
24 
26 {
27  fgTheInstance = 0;
28 }
29 
31 {
32  // Cleaner dtor calls GFlavorMixerFactory dtor at job end
33  static Cleaner cleaner;
34 
35  if ( ! fgTheInstance ) {
36  // need to create one
37  cleaner.UseMe(); // dummy call to quiet compiler warnings
39  }
40 
41  return *fgTheInstance;
42 }
43 
46 {
47  GFlavorMixerI* p = 0;
48 
49  // we don't want map creating an entry if it doesn't exist
50  // so use map::find() not map::operator[]
52  = fFunctionMap.find(name);
53  if ( fFunctionMap.end() != itr ) {
54  // found an appropriate entry in the list
55  GFlavorMixerICtorFuncPtr_t foo = itr->second; // this is the function
56  p = (*foo)(); // use function to create the GFlavorMixerI
57  }
58  if ( ! p ) {
59  LOG("Flux",pWARN) << "### GFlavorMixerFactory WARNING: "
60  << "GFlavorMixerI " << name << " is not known";
61  }
62  return p;
63 }
64 
66 {
67  // check if we know the name
68  bool res = false;
70  = fFunctionMap.find(name);
71  if ( fFunctionMap.end() != itr ) res = true;
72  return res;
73 }
74 
75 const std::vector<std::string>&
77 {
78  // list of names might be out of date due to new registrations
79  // rescan the std::map on each call (which won't be frequent)
80  listnames.clear();
81 
82  // scan map for registered names
84  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
85  listnames.push_back(itr->first);
86 
87  return listnames;
88 }
89 
92  bool* boolptr)
93 {
94  // record new functions for creating processes
95  fFunctionMap[name] = foo;
96  fBoolPtrMap[name] = boolptr;
97  return true;
98 }
99 
100 } // namespace flux
101 } // namespace genie
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
static GFlavorMixerFactory & Instance()
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
genie::flux::GFlavorMixerI *(* GFlavorMixerICtorFuncPtr_t)()
std::string string
Definition: nybbler.cc:12
static GFlavorMixerFactory * fgTheInstance
intermediate_table::const_iterator const_iterator
genie::flux::GFlavorMixerI * GetFlavorMixer(const std::string &)
std::vector< std::string > listnames
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
std::map< std::string, bool * > fBoolPtrMap
GENIE interface for flavor modification.
Definition: GFlavorMixerI.h:42
p
Definition: test.py:223
#define pWARN
Definition: Messenger.h:60
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
const std::vector< std::string > & AvailableFlavorMixers() const
bool IsKnownFlavorMixer(const std::string &)
A class for generating concrete GFlavorMixerI derived classes based on the factory pattern...
bool RegisterCreator(std::string name, GFlavorMixerICtorFuncPtr_t ctorptr, bool *ptr)