• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/Users/jmonk/Physics/ForIA/src/AnalysisFactory.cxx

Go to the documentation of this file.
00001 #include "ForIA/AnalysisFactory.hh"
00002 #include "ForIA/binreloc.h"
00003 
00004 #include <sstream>
00005 #include <dlfcn.h>
00006 #include <stdexcept>
00007 
00008 namespace ForIA{
00009    
00010   using std::stringstream;
00011   
00012   AnalysisFactory::AnalysisFactory(){
00013     
00014   }
00015   
00016   AnalysisPtr AnalysisFactory::createAnalysis(const string &name, 
00017                                               IHistogrammer *histogrammer)const{
00018     map<string, const ICreator*>::const_iterator it = s_creators().find(name);
00019     
00020     if(it == s_creators().end()){
00021       throw std::runtime_error("AnalysisFactory::createAnalysis: Analysis " + name + " is not available!");
00022     }else{
00023       std::cout<<"Creating analysis "<<name<<std::endl;
00024     }
00025     return it->second->create(histogrammer);
00026   }
00027  
00028   vector<string> AnalysisFactory::listAnalyses()const{
00029     vector<string> names;
00030     
00031     for(map<string, const ICreator*>::const_iterator name = s_creators().begin();
00032         name != s_creators().end(); ++name){
00033       names.push_back(name->first);
00034     }
00035     return names;
00036   }
00037   
00038   map<string, const AnalysisFactory::ICreator*> &AnalysisFactory::s_creators(){
00039     static map<string, const AnalysisFactory::ICreator*> creators;
00040     return creators;
00041   }
00042   
00043   void AnalysisFactory::addCreator(const ICreator *creator){
00044    
00045     AnalysisPtr tmp = creator->create(0);
00046     string name = tmp->name();
00047     std::cout<<"adding "<<name<<std::endl;
00048     
00049     s_creators().insert(std::make_pair(name, creator));
00050     return;
00051   }
00052   
00053   void AnalysisFactory::loadAnalysisLibrary(const string &libName){
00054    
00055     string soName;
00056     
00057     if(libName.find(".so") == string::npos){
00058       soName = "ForIA" + libName + ".so";
00059     }else{
00060       soName = libName; 
00061     }
00062     
00063     char *envPath=0;
00064     envPath = getenv("FORIA_LIB_PATH");
00065     
00066     string path;
00067     
00068     if(envPath){
00069       path = envPath;
00070     }else{
00071       BrInitError brError;
00072       br_init_lib(&brError);
00073       path = br_find_data_dir(DEFAULTLIBDIR);
00074     }
00075     
00076     path = path + "/" + soName;
00077     
00078     void *ptr = dlopen(path.c_str(), RTLD_LAZY);
00079     
00080     if(ptr == 0){
00081       string msg = "AnalysisFactory::loadAnalysisLibrary: Unable to open library: " + path;
00082       throw std::runtime_error(msg);
00083     }
00084     
00085     return;
00086   }
00087   
00088   void AnalysisFactory::loadAnalysisLibraries(const vector<string> &libList){
00089     
00090     for(vector<string>::const_iterator lib = libList.begin();
00091         lib != libList.end(); ++lib){
00092       loadAnalysisLibrary(*lib);
00093     }
00094     return;
00095   }
00096   
00097   void AnalysisFactory::loadAnalysisLibraries(const string &libList){
00098    
00099     stringstream ss(libList);
00100     string lib;
00101     
00102     while(getline(ss, lib, *(","))){
00103       loadAnalysisLibrary(lib);
00104     }
00105     
00106     return;
00107   }
00108   
00109   
00110 }

Generated on Mon Jul 30 2012 16:56:35 for ForIA by  doxygen 1.7.2