00001 00029 #ifndef EVTKINFACTORY_H 00030 #define EVTKINFACTORY_H 00031 00032 #include "TObject.h" 00033 00034 #include <string> 00035 #include <map> 00036 00037 class FluxGenerator; 00038 class FlavorModifier; 00039 class InteractionGenerator; 00040 class TGeometry; 00041 00042 class EvtKinFactory { 00043 00044 public: 00046 typedef FluxGenerator* (*FluxCreator)(); 00047 typedef FlavorModifier* (*FlavorCreator)(); 00048 typedef InteractionGenerator* (*InteractionCreator)(); 00049 00050 private: 00052 typedef std::map<std::string, FluxCreator> CallbackMapFlux; 00053 typedef std::map<std::string, FlavorCreator> CallbackMapFlavor; 00054 typedef std::map<std::string, InteractionCreator> CallbackMapInteraction; 00055 00056 public: 00057 00058 // get reference to EvtKinFactory singleton 00059 static EvtKinFactory& Instance(); 00060 00062 bool RegisterFlux(const std::string& fluxname, FluxCreator creator); 00063 bool RegisterFlavor(const std::string& flavorname, FlavorCreator creator); 00064 bool RegisterInteraction(const std::string& intername, InteractionCreator creator); 00065 00067 bool UnregisterFlux(const std::string& fluxname); 00068 bool UnregisterFlavor(const std::string& flavorname); 00069 bool UnregisterInteraction(const std::string& intername); 00070 00072 FluxGenerator* CreateFluxGenerator(const std::string& fluxname); 00073 FlavorModifier* CreateFlavorModifier(const std::string& flavorname); 00074 InteractionGenerator* CreateInteractionGenerator(const std::string& intername); 00075 00077 void Print(Option_t* option = "") const; 00078 00079 private: 00080 static EvtKinFactory* fInstance; 00081 CallbackMapFlux fFluxCallbacks; 00082 CallbackMapFlavor fFlavorCallbacks; 00083 CallbackMapInteraction fInteractionCallbacks; 00084 00086 EvtKinFactory(); 00087 EvtKinFactory(const EvtKinFactory&); 00088 00089 }; 00090 00091 00092 #if !defined(__CINT__) || defined(__MAKECINT__) 00102 00103 #define REGISTERFLUX(CLASS) \ 00104 static const std::string FLUX_NAME = "" #CLASS ""; \ 00105 namespace { \ 00106 FluxGenerator* CreateFlux() { return new CLASS; } \ 00107 bool registered = EvtKinFactory::Instance(). \ 00108 RegisterFlux(FLUX_NAME, CreateFlux); \ 00109 } 00110 00111 #define REGISTERFLAVOR(CLASS) \ 00112 static const string FLAVOR_NAME = "" #CLASS ""; \ 00113 namespace { \ 00114 FlavorModifier* CreateFlavor() { return new CLASS; } \ 00115 bool registered = EvtKinFactory::Instance(). \ 00116 RegisterFlavor(FLAVOR_NAME, CreateFlavor); \ 00117 } 00118 00119 #define REGISTERINTERACTION(CLASS) \ 00120 static const std::string INTER_NAME = "" #CLASS ""; \ 00121 namespace { \ 00122 InteractionGenerator* CreateInteraction() { return new CLASS; } \ 00123 bool registered = EvtKinFactory::Instance(). \ 00124 RegisterInteraction(INTER_NAME, CreateInteraction); \ 00125 } 00126 #endif /* __CINT__ */ 00127 00128 #endif