]>
Commit | Line | Data |
---|---|---|
286382a3 | 1 | /************************************************************************** |
2 | * Copyright(c) 2008-2010, 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 | // Author: A. Mastroserio // | |
20 | // This class is used within the detector algorithm framework // | |
21 | // to write and read FO scan data. // | |
22 | //////////////////////////////////////////////////////////////// | |
23 | ||
24 | #include <TFile.h> | |
25 | #include <Riostream.h> | |
26 | #include <TSystem.h> | |
27 | #include <TObjArray.h> | |
28 | #include <TObjString.h> | |
29 | #include <TArrayI.h> | |
30 | #include <TIterator.h> | |
31 | #include <TKey.h> | |
32 | #include <TMath.h> | |
33 | #include <TList.h> | |
34 | #include "AliLog.h" | |
35 | #include "AliITSOnlineSPDfoChipConfig.h" | |
36 | #include "AliITSOnlineSPDfoChip.h" | |
37 | #include "AliITSOnlineSPDfoInfo.h" | |
38 | #include "AliITSOnlineSPDfo.h" | |
39 | ||
40 | ||
41 | ClassImp(AliITSOnlineSPDfo) | |
42 | //----------------------------------------------- | |
43 | AliITSOnlineSPDfo::AliITSOnlineSPDfo(): | |
44 | fRunNr(0), | |
45 | fNdacs(0), | |
46 | fFileName(""), | |
47 | fFile(0x0), | |
48 | fInfo(0x0), | |
49 | fDACnames(0x0), | |
50 | fArray(0x0), | |
51 | fCheckIndex(-1), | |
52 | fIndex(-1), | |
53 | fInitialConfiguration("") | |
54 | { | |
55 | // default constructor | |
56 | } | |
57 | ||
58 | //------------------------------------------------- | |
59 | AliITSOnlineSPDfo::AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId): | |
60 | fRunNr(runNr), | |
61 | fNdacs(0), | |
62 | fFileName(""), | |
63 | fFile(0x0), | |
64 | fInfo(0x0), | |
65 | fDACnames(0x0), | |
66 | fArray(0x0), | |
67 | fCheckIndex(-1), | |
68 | fIndex(-1), | |
69 | fInitialConfiguration("") | |
70 | { | |
71 | // | |
72 | // constructor | |
73 | // | |
74 | fFileName=Form("%i_%s%02i.root",runNr,inputfile.Data(),eqId); | |
75 | fFile = TFile::Open(fFileName.Data()); | |
76 | fArray = new TObjArray(); | |
77 | fDACnames = new THashList(); | |
78 | } | |
79 | //-------------------------------------------------- | |
80 | AliITSOnlineSPDfo::AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c): | |
81 | fRunNr(c.fRunNr), | |
82 | fNdacs(c.fNdacs), | |
83 | fFileName(c.fFileName), | |
84 | fFile(c.fFile), | |
85 | fInfo(c.fInfo), | |
86 | fDACnames(c.fDACnames), | |
87 | fArray(c.fArray), | |
88 | fCheckIndex(c.fCheckIndex), | |
89 | fIndex(c.fIndex), | |
90 | fInitialConfiguration(c.fInitialConfiguration) | |
91 | { | |
92 | // | |
93 | //copy constructor | |
94 | // | |
95 | } | |
96 | //-------------------------------------------------- | |
97 | void AliITSOnlineSPDfo::SetFile(TString inputfile) | |
98 | { | |
99 | // | |
100 | // open the file where the data are | |
101 | // | |
102 | ||
103 | if(fFile) { | |
104 | fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo"); | |
105 | return; | |
106 | } else { | |
107 | fFile = TFile::Open(inputfile.Data()); | |
108 | if(!fFile) { | |
fecad5d9 | 109 | Info("AliITSOnlineSPDfo::SetFile"," %s not existing.... The scan info are not available....crash is expected \n",inputfile.Data()); |
286382a3 | 110 | return; |
111 | } else { | |
112 | fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo"); | |
113 | fNdacs = fInfo->GetNumDACindex(); | |
114 | } | |
115 | } | |
116 | ||
117 | } | |
118 | ||
119 | //------------------------------------------------------ | |
120 | void AliITSOnlineSPDfo::CreateOutputFile() | |
121 | { | |
122 | // | |
123 | // Create the file (needed only in the DA ), will delete the previous one! | |
124 | // | |
125 | if(fFile) Info("AliITSOnlineSPDfo::CreateOutputFile","removing previous file....\n"); | |
126 | fFile = TFile::Open(fFileName.Data(),"RECREATE"); | |
127 | ||
128 | } | |
129 | //------------------------------------------------------ | |
130 | void AliITSOnlineSPDfo::AddMeasurement(const TArrayS dac, Short_t measure[4], Int_t hs, Int_t chipId) | |
131 | { | |
132 | /* | |
133 | // Here a single measurement is added to the chip container. | |
134 | // A single measurement corresponds to a specific pixel-configuration output | |
135 | // in the Fast-OR chip. If N configurations are considered, then | |
136 | // the data structure is the following: | |
137 | // | |
138 | // -> HS0_CHIP0 -> measure0[4] | |
139 | // / measure1[4] | |
140 | // / ... | |
141 | // fArray->At(i) = DAC1-DAC2-DAC3-DAC4 measureN[4] | |
142 | // \ | |
143 | // \ | |
144 | // -> HS0_CHIP1 -> measure0[4] | |
145 | // measure1[4] | |
146 | // .... | |
147 | // measureN[4] | |
148 | // | |
149 | */ | |
150 | ||
151 | AliITSOnlineSPDfoChipConfig *counts = new AliITSOnlineSPDfoChipConfig(measure); | |
152 | Int_t arrayelement = CheckDACEntry(dac); | |
153 | ||
154 | if(arrayelement< 0){ | |
155 | TString dacname = CreateDACEntry(dac); | |
156 | TObjString *string = new TObjString(dacname.Data()); | |
157 | fDACnames->Add(string); | |
158 | ||
159 | TObjArray *array = new TObjArray(60); | |
160 | AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize()); | |
161 | chip->SetActiveHS(hs); | |
162 | chip->SetChipId(chipId); | |
163 | for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i)); | |
164 | chip->AddMeasurement(counts); | |
165 | array->AddAt(chip,hs*10+chipId); | |
166 | fArray->AddLast(array); | |
167 | ||
168 | } else { | |
169 | ||
170 | TObjArray *arr = (TObjArray*)fArray->At(arrayelement); | |
171 | if(!arr->At(hs*10+chipId)){ | |
172 | AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize()); | |
173 | chip->SetActiveHS(hs); | |
174 | chip->SetChipId(chipId); | |
175 | for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i)); | |
176 | chip->AddMeasurement(counts); | |
177 | arr->AddAt(chip,hs*10+chipId); | |
178 | ||
179 | } else { | |
180 | ||
181 | AliITSOnlineSPDfoChip *c = (AliITSOnlineSPDfoChip *)arr->At(hs*10+chipId); | |
182 | if(c)c->AddMeasurement(counts); | |
183 | } | |
184 | } | |
185 | } | |
186 | //--------------------------------------- | |
187 | Int_t AliITSOnlineSPDfo::CheckDACEntry(const TArrayS dac) | |
188 | { | |
189 | // | |
190 | // Check if the set of dacs has been already added to the array | |
191 | // | |
192 | ||
193 | ||
194 | TString name = CreateDACEntry(dac); | |
195 | ||
196 | if(!fDACnames) { | |
197 | Info("AliITSOnlineSPDfo::CheckDACEntry"," NO DAC name array is present, exiting.... \n"); | |
198 | return -1; | |
199 | } | |
200 | ||
201 | Double_t c = 0; | |
202 | for(Int_t i=0; i< fNdacs; i++) c+=dac.At(i)*TMath::Power(10,3*i); | |
203 | if(c==fCheckIndex) return fIndex; | |
204 | ||
205 | ||
206 | ||
207 | Int_t idx = -1; | |
208 | ||
209 | if(fDACnames->FindObject( name.Data() )) { | |
210 | idx = fDACnames->IndexOf( fDACnames->FindObject( name.Data() ) ); | |
211 | fCheckIndex=0; | |
212 | for(Int_t i=0; i< fNdacs; i++) fCheckIndex+=dac.At(i)*TMath::Power(10,3*i); | |
213 | fIndex=idx; | |
214 | ||
215 | } | |
216 | return idx; | |
217 | ||
218 | } | |
219 | //_________________________________________________________ | |
220 | void AliITSOnlineSPDfo::WriteToFile() | |
221 | { | |
222 | // | |
223 | //The array of DACS and all its content is written to file. | |
224 | // Here the general info on the FO calibration scan are | |
225 | // written in the same file | |
226 | ||
227 | if(fDACnames->GetEntries() != fArray->GetEntries()) { | |
228 | printf("mismatch names-array. Exiting...."); | |
229 | return; | |
230 | } | |
231 | ||
232 | for(Int_t i=0; i< fDACnames->GetEntries(); i++){ | |
233 | fFile->WriteObject(fArray->At(i),fDACnames->At(i)->GetName()); | |
234 | } | |
235 | fFile->WriteTObject(fInfo,"generalinfo"); | |
236 | fFile->Close(); | |
237 | ||
238 | } | |
239 | //______________________________________________________ | |
240 | ||
241 | TString AliITSOnlineSPDfo::CreateDACEntry(const TArrayS dacs) const | |
242 | { | |
243 | // | |
244 | // The string of DACs is build | |
245 | // | |
246 | ||
247 | TString dacvalues; | |
248 | for(Int_t i=0; i<dacs.GetSize(); i++) dacvalues+=Form("-%i",dacs.At(i)); | |
249 | dacvalues.Remove(0,1); | |
250 | return dacvalues; | |
251 | ||
252 | } | |
253 | //_____________________________________________________ | |
254 | TArrayI AliITSOnlineSPDfo::GetDACscanParams() const | |
255 | { | |
256 | // | |
257 | // this method retrieves the DAC value range and its steps | |
258 | // | |
259 | TFile *f =0x0; | |
260 | if(fFile->IsOpen()) f = fFile; | |
261 | else f = TFile::Open(fFileName.Data()); | |
262 | ||
263 | TArrayI dacs; | |
264 | if(f->GetNkeys() < 2) return dacs; | |
265 | dacs.Set(fNdacs*3); | |
266 | ||
267 | TArrayI min(fNdacs), max(fNdacs),step(fNdacs), check(fNdacs), refvalues(fNdacs); | |
268 | ||
269 | for(Int_t i=0; i< fNdacs ; i++) { | |
270 | min.AddAt(9999,i); | |
271 | max.AddAt(0,i); | |
272 | step.AddAt(0,i); | |
273 | check.AddAt(0,i); | |
274 | } | |
275 | ||
276 | ||
277 | TKey *key; | |
278 | TIter iter(f->GetListOfKeys()); | |
279 | while ((key = (TKey*)(iter.Next()))) { | |
280 | TString classname = key->GetClassName(); | |
281 | if(classname.Contains("OnlineSPD")) break; | |
282 | ||
283 | TString values = key->GetName(); | |
284 | Int_t *val = GetDACvalues(values,fNdacs); // the user has to delete it! | |
285 | ||
286 | for(Int_t i=0; i< fNdacs; i++) { | |
287 | if(val[i]<=min.At(i)) min.AddAt(val[i],i); | |
288 | if(val[i] >= max.At(i)) max.AddAt(val[i],i); | |
289 | // procedure to get the step size; | |
290 | if(!check.At(i)) { | |
291 | refvalues.AddAt(val[i],i); | |
292 | check.AddAt(1,i); | |
293 | } | |
294 | if(step.At(i) ==0 && check.At(i)){ | |
295 | if(val[i]!=refvalues.At(i)) step.AddAt(TMath::Abs(refvalues.At(i) - val[i]),i); | |
296 | } | |
297 | // end procedure to get the step size | |
298 | } | |
299 | delete [] val; | |
300 | } | |
301 | ||
302 | ||
14374702 | 303 | |
286382a3 | 304 | for(Int_t i=0; i<fNdacs; i++) { |
14374702 | 305 | dacs.AddAt(min.At(i),3*i); |
306 | dacs.AddAt(max.At(i),3*i+1); | |
286382a3 | 307 | dacs.AddAt(step.At(i),3*i+2); |
308 | } | |
309 | ||
310 | ||
311 | return dacs; | |
312 | } | |
313 | //___________________________________________________________________ | |
314 | Int_t* AliITSOnlineSPDfo::GetDACvalues(TString s, const Int_t ndacs) const | |
315 | { | |
316 | // | |
317 | // Translates the string of DACS values into an array of integers | |
318 | // | |
319 | ||
320 | Int_t *val = new Int_t[ndacs]; | |
321 | ||
322 | s.ReplaceAll("-"," "); | |
323 | char *pEnd = Form("%s",s.Data()); | |
324 | for(Int_t i=0; i< ndacs; i++) { | |
325 | val[i] = strtol(pEnd,&pEnd,10); // conversion from string to long | |
326 | } | |
327 | return val; | |
328 | } | |
329 | ||
330 | //___________________________________________________________________ | |
331 | Double_t* AliITSOnlineSPDfo::GetDACvaluesD(TString s, const Int_t ndacs) const | |
332 | { | |
333 | // | |
334 | // Translates the string of DACS values into an array of doubles | |
335 | // (needed to fill the thnsparse) | |
336 | // | |
337 | Double_t *val = new Double_t[ndacs]; | |
338 | Int_t *values = GetDACvalues(s,ndacs); | |
339 | for(Int_t i=0; i< ndacs; i++) val[i] = (Double_t)values[i]; | |
340 | delete [] values; | |
341 | ||
342 | return val; | |
343 | } | |
344 | //------------------------------------------------------------------- | |
345 | TArrayS AliITSOnlineSPDfo::CreateDACArray(const TArrayS dacs, const TArrayS dacId) const | |
346 | { | |
347 | // | |
348 | // method to order the data according to the DAC index | |
349 | // | |
350 | ||
351 | TArrayS dacarray(dacs.GetSize()); | |
352 | for(Int_t i=0; i<dacs.GetSize(); i++) { | |
353 | if(dacId.At(i)==kIdFOPOL) dacarray.AddAt(dacs.At(i),kFOPOL); | |
354 | else if(dacId.At(i)==kIdCONVPOL) dacarray.AddAt(dacs.At(i),kCONVPOL); | |
355 | else if(dacId.At(i)==kIdCOMPREF) dacarray.AddAt(dacs.At(i),kCOMPREF); | |
356 | else if(dacId.At(i)==kIdPreVTH) dacarray.AddAt(dacs.At(i),kPreVTH); | |
14374702 | 357 | else if(dacId.At(i)==kIdCGPOL) dacarray.AddAt(dacs.At(i),kCGPOL); |
358 | else printf("new DAC included in the scan??\n"); | |
286382a3 | 359 | |
360 | } | |
361 | ||
362 | return dacarray; | |
363 | ||
364 | } | |
365 | ||
366 |