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