1 /**************************************************************************
2 * Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////
19 // Author: A. Mastroserio //
20 // This class is used within the detector algorithm framework //
21 // to write and read FO scan data. //
22 ////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
27 #include <TObjArray.h>
28 #include <TObjString.h>
30 #include <TIterator.h>
35 #include "AliITSOnlineSPDfoChipConfig.h"
36 #include "AliITSOnlineSPDfoChip.h"
37 #include "AliITSOnlineSPDfoInfo.h"
38 #include "AliITSOnlineSPDfo.h"
41 ClassImp(AliITSOnlineSPDfo)
42 //-----------------------------------------------
43 AliITSOnlineSPDfo::AliITSOnlineSPDfo():
53 fInitialConfiguration("")
55 // default constructor
58 //-------------------------------------------------
59 AliITSOnlineSPDfo::AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId):
69 fInitialConfiguration("")
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();
79 //--------------------------------------------------
80 AliITSOnlineSPDfo::AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c):
83 fFileName(c.fFileName),
86 fDACnames(c.fDACnames),
88 fCheckIndex(c.fCheckIndex),
90 fInitialConfiguration(c.fInitialConfiguration)
96 //--------------------------------------------------
97 void AliITSOnlineSPDfo::SetFile(TString inputfile)
100 // open the file where the data are
104 fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
107 fFile = TFile::Open(inputfile.Data());
109 Info("AliITSOnlineSPDfo::SetFile"," %s not existing.... The scan info are not available....crash is expected \n",inputfile.Data());
112 fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
113 fNdacs = fInfo->GetNumDACindex();
119 //------------------------------------------------------
120 void AliITSOnlineSPDfo::CreateOutputFile()
123 // Create the file (needed only in the DA ), will delete the previous one!
125 if(fFile) Info("AliITSOnlineSPDfo::CreateOutputFile","removing previous file....\n");
126 fFile = TFile::Open(fFileName.Data(),"RECREATE");
129 //------------------------------------------------------
130 void AliITSOnlineSPDfo::AddMeasurement(const TArrayS dac, Short_t measure[4], Int_t hs, Int_t chipId)
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:
138 // -> HS0_CHIP0 -> measure0[4]
141 // fArray->At(i) = DAC1-DAC2-DAC3-DAC4 measureN[4]
144 // -> HS0_CHIP1 -> measure0[4]
151 AliITSOnlineSPDfoChipConfig *counts = new AliITSOnlineSPDfoChipConfig(measure);
152 Int_t arrayelement = CheckDACEntry(dac);
155 TString dacname = CreateDACEntry(dac);
156 TObjString *string = new TObjString(dacname.Data());
157 fDACnames->Add(string);
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);
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);
181 AliITSOnlineSPDfoChip *c = (AliITSOnlineSPDfoChip *)arr->At(hs*10+chipId);
182 if(c)c->AddMeasurement(counts);
186 //---------------------------------------
187 Int_t AliITSOnlineSPDfo::CheckDACEntry(const TArrayS dac)
190 // Check if the set of dacs has been already added to the array
194 TString name = CreateDACEntry(dac);
197 Info("AliITSOnlineSPDfo::CheckDACEntry"," NO DAC name array is present, exiting.... \n");
202 for(Int_t i=0; i< fNdacs; i++) c+=dac.At(i)*TMath::Power(10,3*i);
203 if(c==fCheckIndex) return fIndex;
209 if(fDACnames->FindObject( name.Data() )) {
210 idx = fDACnames->IndexOf( fDACnames->FindObject( name.Data() ) );
212 for(Int_t i=0; i< fNdacs; i++) fCheckIndex+=dac.At(i)*TMath::Power(10,3*i);
219 //_________________________________________________________
220 void AliITSOnlineSPDfo::WriteToFile()
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
227 if(fDACnames->GetEntries() != fArray->GetEntries()) {
228 printf("mismatch names-array. Exiting....");
232 for(Int_t i=0; i< fDACnames->GetEntries(); i++){
233 fFile->WriteObject(fArray->At(i),fDACnames->At(i)->GetName());
235 fFile->WriteTObject(fInfo,"generalinfo");
239 //______________________________________________________
241 TString AliITSOnlineSPDfo::CreateDACEntry(const TArrayS dacs) const
244 // The string of DACs is build
248 for(Int_t i=0; i<dacs.GetSize(); i++) dacvalues+=Form("-%i",dacs.At(i));
249 dacvalues.Remove(0,1);
253 //_____________________________________________________
254 TArrayI AliITSOnlineSPDfo::GetDACscanParams() const
257 // this method retrieves the DAC value range and its steps
260 if(fFile->IsOpen()) f = fFile;
261 else f = TFile::Open(fFileName.Data());
264 if(f->GetNkeys() < 2) return dacs;
267 TArrayI min(fNdacs), max(fNdacs),step(fNdacs), check(fNdacs), refvalues(fNdacs);
269 for(Int_t i=0; i< fNdacs ; i++) {
278 TIter iter(f->GetListOfKeys());
279 while ((key = (TKey*)(iter.Next()))) {
280 TString classname = key->GetClassName();
281 if(classname.Contains("OnlineSPD")) break;
283 TString values = key->GetName();
284 Int_t *val = GetDACvalues(values,fNdacs); // the user has to delete it!
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;
291 refvalues.AddAt(val[i],i);
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);
297 // end procedure to get the step size
304 for(Int_t i=0; i<fNdacs; i++) {
305 dacs.AddAt(min.At(i),3*i);
306 dacs.AddAt(max.At(i),3*i+1);
307 dacs.AddAt(step.At(i),3*i+2);
313 //___________________________________________________________________
314 Int_t* AliITSOnlineSPDfo::GetDACvalues(TString s, const Int_t ndacs) const
317 // Translates the string of DACS values into an array of integers
320 Int_t *val = new Int_t[ndacs];
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
330 //___________________________________________________________________
331 Double_t* AliITSOnlineSPDfo::GetDACvaluesD(TString s, const Int_t ndacs) const
334 // Translates the string of DACS values into an array of doubles
335 // (needed to fill the thnsparse)
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];
344 //-------------------------------------------------------------------
345 TArrayS AliITSOnlineSPDfo::CreateDACArray(const TArrayS dacs, const TArrayS dacId) const
348 // method to order the data according to the DAC index
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);
357 else if(dacId.At(i)==kIdCGPOL) dacarray.AddAt(dacs.At(i),kCGPOL);
358 else printf("new DAC included in the scan??\n");