Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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 return nullptr;
105 }
106
107 return (it->second)(job, title, dsi, option);
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// creates the method if needed based on the method name using the
112/// creator function the factory has stored
113
115 DataSetInfo& dsi,
116 const TString& weightfile )
117{
118 // additional options are passed to the creator function (the
119 // second method constructor)
120
121 CallMap::const_iterator it = fCalls.find(name);
122
123 // handle unknown algorithm request
124 if (it == fCalls.end()) {
125 std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
126 assert(0);
127 return nullptr;
128 }
129
130 return (it->second)("", "", dsi, weightfile);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// returns a vector of the method type names of registered methods
135
136const std::vector<std::string> TMVA::ClassifierFactory::List() const
137{
138 std::vector<std::string> svec;
139
140 CallMap::const_iterator it = fCalls.begin();
141 for (; it != fCalls.end(); ++it) svec.push_back(it -> first);
142
143 return svec;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// prints the registered method type names
148
150{
151 std::cout << "Print: ClassifierFactory<> knows about " << fCalls.size() << " objects" << std::endl;
152
153 CallMap::const_iterator it = fCalls.begin();
154 for (; it != fCalls.end(); ++it) std::cout << "Registered object name " << it -> first << std::endl;
155}
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
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:62
Interface for all concrete MVA method implementations.
Definition IMethod.h:53
Basic string class.
Definition TString.h:139