]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - ZDC/AliZDCPreprocessor.cxx
Adding comparison (Marian)
[u/mrichter/AliRoot.git] / ZDC / AliZDCPreprocessor.cxx
... / ...
CommitLineData
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 "AliAlignObjAngles.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
25ClassImp(AliZDCPreprocessor)
26
27//______________________________________________________________________________________________
28AliZDCPreprocessor::AliZDCPreprocessor(const char* detector, AliShuttleInterface* shuttle) :
29 AliPreprocessor(detector, shuttle),
30 fData(0)
31{
32 // constructor
33}
34
35//______________________________________________________________________________________________
36AliZDCPreprocessor::~AliZDCPreprocessor()
37{
38 // destructor
39}
40
41
42//______________________________________________________________________________________________
43void 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//______________________________________________________________________________________________
62UInt_t AliZDCPreprocessor::Process(TMap* dcsAliasMap)
63{
64 // *************** From DCS ******************
65 // Fills data into a AliZDCDataDCS object
66 if(!dcsAliasMap) return 0;
67
68 // The processing of the DCS input data is forwarded to AliZDCDataDCS
69 Float_t DCSValues[26];
70 fData->ProcessData(*dcsAliasMap, DCSValues);
71 //dcsAliasMap->Print("");
72 //
73 // --- Writing ZDC table positions into alignment object
74 TClonesArray *array = new TClonesArray("AliAlignObjAngles",10);
75 TClonesArray &alobj = *array;
76 AliAlignObjAngles 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]) AliAlignObjAngles(ZDCn1, volid, dx, dyZN1, dz, dpsi, dtheta, dphi, kTRUE);
92 new(alobj[1]) AliAlignObjAngles(ZDCp1, volid, dx, dyZP1, dz, dpsi, dtheta, dphi, kTRUE);
93 new(alobj[2]) AliAlignObjAngles(ZDCn2, volid, dx, dyZN2, dz, dpsi, dtheta, dphi, kTRUE);
94 new(alobj[3]) AliAlignObjAngles(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 UInt_t resultAl = 0;
100 resultAl = Store("Align","Data", array, &md, 0, 0);
101
102 // --- Writing ZDC PTMs HV values into calibration object
103 AliZDCCalibData *calibdata = new AliZDCCalibData("ZDC");
104 for(Int_t j=0; j<22; j++)
105 calibdata->SetPMTHVVal(j,DCSValues[j+4]);
106
107
108 // *************** From DAQ ******************
109 // [a] PEDESTALS
110TString runType = GetRunType();
111 TList* daqSources = GetFileSources(kDAQ, "PEDESTALS");
112 if(!daqSources){
113 Log(Form("No source for PEDESTALS run %d !", fRun));
114 return 0;
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 0;
128 }
129 const char* PedFileName = stringPedFileName.Data();
130 const Int_t NZDCch = 44;
131 if(PedFileName){
132 FILE *file;
133 if((file = fopen(PedFileName,"r")) == NULL){
134 printf("Cannot open file %s \n",PedFileName);
135 return 0;
136 }
137 Log(Form("File %s connected to analyze pedestal events", PedFileName));
138 Float_t PedVal[(3*NZDCch)][2];
139 for(Int_t i=0; i<(3*NZDCch); i++){
140 for(Int_t j=0; j<2; j++){
141 fscanf(file,"%f",&PedVal[i][j]);
142 //if(j==1) printf("PedVal[%d] -> %f, %f \n",i,PedVal[i][0],PedVal[i][1]);
143 }
144 if(i<NZDCch){
145 calibdata->SetMeanPed(i,PedVal[i][0]);
146 calibdata->SetMeanPedWidth(i,PedVal[i][1]);
147 }
148 else if(i>=NZDCch && i<(2*NZDCch)){
149 calibdata->SetOOTPed(i-NZDCch,PedVal[i][0]);
150 calibdata->SetOOTPedWidth(i-NZDCch,PedVal[i][1]);
151 }
152 else if(i>=(2*NZDCch) && i<(3*NZDCch)){
153 calibdata->SetPedCorrCoeff(i-(2*NZDCch),PedVal[i][0],PedVal[i][1]);
154 }
155 }
156 }
157 else{
158 Log(Form("File %s not found", PedFileName));
159 return 0;
160 }
161 //
162 //calibdata->Print("");
163 }
164 delete daqSources; daqSources = 0;
165 // [a] EMD EVENTS
166if (runType != "PEDESTALS") {
167 TList* daqSources = GetFileSources(kDAQ, "EMDCALIB");
168 if(!daqSources){
169 AliError(Form("No sources for EMDCALIB run %d !", fRun));
170 return 0;
171 }
172 Log("\t List of sources for EMDCALIB");
173 daqSources->Print();
174 //
175 TIter iter2(daqSources);
176 TObjString* source = 0;
177 Int_t j=0;
178 while((source = dynamic_cast<TObjString*> (iter2.Next()))){
179 Log(Form("\n\t Getting file #%d\n",++j));
180 TString stringEMDFileName = GetFile(kDAQ, "EMDCALIB", source->GetName());
181 if(stringEMDFileName.Length() <= 0){
182 Log(Form("No EMDCALIB file from source %s!", source->GetName()));
183 return 0;
184 }
185 const char* EMDFileName = stringEMDFileName.Data();
186 if(EMDFileName){
187 FILE *file;
188 if((file = fopen(EMDFileName,"r")) == NULL){
189 printf("Cannot open file %s \n",EMDFileName);
190 return 0;
191 }
192 Log(Form("File %s connected to analyze EM dissociation events", EMDFileName));
193 Float_t EMDFitVal[2];
194 for(Int_t j=0; j<2; j++){
195 fscanf(file,"%f",&EMDFitVal[j]);
196 }
197 calibdata->SetEnCalib(EMDFitVal);
198 }
199 else{
200 Log(Form("File %s not found", EMDFileName));
201 return 0;
202 }
203 //calibdata->Print("");
204 }
205}
206 // note that the parameters are returned as character strings!
207 const char* nEvents = GetRunParameter("totalEvents");
208 if(nEvents) Log(Form("Number of events for run %d: %s",fRun, nEvents));
209 else Log(Form("Number of events not put in logbook!"));
210
211 // Storing the final CDB file
212 AliCDBMetaData metaData;
213 metaData.SetBeamPeriod(0);
214 metaData.SetResponsible("Chiara");
215 metaData.SetComment("Filling AliZDCCalibData object");
216
217 UInt_t resultCal = 0;
218 resultCal = Store("Calib","Data",calibdata, &metaData, 0, 1);
219
220 UInt_t result = 0;
221 if(resultAl!=0 && resultCal!=0){
222 if(resultAl==1 && resultCal==1) result = 1;
223 else result = 2;
224 }
225
226 return result;
227
228}
229