00001 //_____________________________________________________________________________ 00017 00018 #include <iostream> 00019 #include <cassert> 00020 00021 #include "Rtypes.h" 00022 00023 #include "MessageService/MsgService.h" 00024 00025 #include "CandFitTrackSA/FitStateFactory.h" 00026 #include "CandFitTrackSA/TracerSA.h" 00027 00028 using std::map; 00029 using std::string; 00030 00031 CVSID("$Id: FitStateFactory.cxx,v 1.1 2006/02/04 07:14:12 avva Exp $"); 00032 00034 FitStateFactory* FitStateFactory::fInstance = 0; 00035 00038 FitStateFactory& FitStateFactory::Instance() 00039 { 00040 TracerSA trace("FitStateFactory::Instance()"); 00041 00042 if ( !fInstance ) fInstance = new FitStateFactory; 00043 return *fInstance; 00044 } // FitStateFactory& FitStateFactory::Instance() 00045 00046 00047 00050 bool FitStateFactory::RegisterFitState( 00051 const string& hbname, 00052 FSCreator creator) 00053 { 00054 TracerSA trace("FitStateFactory::RegisterFitState(string, FSCreator)"); 00055 00056 // map<>::insert(value_type) returns pair<iterator, bool> 00057 return fCallbacks.insert(CallbackMap::value_type(hbname, creator)).second; 00058 } // bool FitStateFactory::RegisterFitState(string, FSCreator) 00059 00060 00061 00064 bool FitStateFactory::UnregisterFitState(const string& hbname) 00065 { 00066 TracerSA trace("FitStateFactory::UnregisterFitState(string)"); 00067 00068 return fCallbacks.erase(hbname) == 1; 00069 } // bool FitStateFactory::UnregisterFitState(string) 00070 00071 00076 FitState* FitStateFactory::GetFitState(const string& fsname) 00077 { 00078 TracerSA trace("FitStateFactory::GetFitState(string)"); 00079 00080 // check if requested state already exists 00081 StateMap::const_iterator i = fFitStates.find(fsname); 00082 00083 // return state if exists 00084 if ( i != fFitStates.end() ) { 00085 return i->second; 00086 } 00087 00088 // create it if doesn't exist 00089 FitState* state = CreateFitState(fsname); 00090 if ( state ) { 00091 fFitStates[fsname] = state; 00092 return state; 00093 } 00094 00095 assert(kFALSE && "Unknown state requested!!"); 00096 } // FitState* FitStateFactory::GetFitState(string) 00097 00098 FitState* FitStateFactory::GetFitState(const char* fsname) 00099 { 00100 return GetFitState(std::string(fsname)); 00101 } 00102 00106 FitState* 00107 FitStateFactory::CreateFitState(const string& hbname) 00108 { 00109 TracerSA trace("FitStateFactory::CreateFitState(const string&)"); 00110 00111 // find fitter state creator callback 00112 CallbackMap::const_iterator i = fCallbacks.find(hbname); 00113 00114 // create if callback found 00115 if ( i != fCallbacks.end() ) { 00116 return (i->second)(); 00117 } 00118 00119 MSG("FitTrackSA",Msg::kError) 00120 << "Dont know anything about " << hbname << endl; 00121 return 0; 00122 } // FitState* FitStateFactory::CreateFitState(string) 00123 00124 00125 // ctor and copy-ctor are private 00126 FitStateFactory::FitStateFactory(){} 00127 FitStateFactory::FitStateFactory(const FitStateFactory&){} 00128 // FitStateFactory&FitStateFactory::operator=(constFitStateFactory&){} 00129 // FitStateFactory::~FitStateFactory(){}
1.3.9.1