Go to the documentation of this file.00001 #ifndef FORIA_ANALYSISFACTORY_HH
00002 #define FORIA_ANALYSISFACTORY_HH
00003
00004 #include "ForIA/IHistogrammer.hh"
00005 #include "ForIA/Analysis.hh"
00006
00007 #include <string>
00008 #include <map>
00009 #include <iostream>
00010
00011 namespace ForIA{
00012
00013 using std::string;
00014 using std::map;
00015
00017
00018 class AnalysisFactory {
00019
00020 public:
00021
00023 AnalysisFactory();
00024
00032 AnalysisPtr createAnalysis(const string &name, IHistogrammer *histogrammer)const;
00033
00039 vector<string> listAnalyses()const;
00040
00044 static void loadAnalysisLibrary(const string &libName);
00045
00049 static void loadAnalysisLibraries(const string &libList);
00050
00054 static void loadAnalysisLibraries(const vector<string> &libList);
00055
00056 private:
00057
00058 class ICreator{
00059
00060 public:
00061 virtual AnalysisPtr create(IHistogrammer *histogrammer) const = 0;
00062 virtual ~ICreator(){}
00063
00064 protected:
00065 void init(){
00066
00067 AnalysisFactory::s_creators()[name()] = this;
00068
00069 return;
00070 }
00071
00072 string name(){
00073 AnalysisPtr tmp = this->create(0);
00074 return tmp->name();
00075 }
00076 };
00077
00078 static void addCreator(const ICreator *creator);
00079
00080
00081 public:
00082
00083 template <class T>
00084 class Creator : public ICreator{
00085 public:
00086
00087 Creator(){
00088 this->init();
00089 }
00090
00091 ~Creator(){
00092 string n = name();
00093 if(s_creators()[n] == this){
00094 s_creators().erase(n);
00095 }
00096 }
00097
00098 AnalysisPtr create(IHistogrammer *histogrammer)const{
00099 return AnalysisPtr(new T(histogrammer));
00100 }
00101 };
00102
00103 private:
00104
00105 static map<string, const ICreator*> &s_creators();
00106
00107 };
00108 }
00109
00110
00111 #endif