00001 #include "EventKinematics/EvtKinFactory.h"
00002 #include "EventKinematics/MsgServiceWrapper.h"
00003
00004 #include "EventKinematics/FluxGenerator.h"
00005 #include "EventKinematics/FlavorModifier.h"
00006 #include "EventKinematics/InteractionGenerator.h"
00007
00008 #include <cassert>
00009
00010 CVSID("$Id: EvtKinFactory.cxx,v 1.2 2006/06/06 05:06:26 rhatcher Exp $");
00011
00013 EvtKinFactory* EvtKinFactory::fInstance = 0;
00014
00015
00016
00019 EvtKinFactory& EvtKinFactory::Instance()
00020 {
00021 MSG("EvtKin",Msg::kVerbose)
00022 << "EvtKinFactory::Instance()" << endl;
00023 if ( !fInstance ) fInstance = new EvtKinFactory;
00024 return *fInstance;
00025 }
00026
00027
00028
00031 bool EvtKinFactory::RegisterFlux(const std::string& fluxname,
00032 FluxCreator creator)
00033 {
00034 MSG("EvtKin",Msg::kDebug)
00035 << "EvtKinFactory::RegisterFlux()" << fluxname << endl;
00036
00037 return fFluxCallbacks.insert(CallbackMapFlux::value_type(fluxname,creator)).second;
00038 }
00039
00040 bool EvtKinFactory::RegisterFlavor(const std::string& flavorname,
00041 FlavorCreator creator)
00042 {
00043 MSG("EvtKin",Msg::kDebug)
00044 << "EvtKinFactory::RegisterFlavor()" << flavorname << endl;
00045
00046 return fFlavorCallbacks.insert(CallbackMapFlavor::value_type(flavorname,creator)).second;
00047 }
00048
00049 bool EvtKinFactory::RegisterInteraction(const std::string& intername,
00050 InteractionCreator creator)
00051 {
00052 MSG("EvtKin",Msg::kDebug)
00053 << "EvtKinFactory::RegisterInteractor()" << intername << endl;
00054
00055 return fInteractionCallbacks.insert(CallbackMapInteraction::value_type(intername,creator)).second;
00056 }
00057
00058
00059
00062 bool EvtKinFactory::UnregisterFlux(const std::string& fluxname)
00063 {
00064 MSG("EvtKin",Msg::kDebug)
00065 << "EvtKinFactory::UnregisterFlux()" << fluxname << endl;
00066
00067 return fFluxCallbacks.erase(fluxname) == 1;
00068 }
00069
00070 bool EvtKinFactory::UnregisterFlavor(const std::string& flavorname)
00071 {
00072 MSG("EvtKin",Msg::kDebug)
00073 << "EvtKinFactory::UnregisterFlavor()" << flavorname << endl;
00074
00075 return fFlavorCallbacks.erase(flavorname) == 1;
00076 }
00077
00078 bool EvtKinFactory::UnregisterInteraction(const std::string& intername)
00079 {
00080 MSG("EvtKin",Msg::kDebug)
00081 << "EvtKinFactory::UnregisterInteractor()" << intername << endl;
00082
00083 return fInteractionCallbacks.erase(intername) == 1;
00084 }
00085
00086
00087
00090 FluxGenerator* EvtKinFactory::CreateFluxGenerator(const std::string& fluxname)
00091 {
00092 MSG("EvtKin",Msg::kDebug)
00093 << "EvtKinFactory::CreateFluxGenerator() " << fluxname << endl;
00094
00095 CallbackMapFlux::const_iterator i = fFluxCallbacks.find(fluxname);
00096
00097
00098 if (i == fFluxCallbacks.end()) {
00099 MSG("EvtKin",Msg::kDebug)
00100 << "Unknown FluxGenerator: " << fluxname << endl;
00101 return 0;
00102 }
00103
00104
00105 return (i->second)();
00106 }
00107
00108 FlavorModifier* EvtKinFactory::CreateFlavorModifier(const std::string& flavorname)
00109 {
00110 MSG("EvtKin",Msg::kDebug)
00111 << "EvtKinFactory::CreateFlavorModifier() " << flavorname << endl;
00112
00113 CallbackMapFlavor::const_iterator i = fFlavorCallbacks.find(flavorname);
00114
00115
00116 if (i == fFlavorCallbacks.end()) {
00117 MSG("EvtKin",Msg::kDebug)
00118 << "Unknown FlavorModifier: " << flavorname << endl;
00119 return 0;
00120 }
00121
00122
00123 return (i->second)();
00124 }
00125
00126 InteractionGenerator* EvtKinFactory::CreateInteractionGenerator(const std::string& intername)
00127 {
00128 MSG("EvtKin",Msg::kDebug)
00129 << "EvtKinFactory::CreateInteractionGenerator() " << intername << endl;
00130
00131 CallbackMapInteraction::const_iterator i = fInteractionCallbacks.find(intername);
00132
00133
00134 if (i == fInteractionCallbacks.end()) {
00135 MSG("EvtKin",Msg::kDebug)
00136 << "Unknown InteractionGenerator: " << intername << endl;
00137 return 0;
00138 }
00139
00140
00141 return (i->second)();
00142 }
00143
00144
00145
00146 void EvtKinFactory::Print(Option_t* option) const
00147 {
00148 MSG("EvtKin",Msg::kInfo)
00149 << "EvtKinFactory::Print(\"" << option << "\"):" << endl << endl;
00150
00151 MSG("EvtKin",Msg::kInfo)
00152 << " FluxGenerators:" << endl;
00153 int nf = 0;
00154 CallbackMapFlux::const_iterator fitr = fFluxCallbacks.begin();
00155 while ( fitr != fFluxCallbacks.end() ) {
00156 MSG("EvtKin",Msg::kInfo)
00157 << " [" << nf++ << "] "
00158 << fitr->first
00159 << endl;
00160 fitr++;
00161 }
00162 MSG("EvtKin",Msg::kInfo) << endl;
00163
00164 MSG("EvtKin",Msg::kInfo)
00165 << " FlavorModifiers:" << endl;
00166 int nm = 0;
00167 CallbackMapFlavor::const_iterator mitr = fFlavorCallbacks.begin();
00168 while ( mitr != fFlavorCallbacks.end() ) {
00169 MSG("EvtKin",Msg::kInfo)
00170 << " [" << nm++ << "] "
00171 << mitr->first
00172 << endl;
00173 mitr++;
00174 }
00175 MSG("EvtKin",Msg::kInfo) << endl;
00176
00177 MSG("EvtKin",Msg::kInfo)
00178 << " InteractionGenerators:" << endl;
00179 int ni = 0;
00180 CallbackMapInteraction::const_iterator iitr = fInteractionCallbacks.begin();
00181 while ( iitr != fInteractionCallbacks.end() ) {
00182 MSG("EvtKin",Msg::kInfo)
00183 << " [" << ni++ << "] "
00184 << iitr->first
00185 << endl;
00186 iitr++;
00187 }
00188 MSG("EvtKin",Msg::kInfo) << endl;
00189
00190 }
00191
00192
00193
00195 EvtKinFactory::EvtKinFactory() { }
00196 EvtKinFactory::EvtKinFactory(const EvtKinFactory&) { }
00197
00198