GENIEGenerator
Loading...
Searching...
No Matches
GFluxDriverFactory.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
12
14#include <iostream>
15#include <iomanip>
16
17namespace genie {
18namespace flux {
19
20// Define static variable which holds the one-and-only instance
22
24{
25 fgTheInstance = this; // record created self in static pointer
26}
27
32
34{
35 // Cleaner dtor calls GFluxDriverFactory dtor at job end
36 static Cleaner cleaner;
37
38 if ( ! fgTheInstance ) {
39 // need to create one
40 cleaner.UseMe(); // dummy call to quiet compiler warnings
42 }
43
44 return *fgTheInstance;
45}
46
47GFluxI*
48GFluxDriverFactory::GetFluxDriver(const std::string& name)
49{
50 GFluxI* p = 0;
51
52 // we don't want map creating an entry if it doesn't exist
53 // so use map::find() not map::operator[]
54 std::map<std::string, GFluxICtorFuncPtr_t>::iterator itr
55 = fFunctionMap.find(name);
56 if ( fFunctionMap.end() != itr ) {
57 // found an appropriate entry in the list
58 GFluxICtorFuncPtr_t foo = itr->second; // this is the function
59 p = (*foo)(); // use function to create the GFluxI
60 }
61 if ( ! p ) {
62 LOG("Flux",pWARN) << "### GFluxDriverFactory WARNING: "
63 << "GFluxI " << name << " is not known";
64 }
65 return p;
66}
67
68bool GFluxDriverFactory::IsKnownFluxDriver(const std::string& name)
69{
70 // check if we know the name
71 bool res = false;
72 std::map<std::string, GFluxICtorFuncPtr_t>::iterator itr
73 = fFunctionMap.find(name);
74 if ( fFunctionMap.end() != itr ) res = true;
75 return res;
76}
77
78const std::vector<std::string>&
80{
81 // list of names might be out of date due to new registrations
82 // rescan the std::map on each call (which won't be frequent)
83 listnames.clear();
84
85 // scan map for registered names
86 std::map<std::string, GFluxICtorFuncPtr_t>::const_iterator itr;
87 for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
88 listnames.push_back(itr->first);
89
90 return listnames;
91}
92
95 bool* boolptr)
96{
97 // record new functions for creating processes
98 fFunctionMap[name] = foo;
99 fBoolPtrMap[name] = boolptr;
100 return true;
101}
102
104{
105 const std::vector<std::string>& avail = AvailableFluxDrivers();
106 size_t n = avail.size();
107 std::cout << "GFluxDriverFactory has the following drivers registered:"
108 << std::endl;
109 for (size_t i=0; i<n; ++i) {
110 std::cout << " [" << std::setw(3) << i << "] "
111 << avail[i] << std::endl;
112 }
113}
114
115} // namespace flux
116} // 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
GENIE Interface for user-defined flux classes.
Definition GFluxI.h:29
A class for generating concrete GFluxI derived classes based on the factory pattern....
bool IsKnownFluxDriver(const std::string &)
std::vector< std::string > listnames
bool RegisterCreator(std::string name, GFluxICtorFuncPtr_t ctorptr, bool *ptr)
const std::vector< std::string > & AvailableFluxDrivers() const
genie::GFluxI * GetFluxDriver(const std::string &)
static GFluxDriverFactory & Instance()
std::map< std::string, GFluxICtorFuncPtr_t > fFunctionMap
static GFluxDriverFactory * fgTheInstance
std::map< std::string, bool * > fBoolPtrMap
GENIE flux drivers.
genie::GFluxI *(* GFluxICtorFuncPtr_t)()
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25