Bug fix
[u/mrichter/AliRoot.git] / ITS / AliITSPreprocessorSDD.cxx
CommitLineData
e56160b8 1/////////////////////////////////////////
2// Class for SDD digits preprocessing //
7537d03c 3// //
4// //
e56160b8 5////////////////////////////////////////
6
5a9fd7dd 7/* $Id$ */
8
e56160b8 9#include "AliITSPreprocessorSDD.h"
10#include "AliITSCalibrationSDD.h"
18da6e54 11#include "AliITSDriftSpeedSDD.h"
12#include "AliITSDriftSpeedArraySDD.h"
cfaccd71 13#include "AliITSDCSAnalyzerSDD.h"
e56160b8 14#include "AliShuttleInterface.h"
15#include "AliCDBMetaData.h"
16#include "TObjArray.h"
e56160b8 17#include "AliLog.h"
dfb8947f 18#include <TObjString.h>
19#include <TSystem.h>
20#include <TList.h>
e56160b8 21
22const Int_t AliITSPreprocessorSDD::fgkNumberOfSDD = 260;
23const Int_t AliITSPreprocessorSDD::fgkNumberOfChannels = 512;
7537d03c 24const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal";
25const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise";
e56160b8 26ClassImp(AliITSPreprocessorSDD)
27
28
cfaccd71 29UInt_t AliITSPreprocessorSDD::Process(TMap* dcsAliasMap){
e56160b8 30
31 //preprocessing.
32
18da6e54 33 TString runType = GetRunType();
34 Bool_t retcode;
c2bd28b6 35 Char_t command[100];
18da6e54 36 Char_t inpFileName[100];
37 AliCDBMetaData *md1= new AliCDBMetaData();
38 md1->SetResponsible("Elisabetta Crescio, Francesco Prino");
39 md1->SetBeamPeriod(0);
40 md1->SetAliRootVersion("head 30 November 2007"); //root version
41 md1->SetComment("This is a test");
c2bd28b6 42
18da6e54 43 if (runType == "PULSER_RUN"){
44 TObjArray calSDD(fgkNumberOfSDD);
45 calSDD.SetOwner(kFALSE);
46 Float_t baseline,rawnoise,cmn,corn,gain;
af066a8f 47 Int_t isgoodan,i,im,is,isgoodmod,basmin,basoff;
18da6e54 48 Int_t numOfBadChannels[fgkNumberOfSDD];
49
50 TList* sourceList = GetFileSources(kDAQ, "SDD_Calib");
51 if (!sourceList){
52 Log("Error: no sources found for SDD_Calib");
ba541030 53 return 2;
54 }
dfb8947f 55
18da6e54 56 Int_t ind = 0;
57 while (sourceList->At(ind)!=NULL) {
58 TObjString* tarId = (TObjString*) sourceList->At(ind);
59 TString tarName = GetFile(kDAQ, "SDD_Calib", tarId->GetString().Data());
60 if(tarName.Length()==0){
61 Log(Form("Baseline tar file from source %d not found.",ind));
dfb8947f 62 return 2;
afa07040 63 }
18da6e54 64 sprintf(command,"tar -xf %s",tarName.Data());
65 gSystem->Exec(command);
66 ind++;
67 }
68 delete sourceList;
c2bd28b6 69
18da6e54 70 for(Int_t imod=0;imod<fgkNumberOfSDD;imod++){
71 AliITSCalibrationSDD *cal = new AliITSCalibrationSDD("simulated");
72 numOfBadChannels[imod]=0;
73 Int_t badch[fgkNumberOfChannels];
74 for(Int_t isid=0;isid<=1;isid++){
75 sprintf(inpFileName,"./SDDbase_mod%03d_sid%d.data",imod,isid);
76 FILE* basFil = fopen(inpFileName,"read");
77 if (basFil == 0) {
78 Log(Form("File %s not found.",inpFileName));
79 return 2;
80 }
81 fscanf(basFil,"%d %d %d\n",&im,&is,&isgoodmod);
82 if(!isgoodmod) cal->SetDead();
83 for(Int_t ian=0;ian<(fgkNumberOfChannels/2);ian++){
af066a8f 84 fscanf(basFil,"%d %d %f %d %d %f %f %f %f\n",&i,&isgoodan,&baseline,&basmin,&basoff,&rawnoise,&cmn,&corn,&gain);
18da6e54 85 Int_t ich=ian;
86 if(isid==1) ich+=256;
87 if(!isgoodan){
88 Int_t ibad=numOfBadChannels[imod];
89 numOfBadChannels[imod]++;
90 badch[ibad]=ich;
91 }
92 cal->SetBaseline(ich,baseline);
93 cal->SetNoiseAfterElectronics(ich,rawnoise);
94 Int_t iChip=cal->GetChip(ich);
95 Int_t iChInChip=cal->GetChipChannel(ich);
96 cal->SetGain(gain,isid,iChip,iChInChip);
97 }
98 cal->SetDeadChannels(numOfBadChannels[imod]);
99 for(Int_t ibad=0;ibad<numOfBadChannels[imod];ibad++){
100 cal->SetBadChannel(ibad,badch[ibad]);
101 }
102 fclose(basFil);
c2bd28b6 103 }
18da6e54 104 calSDD.Add(cal);
e56160b8 105 }
18da6e54 106 md1->SetObjectClassName("AliITSCalibration");
107 retcode = Store("Calib","CalibSDD",&calSDD,md1, 0, kTRUE);
108 }else if(runType == "PHYSICS"){
e56160b8 109
18da6e54 110 TObjArray vdrift(2*fgkNumberOfSDD);
111 vdrift.SetOwner(kFALSE);
112 Int_t evNumb,polDeg;
113 UInt_t timeStamp;
114 Float_t param[4];
e56160b8 115
18da6e54 116 TList* sourceList = GetFileSources(kDAQ, "SDD_Injec");
117 if (!sourceList){
118 Log("Error: no sources found for SDD_Injec");
119 return 2;
120 }
121 Int_t ind = 0;
122 while (sourceList->At(ind)!=NULL) {
123 TObjString* tarId = (TObjString*) sourceList->At(ind);
124 TString tarName = GetFile(kDAQ, "SDD_Injec", tarId->GetString().Data());
125 if(tarName.Length()==0){
126 Log(Form("Injector tar file from source %d not found.",ind));
127 return 2;
128 }
129 sprintf(command,"tar -xf %s",tarName.Data());
130 gSystem->Exec(command);
131 ind++;
132 }
133 delete sourceList;
e56160b8 134
18da6e54 135 for(Int_t imod=0;imod<fgkNumberOfSDD;imod++){
136 for(Int_t isid=0;isid<=1;isid++){
137 AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
138 sprintf(inpFileName,"./SDDinj_mod%03d_sid%d.data",imod,isid);
139 FILE* injFil = fopen(inpFileName,"read");
140 if (injFil == 0) {
141 Log(Form("File %s not found.",inpFileName));
142 return 2;
143 }
144 fscanf(injFil,"%d",&polDeg);
145 while (!feof(injFil)){
146 fscanf(injFil,"%d %d",&evNumb,&timeStamp);
147 if(feof(injFil)) break;
148 for(Int_t ic=0;ic<4;ic++) fscanf(injFil,"%f",&param[ic]);
149 AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,param);
150 arr->AddDriftSpeed(dsp);
151 }
152 vdrift.Add(arr);
153 }
154 }
155 md1->SetObjectClassName("AliITSDriftSpeedArraySDD");
156 retcode = Store("Calib","DriftSpeedSDD",&vdrift,md1,0, kTRUE);
157 }else{
158 // do nothing for other run types
159 retcode=1;
160 }
cfaccd71 161 if(retcode){
162 // process DCS data
163 AliITSDCSAnalyzerSDD *dcs=new AliITSDCSAnalyzerSDD();
164 dcs->AnalyzeData(dcsAliasMap);
165 TObjArray refDCS(fgkNumberOfSDD);
166 refDCS.SetOwner(kFALSE);
167 for(Int_t imod=0;imod<fgkNumberOfSDD;imod++){
168 AliITSDCSDataSDD *dcsdata=dcs->GetDCSData(imod);
169 refDCS.Add(dcsdata);
170 }
171
172 AliCDBMetaData *mddcs= new AliCDBMetaData();
173 mddcs->SetResponsible("Francesco Prino");
174 mddcs->SetBeamPeriod(0);
175 mddcs->SetAliRootVersion("head 18 December 2007"); //root version
176 mddcs->SetComment("This is a test");
177 mddcs->SetObjectClassName("AliITSDCSDataSDD");
178 Int_t retcodedcs = StoreReferenceData("DCS","DataSDD",&refDCS,mddcs);
179
180 if(retcodedcs) return 0;
181 }
182 return 1;
e56160b8 183}