GENIEGenerator
Loading...
Searching...
No Matches
GFlavorMixerFactory.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*!
3 Copyright (c) 2003-2025, 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
14namespace genie {
15namespace flux {
16
17// Define static variable which holds the one-and-only instance
19
21{
22 fgTheInstance = this; // record created self in static pointer
23}
24
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[]
51 std::map<std::string, GFlavorMixerICtorFuncPtr_t>::iterator itr
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
65bool GFlavorMixerFactory::IsKnownFlavorMixer(const std::string& name)
66{
67 // check if we know the name
68 bool res = false;
69 std::map<std::string, GFlavorMixerICtorFuncPtr_t>::iterator itr
70 = fFunctionMap.find(name);
71 if ( fFunctionMap.end() != itr ) res = true;
72 return res;
73}
74
75const 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
83 std::map<std::string, GFlavorMixerICtorFuncPtr_t>::const_iterator itr;
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
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
#define pWARN
Definition Messenger.h:60
A class for generating concrete GFlavorMixerI derived classes based on the factory pattern....
static GFlavorMixerFactory & Instance()
static GFlavorMixerFactory * fgTheInstance
genie::flux::GFlavorMixerI * GetFlavorMixer(const std::string &)
std::vector< std::string > listnames
bool RegisterCreator(std::string name, GFlavorMixerICtorFuncPtr_t ctorptr, bool *ptr)
std::map< std::string, bool * > fBoolPtrMap
const std::vector< std::string > & AvailableFlavorMixers() const
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
bool IsKnownFlavorMixer(const std::string &)
GENIE interface for flavor modification.
GENIE flux drivers.
genie::flux::GFlavorMixerI *(* GFlavorMixerICtorFuncPtr_t)()
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25