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