]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCPreprocessor.cxx
Ignoring smell subdet
[u/mrichter/AliRoot.git] / ZDC / AliZDCPreprocessor.cxx
1 // --- ROOT system
2 #include <TFile.h>
3 #include <TClonesArray.h>
4 #include <TList.h>
5 #include <TObjString.h>
6 #include <TTimeStamp.h>
7
8 #include "AliZDCPreprocessor.h"
9 #include "AliCDBManager.h"
10 #include "AliCDBEntry.h"
11 #include "AliCDBMetaData.h"
12 #include "AliDCSValue.h"
13 #include "AliAlignObj.h"
14 #include "AliAlignObjParams.h"
15 #include "AliLog.h"
16 #include "AliZDCDataDCS.h"
17 #include "AliZDCCalibData.h"
18
19 //
20 // Class implementing ZDC pre-processor.
21 // It takes data from DCS and passes it to the class AliZDCDataDCS.
22 // The class is then written to the CDB.
23 //
24
25 ClassImp(AliZDCPreprocessor)
26
27 //______________________________________________________________________________________________
28 AliZDCPreprocessor::AliZDCPreprocessor(AliShuttleInterface* shuttle) :
29   AliPreprocessor("ZDC", shuttle),
30   fData(0)
31 {
32   // constructor
33 }
34
35 //______________________________________________________________________________________________
36 AliZDCPreprocessor::~AliZDCPreprocessor()
37 {
38   // destructor
39 }
40
41
42 //______________________________________________________________________________________________
43 void AliZDCPreprocessor::Initialize(Int_t run, UInt_t startTime,
44         UInt_t endTime)
45 {
46   // Creates AliZDCDataDCS object
47
48   AliPreprocessor::Initialize(run, startTime, endTime);
49
50         Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
51                 TTimeStamp(startTime).AsString(),
52                 TTimeStamp(endTime).AsString()));
53
54         fRun = run;
55         fStartTime = startTime;
56         fEndTime = endTime;
57
58         fData = new AliZDCDataDCS(fRun, fStartTime, fEndTime);
59 }
60
61 //______________________________________________________________________________________________
62 UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
63 {
64   // *************** From DCS ******************
65   // Fills data into a AliZDCDataDCS object
66   if(!dcsAliasMap) return 1;
67
68   // The processing of the DCS input data is forwarded to AliZDCDataDCS
69   Float_t DCSValues[28]; // DCSAliases=28
70   fData->ProcessData(*dcsAliasMap, DCSValues);
71   //dcsAliasMap->Print("");
72   //
73   // --- Writing ZDC table positions into alignment object
74   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
75   TClonesArray &alobj = *array;
76   AliAlignObjParams a;
77   Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
78   // Vertical table position in mm from DCS
79   Double_t dyZN1 = (Double_t) (DCSValues[0]/10.);
80   Double_t dyZP1 = (Double_t) (DCSValues[1]/10.);
81   Double_t dyZN2 = (Double_t) (DCSValues[2]/10.);
82   Double_t dyZP2 = (Double_t) (DCSValues[3]/10.);
83   const char *ZDCn1="ZDC/NeutronZDC1";
84   const char *ZDCp1="ZDC/ProtonZDC1";
85   const char *ZDCn2="ZDC/NeutronZDC2";
86   const char *ZDCp2="ZDC/ProtonZDC2";
87   UShort_t iIndex=0;
88   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
89   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
90   //
91   new(alobj[0]) AliAlignObjParams(ZDCn1, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
92   new(alobj[1]) AliAlignObjParams(ZDCp1, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
93   new(alobj[2]) AliAlignObjParams(ZDCn2, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
94   new(alobj[3]) AliAlignObjParams(ZDCp2, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
95   // save in CDB storage
96   AliCDBMetaData md;
97   md.SetResponsible("Chiara Oppedisano");
98   md.SetComment("Alignment object for ZDC");
99   Bool_t resultAl = kFALSE;
100   resultAl = Store("Align","Data", array, &md, 0, 0);
101   
102   AliZDCCalibData *calibdata = new AliZDCCalibData("ZDC");
103   
104 // *************** From DAQ ******************
105 // *****************************************************
106 // [a] PEDESTALS -> Pedestal subtraction
107 // *****************************************************
108 TString runType = GetRunType();
109 printf("\n\t AliZDCPreprocessor -> runType detected %s\n\n",runType.Data());
110 if(runType == "PEDESTAL_RUN"){
111   TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
112   if(!daqSources){
113     Log(Form("No source for PEDESTALS run %d !", fRun));
114     return 1;
115   }
116   Log("\t List of sources for PEDESTALS");
117   daqSources->Print();
118   //
119   TIter iter(daqSources);
120   TObjString* source = 0;
121   Int_t i=0;
122   while((source = dynamic_cast<TObjString*> (iter.Next()))){
123        Log(Form("\n\t Getting file #%d\n",++i));
124        TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName());
125        if(stringPedFileName.Length() <= 0){
126           Log(Form("No PEDESTAL file from source %s!", source->GetName()));
127           return 1;
128        }
129        const char* PedFileName = stringPedFileName.Data();
130        // no. ADCch = (22 signal ch. + 2 reference PMs) * 2 gain chain = 48
131        const Int_t NZDCch = 48;
132        if(PedFileName){
133          FILE *file;
134          if((file = fopen(PedFileName,"r")) == NULL){
135            printf("Cannot open file %s \n",PedFileName);
136            return 1;
137          }
138          Log(Form("File %s connected to process pedestal data", PedFileName));
139          Float_t PedVal[(3*NZDCch)][2];
140          for(Int_t i=0; i<(3*NZDCch); i++){
141             for(Int_t j=0; j<2; j++){
142                fscanf(file,"%f",&PedVal[i][j]);
143                //if(j==1) printf("PedVal[%d] -> %f, %f \n",i,PedVal[i][0],PedVal[i][1]);
144             }
145             if(i<NZDCch){
146               calibdata->SetMeanPed(i,PedVal[i][0]);
147               calibdata->SetMeanPedWidth(i,PedVal[i][1]);
148             }
149             else if(i>=NZDCch && i<(2*NZDCch)){
150               calibdata->SetOOTPed(i-NZDCch,PedVal[i][0]);
151               calibdata->SetOOTPedWidth(i-NZDCch,PedVal[i][1]);
152             }
153             else if(i>=(2*NZDCch) && i<(3*NZDCch)){
154               calibdata->SetPedCorrCoeff(i-(2*NZDCch),PedVal[i][0],PedVal[i][1]);
155             }
156          }
157        }
158        else{
159           Log(Form("File %s not found", PedFileName));
160           return 1;
161        }
162        //
163       //calibdata->Print("");
164   }
165   delete daqSources; daqSources = 0;
166 }
167 // *****************************************************
168 // [b] EMD EVENTS -> Energy calibration and equalization
169 // *****************************************************
170 else if(runType == "PULSER_RUN"){
171   TList* daqSources = GetFileSources(kDAQ, "EMDCALIB");
172   if(!daqSources){
173     AliError(Form("No sources for PULSER_RUN run %d !", fRun));
174     return 1;
175   }
176   Log("\t List of sources for PULSER_RUN");
177   daqSources->Print();
178   //
179   TIter iter2(daqSources);
180   TObjString* source = 0;
181   Int_t j=0;
182   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
183        Log(Form("\n\t Getting file #%d\n",++j));
184        TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName());
185        if(stringEMDFileName.Length() <= 0){
186          Log(Form("No EMDCALIB file from source %s!", source->GetName()));
187          return 1;
188        }
189        const char* EMDFileName = stringEMDFileName.Data();
190        if(EMDFileName){
191          FILE *file;
192          if((file = fopen(EMDFileName,"r")) == NULL){
193            printf("Cannot open file %s \n",EMDFileName);
194            return 1;
195          }
196          Log(Form("File %s connected to process data from EM dissociation events", EMDFileName));
197          //
198          Float_t fitValEMD[6]; Float_t equalCoeff[5][4];
199          Float_t CalibVal[4];
200          for(Int_t j=0; j<10; j++){         
201            if(j<6){
202              fscanf(file,"%f",&fitValEMD[j]);
203              if(j<4){
204                CalibVal[j] = fitValEMD[j]/2.76;
205                calibdata->SetEnCalib(j,CalibVal[j]);
206              }
207              else calibdata->SetEnCalib(j,fitValEMD[j]);
208            }
209            else{
210              for(Int_t k=0; k<5; k++){
211                 fscanf(file,"%f",&equalCoeff[j][k]);
212                 if(j==6) calibdata->SetZN1EqualCoeff(k, equalCoeff[j][k]);
213                 else if(j==7) calibdata->SetZP1EqualCoeff(k, equalCoeff[j][k]);
214                 else if(j==8) calibdata->SetZN2EqualCoeff(k, equalCoeff[j][k]);
215                 else if(j==9) calibdata->SetZP2EqualCoeff(k, equalCoeff[j][k]);  
216              }
217            }
218          }
219        }
220        else{
221          Log(Form("File %s not found", EMDFileName));
222          return 1;
223        }
224        //calibdata->Print("");
225   }
226 }
227 // ********************************************************
228 // [c] PHYSICS RUNS -> Parameters needed for reconstruction
229 // ********************************************************
230 else if(runType == "PHYSICS"){
231   TList* daqSources = GetFileSources(kDAQ, "PHYSICS");
232   if(!daqSources){
233     AliError(Form("No sources for PHYSICS run %d !", fRun));
234     return 1;
235   }
236   Log("\t List of sources for PHYSICS");
237   daqSources->Print();
238   //
239   TIter iter2(daqSources);
240   TObjString* source = 0;
241   Int_t j=0;
242   while((source = dynamic_cast<TObjString*> (iter2.Next()))){
243        Log(Form("\n\t Getting file #%d\n",++j));
244        TString stringPHYSFileName = GetFile(kDAQ, "PHYSICS", source->GetName());
245        if(stringPHYSFileName.Length() <= 0){
246          Log(Form("No PHYSICS file from source %s!", source->GetName()));
247          return 1;
248        }
249        const char* PHYSFileName = stringPHYSFileName.Data();
250        if(PHYSFileName){
251          FILE *file;
252          if((file = fopen(PHYSFileName,"r")) == NULL){
253            printf("Cannot open file %s \n",PHYSFileName);
254            return 1;
255          }
256          Log(Form("File %s connected to process data from PHYSICS runs", PHYSFileName));
257          //
258          Float_t PHYSRecParam[10]; 
259          for(Int_t j=0; j<10; j++) fscanf(file,"%f",&PHYSRecParam[j]);
260          calibdata->SetZEMEndValue(PHYSRecParam[0]);
261          calibdata->SetZEMCutFraction(PHYSRecParam[1]);
262          calibdata->SetDZEMSup(PHYSRecParam[2]);
263          calibdata->SetDZEMInf(PHYSRecParam[3]);
264          calibdata->SetEZN1MaxValue(PHYSRecParam[4]);
265          calibdata->SetEZP1MaxValue(PHYSRecParam[5]);
266          calibdata->SetEZDC1MaxValue(PHYSRecParam[6]);
267          calibdata->SetEZN2MaxValue(PHYSRecParam[7]);
268          calibdata->SetEZP2MaxValue(PHYSRecParam[8]);
269          calibdata->SetEZDC2MaxValue(PHYSRecParam[9]);
270        }
271        else{
272          Log(Form("File %s not found", PHYSFileName));
273          return 1;
274        }
275        //calibdata->Print("");
276   }
277
278 else {
279   Log(Form("Nothing to do: run type is %s", runType.Data()));
280   return 0;
281
282
283   // note that the parameters are returned as character strings!
284   const char* nEvents = GetRunParameter("totalEvents");
285   if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
286   else Log(Form("Number of events not put in logbook!"));
287
288   // Storing the final CDB file
289   AliCDBMetaData metaData;
290   metaData.SetBeamPeriod(0);
291   metaData.SetResponsible("Chiara");
292   metaData.SetComment("Filling AliZDCCalibData object");
293
294   Bool_t resultCal = kFALSE;
295   resultCal = Store("Calib","Data",calibdata, &metaData, 0, 1);
296  
297   UInt_t result = 0;
298   if(resultAl == kFALSE || resultCal == kFALSE){
299     if(resultAl == kFALSE  && resultCal == kFALSE ) result = 3;
300     else result = 2;
301   }
302   
303   return result;
304   
305 }