improved Preprocessor for cosmic from Michal
[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
5a9fd7dd 16/* $Id$ */
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"
979b5a5f 29#include "AliITSDDLModuleMapSDD.h"
18da6e54 30#include "AliITSDriftSpeedArraySDD.h"
cfaccd71 31#include "AliITSDCSAnalyzerSDD.h"
e56160b8 32#include "AliShuttleInterface.h"
979b5a5f 33#include "AliCDBEntry.h"
e56160b8 34#include "AliCDBMetaData.h"
35#include "TObjArray.h"
e56160b8 36#include "AliLog.h"
dfb8947f 37#include <TObjString.h>
38#include <TSystem.h>
39#include <TList.h>
e56160b8 40
7537d03c 41const TString AliITSPreprocessorSDD::fgkNameHistoPedestals = "hpedestal";
42const TString AliITSPreprocessorSDD::fgkNameHistoNoise = "hnoise";
e56160b8 43ClassImp(AliITSPreprocessorSDD)
44
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 Char_t command[100];
18da6e54 64 Char_t inpFileName[100];
65 AliCDBMetaData *md1= new AliCDBMetaData();
979b5a5f 66 md1->SetResponsible("Francesco Prino");
18da6e54 67 md1->SetBeamPeriod(0);
68 md1->SetAliRootVersion("head 30 November 2007"); //root version
69 md1->SetComment("This is a test");
c2bd28b6 70
ad2585ed 71 if (runType == "PULSER"){
979b5a5f 72 TObjArray calSDD(kNumberOfSDD);
18da6e54 73 calSDD.SetOwner(kFALSE);
74 Float_t baseline,rawnoise,cmn,corn,gain;
af066a8f 75 Int_t isgoodan,i,im,is,isgoodmod,basmin,basoff;
979b5a5f 76 Int_t numOfBadChannels[kNumberOfSDD];
18da6e54 77
78 TList* sourceList = GetFileSources(kDAQ, "SDD_Calib");
79 if (!sourceList){
80 Log("Error: no sources found for SDD_Calib");
ba541030 81 return 2;
82 }
dfb8947f 83
18da6e54 84 Int_t ind = 0;
85 while (sourceList->At(ind)!=NULL) {
86 TObjString* tarId = (TObjString*) sourceList->At(ind);
87 TString tarName = GetFile(kDAQ, "SDD_Calib", tarId->GetString().Data());
88 if(tarName.Length()==0){
89 Log(Form("Baseline tar file from source %d not found.",ind));
dfb8947f 90 return 2;
afa07040 91 }
18da6e54 92 sprintf(command,"tar -xf %s",tarName.Data());
93 gSystem->Exec(command);
94 ind++;
95 }
96 delete sourceList;
c2bd28b6 97
979b5a5f 98 for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
99 for(Int_t imod=0;imod<kModulesPerDDL;imod++){
100 Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
101 if(modID==-1) continue;
102 modID-=240; // to have SDD modules numbering from 0 to 260
103 AliITSCalibrationSDD *cal = new AliITSCalibrationSDD("simulated");
104 numOfBadChannels[modID]=0;
105 Int_t badch[kNumberOfChannels];
106 for(Int_t isid=0;isid<=1;isid++){
107 sprintf(inpFileName,"./SDDbase_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
108 FILE* basFil = fopen(inpFileName,"read");
109 if (basFil == 0) {
110 Log(Form("File %s not found.",inpFileName));
eefec958 111 return 2;
979b5a5f 112 }
113 fscanf(basFil,"%d %d %d\n",&im,&is,&isgoodmod);
eefec958 114 if(!isgoodmod) cal->SetBad();
979b5a5f 115 for(Int_t ian=0;ian<(kNumberOfChannels/2);ian++){
116 fscanf(basFil,"%d %d %f %d %d %f %f %f %f\n",&i,&isgoodan,&baseline,&basmin,&basoff,&rawnoise,&cmn,&corn,&gain);
117 Int_t ich=ian;
118 if(isid==1) ich+=256;
119 if(!isgoodan){
120 Int_t ibad=numOfBadChannels[modID];
121 badch[ibad]=ich;
122 numOfBadChannels[modID]++;
123 }
124 cal->SetBaseline(ich,baseline);
125 cal->SetNoiseAfterElectronics(ich,rawnoise);
eefec958 126 cal->SetGain(ich,gain);
979b5a5f 127 }
128 cal->SetDeadChannels(numOfBadChannels[modID]);
129 for(Int_t ibad=0;ibad<numOfBadChannels[modID];ibad++){
130 cal->SetBadChannel(ibad,badch[ibad]);
131 }
132 fclose(basFil);
133 }
134 calSDD.AddAt(cal,modID);
c2bd28b6 135 }
e56160b8 136 }
18da6e54 137 md1->SetObjectClassName("AliITSCalibration");
138 retcode = Store("Calib","CalibSDD",&calSDD,md1, 0, kTRUE);
eefec958 139 }else if(runType == "PHYSICS" || runType== "INJECTOR"){
e56160b8 140
979b5a5f 141 TObjArray vdrift(2*kNumberOfSDD);
18da6e54 142 vdrift.SetOwner(kFALSE);
143 Int_t evNumb,polDeg;
144 UInt_t timeStamp;
145 Float_t param[4];
e56160b8 146
18da6e54 147 TList* sourceList = GetFileSources(kDAQ, "SDD_Injec");
148 if (!sourceList){
149 Log("Error: no sources found for SDD_Injec");
150 return 2;
151 }
152 Int_t ind = 0;
153 while (sourceList->At(ind)!=NULL) {
154 TObjString* tarId = (TObjString*) sourceList->At(ind);
155 TString tarName = GetFile(kDAQ, "SDD_Injec", tarId->GetString().Data());
156 if(tarName.Length()==0){
157 Log(Form("Injector tar file from source %d not found.",ind));
158 return 2;
159 }
160 sprintf(command,"tar -xf %s",tarName.Data());
161 gSystem->Exec(command);
162 ind++;
163 }
164 delete sourceList;
e56160b8 165
979b5a5f 166 for(Int_t iddl=0;iddl<kNumberOfDDL;iddl++){
167 for(Int_t imod=0;imod<kModulesPerDDL;imod++){
168 Int_t modID=ddlmap->GetModuleNumber(iddl,imod);
169 if(modID==-1) continue;
170 modID-=240; // to have SDD modules numbering from 0 to 260
171 for(Int_t isid=0;isid<=1;isid++){
172 AliITSDriftSpeedArraySDD *arr=new AliITSDriftSpeedArraySDD();
173 sprintf(inpFileName,"./SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
174 FILE* injFil = fopen(inpFileName,"read");
175 if (injFil == 0) {
176 Log(Form("File %s not found.",inpFileName));
eefec958 177 return 2;
979b5a5f 178 }
179 fscanf(injFil,"%d",&polDeg);
180 while (!feof(injFil)){
181 fscanf(injFil,"%d %d",&evNumb,&timeStamp);
182 if(feof(injFil)) break;
183 for(Int_t ic=0;ic<4;ic++) fscanf(injFil,"%f",&param[ic]);
184 AliITSDriftSpeedSDD *dsp=new AliITSDriftSpeedSDD(evNumb,timeStamp,polDeg,param);
185 arr->AddDriftSpeed(dsp);
186 }
187 vdrift.AddAt(arr,2*modID+isid);
18da6e54 188 }
18da6e54 189 }
190 }
191 md1->SetObjectClassName("AliITSDriftSpeedArraySDD");
192 retcode = Store("Calib","DriftSpeedSDD",&vdrift,md1,0, kTRUE);
193 }else{
194 // do nothing for other run types
195 retcode=1;
196 }
cfaccd71 197 if(retcode){
198 // process DCS data
199 AliITSDCSAnalyzerSDD *dcs=new AliITSDCSAnalyzerSDD();
200 dcs->AnalyzeData(dcsAliasMap);
979b5a5f 201 TObjArray refDCS(kNumberOfSDD);
cfaccd71 202 refDCS.SetOwner(kFALSE);
979b5a5f 203 for(Int_t imod=0;imod<kNumberOfSDD;imod++){
cfaccd71 204 AliITSDCSDataSDD *dcsdata=dcs->GetDCSData(imod);
205 refDCS.Add(dcsdata);
206 }
207
208 AliCDBMetaData *mddcs= new AliCDBMetaData();
209 mddcs->SetResponsible("Francesco Prino");
210 mddcs->SetBeamPeriod(0);
211 mddcs->SetAliRootVersion("head 18 December 2007"); //root version
212 mddcs->SetComment("This is a test");
213 mddcs->SetObjectClassName("AliITSDCSDataSDD");
214 Int_t retcodedcs = StoreReferenceData("DCS","DataSDD",&refDCS,mddcs);
215
216 if(retcodedcs) return 0;
217 }
218 return 1;
e56160b8 219}