Changes related to the extraction of the V0 finder into a separate class (A. Dainese...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDfo.cxx
CommitLineData
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
41ClassImp(AliITSOnlineSPDfo)
42//-----------------------------------------------
43AliITSOnlineSPDfo::AliITSOnlineSPDfo():
44fRunNr(0),
45fNdacs(0),
46fFileName(""),
47fFile(0x0),
48fInfo(0x0),
49fDACnames(0x0),
50fArray(0x0),
51fCheckIndex(-1),
52fIndex(-1),
53fInitialConfiguration("")
54{
55// default constructor
56}
57
58//-------------------------------------------------
59AliITSOnlineSPDfo::AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId):
60fRunNr(runNr),
61fNdacs(0),
62fFileName(""),
63fFile(0x0),
64fInfo(0x0),
65fDACnames(0x0),
66fArray(0x0),
67fCheckIndex(-1),
68fIndex(-1),
69fInitialConfiguration("")
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//--------------------------------------------------
80AliITSOnlineSPDfo::AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c):
81fRunNr(c.fRunNr),
82fNdacs(c.fNdacs),
83fFileName(c.fFileName),
84fFile(c.fFile),
85fInfo(c.fInfo),
86fDACnames(c.fDACnames),
87fArray(c.fArray),
88fCheckIndex(c.fCheckIndex),
89fIndex(c.fIndex),
90fInitialConfiguration(c.fInitialConfiguration)
91{
92 //
93 //copy constructor
94 //
95}
96//--------------------------------------------------
97void 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) {
109 Info("AliITSOnlineSPDfo::SetFile",Form(" %s not existing.... The scan info are not available....crash is expected \n",inputfile.Data()));
110 return;
111 } else {
112 fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
113 fNdacs = fInfo->GetNumDACindex();
114 }
115}
116
117}
118
119//------------------------------------------------------
120void 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//------------------------------------------------------
130void 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//---------------------------------------
187Int_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//_________________________________________________________
220void 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
241TString 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//_____________________________________________________
254TArrayI 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
303 for(Int_t i=0; i<fNdacs; i++) {
304 dacs.AddAt(min.At(i),3*i);
305 dacs.AddAt(max.At(i),3*i+1);
306 dacs.AddAt(step.At(i),3*i+2);
307 }
308
309
310 return dacs;
311}
312//___________________________________________________________________
313Int_t* AliITSOnlineSPDfo::GetDACvalues(TString s, const Int_t ndacs) const
314{
315 //
316 // Translates the string of DACS values into an array of integers
317 //
318
319 Int_t *val = new Int_t[ndacs];
320
321 s.ReplaceAll("-"," ");
322 char *pEnd = Form("%s",s.Data());
323 for(Int_t i=0; i< ndacs; i++) {
324 val[i] = strtol(pEnd,&pEnd,10); // conversion from string to long
325 }
326 return val;
327}
328
329//___________________________________________________________________
330Double_t* AliITSOnlineSPDfo::GetDACvaluesD(TString s, const Int_t ndacs) const
331{
332 //
333 // Translates the string of DACS values into an array of doubles
334 // (needed to fill the thnsparse)
335 //
336 Double_t *val = new Double_t[ndacs];
337 Int_t *values = GetDACvalues(s,ndacs);
338 for(Int_t i=0; i< ndacs; i++) val[i] = (Double_t)values[i];
339 delete [] values;
340
341 return val;
342}
343//-------------------------------------------------------------------
344TArrayS AliITSOnlineSPDfo::CreateDACArray(const TArrayS dacs, const TArrayS dacId) const
345{
346 //
347 // method to order the data according to the DAC index
348 //
349
350 TArrayS dacarray(dacs.GetSize());
351 for(Int_t i=0; i<dacs.GetSize(); i++) {
352 if(dacId.At(i)==kIdFOPOL) dacarray.AddAt(dacs.At(i),kFOPOL);
353 else if(dacId.At(i)==kIdCONVPOL) dacarray.AddAt(dacs.At(i),kCONVPOL);
354 else if(dacId.At(i)==kIdCOMPREF) dacarray.AddAt(dacs.At(i),kCOMPREF);
355 else if(dacId.At(i)==kIdPreVTH) dacarray.AddAt(dacs.At(i),kPreVTH);
356 else dacarray.AddAt(dacs.At(i),i);
357
358 }
359
360 return dacarray;
361
362}
363
364