Logo ROOT  
Reference Guide
ClassifierFactory.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 : Factory *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Joerg Stelzer <stelzer@cern.ch> - DESY, Germany *
15 * *
16 * Copyright (c) 2008: *
17 * DESY, Germany *
18 * *
19 * Redistribution and use in source and binary forms, with or without *
20 * modification, are permitted according to the terms listed in LICENSE *
21 * (http://tmva.sourceforge.net/LICENSE) *
22 **********************************************************************************/
23
24/*! \class TMVA::ClassifierFactory
25\ingroup TMVA
26This is the MVA factory.
27*/
28
30
31#include "RtypesCore.h"
32#include "TString.h"
33
34#include <assert.h>
35#include <iostream>
36
37class TString;
38
39///
40/// Initialize static singleton pointer
41///
43
44////////////////////////////////////////////////////////////////////////////////
45/// access to the ClassifierFactory singleton
46/// creates the instance if needed
47
49{
51
52 return *fgInstance;
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// destroy the singleton instance
57
59{
60 if (fgInstance!=0) delete fgInstance;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// registers a classifier creator function under the method type name
65
66Bool_t TMVA::ClassifierFactory::Register( const std::string &name, Creator creator )
67{
68 if(fCalls.find(name) != fCalls.end())
69 {
70 std::cerr << "ClassifierFactory<>::Register - " << name << " already exists" << std::endl;
71 return false;
72 }
73
74 return fCalls.insert(CallMap::value_type(name, creator)).second;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// unregisters a classifier type name
79
81{
82 return fCalls.erase(name) == 1;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// creates the method if needed based on the method name using the
87/// creator function the factory has stored
88
90 const TString& job,
91 const TString& title,
92 DataSetInfo& dsi,
93 const TString& option )
94{
95 // additional options are passed to the creator function (the
96 // method constructor)
97
98 CallMap::const_iterator it = fCalls.find(name);
99
100 // handle unknown algorithm request
101 if (it == fCalls.end()) {
102 std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
103 assert(0);
104 }
105
106 return (it->second)(job, title, dsi, option);
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// creates the method if needed based on the method name using the
111/// creator function the factory has stored
112
114 DataSetInfo& dsi,
115 const TString& weightfile )
116{
117 // additional options are passed to the creator function (the
118 // second method constructor)
119
120 CallMap::const_iterator it = fCalls.find(name);
121
122 // handle unknown algorithm request
123 if (it == fCalls.end()) {
124 std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
125 assert(0);
126 }
127
128 return (it->second)("", "", dsi, weightfile);
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// returns a vector of the method type names of registered methods
133
134const std::vector<std::string> TMVA::ClassifierFactory::List() const
135{
136 std::vector<std::string> svec;
137
138 CallMap::const_iterator it = fCalls.begin();
139 for (; it != fCalls.end(); ++it) svec.push_back(it -> first);
140
141 return svec;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// prints the registered method type names
146
148{
149 std::cout << "Print: ClassifierFactory<> knows about " << fCalls.size() << " objects" << std::endl;
150
151 CallMap::const_iterator it = fCalls.begin();
152 for (; it != fCalls.end(); ++it) std::cout << "Registered object name " << it -> first << std::endl;
153}
bool Bool_t
Definition: RtypesCore.h:59
char name[80]
Definition: TGX11.cxx:109
This is the MVA factory.
IMethod * Create(const std::string &name, const TString &job, const TString &title, DataSetInfo &dsi, const TString &option)
creates the method if needed based on the method name using the creator function the factory has stor...
static ClassifierFactory * fgInstance
Initialize static singleton pointer.
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
static void DestroyInstance()
destroy the singleton instance
Bool_t Unregister(const std::string &name)
unregisters a classifier type name
void Print() const
prints the registered method type names
const std::vector< std::string > List() const
returns a vector of the method type names of registered methods
Bool_t Register(const std::string &name, Creator creator)
registers a classifier creator function under the method type name
Class that contains all the data information.
Definition: DataSetInfo.h:60
Interface for all concrete MVA method implementations.
Definition: IMethod.h:54
Basic string class.
Definition: TString.h:131
Definition: first.py:1