Logo ROOT  
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/*! \class TMVA::CreateMethodPlugins
34\ingroup TMVA
35
36Plugins analysis
37
38The MethodPlugins is actually not a real method, but it is just a wrapper to call
39the TPluginsManager of ROOT and find a external method which can be used to extend
40TMVA by another classifier. The only methods which are actually really implemented
41are the constructors which fulfill the plugins handling. The others will produce
42FATAL warnings and stop TMVA execution.
43
44Right after the constructor, the additional method 'getPlugedinMethod()' is called,
45which returns the method loaded by the plugin manager, and the MethodPlugins object
46is already deleted.
47
48*/
49
50#include "TPluginManager.h"
51#include "TROOT.h"
52
54#include "TMVA/Ranking.h"
55#include "TMVA/Tools.h"
56#include "TMVA/Types.h"
57
58#include <cstdio>
59#include <iostream>
60
61namespace
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() {
104 }
105 } instance;
106}
107
#define gROOT
Definition: TROOT.h:404
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
Bool_t Register(const std::string &name, Creator creator)
registers a classifier creator function under the method type name
Plugins analysis.
Class that contains all the data information.
Definition: DataSetInfo.h:62
Interface for all concrete MVA method implementations.
Definition: IMethod.h:53
static Types & Instance()
The single instance of "Types" if existing already, or create it (Singleton)
Definition: Types.cxx:70
Bool_t AddTypeMapping(Types::EMVA method, const TString &methodname)
Definition: Types.cxx:101
@ kPlugins
Definition: Types.h:96
Longptr_t ExecPlugin(int nargs, const T &... params)
Int_t LoadPlugin()
Load the plugin library for this handler.
This class implements a plugin library manager.
TPluginHandler * FindHandler(const char *base, const char *uri=nullptr)
Returns the handler if there exists a handler for the specified URI.
Basic string class.
Definition: TString.h:136
TString Copy() const
Copy a string.
Definition: TString.cxx:519
Ssiz_t Length() const
Definition: TString.h:410
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:528
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:921
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
static Roo_reg_AGKInteg1D instance