00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 #include "EvtDataOverlay/EvtTimeDistFactory.h" 00013 #include <iostream> 00014 00015 namespace simb { 00016 00017 // Define static variable which holds the one-and-only instance 00018 EvtTimeDistFactory* EvtTimeDistFactory::fgTheInstance; 00019 00020 EvtTimeDistFactory::EvtTimeDistFactory() 00021 { 00022 fgTheInstance = this; // record created self in static pointer 00023 } 00024 00025 EvtTimeDistFactory::~EvtTimeDistFactory() 00026 { 00027 fgTheInstance = 0; 00028 } 00029 00030 EvtTimeDistFactory& EvtTimeDistFactory::Instance() 00031 { 00032 // Cleaner dtor calls EvtTimeDistFactory dtor at job end 00033 static Cleaner cleaner; 00034 00035 if ( ! fgTheInstance ) { 00036 // need to create one 00037 cleaner.UseMe(); // dummy call to quiet compiler warnings 00038 fgTheInstance = new EvtTimeDistFactory(); 00039 } 00040 00041 return *fgTheInstance; 00042 } 00043 00044 simb::EvtTimeDistI* 00045 EvtTimeDistFactory::GetEvtTimeDist(const std::string& name, 00046 const std::string& config) 00047 { 00048 simb::EvtTimeDistI* p = 0; 00049 00050 // we don't want map creating an entry if it doesn't exist 00051 // so use map::find() not map::operator[] 00052 std::map<std::string, EvtTimeDistICtorFuncPtr_t>::iterator itr 00053 = fFunctionMap.find(name); 00054 if ( fFunctionMap.end() != itr ) { 00055 // found an appropriate entry in the list 00056 EvtTimeDistICtorFuncPtr_t foo = itr->second; // this is the function 00057 p = (*foo)(config); // use function to create the EvtTimeDistI 00058 } 00059 if ( ! p ) { 00060 std::cerr << "### EvtTimeDistFactory WARNING: " 00061 << "EvtTimeDistI " << name << " is not known" << std::endl; 00062 } 00063 return p; 00064 } 00065 00066 bool EvtTimeDistFactory::IsKnownEvtTimeDist(const std::string& name) 00067 { 00068 // check if we know the name 00069 bool res = false; 00070 std::map<std::string, EvtTimeDistICtorFuncPtr_t>::iterator itr 00071 = fFunctionMap.find(name); 00072 if ( fFunctionMap.end() != itr ) res = true; 00073 return res; 00074 } 00075 00076 const std::vector<std::string>& 00077 EvtTimeDistFactory::AvailableEvtTimeDist() const 00078 { 00079 // list of names might be out of date due to new registrations 00080 // rescan the std::map on each call (which won't be frequent) 00081 listnames.clear(); 00082 00083 // scan map for registered names 00084 std::map<std::string, EvtTimeDistICtorFuncPtr_t>::const_iterator itr; 00085 for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr ) 00086 listnames.push_back(itr->first); 00087 00088 return listnames; 00089 } 00090 00091 bool EvtTimeDistFactory::RegisterCreator(std::string name, 00092 EvtTimeDistICtorFuncPtr_t foo, 00093 bool* boolptr) 00094 { 00095 // record new functions for creating processes 00096 fFunctionMap[name] = foo; 00097 fBoolPtrMap[name] = boolptr; 00098 return true; 00099 } 00100 00101 } // namespace simb 00102