Bug fix in the destructor
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSDD.cxx
CommitLineData
979b5a5f 1/**************************************************************************
2 * Copyright(c) 2007-2009, 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 **************************************************************************/
e56160b8 15
20f3f947 16/* $Id$ */
5a9fd7dd 17
979b5a5f 18///////////////////////////////////////////////////////////////////
19// //
20// Implementation of the class for SDD preprocessing //
21// Origin: E.Crescio, Torino, crescio@to.infn.it //
22// F.Prino, Torino, prino@to.infn.it //
23// //
24///////////////////////////////////////////////////////////////////
25
e56160b8 26#include "AliITSPreprocessorSDD.h"
27#include "AliITSCalibrationSDD.h"
18da6e54 28#include "AliITSDriftSpeedSDD.h"
29#include "AliITSDriftSpeedArraySDD.h"
cfaccd71 30#include "AliITSDCSAnalyzerSDD.h"
e56160b8 31#include "AliShuttleInterface.h"
979b5a5f 32#include "AliCDBEntry.h"
e56160b8 33#include "AliCDBMetaData.h"
34#include "TObjArray.h"
e56160b8 35#include "AliLog.h"
dfb8947f 36#include <TObjString.h>
37#include <TSystem.h>
38#include <TList.h>
e56160b8 39
7537d03c 40const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal";
41const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise";
e56160b8 42ClassImp(AliITSPreprocessorSDD)
43
44
317e638f 45//______________________________________________________________________
cfaccd71 46UInt_t AliITSPreprocessorSDD::Process(TMap* dcsAliasMap){
e56160b8 47
979b5a5f 48 // Get DDL map from OCDB
49 AliCDBEntry* entry = GetFromOCDB("Calib", "DDLMapSDD");
50 if(!entry){
51 Log("DDL map file not found in OCDB.");
52 return 2;
53 }
54 AliITSDDLModuleMapSDD* ddlmap = (AliITSDDLModuleMapSDD*)entry->GetObject();
55 if(!ddlmap){
56 Log("AliITSDDLModuleMapSDD object not in file.");
57 return 2;
58 }
e56160b8 59
979b5a5f 60 //preprocessing
18da6e54 61 TString runType = GetRunType();
62 Bool_t retcode;
c2bd28b6 63
ad2585ed 64 if (runType == "PULSER"){
317e638f 65 retcode=ProcessPulser(ddlmap);
66 }else if(runType== "INJECTOR"){
67 retcode=ProcessInjector(ddlmap);
68 }else{
69 // do nothing for other run types
70 retcode=1;
71 }
72 if(retcode){
73 Bool_t retcodedcs =ProcessDCSDataPoints(dcsAliasMap);
74 if(retcodedcs) return 0;
75 }
76 return 1;
77}
78//______________________________________________________________________
79Bool_t AliITSPreprocessorSDD::ProcessPulser(AliITSDDLModuleMapSDD* ddlmap){
80 // Process FXS files from PULSER run (baseline, noise, gain)
81 TObjArray calSDD(kNumberOfSDD);
82 calSDD.SetOwner(kFALSE);
83 Char_t command[100];
84 Char_t inpFileName[100];
85 Float_t baseline,rawnoise,cmn,corn,gain;
86 Int_t isgoodan,i,im,is,isgoodmod,basmin,basoff;
e7610d19 87 Int_t th,tl;
317e638f 88 Int_t numOfBadChannels[kNumberOfSDD];
18da6e54 89
317e638f 90 TList* sourceList = GetFileSources(kDAQ, "SDD_Calib");
91 if (!sourceList){
92 Log("Error: no sources found for SDD_Calib");
93 return 2;
94 }
dfb8947f 95
317e638f 96 Int_t ind = 0;
97 while (sourceList->At(ind)!=NULL) {
98 TObjString* tarId = (TObjString*) sourceList->At(ind);
99 TString tarName = GetFile(kDAQ, "SDD_Calib", tarId->GetString().Data());
100 if(tarName.Length()==0){
101 Log(Form("Baseline tar file from source %d not found.",ind));
102 return 2;
18da6e54 103 }
317e638f 104 sprintf(command,"tar -xf %s",tarName.Data());
105 gSystem->Exec(command);
106 ind++;
107 }
108 delete sourceList;
109
110 for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
111 for(Int_t imod=0;imod<kModulesPerDDL;imod++){
112 Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
113 if(modID==-1) continue;
114 modID-=240; // to have SDD modules numbering from 0 to 260
115 AliITSCalibrationSDD *cal = new AliITSCalibrationSDD("simulated");
116 numOfBadChannels[modID]=0;
117 Int_t badch[kNumberOfChannels];
118 for(Int_t isid=0;isid<=1;isid++){
119 sprintf(inpFileName,"./SDDbase_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
120 FILE* basFil = fopen(inpFileName,"read");
121 if (basFil == 0) {
122 Log(Form("File %s not found.",inpFileName));
123 cal->SetBad();
124 continue;
125 }
126 fscanf(basFil,"%d %d %d\n",&im,&is,&isgoodmod);
20f3f947 127 if(!isgoodmod) cal->SetBad();
e7610d19 128 fscanf(basFil,"%d\n",&th);
129 fscanf(basFil,"%d\n",&tl);
20f3f947 130 cal->SetZSLowThreshold(isid,tl);
131 cal->SetZSHighThreshold(isid,th);
317e638f 132 for(Int_t ian=0;ian<(kNumberOfChannels/2);ian++){
133 fscanf(basFil,"%d %d %f %d %d %f %f %f %f\n",&i,&isgoodan,&baseline,&basmin,&basoff,&rawnoise,&cmn,&corn,&gain);
134 Int_t ich=ian;
135 if(isid==1) ich+=256;
136 if(!isgoodan){
137 Int_t ibad=numOfBadChannels[modID];
138 badch[ibad]=ich;
139 numOfBadChannels[modID]++;
979b5a5f 140 }
20f3f947 141 cal->SetBaseline(ich,baseline-basoff);
317e638f 142 cal->SetNoiseAfterElectronics(ich,rawnoise);
143 cal->SetGain(ich,gain);
979b5a5f 144 }
317e638f 145 cal->SetDeadChannels(numOfBadChannels[modID]);
146 for(Int_t ibad=0;ibad<numOfBadChannels[modID];ibad++){
147 cal->SetBadChannel(ibad,badch[ibad]);
148 }
149 fclose(basFil);
c2bd28b6 150 }
317e638f 151 calSDD.AddAt(cal,modID);
e56160b8 152 }
317e638f 153 }
154 AliCDBMetaData *md= new AliCDBMetaData();
155 md->SetResponsible("Francesco Prino");
156 md->SetBeamPeriod(0);
157 md->SetComment("AliITSCalibrationSDD from PEDESTAL+PULSER runs");
158 Bool_t retCode = Store("Calib","CalibSDD",&calSDD,md, 0, kTRUE);
159 return retCode;
160}
161//______________________________________________________________________
162Bool_t AliITSPreprocessorSDD::ProcessInjector(AliITSDDLModuleMapSDD* ddlmap){
163 // Process FXS files from injector events (INJECTOR or PHYSICS runs)
164 TObjArray vdrift(2*kNumberOfSDD);
165 vdrift.SetOwner(kFALSE);
166 Char_t command[100];
167 Char_t inpFileName[100];
168 Int_t evNumb,polDeg;
169 UInt_t timeStamp;
170 Float_t param[4];
e56160b8 171
317e638f 172 TList* sourceList = GetFileSources(kDAQ, "SDD_Injec");
173 if (!sourceList){
174 Log("Error: no sources found for SDD_Injec");
175 return 2;
176 }
177 Int_t ind = 0;
178 while (sourceList->At(ind)!=NULL) {
179 TObjString* tarId = (TObjString*) sourceList->At(ind);
180 TString tarName = GetFile(kDAQ, "SDD_Injec", tarId->GetString().Data());
181 if(tarName.Length()==0){
182 Log(Form("Injector tar file from source %d not found.",ind));
18da6e54 183 return 2;
184 }
317e638f 185 sprintf(command,"tar -xf %s",tarName.Data());
186 gSystem->Exec(command);
187 ind++;
188 }
189 delete sourceList;
190
191 for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
192 for(Int_t imod=0;imod<kModulesPerDDL;imod++){
193 Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
194 if(modID==-1) continue;
195 modID-=240; // to have SDD modules numbering from 0 to 260
196 for(Int_t isid=0;isid<=1;isid++){
197 AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
198 sprintf(inpFileName,"./SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
199 FILE* injFil = fopen(inpFileName,"read");
200 if (injFil == 0) {
201 Log(Form("File %s not found.",inpFileName));
202 AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD();
203 arr->AddDriftSpeed(dsp);
979b5a5f 204 vdrift.AddAt(arr,2*modID+isid);
317e638f 205 continue;
206 }
207 fscanf(injFil,"%d",&polDeg);
208 while (!feof(injFil)){
209 fscanf(injFil,"%d %d",&evNumb,&timeStamp);
210 if(feof(injFil)) break;
211 for(Int_t ic=0;ic<4;ic++) fscanf(injFil,"%f",&param[ic]);
212 AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,param);
213 arr->AddDriftSpeed(dsp);
18da6e54 214 }
317e638f 215 vdrift.AddAt(arr,2*modID+isid);
18da6e54 216 }
217 }
cfaccd71 218 }
317e638f 219 AliCDBMetaData *md= new AliCDBMetaData();
220 md->SetResponsible("Francesco Prino");
221 md->SetBeamPeriod(0);
222 md->SetComment("AliITSDriftSpeedSDD from injector events");
223 Bool_t retCode = Store("Calib","DriftSpeedSDD",&vdrift,md,0, kTRUE);
224 return retCode;
225}
226//______________________________________________________________________
227Bool_t AliITSPreprocessorSDD::ProcessDCSDataPoints(TMap* dcsAliasMap){
228 // Process DCS data
229 AliITSDCSAnalyzerSDD *dcs=new AliITSDCSAnalyzerSDD();
230 dcs->AnalyzeData(dcsAliasMap);
231 TObjArray refDCS(kNumberOfSDD);
232 refDCS.SetOwner(kFALSE);
233 for(Int_t imod=0;imod<kNumberOfSDD;imod++){
234 AliITSDCSDataSDD *dcsdata=dcs->GetDCSData(imod);
235 refDCS.Add(dcsdata);
236 }
237 AliCDBMetaData *md= new AliCDBMetaData();
238 md->SetResponsible("Francesco Prino");
239 md->SetBeamPeriod(0);
240 md->SetComment("AliITSDCSDataSDD objects from DCS DB");
241 Bool_t retCode = StoreReferenceData("DCS","DataSDD",&refDCS,md);
242 return retCode;
e56160b8 243}