Added AliRsnCutEventUtils class: interface to /Users/bellini/alisoft/aliroot/last_tru...
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnTrainManager.cxx
CommitLineData
0364ec3a 1//
2// *** Class AliRsnTrainManager ***
3//
4// Base class for Action
5//
6// authors: Martin Vala (martin.vala@cern.ch)
7// Jan Musinsky (jan.musinsky@cern.ch)
8//
9
10#include <TError.h>
11#include <TObjString.h>
12#include <TMap.h>
13#include <TClass.h>
14
15#include "AliRsnTrainManager.h"
16
17ClassImp(AliRsnTrainManager)
18
19AliRsnTrainManager *AliRsnTrainManager::fgRsnTrainManager = 0;
20
21//__________________________________________________________________________________________________
22AliRsnTrainManager::AliRsnTrainManager(const char *name,const char *title) : TNamed(name,title),
ae15a5ec 23 fGlobals(0)
0364ec3a 24{
ae15a5ec 25 //
26 // Default constructor
27 //
0364ec3a 28
ae15a5ec 29 fgRsnTrainManager = this;
0364ec3a 30
ae15a5ec 31 if (TClass::IsCallingNew() != TClass::kDummyNew) {
32 fGlobals = new TMap();
33 }
0364ec3a 34
35}
36
37//__________________________________________________________________________________________________
38AliRsnTrainManager::AliRsnTrainManager(const AliRsnTrainManager &copy) : TNamed(copy),
ae15a5ec 39 fGlobals(copy.fGlobals)
0364ec3a 40{
ae15a5ec 41 //
42 // Copy constructor
43 //
0364ec3a 44}
45
46//__________________________________________________________________________________________________
47AliRsnTrainManager &AliRsnTrainManager::operator=(const AliRsnTrainManager &copy)
48{
ae15a5ec 49 //
50 // Assignment constructor
51 //
52 TNamed::operator=(copy);
53 if (this == &copy)
54 return *this;
55
56 fGlobals = copy.fGlobals;
57 return (*this);
0364ec3a 58}
59
60//__________________________________________________________________________________________________
61AliRsnTrainManager::~AliRsnTrainManager()
62{
ae15a5ec 63 //
64 // Destructor
65 //
66 delete fGlobals;
67 fgRsnTrainManager = 0;
0364ec3a 68}
69
70//______________________________________________________________________________
ae15a5ec 71void AliRsnTrainManager::SetGlobalStr(const char *key, const char *value,Bool_t verbose)
0364ec3a 72{
ae15a5ec 73 // Define a custom string variable mapped to a global unique name. The variable
74 // can be then retrieved by a given analysis macro via GetGlobalStr(key).
75 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
76 if (!mgr) {
77 ::Error("AliRsnTrainManager::SetGlobalStr", "No analysis manager defined");
78 return;
79 }
80 Bool_t valid = kFALSE;
81 TString existing = AliRsnTrainManager::GetGlobalStr(key, valid);
82 if (valid) {
83 if (verbose) ::Error("AliRsnTrainManager::SetGlobalStr", "Global %s = %s already defined.", key, existing.Data());
84 return;
85 }
86 mgr->GetGlobals()->Add(new TObjString(key), new TObjString(value));
0364ec3a 87}
88
89//______________________________________________________________________________
90const char *AliRsnTrainManager::GetGlobalStr(const char *key, Bool_t &valid)
91{
ae15a5ec 92 // Static method to retrieve a global variable defined via SetGlobalStr.
93 valid = kFALSE;
94 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
95 if (!mgr) return 0;
96 TObject *value = mgr->GetGlobals()->GetValue(key);
97 if (!value) return 0;
98 valid = kTRUE;
99 return value->GetName();
0364ec3a 100}
101
102//______________________________________________________________________________
ae15a5ec 103void AliRsnTrainManager::SetGlobalInt(const char *key, Int_t value,Bool_t verbose)
0364ec3a 104{
ae15a5ec 105 // Define a custom integer variable mapped to a global unique name. The variable
106 // can be then retrieved by a given analysis macro via GetGlobalInt(key).
107 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
108 if (!mgr) {
109 ::Error("AliRsnTrainManager::SetGlobalStr", "No analysis manager defined");
110 return;
111 }
112 Bool_t valid = kFALSE;
113 Int_t existing = AliRsnTrainManager::GetGlobalInt(key, valid);
114 if (valid) {
115 if (verbose) ::Error("AliRsnTrainManager::SetGlobalInt", "Global %s = %i already defined.", key, existing);
116 return;
117 }
118 mgr->GetGlobals()->Add(new TObjString(key), new TObjString(TString::Format("%i",value)));
0364ec3a 119}
120
121//______________________________________________________________________________
122Int_t AliRsnTrainManager::GetGlobalInt(const char *key, Bool_t &valid)
123{
ae15a5ec 124 // Static method to retrieve a global variable defined via SetGlobalInt.
125 valid = kFALSE;
126 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
127 if (!mgr) return 0;
128 TObject *value = mgr->GetGlobals()->GetValue(key);
129 if (!value) return 0;
130 valid = kTRUE;
131 TString s = value->GetName();
132 return s.Atoi();
0364ec3a 133}
134
135//______________________________________________________________________________
ae15a5ec 136void AliRsnTrainManager::SetGlobalDbl(const char *key, Double_t value,Bool_t verbose)
0364ec3a 137{
ae15a5ec 138 // Define a custom double precision variable mapped to a global unique name. The variable
139 // can be then retrieved by a given analysis macro via GetGlobalInt(key).
140 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
141 if (!mgr) {
142 ::Error("AliRsnTrainManager::SetGlobalStr", "No analysis manager defined");
143 return;
144 }
145 Bool_t valid = kFALSE;
146 Double_t existing = AliRsnTrainManager::GetGlobalDbl(key, valid);
147 if (valid) {
148 if (verbose) ::Error("AliRsnTrainManager::SetGlobalInt", "Global %s = %g already defined.", key, existing);
149 return;
150 }
151 mgr->GetGlobals()->Add(new TObjString(key), new TObjString(TString::Format("%f",value)));
0364ec3a 152}
153
154//______________________________________________________________________________
155Double_t AliRsnTrainManager::GetGlobalDbl(const char *key, Bool_t &valid)
156{
ae15a5ec 157 // Static method to retrieve a global variable defined via SetGlobalDbl.
158 valid = kFALSE;
159 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
160 if (!mgr) return 0;
161 TObject *value = mgr->GetGlobals()->GetValue(key);
162 if (!value) return 0;
163 valid = kTRUE;
164 TString s = value->GetName();
165 return s.Atof();
0364ec3a 166}
167
168//______________________________________________________________________________
ae15a5ec 169void AliRsnTrainManager::SetGlobalObj(const char *key, TObject *value,Bool_t verbose)
0364ec3a 170{
ae15a5ec 171 // Define a custom double precision variable mapped to a global unique name. The variable
172 // can be then retrieved by a given analysis macro via GetGlobalInt(key).
173 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
174 if (!mgr) {
175 ::Error("AliRsnTrainManager::SetGlobalStr", "No analysis manager defined");
176 return;
177 }
178 Bool_t valid = kFALSE;
179 TObject *existing = AliRsnTrainManager::GetGlobalObj(key, valid);
180 if (valid) {
181 if (verbose) ::Error("AliRsnTrainManager::SetGlobalInt", "Global %s = %p already defined.", key, existing);
182 return;
183 }
184 mgr->GetGlobals()->Add(new TObjString(key), value->Clone());
0364ec3a 185}
186
187//______________________________________________________________________________
188TObject *AliRsnTrainManager::GetGlobalObj(const char *key, Bool_t &valid)
189{
ae15a5ec 190 // Static method to retrieve a global variable defined via SetGlobalDbl.
191 valid = kFALSE;
192 AliRsnTrainManager *mgr = AliRsnTrainManager::GetRsnTrainManager();
193 if (!mgr) return 0;
194 TObject *value = mgr->GetGlobals()->GetValue(key);
195 return value;
0364ec3a 196}
197
198//______________________________________________________________________________
199void AliRsnTrainManager::Print(Option_t */*option*/) const {
200
201
202
ae15a5ec 203 if (!fGlobals) return;
204 Printf("=========================================================");
205
206 Printf(" Rsn Global variables: \n");
207 TIter next(fGlobals->GetTable());
208 TPair *a;
209 TObjString *str;
210 while ((a = (TPair *)next())) {
211 str = 0;
212// if (a->Key()&& a->Key()->IsOnHeap()){
213// }
214 if (a->Value() && a->Value()->IsOnHeap()) {
215 str = dynamic_cast<TObjString *>(a->Value());
216 }
217 if (str) {
218 if (str) Printf(" %20s = %-20s",a->Key()->GetName(),str->GetString().Data());
219 }
220 }
221 Printf("\n=========================================================");
222
223 /* Printf(" Rsn Particles and Cuts \n");
224
225
226 next.Reset();
227 // AliRsnCut
228 while ((a = (TPair *)next())) {
229 str = 0;
230 // if (a->Key()&& a->Key()->IsOnHeap()){
231 // }
232 if (a->Value() && a->Value()->IsOnHeap()){
233 str = dynamic_cast<TObjString *>(a->Value());
234 }
235 if (str) {
236 if (str) Printf(" %20s = %-20s",a->Key()->GetName(),str->GetString().Data());
237 }
238 }
239
240 Printf("\n=========================================================");
241
242 */
0364ec3a 243}