Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 /*! \class TMVA::CreateMethodPlugins
34 \ingroup TMVA
35 
36 Plugins analysis
37 
38 The MethodPlugins is actually not a real method, but it is just a wrapper to call
39 the TPluginsManager of ROOT and find a external method which can be used to extend
40 TMVA by another classifier. The only methods which are actually really implemented
41 are the constructors which fulfill the plugins handling. The others will produce
42 FATAL warnings and stop TMVA execution.
43 
44 Right after the constructor, the additional method 'getPlugedinMethod()' is called,
45 which returns the method loaded by the plugin manager, and the MethodPlugins object
46 is already deleted.
47 
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);
103  TMVA::Types::Instance().AddTypeMapping(TMVA::Types::kPlugins, "Plugins");
104  }
105  } instance;
106 }
107