]>
Commit | Line | Data |
---|---|---|
905cc85c | 1 | /************************************************************************** |
2 | * Copyright(c) 2009-2011, 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 | $Id$ | |
17 | */ | |
18 | ||
19 | //------------------------------------------------------------------------- | |
20 | // Class AliITSQASSDRefData | |
21 | // ITS SSD reference values for the QA | |
22 | // | |
23 | // Origin: Panos.Christakoglou@cern.ch, NIKHEF-Utrecht University | |
24 | //------------------------------------------------------------------------- | |
25 | ||
26 | #include <Riostream.h> | |
27 | #include <fstream> | |
28 | #include <TArray.h> | |
29 | #include <TString.h> | |
30 | #include <TObjString.h> | |
31 | #include <TObjArray.h> | |
32 | ||
33 | #include "AliLog.h" | |
34 | #include "AliITSQASSDRefData.h" | |
35 | ||
36 | ClassImp(AliITSQASSDRefData) | |
37 | ||
38 | //___________________________________________________________________________ | |
39 | AliITSQASSDRefData::AliITSQASSDRefData() : | |
40 | TObject(), | |
41 | fRefList(0), | |
42 | fNameList(0) { | |
43 | //Default constructor | |
44 | } | |
45 | ||
46 | //___________________________________________________________________________ | |
47 | AliITSQASSDRefData::AliITSQASSDRefData(Int_t specie) : | |
48 | TObject(), | |
49 | fRefList(0), | |
50 | fNameList(0) { | |
51 | //Default constructor | |
52 | SetDefault(specie); | |
53 | } | |
54 | ||
55 | //___________________________________________________________________________ | |
56 | AliITSQASSDRefData::AliITSQASSDRefData(const char* path) : | |
57 | TObject(), | |
58 | fRefList(0), | |
59 | fNameList(0) { | |
60 | //Constructor with the path of the ascii file as an argument | |
61 | SetReferenceData(path); | |
62 | } | |
63 | ||
64 | //___________________________________________________________________________ | |
65 | AliITSQASSDRefData::AliITSQASSDRefData(const AliITSQASSDRefData& refData): | |
66 | TObject(), | |
67 | fRefList(refData.fRefList), | |
68 | fNameList(refData.fNameList) { | |
69 | //Copy constructor | |
70 | } | |
71 | ||
72 | //___________________________________________________________________________ | |
73 | AliITSQASSDRefData& AliITSQASSDRefData::operator = (const AliITSQASSDRefData& refData) { | |
74 | //assignment operator | |
75 | if(&refData != this) { | |
76 | fRefList = refData.fRefList; | |
77 | fNameList = refData.fNameList; | |
78 | } | |
79 | return *this ; | |
80 | } | |
81 | ||
82 | //___________________________________________________________________________ | |
83 | AliITSQASSDRefData::~AliITSQASSDRefData() { | |
84 | //Destructor | |
85 | if(fRefList) delete fRefList; | |
86 | if(fNameList) delete fNameList; | |
87 | } | |
88 | ||
89 | //___________________________________________________________________________ | |
90 | void AliITSQASSDRefData::AddReference(const char* name="", | |
91 | Int_t id=-1, | |
92 | Double_t value=0) { | |
93 | //Adding a ref. value to the list | |
94 | //Printf("(AliITSQASSDRefData::AddReference) Name: %s - Id: %d - Value: %lf",name,id,value); | |
95 | if(id>-1&&id<fRefList->GetSize()) { | |
96 | AliError(Form("Reference with id %i already exists. Choose other id or use SetReferenceValue(Int_t, Double_t) to overwrite",id)); | |
97 | return; | |
98 | } | |
99 | ||
324c25b5 | 100 | if( (strcmp(name,"")!=0) && GetID(name)!=-1) { |
905cc85c | 101 | AliError(Form("Reference with name %s already exists. Choose other name or use SetReferenceValue(const char*, Double_t) to overwrite",name)); |
102 | return; | |
103 | } | |
104 | ||
105 | if(id==-1) id=fRefList->GetSize(); | |
106 | fRefList->Set(id+1); | |
107 | fRefList->AddAt(value,id); | |
108 | fNameList->AddAt(new TObjString(name),id); | |
109 | } | |
110 | ||
111 | //___________________________________________________________________________ | |
112 | Int_t AliITSQASSDRefData::GetID(const char* name) { | |
113 | //Get the id of the reference value | |
114 | Int_t status = -1; | |
115 | TString refName = ""; | |
116 | TString stringName = name; | |
117 | TObjString *dummyString = 0; | |
118 | for (Int_t id=0; id<fNameList->GetEntriesFast(); id++){ | |
5e24ec01 | 119 | dummyString = static_cast <TObjString *>(fNameList->At(id)); |
905cc85c | 120 | refName = dummyString->GetString(); |
905cc85c | 121 | if(refName == stringName) { |
122 | status = id; | |
905cc85c | 123 | } |
124 | } | |
125 | ||
126 | return status; | |
127 | } | |
128 | ||
129 | //___________________________________________________________________________ | |
130 | Double_t AliITSQASSDRefData::GetReferenceValue(const char* name) { | |
131 | //Returns the ref. value based on the given name | |
132 | TString refName = ""; | |
133 | TObjString *dummyString = 0; | |
134 | for (Int_t id=0; id<fNameList->GetEntriesFast(); id++){ | |
5e24ec01 | 135 | dummyString = static_cast <TObjString *>(fNameList->At(id)); |
905cc85c | 136 | refName = dummyString->GetString(); |
137 | ||
5e24ec01 | 138 | if(refName.Data()==name) return fRefList->At(id); |
905cc85c | 139 | } |
140 | AliError(Form("Reference name %s unknown",name)); | |
141 | return -1; | |
142 | } | |
143 | ||
144 | //___________________________________________________________________________ | |
145 | Double_t AliITSQASSDRefData::GetReferenceValue(Int_t id) { | |
146 | //Returns the ref. value based on the given id | |
147 | if (id<0||id>fRefList->GetSize()-1){ | |
148 | AliError("Reference ID out of range"); | |
149 | return 0; | |
150 | } | |
151 | return fRefList->At(id); | |
152 | ||
153 | } | |
154 | ||
155 | //___________________________________________________________________________ | |
156 | void AliITSQASSDRefData::PrintTable() { | |
157 | //Prints the list of reference values | |
158 | Printf("___ SSD REFERENCE DATA ___ "); | |
159 | Printf("ID ----- Value ------- Name"); | |
160 | Int_t id=0; | |
161 | TString refName = ""; | |
162 | TObjString *dummyString = 0; | |
163 | for(id=0; id<fRefList->GetSize()-1; id++) { | |
5e24ec01 | 164 | dummyString = static_cast <TObjString *>(fNameList->At(id)); |
905cc85c | 165 | refName = dummyString->GetString(); |
166 | Printf("%i ------ %4.3g -------- %s",id,fRefList->At(id),refName.Data()); | |
167 | ||
168 | } | |
169 | ||
170 | } | |
171 | ||
172 | //___________________________________________________________________________ | |
173 | void AliITSQASSDRefData::SetDefault(Int_t specie) { | |
174 | //Sets the default values | |
175 | if(!fNameList) fNameList = new TObjArray(); | |
176 | fNameList->Add(new TObjString("minSSDDataSize")); | |
177 | fNameList->Add(new TObjString("maxSSDDataSize")); | |
178 | fNameList->Add(new TObjString("minDDLDataSize")); | |
179 | fNameList->Add(new TObjString("maxDDLDataSize")); | |
180 | fNameList->Add(new TObjString("minLDCDataSize")); | |
181 | fNameList->Add(new TObjString("maxLDCDataSize")); | |
182 | fNameList->Add(new TObjString("minMeanDDLDataSize")); | |
183 | fNameList->Add(new TObjString("maxMeanDDLDataSize")); | |
184 | fNameList->Add(new TObjString("minMeanLDCDataSize")); | |
185 | fNameList->Add(new TObjString("maxMeanLDCDataSize")); | |
186 | fNameList->Add(new TObjString("maxOccupancy")); | |
187 | fNameList->SetOwner(kTRUE); | |
188 | ||
189 | //specie == 0 ==> Default | |
190 | Double_t refValues[11] = {0,0.0,0,0,0,0,0,0,0,0}; | |
191 | //specie == 1 ==> Low multiplicity | |
192 | if(specie == 1) { | |
193 | refValues[0] = 0; refValues[1] = 500; refValues[2] = 0; refValues[3] = 50; | |
194 | refValues[4] = 0; refValues[5] = 100; refValues[6] = 0; refValues[7] = 50; | |
195 | refValues[8] = 0; refValues[9] = 100; refValues[10] = 5; | |
196 | } | |
197 | //specie == 2 ==> High multiplicity | |
198 | if(specie == 2) { | |
199 | refValues[0] = 0; refValues[1] = 500; refValues[2] = 0; refValues[3] = 50; | |
200 | refValues[4] = 0; refValues[5] = 100; refValues[6] = 0; refValues[7] = 50; | |
201 | refValues[8] = 0; refValues[9] = 100; refValues[10] = 5; | |
202 | } | |
203 | //specie == 3 ==> Cosmics | |
204 | if(specie == 3) { | |
205 | refValues[0] = 0; refValues[1] = 500; refValues[2] = 0; refValues[3] = 50; | |
206 | refValues[4] = 0; refValues[5] = 100; refValues[6] = 0; refValues[7] = 50; | |
207 | refValues[8] = 0; refValues[9] = 100; refValues[10] = 5; | |
208 | } | |
209 | //specie == 4 ==> Calibration | |
210 | if(specie == 4) { | |
211 | refValues[0] = 0; refValues[1] = 500; refValues[2] = 0; refValues[3] = 50; | |
212 | refValues[4] = 0; refValues[5] = 100; refValues[6] = 0; refValues[7] = 50; | |
213 | refValues[8] = 0; refValues[9] = 100; refValues[10] = 5; | |
214 | } | |
215 | ||
216 | if(!fRefList) fRefList = new TArrayD(); | |
217 | fRefList->Set(11,refValues); | |
218 | } | |
219 | ||
220 | //___________________________________________________________________________ | |
221 | void AliITSQASSDRefData::SetReferenceData(const char* path) { | |
222 | //Parses an ascii file with the reference values | |
223 | if(!fRefList) fRefList = new TArrayD(); | |
224 | if(!fNameList) fNameList = new TObjArray(); | |
225 | ||
226 | ifstream file; | |
227 | file.open(path); | |
228 | ||
229 | if (!file) { | |
230 | AliWarning(Form("No file found at %s",path)); | |
231 | SetDefault(0); | |
232 | return; | |
233 | } | |
234 | if(file.bad()){ | |
235 | AliWarning("Reference data could not be read: Default values are used."); | |
236 | SetDefault(0); | |
237 | return; | |
238 | } | |
239 | ||
240 | fRefList->Set(0); | |
241 | Int_t id = 0, newid = -1; | |
242 | Double_t value = 0; | |
243 | TString name = ""; | |
244 | ||
245 | while (!file.eof()) { | |
246 | //file >> newid; | |
247 | file >> name >> id >> value; | |
248 | //Printf("Name: %s - Id: %d - Value: %lf",name.Data(),id,value); | |
249 | ||
250 | if (newid==id) continue; //skip line if id is the same as previous | |
251 | AddReference(name.Data(), id, value); | |
252 | newid = id; | |
253 | } | |
254 | ||
255 | file.close(); | |
256 | } | |
257 | ||
258 | //___________________________________________________________________________ | |
259 | void AliITSQASSDRefData::SetReferenceValue(Int_t id, Double_t value) { | |
260 | //Adding a single reference value by id | |
261 | if(id<0||id>fRefList->GetSize()-1) { | |
262 | AliWarning(Form("Reference ID %i out of range: value not set",id)); | |
263 | } | |
264 | else fRefList->SetAt(value,id); | |
265 | ||
266 | } | |
267 | ||
268 | //___________________________________________________________________________ | |
269 | void AliITSQASSDRefData::SetReferenceValue(const char* name, Double_t value) { | |
270 | //Adding a single reference value by name | |
271 | Int_t id = GetID(name); | |
272 | //Printf("Name: %s - Id: %d",name,id); | |
273 | if(id == -1) { | |
274 | AliError(Form("Reference name %s unknown: value not set",name)); | |
275 | return; | |
276 | } | |
277 | ||
278 | fRefList->SetAt(value,id); | |
279 | } |