Logo ROOT   6.08/07
Reference Guide
MethodPlugins.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate Data analysis *
6  * Package: TMVA *
7  * Class : TMVA::MethodPlugins *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <stelzer@cern.ch> - DESY, Germany *
16  * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland *
17  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
19  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
20  * Daniel Martscheit <martschei@ekp.uni-karlsruhe.de> -KIT Karlsruhe, Ger. *
21  * *
22  * Copyright (c) 2005-2011: *
23  * CERN, Switzerland *
24  * U. of Victoria, Canada *
25  * MPI-K Heidelberg, Germany *
26  * U. of Bonn, Germany *
27  * *
28  * Redistribution and use in source and binary forms, with or without *
29  * modification, are permitted according to the terms listed in LICENSE *
30  * (http://tmva.sourceforge.net/LICENSE) *
31  **********************************************************************************/
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 /* Begin_Html
36 
37  Plugins analysis
38 
39  <p>
40  The MethodPlugins is actually not a real method, but it is just a wrapper to call the TPluginsManager of ROOT and find
41  a external method which can be used to extend TMVA by another classifier. The only methods which are actually really implemented are the
42  constructors which fulfill the plugins handling. The others will produce FATAL warnings and stop TMVA execution.
43  <p>
44  Right after the constructor, the additional method 'getPlugedinMethod()' is called, which returns the method loaded by the plugin manager,
45  and the MethodPlugins object is already deleted.
46 
47  End_Html */
48 //_______________________________________________________________________
49 
50 #include "TPluginManager.h"
51 #include "TROOT.h"
52 
53 #include "TMVA/ClassifierFactory.h"
54 #include "TMVA/Ranking.h"
55 #include "TMVA/Tools.h"
56 #include "TMVA/Types.h"
57 
58 #include <cstdio>
59 #include <iostream>
60 
61 namespace
62 {
63  TMVA::IMethod* CreateMethodPlugins(const TString& jobName, const TString& methodTitle, TMVA::DataSetInfo& theData, const TString& theOption)
64  {
65  //std::cout << "CreateMethodPlugins is called with options : '" << jobName << "', '" << methodTitle<< "', " << theOption<< "'" << std::endl;
66  TPluginManager *pluginManager(0);
67  TPluginHandler *pluginHandler(0);
68  pluginManager = gROOT->GetPluginManager();
69  //An empty methodTitle is a Problem for the PluginHandler, so we need to fiddle it out of the weightsfilename
70  TString myMethodTitle;
71  if(jobName=="" && methodTitle=="") { //This is most likely a call to the Classifier (not for training)
72  myMethodTitle = theOption.Copy();
73  Ssiz_t firstUnderscore = myMethodTitle.First('_');
74  Ssiz_t firstPoint = myMethodTitle.Last('.');
75  myMethodTitle.Remove(firstPoint,myMethodTitle.Length() - firstPoint);
76  myMethodTitle.Remove(0,firstUnderscore-1); //leave the underscore
77  }
78  else myMethodTitle = methodTitle;
79  pluginHandler = pluginManager->FindHandler("TMVA@@MethodBase", myMethodTitle);
80  if(!pluginHandler)
81  {
82  std::cerr << "Couldn't find plugin handler for TMVA@@MethodBase and " << methodTitle << std::endl;
83  return 0;
84  }
85  //std::cout << "pluginHandler found myMethodTitle=" << myMethodTitle<<std::endl;
86  if (pluginHandler->LoadPlugin() == 0) {
87  if(jobName=="" && methodTitle=="") {
88  //std::cout << "Calling ExpertPlugin " << std::endl;
89  return (TMVA::IMethod*) pluginHandler->ExecPlugin(2, &theData, &theOption);
90  } else {
91  //std::cout << "Calling TeacherPlugin " << std::endl;
92  // pluginHandler->Print("a");
93  return (TMVA::IMethod*) pluginHandler->ExecPlugin(4, &jobName, &methodTitle, &theData, &theOption);
94  }
95  }
96  //std::cout << "plugin done" << std::endl;
97  return 0; // end of function should never be reached. This is here to silence the compiler
98  }
99 
100  struct registration {
101  registration() {
102  TMVA::ClassifierFactory::Instance().Register("Plugins", CreateMethodPlugins);
104  }
105  } instance;
106 }
107 
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
static Types & Instance()
the the single instance of "Types" if existin already, or create it (Signleton)
Definition: Types.cxx:64
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
TString Copy() const
Copy a string.
Definition: TString.cxx:458
Bool_t AddTypeMapping(Types::EMVA method, const TString &methodname)
Definition: Types.cxx:95
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:467
Ssiz_t Length() const
Definition: TString.h:390
This class implements a plugin library manager.
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
int Ssiz_t
Definition: RtypesCore.h:63
Bool_t Register(const std::string &name, Creator creator)
registers a classifier creator function under the method type name
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:865