Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ClassifierFactory.h
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 * This template creates ClassifierFactory stores creator functors *
12 * to template parameter class. ClassifierFactory is a singelton class *
13 * which is explicitly deleted. *
14 * *
15 * Authors (alphabetical): *
16 * Joerg Stelzer <stelzer@cern.ch> - DESY, Germany *
17 * *
18 * Copyright (c) 2008: *
19 * DESY, Germany *
20 * *
21 * Redistribution and use in source and binary forms, with or without *
22 * modification, are permitted according to the terms listed in LICENSE *
23 * (http://tmva.sourceforge.net/LICENSE) *
24 **********************************************************************************/
25
26#ifndef ROOT_TMVA_ClassifierFactory
27#define ROOT_TMVA_ClassifierFactory
28
29/////////////////////////////////////////////////////////////////
30//
31// Abstract ClassifierFactory template that handles arbitrary types
32//
33// This template creates ClassifierFactory stores creator functors
34// to template parameter class. ClassifierFactory is a singelton class
35// which is explicitly deleted.
36//
37// Source: Andrei Alexandrescu, Modern C++ Design
38//
39/////////////////////////////////////////////////////////////////
40
41// C++
42#include <map>
43#include <string>
44#include <vector>
45
46// Local
47#include "TString.h"
48
49
50namespace TMVA {
51
52 class IMethod;
53 class DataSetInfo;
54
56
57 public:
58
59 // typedef for functor that creates object of class IMethod
60 typedef IMethod* (*Creator)(const TString& job, const TString& title,
61 DataSetInfo& dsi, const TString& option );
62
63 public:
64
66 static void DestroyInstance();
67
68 Bool_t Register ( const std::string &name, Creator creator );
69 Bool_t Unregister( const std::string &name );
70
71 IMethod* Create ( const std::string &name,
72 const TString& job,
73 const TString& title,
74 DataSetInfo& dsi,
75 const TString& option );
76 IMethod* Create ( const std::string &name,
77 DataSetInfo& dsi,
78 const TString& weightfile ="" );
79
80 const std::vector<std::string> List() const;
81
82 void Print() const;
83
84 private:
85
86 // must use Instance() method to access/create ClassifierFactory
89
90 // ClassifierFactory is singleton and can not be copied
91 // These two methods are private and not defined by design
94
95 private:
96
98 typedef std::map<std::string, Creator> CallMap;
99
101 };
102}
103
104/////////////////////////////////////////////////////////////////
105///
106/// for example
107///
108/// REGISTER_METHOD(Fisher)
109///
110/// expands to this code:
111///
112/// namespace
113/// {
114/// TMVA::IMethod* CreateMethod()
115/// {
116/// return (TMVA::IMethod*) new TMVA::MethodFisher;
117/// }
118/// Bool_t RegisteredMethod = TMVA::ClassifierFactory<TMVA::MethodBase>::Instance().
119/// Register("Method", CreateMethodFisher);
120/// }
121///
122/////////////////////////////////////////////////////////////////
123
124#define REGISTER_METHOD(CLASS) \
125 namespace \
126 { \
127 struct RegisterTMVAMethod { \
128 static TMVA::IMethod* CreateMethod##CLASS(const TString& job, const TString& title, TMVA::DataSetInfo& dsi, const TString& option) \
129 { \
130 if(job=="" && title=="") { \
131 return (TMVA::IMethod*) new TMVA::Method##CLASS(dsi, option); \
132 } else { \
133 return (TMVA::IMethod*) new TMVA::Method##CLASS(job, title, dsi, option); \
134 } \
135 } \
136 RegisterTMVAMethod() { \
137 TMVA::ClassifierFactory::Instance(). Register(#CLASS, CreateMethod##CLASS); \
138 TMVA::Types::Instance().AddTypeMapping(TMVA::Types::k##CLASS, #CLASS); \
139 } \
140 }; \
141 static RegisterTMVAMethod RegisterTMVAMethod_instance; \
142 }
143
144
145#endif
146
147
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
std::map< std::string, Creator > CallMap
static void DestroyInstance()
destroy the singleton instance
IMethod *(* Creator)(const TString &job, const TString &title, DataSetInfo &dsi, const TString &option)
ClassifierFactory(const ClassifierFactory &)
Bool_t Unregister(const std::string &name)
unregisters a classifier type name
const ClassifierFactory & operator=(const ClassifierFactory &)
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
create variable transformations