AnalysisAlgorithmMap.cpp

00001 #include "AnalysisAlgorithmMap.h"
00002 #include "AnalysisAlgorithm.h"
00003 #include "CalibrationController/IS/TestData.h"
00004 #include <sstream>
00005 
00006 using namespace std;
00007 
00008 namespace SctAnalysis {
00009 
00010 typedef map<string, shared_ptr<AnalysisAlgorithm> > MapType;
00011     
00012 AnalysisAlgorithmMap& AnalysisAlgorithmMap::instance() {
00013     static AnalysisAlgorithmMap* instance = new AnalysisAlgorithmMap();
00014     return *instance;
00015 }
00016     
00017 shared_ptr <AnalysisAlgorithm> AnalysisAlgorithmMap::getAlgorithm(shared_ptr<const TestData> testData, const string& moduleName) const throw(Sct::InvalidArgument) {
00018   if (!testData.get()) throw Sct::InvalidArgumentError("Attempt to use null TestData",__FILE__,__LINE__);
00019     string nameToUse = testData->testName;
00020     if (nameToUse=="NONE") {
00021       shared_ptr<AnalysisAlgorithm> alg;
00022       return alg;
00023     }
00024 
00025     if (testData->analysisAlgorithm!=""){
00026       nameToUse=testData->analysisAlgorithm;
00027     }
00028 
00029     if (algMap.count(nameToUse) == 0) {
00030     Sct::InvalidArgumentError iae("No map for Test: " + nameToUse, __FILE__, __LINE__);
00031     iae.setSeverity(MRS_DIAGNOSTIC);
00032     throw iae;
00033     }
00034     
00035     return (*algMap.find(nameToUse)).second->clone(testData, moduleName);
00036 }
00037     
00038 bool AnalysisAlgorithmMap::setAlgorithm(const string testName, auto_ptr<AnalysisAlgorithm> alg) throw() {
00039     algMap[testName] = shared_ptr<AnalysisAlgorithm>(alg);
00040     std::cout << "Have registered algorithm for test [" << testName << "]" << std::endl;
00041     return true;    
00042 }
00043 
00044 string AnalysisAlgorithmMap::getStatus(string testName) {
00045     if (algMap.count(testName) == 0) {
00046     return string();
00047     }
00048     return algMap[testName]->getStatus();
00049 }
00050     
00051 string AnalysisAlgorithmMap::getAllStatus() {
00052     ostringstream status;
00053     for (MapType::const_iterator i=algMap.begin(); i!=algMap.end(); ++i) {
00054     status << i->first << " Algorithm " << i->second->getStatus() << "\n";
00055     }
00056     return status.str();
00057 }
00058 
00059 std::list<std::string> AnalysisAlgorithmMap::listAlgorithms(){
00060   std::list<std::string> alg_list;
00061   for (MapType::const_iterator i=algMap.begin(); i!=algMap.end(); ++i) {
00062     alg_list.push_back(i->first);
00063   }
00064   return alg_list;
00065 }
00066     
00067 }

Generated on Mon Feb 6 14:01:16 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6