Logo ROOT   6.08/07
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 //_______________________________________________________________________
25 //
26 // This is the MVA factory
27 //_______________________________________________________________________
28 
29 
30 #include "TMVA/ClassifierFactory.h"
31 
32 #include "RtypesCore.h"
33 #include "TString.h"
34 
35 #include <assert.h>
36 #include <iostream>
37 
38 class TString;
39 
40 ///
41 /// Initialize static singleton pointer
42 ///
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// access to the ClassifierFactory singleton
47 /// creates the instance if needed
48 
50 {
52 
53  return *fgInstance;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// destroy the singleton instance
58 
60 {
61  if (fgInstance!=0) delete fgInstance;
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// registers a classifier creator function under the method type name
66 
67 Bool_t TMVA::ClassifierFactory::Register( const std::string &name, Creator creator )
68 {
69  if(fCalls.find(name) != fCalls.end())
70  {
71  std::cerr << "ClassifierFactory<>::Register - " << name << " already exists" << std::endl;
72  return false;
73  }
74 
75  return fCalls.insert(CallMap::value_type(name, creator)).second;
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// unregisters a classifier type name
80 
82 {
83  return fCalls.erase(name) == 1;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// creates the method if needed based on the method name using the
88 /// creator function the factory has stored
89 
91  const TString& job,
92  const TString& title,
93  DataSetInfo& dsi,
94  const TString& option )
95 {
96  // additional options are passed to the creator function (the
97  // method constructor)
98 
99  CallMap::const_iterator it = fCalls.find(name);
100 
101  // handle unknown algorithm request
102  if (it == fCalls.end()) {
103  std::cerr << "ClassifierFactory<>::Create - don't know anything about " << name << std::endl;
104  assert(0);
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  }
128 
129  return (it->second)("", "", dsi, weightfile);
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// returns a vector of the method type names of registered methods
134 
135 const std::vector<std::string> TMVA::ClassifierFactory::List() const
136 {
137  std::vector<std::string> svec;
138 
139  CallMap::const_iterator it = fCalls.begin();
140  for (; it != fCalls.end(); ++it) svec.push_back(it -> first);
141 
142  return svec;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// prints the registered method type names
147 
149 {
150  std::cout << "Print: ClassifierFactory<> knows about " << fCalls.size() << " objects" << std::endl;
151 
152  CallMap::const_iterator it = fCalls.begin();
153  for (; it != fCalls.end(); ++it) std::cout << "Registered object name " << it -> first << std::endl;
154 }
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 & Instance()
access to the ClassifierFactory singleton creates the instance if needed
const std::vector< std::string > List() const
returns a vector of the method type names of registered methods
static ClassifierFactory * fgInstance
Initialize static singleton pointer.
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
IMethod *(* Creator)(const TString &job, const TString &title, DataSetInfo &dsi, const TString &option)
static void DestroyInstance()
destroy the singleton instance
void Print() const
prints the registered method type names
Bool_t Unregister(const std::string &name)
unregisters a classifier type name
Bool_t Register(const std::string &name, Creator creator)
registers a classifier creator function under the method type name
Definition: first.py:1
char name[80]
Definition: TGX11.cxx:109