]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliTRDPIDParams.cxx
Fixes for coverity: SELF_ASSIGN
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDPIDParams.cxx
CommitLineData
ce487a7f 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15//
16// Container for TRD Threshold parameters stored in the OADB
17//
18// Author: Markus Fasel <M.Fasel@gsi.de>
19//
20#include <TMath.h>
21#include <TSortedList.h>
22
23#include "AliLog.h"
24
25#include "AliTRDPIDParams.h"
26
27ClassImp(AliTRDPIDParams)
28
29const Double_t AliTRDPIDParams::kVerySmall = 1e-5;
30
31//____________________________________________________________
32AliTRDPIDParams::AliTRDPIDParams():
33 TNamed(),
34 fEntries(NULL)
35{
36 //
37 // Dummy constructor
38 //
39}
40
41//____________________________________________________________
42AliTRDPIDParams::AliTRDPIDParams(const char *name) :
43 TNamed(name, ""),
44 fEntries(NULL)
45{
46 //
47 // Default constructor
48 //
49 fEntries = new TSortedList;
50}
51
52//____________________________________________________________
53AliTRDPIDParams::~AliTRDPIDParams(){
54 //
55 // Destructor
56 //
57 delete fEntries;
58}
59
60//____________________________________________________________
61Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
62 //
63 // Retrieve params
64 // Use IsEqual definition
65 //
66 AliTRDPIDThresholds test(ntracklets, efficiency);
67 TObject *result = fEntries->FindObject(&test);
68 if(!result){
69 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
70 return kFALSE;
71 }
72 AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
73 AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
74 memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
75 return kTRUE;
76}
77
78//____________________________________________________________
79void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
80 //
81 // Store new Params in the Object
82 //
83 if(effMin > effMax){
84 AliError("Min. efficiency has to be >= max. efficiency");
85 return;
86 }
87 AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
88 fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
89}
90
91//____________________________________________________________
92void AliTRDPIDParams::Print(Option_t *) const {
93 printf("Available thresholds:\n");
94 printf("_________________________________________\n");
95 TIter objects(fEntries);
96 AliTRDPIDThresholds *par;
97 while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
98 printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), par->GetElectronEfficiency());
99 }
100}
101
102//____________________________________________________________
103AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
104 TObject(),
105 fNTracklets(0)
106{
107 //
108 // Default constructor
109 //
110 memset(fParams, 0, sizeof(Double_t) * 4);
111 memset(fEfficiency, 0, sizeof(Double_t) * 2);
112}
113
114//____________________________________________________________
115AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
116 TObject(),
117 fNTracklets(nTracklets)
118{
119 //
120 // Default Constructor
121 //
122 fEfficiency[0] = effMin;
123 fEfficiency[1] = effMax;
124 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
125 else memset(fParams, 0, sizeof(Double_t) * 4);
126}
127
128//____________________________________________________________
129AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
130 TObject(),
131 fNTracklets(nTracklets)
132{
133 //
134 // Constructor used to find object in sorted list
135 //
136 fEfficiency[0] = fEfficiency[1] = eff;
137 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
138 else memset(fParams, 0, sizeof(Double_t) * 4);
139}
140
141//____________________________________________________________
142AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
143 TObject(ref),
144 fNTracklets(ref.fNTracklets)
145{
146 //
147 // Copy constructor
148 //
149 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
150 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
151}
152
153//____________________________________________________________
154AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
155 //
156 // Assignment operator
157 //
e99fb5c9 158 if(&ref == this) return *this;
159
ce487a7f 160 TObject::operator=(ref);
161
162 fNTracklets = ref.fNTracklets;
163 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
164 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
165 return *this;
166}
167
168//____________________________________________________________
169Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
170 //
171 // Compares two objects
172 // Order:
173 // First compare number of tracklets, if they are equal compare electron efficiency
174 //
175 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
176 if(fNTracklets < refObj->GetNTracklets()) return -1;
177 else if(fNTracklets > refObj->GetNTracklets()) return 1;
178 else{
179 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
180 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
181 else return 0;
182 }
183}
184
185//____________________________________________________________
186Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
187 //
188 // Check for equality
189 // Tracklets and Efficiency are used
190 //
191 const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
192 if(!refObj) return kFALSE;
193 Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
194 Bool_t eqEff = kFALSE;
195 Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
196 Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
197 if(hasRange && hasRangeRef){
198 // Both have ranges, check if they match
199 eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
200 } else if(hasRange){
201 // this object has ranges, check if the efficiency of ref is inside the range
202 eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
203 } else {
204 // ref has ranges, check if this is in range
205 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
206 }
207
208 return eqNTracklets && eqEff;
209}