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