ClassifierFactory.cxx

Go to the documentation of this file.
00001 // @(#)Root/tmva $Id: ClassifierFactory.cxx 33928 2010-06-15 16:19:31Z stelzer $   
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss 
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : Factory                                                               *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header for description)                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Joerg Stelzer   <stelzer@cern.ch>        - DESY, Germany                  *
00015  *                                                                                *
00016  * Copyright (c) 2008:                                                            *
00017  *      DESY, Germany                                                             * 
00018  *                                                                                *
00019  * Redistribution and use in source and binary forms, with or without             *
00020  * modification, are permitted according to the terms listed in LICENSE           *
00021  * (http://tmva.sourceforge.net/LICENSE)                                          *
00022  **********************************************************************************/
00023 
00024 //_______________________________________________________________________
00025 //                                                                      
00026 // This is the MVA factory
00027 //_______________________________________________________________________
00028 
00029 
00030 #include "TMVA/ClassifierFactory.h"
00031 #include <assert.h>
00032 #include <iostream>
00033 
00034 ///
00035 /// Initialize static singleton pointer
00036 ///
00037 TMVA::ClassifierFactory* TMVA::ClassifierFactory::fgInstance = 0;
00038 
00039 //_______________________________________________________________________
00040 TMVA::ClassifierFactory& TMVA::ClassifierFactory::Instance()
00041 {
00042    // access to the ClassifierFactory singleton
00043    // creates the instance if needed
00044 
00045    if (!fgInstance) fgInstance = new TMVA::ClassifierFactory();
00046 
00047    return *fgInstance;
00048 }
00049 
00050 //_______________________________________________________________________
00051 void TMVA::ClassifierFactory::DestroyInstance() 
00052 {
00053    // destroy the singleton instance
00054 
00055    if (fgInstance!=0) delete fgInstance;
00056 }
00057 
00058 //_______________________________________________________________________
00059 Bool_t TMVA::ClassifierFactory::Register( const std::string &name, Creator creator ) 
00060 { 
00061    // registers a classifier creator function under the method type name
00062 
00063    if(fCalls.find(name) != fCalls.end())
00064       {
00065          std::cerr << "ClassifierFactory<>::Register - " << name << " already exists" << std::endl;
00066          return false;
00067       }
00068 
00069    return fCalls.insert(CallMap::value_type(name, creator)).second;
00070 }
00071 
00072 //_______________________________________________________________________
00073 Bool_t TMVA::ClassifierFactory::Unregister( const std::string &name ) 
00074 { 
00075    // unregisters a classifier type name
00076 
00077    return fCalls.erase(name) == 1; 
00078 }
00079 
00080 //_______________________________________________________________________
00081 TMVA::IMethod* TMVA::ClassifierFactory::Create( const std::string &name,
00082                                                 const TString& job,
00083                                                 const TString& title,
00084                                                 DataSetInfo& dsi,
00085                                                 const TString& option ) 
00086 {
00087    // creates the method if needed based on the method name using the
00088    // creator function the factory has stored
00089 
00090    // additional options are passed to the creator function (the
00091    // method constructor)
00092 
00093    CallMap::const_iterator it = fCalls.find(name);
00094    
00095    // handle unknown algorithm request
00096    if (it == fCalls.end()) {
00097       std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
00098       assert(0);
00099    }
00100    
00101    return (it->second)(job, title, dsi, option);
00102 }
00103 
00104 //_______________________________________________________________________
00105 TMVA::IMethod* TMVA::ClassifierFactory::Create( const std::string &name,
00106                                                 DataSetInfo& dsi,
00107                                                 const TString& weightfile )
00108 {
00109    // creates the method if needed based on the method name using the
00110    // creator function the factory has stored
00111 
00112    // additional options are passed to the creator function (the
00113    // second method constructor)
00114 
00115    CallMap::const_iterator it = fCalls.find(name);
00116    
00117    // handle unknown algorithm request
00118    if (it == fCalls.end()) {
00119       std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
00120       assert(0);
00121    }
00122    
00123    return (it->second)("", "", dsi, weightfile);
00124 }
00125 
00126 //_______________________________________________________________________
00127 const std::vector<std::string> TMVA::ClassifierFactory::List() const
00128 {
00129    // returns a vector of the method type names of registered methods
00130    
00131    std::vector<std::string> svec;
00132 
00133    CallMap::const_iterator it = fCalls.begin();
00134    for (; it != fCalls.end(); ++it) svec.push_back(it -> first);
00135 
00136    return svec;
00137 }
00138 
00139 //_______________________________________________________________________
00140 void TMVA::ClassifierFactory::Print() const
00141 {
00142    // prints the registered method type names
00143 
00144    std::cout << "Print: ClassifierFactory<> knows about " << fCalls.size() << " objects" << std::endl;  
00145 
00146    CallMap::const_iterator it = fCalls.begin();
00147    for (; it != fCalls.end(); ++it) std::cout << "Registered object name " << it -> first << std::endl;
00148 }

Generated on Tue Jul 5 15:16:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1