]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCPreprocessor.cxx
Digits and raw data updated for commissioning
[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[26];
70   fData->ProcessData(*dcsAliasMap, DCSValues);
71   // Store DCS data for reference
72   AliCDBMetaData metadata;
73   metadata.SetResponsible("Chiara Oppedisano");
74   metadata.SetComment("DCS data for ZDC");
75   Bool_t resStore = kFALSE;
76   resStore = StoreReferenceData("DCS","Data",fData,&metadata);
77   //dcsAliasMap->Print("");
78   //
79   // --- Writing ZDC table positions into alignment object
80   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
81   TClonesArray &alobj = *array;
82   AliAlignObjParams a;
83   Double_t dx=0., dz=0., dpsi=0., dtheta=0., dphi=0.;
84   // Vertical table position in mm from DCS
85   Double_t dyZN1 = (Double_t) (DCSValues[0]/10.);
86   Double_t dyZP1 = (Double_t) (DCSValues[1]/10.);
87   Double_t dyZN2 = (Double_t) (DCSValues[2]/10.);
88   Double_t dyZP2 = (Double_t) (DCSValues[3]/10.);
89   const char *ZDCn1="ZDC/NeutronZDC1";
90   const char *ZDCp1="ZDC/ProtonZDC1";
91   const char *ZDCn2="ZDC/NeutronZDC2";
92   const char *ZDCp2="ZDC/ProtonZDC2";
93   UShort_t iIndex=0;
94   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
95   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
96   //
97   new(alobj[0]) AliAlignObjParams(ZDCn1, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
98   new(alobj[1]) AliAlignObjParams(ZDCp1, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
99   new(alobj[2]) AliAlignObjParams(ZDCn2, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
100   new(alobj[3]) AliAlignObjParams(ZDCp2, volid, dx, dyZP2, dz, dpsi, dtheta, dphi, kTRUE);
101   // save in CDB storage
102   AliCDBMetaData md;
103   md.SetResponsible("Chiara Oppedisano");
104   md.SetComment("Alignment object for ZDC");
105   Bool_t resultAl = kFALSE;
106   resultAl = Store("Align","Data", array, &md, 0, 0);
107   
108   AliZDCCalibData *calibdata = new AliZDCCalibData("ZDC");
109   
110   // *************** From DAQ ******************
111   // [a] PEDESTALS
112 TString runType = GetRunType();
113 if (runType = "PEDESTAL_RUN") {
114   TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
115   if(!daqSources){
116     Log(Form("No source for PEDESTALS run %d !", fRun));
117     return 1;
118   }
119   Log("\t List of sources for PEDESTALS");
120   daqSources->Print();
121   //
122   TIter iter(daqSources);
123   TObjString* source = 0;
124   Int_t i=0;
125   while((source = dynamic_cast<TObjString*> (iter.Next()))){
126        Log(Form("\n\t Getting file #%d\n",++i));
127        TString stringPedFileName = GetFile(kDAQ, "PEDESTALS", source->GetName());
128        if(stringPedFileName.Length() <= 0){
129           Log(Form("No PEDESTAL file from source %s!", source->GetName()));
130           return 1;
131        }
132        const char* PedFileName = stringPedFileName.Data();
133        const Int_t NZDCch = 44;
134        if(PedFileName){
135          FILE *file;
136          if((file = fopen(PedFileName,"r")) == NULL){
137            printf("Cannot open file %s \n",PedFileName);
138            return 1;
139          }
140          Log(Form("File %s connected to analyze pedestal events", PedFileName));
141          Float_t PedVal[(3*NZDCch)][2];
142          for(Int_t i=0; i<(3*NZDCch); i++){
143             for(Int_t j=0; j<2; j++){
144                fscanf(file,"%f",&PedVal[i][j]);
145                //if(j==1) printf("PedVal[%d] -> %f, %f \n",i,PedVal[i][0],PedVal[i][1]);
146             }
147             if(i<NZDCch){
148               calibdata->SetMeanPed(i,PedVal[i][0]);
149               calibdata->SetMeanPedWidth(i,PedVal[i][1]);
150             }
151             else if(i>=NZDCch && i<(2*NZDCch)){
152               calibdata->SetOOTPed(i-NZDCch,PedVal[i][0]);
153               calibdata->SetOOTPedWidth(i-NZDCch,PedVal[i][1]);
154             }
155             else if(i>=(2*NZDCch) && i<(3*NZDCch)){
156               calibdata->SetPedCorrCoeff(i-(2*NZDCch),PedVal[i][0],PedVal[i][1]);
157             }
158          }
159        }
160        else{
161           Log(Form("File %s not found", PedFileName));
162           return 1;
163        }
164        //
165       //calibdata->Print("");
166   }
167   delete daqSources; daqSources = 0;
168 }
169   // [b] EMD EVENTS
170 else if (runType == "PHYSICS") {
171   TList* daqSources = GetFileSources(kDAQ, "PHYSICS");
172   if(!daqSources){
173     AliError(Form("No sources for PHYSICS run %d !", fRun));
174     return 1;
175   }
176   Log("\t List of sources for PHYSICS");
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, "PHYSICS", source->GetName());
185        if(stringEMDFileName.Length() <= 0){
186          Log(Form("No PHYSICS 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 analyze EM dissociation events", EMDFileName));
197          Float_t EMDFitVal[2];
198          for(Int_t j=0; j<2; j++){          
199            fscanf(file,"%f",&EMDFitVal[j]);
200          }
201          calibdata->SetEnCalib(EMDFitVal);
202        }
203        else{
204          Log(Form("File %s not found", EMDFileName));
205          return 1;
206        }
207        //calibdata->Print("");
208   }
209
210 else {
211   Log(Form("Nothing to do: run type is %s", runType.Data()));
212   return 0;
213
214   // note that the parameters are returned as character strings!
215   const char* nEvents = GetRunParameter("totalEvents");
216   if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
217   else Log(Form("Number of events not put in logbook!"));
218
219   // Storing the final CDB file
220   AliCDBMetaData metaData;
221   metaData.SetBeamPeriod(0);
222   metaData.SetResponsible("Chiara");
223   metaData.SetComment("Filling AliZDCCalibData object");
224
225   Bool_t resultCal = kFALSE;
226   resultCal = Store("Calib","Data",calibdata, &metaData, 0, 1);
227  
228   UInt_t result = 0;
229   if(resultAl == kFALSE || resultCal == kFALSE){
230     if(resultAl == kFALSE  && resultCal == kFALSE ) result = 3;
231     else result = 2;
232   }
233   
234   return result;
235   
236 }