ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Results.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : Results *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * *
19  * Copyright (c) 2006: *
20  * CERN, Switzerland *
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://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #include "TMVA/Results.h"
29 
30 #include "TMVA/MsgLogger.h"
31 #include "TMVA/Types.h"
32 
33 #include "TH1.h"
34 #include "TH2.h"
35 #include "TGraph.h"
36 
37 #include <vector>
38 
39 namespace TMVA {
40  class DataSetInfo;
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// constructor
45 
46 TMVA::Results::Results( const DataSetInfo* dsi, TString resultsName )
47  : fTreeType(Types::kTraining),
48  fDsi(dsi),
49  fStorage( new TList() ),
50  fHistAlias( new std::map<TString, TObject*> ),
51  fLogger( new MsgLogger(Form("Results%s",resultsName.Data()), kINFO) )
52 {
53  fStorage->SetOwner();
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// destructor
58 
60 {
61  // delete result-histograms
62  delete fStorage;
63  delete fHistAlias;
64  delete fLogger;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 
69 void TMVA::Results::Store( TObject* obj, const char* alias )
70 {
71  TListIter l(fStorage);
72  // check if object is already in list
73  while (void* p = (void*)l()) {
74  if(p==obj)
75  *fLogger << kFATAL << "Histogram pointer " << p << " already exists in results storage" << Endl;
76  }
77 
78  TString as(obj->GetName());
79  if (alias!=0) as=TString(alias);
80  if (fHistAlias->find(as) != fHistAlias->end()) {
81  // alias exists
82  *fLogger << kFATAL << "Alias " << as << " already exists in results storage" << Endl;
83  }
84  if( obj->InheritsFrom(TH1::Class()) ) {
85  ((TH1*)obj)->SetDirectory(0);
86  }
87  fStorage->Add( obj );
88  fHistAlias->insert(std::pair<TString, TObject*>(as,obj));
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 
94 {
95  std::map<TString, TObject*>::iterator it = fHistAlias->find(alias);
96 
97  if (it != fHistAlias->end()) return it->second;
98 
99  // alias does not exist
100  return 0;
101 }
102 
103 
105 {
106  TObject* test = GetObject(alias);
107 
108  return test;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 
113 TH1* TMVA::Results::GetHist(const TString & alias) const
114 {
115  TH1* out=dynamic_cast<TH1*>(GetObject(alias));
116  if (!out) Log() <<kWARNING << "You have asked for histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
117  return out;
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 
122 TH2* TMVA::Results::GetHist2D(const TString & alias) const
123 {
124  TH2* out=dynamic_cast<TH2*>(GetObject(alias));
125  if (!out) Log() <<kWARNING << "You have asked for 2D histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
126  return out;
127 }
128 ////////////////////////////////////////////////////////////////////////////////
129 
130 TGraph* TMVA::Results::GetGraph(const TString & alias) const
131 {
132  return (TGraph*)GetObject(alias);
133 }
134 
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// delete all stored histograms
138 
140 {
141  fStorage->Delete();
142  fHistAlias->clear();
143 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:113
Results(const DataSetInfo *dsi, TString resultsName)
constructor
Definition: Results.cxx:46
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Basic string class.
Definition: TString.h:137
TString as(SEXP s)
Definition: RExports.h:85
bool Bool_t
Definition: RtypesCore.h:59
virtual ~Results()
destructor
Definition: Results.cxx:59
Iterator of linked list.
Definition: TList.h:187
TH2 * GetHist2D(const TString &alias) const
Definition: Results.cxx:122
TObject * GetObject(const TString &alias) const
Definition: Results.cxx:93
void Class()
Definition: Class.C:29
std::vector< std::vector< double > > Data
char * out
Definition: TBase64.cxx:29
A doubly linked list.
Definition: TList.h:47
void Delete()
delete all stored histograms
Definition: Results.cxx:139
Service class for 2-Dim histogram classes.
Definition: TH2.h:36
Bool_t DoesExist(const TString &alias) const
Definition: Results.cxx:104
TList * fStorage
a pointer to the datasetinfo-object
Definition: Results.h:95
char * Form(const char *fmt,...)
TLine * l
Definition: textangle.C:4
TGraph * GetGraph(const TString &alias) const
Definition: Results.cxx:130
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
The TH1 histogram class.
Definition: TH1.h:80
Mother of all ROOT objects.
Definition: TObject.h:58
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
void * GetObject() const
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:69
TObject * obj
Definition: math.cpp:60