Logo ROOT  
Reference Guide
Types.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : Types *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Implementation *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
17 * *
18 * Copyright (c) 2005: *
19 * CERN, Switzerland *
20 * U. of Victoria, Canada *
21 * MPI-K Heidelberg, Germany *
22 * *
23 * Redistribution and use in source and binary forms, with or without *
24 * modification, are permitted according to the terms listed in LICENSE *
25 * (http://mva.sourceforge.net/license.txt) *
26 **********************************************************************************/
27
28/*! \class TMVA::Types
29\ingroup TMVA
30Singleton class for Global types used by TMVA
31*/
32
33#include "TMVA/Types.h"
34
35#include "TMVA/MsgLogger.h"
36
37#include "RtypesCore.h"
38#include "TString.h"
39
40#include <map>
41#if __cplusplus > 199711L && !defined _MSC_VER
42#include <mutex>
43#endif
44
45#if __cplusplus > 199711L && !defined _MSC_VER
46std::atomic<TMVA::Types*> TMVA::Types::fgTypesPtr{0};
47static std::mutex gTypesMutex;
48#else
50#endif
51
52////////////////////////////////////////////////////////////////////////////////
53/// constructor
54
56 : fLogger( new MsgLogger("Types") )
57{
58}
59
61{
62 // destructor
63 delete fLogger;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// the the single instance of "Types" if existing already, or create it (Singleton)
68
70{
71#if __cplusplus > 199711L && !defined _MSC_VER
72 if(!fgTypesPtr) {
73 Types* tmp = new Types();
74 Types* expected = 0;
75 if(!fgTypesPtr.compare_exchange_strong(expected,tmp)) {
76 //Another thread already did it
77 delete tmp;
78 }
79 }
80 return *fgTypesPtr;
81#else
82 return fgTypesPtr ? *fgTypesPtr : *(fgTypesPtr = new Types());
83#endif
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// "destructor" of the single instance
88
90{
91#if __cplusplus > 199711L && !defined _MSC_VER
92 if (fgTypesPtr != 0) { delete fgTypesPtr.load(); fgTypesPtr = 0; }
93#else
94 if (fgTypesPtr != 0) { delete fgTypesPtr; fgTypesPtr = 0; }
95#endif
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
101{
102#if __cplusplus > 199711L && !defined _MSC_VER
103 std::lock_guard<std::mutex> guard(gTypesMutex);
104#endif
105 std::map<TString, EMVA>::const_iterator it = fStr2type.find( methodname );
106 if (it != fStr2type.end()) {
107 Log() << kFATAL
108 << "Cannot add method " << methodname
109 << " to the name->type map because it exists already" << Endl;
110 return kFALSE;
111 }
112
113 fStr2type[methodname] = method;
114 return kTRUE;
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// returns the method type (enum) for a given method (string)
119
121{
122#if __cplusplus > 199711L && !defined _MSC_VER
123 std::lock_guard<std::mutex> guard(gTypesMutex);
124#endif
125 std::map<TString, EMVA>::const_iterator it = fStr2type.find( method );
126 if (it == fStr2type.end()) {
127 Log() << kFATAL << "Unknown method in map: " << method << Endl;
128 return kVariable; // Inserted to get rid of GCC warning...
129 }
130 else return it->second;
131}
132
133////////////////////////////////////////////////////////////////////////////////
134
136{
137#if __cplusplus > 199711L && !defined _MSC_VER
138 std::lock_guard<std::mutex> guard(gTypesMutex);
139#endif
140 std::map<TString, EMVA>::const_iterator it = fStr2type.begin();
141 for (; it!=fStr2type.end(); ++it) if (it->second == method) return it->first;
142 Log() << kFATAL << "Unknown method index in map: " << method << Endl;
143 return "";
144}
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Singleton class for Global types used by TMVA.
Definition: Types.h:73
static void DestroyInstance()
"destructor" of the single instance
Definition: Types.cxx:89
TString GetMethodName(Types::EMVA method) const
Definition: Types.cxx:135
static Types & Instance()
the the single instance of "Types" if existing already, or create it (Singleton)
Definition: Types.cxx:69
Bool_t AddTypeMapping(Types::EMVA method, const TString &methodname)
Definition: Types.cxx:100
Types::EMVA GetMethodType(const TString &method) const
returns the method type (enum) for a given method (string)
Definition: Types.cxx:120
Types()
constructor
Definition: Types.cxx:55
static Types * fgTypesPtr
Definition: Types.h:177
@ kFATAL
Definition: Types.h:63
Basic string class.
Definition: TString.h:136
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Double_t Log(Double_t x)
Definition: TMath.h:760