]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, 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 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //#include <Riostream.h> | |
19 | //#include <stdio.h> | |
20 | //#include <stdlib.h> | |
21 | ||
22 | #include <TFile.h> | |
23 | //#include <TH1.h> | |
24 | //#include <TH1F.h> | |
25 | //#include <TH1S.h> | |
26 | #include <TH2S.h> | |
27 | #include <TMath.h> | |
28 | #include <TObjArray.h> | |
29 | #include <TObjString.h> | |
30 | #include <TTimeStamp.h> | |
31 | ||
32 | #include "AliCDBMetaData.h" | |
33 | #include "AliCDBEntry.h" | |
34 | #include "AliLog.h" | |
35 | #include "AliTOFChannelOnline.h" | |
36 | #include "AliTOFChannelOnlineStatus.h" | |
37 | #include "AliTOFDataDCS.h" | |
38 | #include "AliTOFGeometry.h" | |
39 | #include "AliTOFPreprocessor.h" | |
40 | #include "AliTOFFEEReader.h" | |
41 | ||
42 | //class TF1; | |
43 | //class AliDCSValue; | |
44 | //class AliTOFGeometry; | |
45 | ||
46 | // TOF preprocessor class. | |
47 | // It takes data from DCS and passes them to the class AliTOFDataDCS, which | |
48 | // processes them. The result is then written to the CDB. | |
49 | // analogously, it takes data form DAQ (both at Run level and inclusive - | |
50 | // of all the runs - level, processes them, and stores both Reference Data | |
51 | // and Online Calibration files in the CDB. | |
52 | // Processing of Pulser/Noise Run data and of TOF FEE DCS map | |
53 | ||
54 | // return codes: | |
55 | // return=0 : all ok | |
56 | // return=1 : no DCS input data Map | |
57 | // return=2 : no DCS input data processing | |
58 | // return=3 : no DCS processed data was stored in Ref Data | |
59 | // return=4 : no DAQ input for Ref Data | |
60 | // return=5 : failed to store DAQ Ref Data | |
61 | // return=6 : failed to retrieve DAQ data for calibration | |
62 | // return=7 : problems in processing histos in the input DAQ file | |
63 | // return=8 : failed to store Online Delays | |
64 | // return=9 : failed to store Reference Data for Pulser | |
65 | // return=10: failed to retrieve Pulser data | |
66 | // return=11: failed to store Pulser map in OCDB | |
67 | // return=12: failed to store Reference Data for Noise | |
68 | // return=13: failed to retrieve Noise data | |
69 | // return=14: failed to store Noise map in OCDB | |
70 | // return=15: failed to retrieve FEE data from FXS | |
71 | // return=16: failed to retrieve FEE data from OCDB | |
72 | // return=17: failed to store FEE data in OCDB | |
73 | // return=18: failed to store FEE reference data in OCDB | |
74 | ||
75 | ClassImp(AliTOFPreprocessor) | |
76 | ||
77 | const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean | |
78 | const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel | |
79 | const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay | |
80 | ||
81 | //_____________________________________________________________________________ | |
82 | ||
83 | AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) : | |
84 | AliPreprocessor("TOF", shuttle), | |
85 | fData(0), | |
86 | fh2(0), | |
87 | fCal(0), | |
88 | fCalStatus(0), | |
89 | fFEEStatus(0), | |
90 | fNChannels(0), | |
91 | fStoreRefData(kTRUE), | |
92 | fFDRFlag(kTRUE) | |
93 | { | |
94 | // constructor | |
95 | ||
96 | } | |
97 | ||
98 | //_____________________________________________________________________________ | |
99 | ||
100 | AliTOFPreprocessor::~AliTOFPreprocessor() | |
101 | { | |
102 | // destructor | |
103 | if (fData){ | |
104 | delete fData; | |
105 | fData = 0; | |
106 | } | |
107 | if (fh2){ | |
108 | delete fh2; | |
109 | fh2 = 0; | |
110 | } | |
111 | if (fCal){ | |
112 | // fCal->Clear(); | |
113 | delete fCal; | |
114 | fCal = 0; | |
115 | } | |
116 | if (fCalStatus){ | |
117 | delete fCalStatus; | |
118 | fCalStatus = 0; | |
119 | } | |
120 | if (fFEEStatus){ | |
121 | delete fFEEStatus; | |
122 | fFEEStatus = 0; | |
123 | } | |
124 | } | |
125 | ||
126 | //______________________________________________________________________________ | |
127 | void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime, | |
128 | UInt_t endTime) | |
129 | { | |
130 | // Creates AliTOFDataDCS object | |
131 | ||
132 | AliPreprocessor::Initialize(run, startTime, endTime); | |
133 | ||
134 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, | |
135 | TTimeStamp(startTime).AsString(), | |
136 | TTimeStamp(endTime).AsString())); | |
137 | ||
138 | fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime); | |
139 | fData->SetFDRFlag(fFDRFlag); | |
140 | fh2 = 0x0; | |
141 | fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX(); | |
142 | fCal = new TObjArray(fNChannels); | |
143 | fCal->SetOwner(); | |
144 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
145 | AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline(); | |
146 | fCal->AddAt(calChOnline,ich); | |
147 | } | |
148 | fCalStatus = new TObjArray(fNChannels); | |
149 | fCalStatus->SetOwner(); | |
150 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
151 | AliTOFChannelOnlineStatus * calChOnlineStatus = new AliTOFChannelOnlineStatus(); | |
152 | fCalStatus->AddAt(calChOnlineStatus,ich); | |
153 | } | |
154 | fFEEStatus = new TObjArray(fNChannels); | |
155 | fFEEStatus->SetOwner(); | |
156 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
157 | AliTOFChannelOnlineStatus * calChOnlineStatus = new AliTOFChannelOnlineStatus(); | |
158 | fFEEStatus->AddAt(calChOnlineStatus,ich); | |
159 | } | |
160 | } | |
161 | //_____________________________________________________________________________ | |
162 | Bool_t AliTOFPreprocessor::ProcessDCS(){ | |
163 | ||
164 | // check whether DCS should be processed or not... | |
165 | ||
166 | TString runType = GetRunType(); | |
167 | Log(Form("RunType %s",runType.Data())); | |
168 | ||
169 | if (runType != "PHYSICS"){ | |
170 | return kFALSE; | |
171 | } | |
172 | ||
173 | return kTRUE; | |
174 | } | |
175 | //_____________________________________________________________________________ | |
176 | ||
177 | UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap) | |
178 | { | |
179 | // Fills data into a AliTOFDataDCS object | |
180 | ||
181 | ||
182 | Log("Processing DCS DP"); | |
183 | TH1::AddDirectory(0); | |
184 | ||
185 | Bool_t resultDCSMap=kFALSE; | |
186 | Bool_t resultDCSStore=kFALSE; | |
187 | ||
188 | // processing DCS | |
189 | ||
190 | if (!dcsAliasMap){ | |
191 | Log("No DCS map found: TOF exiting from Shuttle"); | |
192 | return 1;// return error Code for DCS input data not found | |
193 | } | |
194 | else { | |
195 | // The processing of the DCS input data is forwarded to AliTOFDataDCS | |
196 | resultDCSMap=fData->ProcessData(*dcsAliasMap); | |
197 | if(!resultDCSMap){ | |
198 | Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle"); | |
199 | return 2;// return error Code for processed DCS data not stored | |
200 | } | |
201 | else{ | |
202 | AliCDBMetaData metaDataDCS; | |
203 | metaDataDCS.SetBeamPeriod(0); | |
204 | metaDataDCS.SetResponsible("Chiara Zampolli"); | |
205 | metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object."); | |
206 | AliInfo("Storing DCS Data"); | |
207 | resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS); | |
208 | if (!resultDCSStore){ | |
209 | Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle"); | |
210 | return 3;// return error Code for processed DCS data not stored | |
211 | // in reference data | |
212 | ||
213 | } | |
214 | } | |
215 | } | |
216 | return 0; | |
217 | } | |
218 | //_____________________________________________________________________________ | |
219 | ||
220 | UInt_t AliTOFPreprocessor::ProcessOnlineDelays() | |
221 | { | |
222 | // Processing data from DAQ for online calibration | |
223 | ||
224 | Log("Processing DAQ delays"); | |
225 | ||
226 | TH1::AddDirectory(0); | |
227 | ||
228 | Bool_t resultDAQRef=kFALSE; | |
229 | Bool_t resultTOFPP=kFALSE; | |
230 | // processing DAQ | |
231 | ||
232 | TFile * daqFile=0x0; | |
233 | ||
234 | if(fStoreRefData){ | |
235 | //retrieving data at Run level | |
236 | TList* list = GetFileSources(kDAQ, "RUNLevel"); | |
237 | if (list !=0x0 && list->GetEntries()!=0) | |
238 | { | |
239 | AliInfo("The following sources produced files with the id RUNLevel"); | |
240 | list->Print(); | |
241 | for (Int_t jj=0;jj<list->GetEntries();jj++){ | |
242 | TObjString * str = dynamic_cast<TObjString*> (list->At(jj)); | |
243 | AliInfo(Form("found source %s", str->String().Data())); | |
244 | // file to be stored run per run | |
245 | TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName()); | |
246 | if (fileNameRun.Length()>0){ | |
247 | AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data())); | |
248 | daqFile = new TFile(fileNameRun.Data(),"READ"); | |
249 | fh2 = (TH2S*) daqFile->Get("htof"); | |
250 | AliCDBMetaData metaDataHisto; | |
251 | metaDataHisto.SetBeamPeriod(0); | |
252 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
253 | metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data."); | |
254 | AliInfo("Storing Reference Data"); | |
255 | resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto); | |
256 | if (!resultDAQRef){ | |
257 | Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle"); | |
258 | return 5;//return error code for failure in storing Ref Data | |
259 | } | |
260 | daqFile->Close(); | |
261 | delete daqFile; | |
262 | } | |
263 | ||
264 | else{ | |
265 | Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
266 | return 4;//return error code for failure in retrieving Ref Data | |
267 | } | |
268 | } | |
269 | delete list; | |
270 | } | |
271 | else{ | |
272 | Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
273 | return 4;//return error code for failure in retrieving Ref Data | |
274 | } | |
275 | } | |
276 | ||
277 | ||
278 | //Total files, with cumulative histos | |
279 | ||
280 | TList* listTot = GetFileSources(kDAQ, "DELAYS"); | |
281 | if (listTot !=0x0 && listTot->GetEntries()!=0) | |
282 | { | |
283 | AliInfo("The following sources produced files with the id DELAYS"); | |
284 | listTot->Print(); | |
285 | for (Int_t jj=0;jj<listTot->GetEntries();jj++){ | |
286 | TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj)); | |
287 | AliInfo(Form("found source %s", str->String().Data())); | |
288 | ||
289 | // file with summed histos, to extract calib params | |
290 | TString fileName = GetFile(kDAQ, "DELAYS", str->GetName()); | |
291 | if (fileName.Length()>0){ | |
292 | AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data())); | |
293 | ||
294 | daqFile = new TFile(fileName.Data(),"READ"); | |
295 | if (fh2) delete fh2; | |
296 | fh2 = (TH2S*) daqFile->Get("htoftot"); | |
297 | if (!fh2){ | |
298 | Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle"); | |
299 | delete daqFile; | |
300 | return 7; //return error code for histograms not existing/junky | |
301 | } | |
302 | else { | |
303 | static const Int_t kSize=fh2->GetNbinsX(); | |
304 | static const Int_t kNBins=fh2->GetNbinsY(); | |
305 | static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1); | |
306 | if (kSize != fNChannels){ | |
307 | Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle"); | |
308 | delete daqFile; | |
309 | return 7; //return error code for histograms not existing/junky | |
310 | } | |
311 | Int_t nNotStatistics = 0; // number of channel with not enough statistics | |
312 | for (Int_t ich=0;ich<kSize;ich++){ | |
313 | TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5); | |
314 | for (Int_t ibin=0;ibin<kNBins;ibin++){ | |
315 | h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1)); | |
316 | } | |
317 | if(h1->Integral()<fgkIntegralThr) { | |
318 | nNotStatistics++; | |
319 | if (!fFDRFlag) Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs | |
320 | delete h1; | |
321 | h1=0x0; | |
322 | continue; | |
323 | } | |
324 | if (!fFDRFlag) { // not computing delays if in FDR runs | |
325 | Bool_t found=kFALSE; | |
326 | Float_t minContent=h1->Integral()*fgkThrPar; | |
327 | Int_t nbinsX = h1->GetNbinsX(); | |
328 | Int_t startBin=1; | |
329 | for (Int_t j=1; j<=nbinsX; j++){ | |
330 | if (( | |
331 | h1->GetBinContent(j) + | |
332 | h1->GetBinContent(j+1)+ | |
333 | h1->GetBinContent(j+2)+ | |
334 | h1->GetBinContent(j+3))>minContent){ | |
335 | found=kTRUE; | |
336 | startBin=j; | |
337 | break; | |
338 | } | |
339 | } | |
340 | if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich)); | |
341 | // Now calculate the mean over the interval. | |
342 | Double_t mean = 0; | |
343 | Double_t sumw2 = 0; | |
344 | Double_t nent = 0; | |
345 | for(Int_t k=0;k<fgkBinRangeAve;k++){ | |
346 | mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k); | |
347 | nent=nent+h1->GetBinContent(startBin+k); | |
348 | sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k)); | |
349 | } | |
350 | mean= mean/nent; //<x> | |
351 | sumw2=sumw2/nent; //<x^2> | |
352 | Double_t rmsmean= 0; | |
353 | rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent); | |
354 | if (ich<fNChannels) { | |
355 | AliTOFChannelOnline * ch = (AliTOFChannelOnline *)fCal->At(ich); | |
356 | ch->SetDelay((Double_t)mean*AliTOFGeometry::TdcBinWidth()*1.E-3); // delay in ns | |
357 | // ch->SetStatus(1); // calibrated channel, removed for the time being from AliTOFChannelOnline | |
358 | } | |
359 | } | |
360 | delete h1; | |
361 | h1=0x0; | |
362 | } | |
363 | if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics)); | |
364 | } | |
365 | daqFile->Close(); | |
366 | delete daqFile; | |
367 | } | |
368 | else{ | |
369 | Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); | |
370 | return 6;//return error code for problems in retrieving DAQ data | |
371 | } | |
372 | } | |
373 | delete listTot; | |
374 | } | |
375 | else{ | |
376 | Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle"); | |
377 | return 6; //return error code for problems in retrieving DAQ data | |
378 | } | |
379 | ||
380 | daqFile=0; | |
381 | AliCDBMetaData metaData; | |
382 | metaData.SetBeamPeriod(0); | |
383 | metaData.SetResponsible("Chiara Zampolli"); | |
384 | metaData.SetComment("This preprocessor fills a TObjArray object."); | |
385 | AliInfo("Storing Calibration Data"); | |
386 | resultTOFPP = Store("Calib","ParOnline",fCal, &metaData,0,kTRUE); | |
387 | if(!resultTOFPP){ | |
388 | Log("Some problems occurred while storing online object resulting from DAQ data processing"); | |
389 | return 8;//return error code for problems in storing DAQ data | |
390 | } | |
391 | ||
392 | return 0; | |
393 | } | |
394 | //_____________________________________________________________________________ | |
395 | ||
396 | UInt_t AliTOFPreprocessor::ProcessPulserData() | |
397 | { | |
398 | // Processing Pulser Run data for TOF channel status | |
399 | ||
400 | Log("Processing Pulser"); | |
401 | ||
402 | TH1::AddDirectory(0); | |
403 | ||
404 | Bool_t resultPulserRef=kFALSE; | |
405 | Bool_t resultPulser=kFALSE; | |
406 | ||
407 | static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors(); | |
408 | TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5); | |
409 | for (Int_t ibin =1;ibin<=kSize;ibin++){ | |
410 | htofPulser->SetBinContent(ibin,-1); | |
411 | } | |
412 | ||
413 | // retrieving last stored pulser object, and copying | |
414 | ||
415 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Pulser"); | |
416 | if (cdbEntry!=0x0){ | |
417 | TObjArray *currentCalStatus = (TObjArray*)cdbEntry->GetObject(); | |
418 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
419 | AliTOFChannelOnlineStatus * calChOnlineSt = (AliTOFChannelOnlineStatus*)fCalStatus->At(ich); | |
420 | calChOnlineSt->SetStatus(((AliTOFChannelOnlineStatus*)currentCalStatus->At(ich))->GetStatus()); | |
421 | } | |
422 | } | |
423 | ||
424 | // processing pulser | |
425 | ||
426 | TFile * daqFile=0x0; | |
427 | TH1S *h1=0x0; | |
428 | ||
429 | //retrieving Pulser data | |
430 | TList* listPulser = GetFileSources(kDAQ, "PULSER"); | |
431 | if (listPulser !=0x0 && listPulser->GetEntries()!=0) | |
432 | { | |
433 | AliInfo("The following sources produced files with the id PULSER"); | |
434 | listPulser->Print(); | |
435 | for (Int_t jj=0;jj<listPulser->GetEntries();jj++){ | |
436 | TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj)); | |
437 | AliInfo(Form("found source %s", str->String().Data())); | |
438 | // file to be stored run per run | |
439 | TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName()); | |
440 | if (fileNamePulser.Length()>0){ | |
441 | // storing refernce data | |
442 | AliInfo(Form("Got the file %s, now we can store the Reference Data for pulser for the current Run.", fileNamePulser.Data())); | |
443 | daqFile = new TFile(fileNamePulser.Data(),"READ"); | |
444 | h1 = (TH1S*) daqFile->Get("hTOFpulser"); | |
445 | for (Int_t ibin=0;ibin<kSize;ibin++){ | |
446 | if ((h1->GetBinContent(ibin+1))!=-1){ | |
447 | if ((htofPulser->GetBinContent(ibin+1))==-1){ | |
448 | htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)); | |
449 | } | |
450 | else { | |
451 | Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin)); | |
452 | } | |
453 | } | |
454 | } | |
455 | // elaborating infos | |
456 | Double_t mean =0; | |
457 | Int_t nread=0; | |
458 | Int_t nreadNotEmpty=0; | |
459 | for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){ | |
460 | ||
461 | /* check whether channel has been read out during current run. | |
462 | * if the status is bad it means it has not been read out. | |
463 | * in this case skip channel in order to not affect the mean */ | |
464 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ientry-1))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
465 | continue; | |
466 | ||
467 | if (h1->GetBinContent(ientry)==-1) continue; | |
468 | else { | |
469 | if (h1->GetBinContent(ientry)>0) { | |
470 | nreadNotEmpty++; | |
471 | AliDebug(1,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty)); | |
472 | } | |
473 | mean+=h1->GetBinContent(ientry); | |
474 | nread++; | |
475 | } | |
476 | } | |
477 | mean/=nread; | |
478 | AliDebug(1,Form(" nread = %i , mean = %f",nread,mean)); | |
479 | for (Int_t ich =0;ich<fNChannels;ich++){ | |
480 | AliTOFChannelOnlineStatus * chSt = (AliTOFChannelOnlineStatus *)fCalStatus->At(ich); | |
481 | if (h1->GetBinContent(ich+1)==-1) continue; | |
482 | AliDebug(1,Form(" channel %i ",ich)); | |
483 | AliDebug(1,Form(" channel status before pulser = %i",(Int_t)chSt->GetStatus())); | |
484 | ||
485 | /* check whether channel has been read out during current run. | |
486 | * if the status is bad it means it has not been read out. | |
487 | * in this case skip channel in order to leave its status | |
488 | * unchanged */ | |
489 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ich))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
490 | continue; | |
491 | ||
492 | if (h1->GetBinContent(ich+1)<0.05*mean){ | |
493 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFPulserBad); // bad status for pulser | |
494 | AliDebug(1,Form(" channel status after pulser = %i",(Int_t)chSt->GetStatus())); | |
495 | } | |
496 | else { | |
497 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFPulserOk); // bad status for pulser | |
498 | AliDebug(1,Form(" channel status after pulser = %i",(Int_t)chSt->GetStatus())); | |
499 | } | |
500 | } | |
501 | ||
502 | daqFile->Close(); | |
503 | delete daqFile; | |
504 | delete h1; | |
505 | } | |
506 | ||
507 | else{ | |
508 | Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle "); | |
509 | return 10;//return error code for failure in retrieving Ref Data | |
510 | } | |
511 | ||
512 | } | |
513 | delete listPulser; | |
514 | } | |
515 | ||
516 | else{ | |
517 | Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle "); | |
518 | return 10;//return error code for failure in retrieving Ref Data | |
519 | } | |
520 | ||
521 | //storing in OCDB | |
522 | ||
523 | AliCDBMetaData metaData; | |
524 | metaData.SetBeamPeriod(0); | |
525 | metaData.SetResponsible("Chiara Zampolli"); | |
526 | metaData.SetComment("This preprocessor fills a TObjArray object for Pulser data."); | |
527 | AliInfo("Storing Calibration Data from Pulser Run"); | |
528 | resultPulser = Store("Calib","Pulser",fCalStatus, &metaData,0,kTRUE); | |
529 | if(!resultPulser){ | |
530 | Log("Some problems occurred while storing online object resulting from Pulser data processing"); | |
531 | return 11;//return error code for problems in storing Pulser data | |
532 | } | |
533 | ||
534 | if(fStoreRefData){ | |
535 | ||
536 | AliCDBMetaData metaDataHisto; | |
537 | metaDataHisto.SetBeamPeriod(0); | |
538 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
539 | char comment[200]; | |
540 | sprintf(comment,"This preprocessor stores the result of the pulser run"); | |
541 | metaDataHisto.SetComment(comment); | |
542 | AliInfo("Storing Reference Data"); | |
543 | resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto); | |
544 | if (!resultPulserRef){ | |
545 | Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle"); | |
546 | return 9;//return error code for failure in storing Ref Data | |
547 | } | |
548 | } | |
549 | ||
550 | daqFile=0; | |
551 | ||
552 | return 0; | |
553 | } | |
554 | //_____________________________________________________________________________ | |
555 | ||
556 | UInt_t AliTOFPreprocessor::ProcessNoiseData() | |
557 | { | |
558 | ||
559 | // Processing Noise Run data for TOF channel status | |
560 | ||
561 | Log("Processing Noise"); | |
562 | ||
563 | TH1::AddDirectory(0); | |
564 | ||
565 | Bool_t resultNoiseRef=kFALSE; | |
566 | Bool_t resultNoise=kFALSE; | |
567 | ||
568 | static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors(); | |
569 | TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5); | |
570 | for (Int_t ibin =1;ibin<=kSize;ibin++){ | |
571 | htofNoise->SetBinContent(ibin,-1); | |
572 | } | |
573 | ||
574 | // retrieving last stored noise object, and copying | |
575 | ||
576 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Noise"); | |
577 | if (cdbEntry!=0x0){ | |
578 | TObjArray *currentCalStatus = (TObjArray*)cdbEntry->GetObject(); | |
579 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
580 | AliTOFChannelOnlineStatus * calChOnlineSt = (AliTOFChannelOnlineStatus*)fCalStatus->At(ich); | |
581 | calChOnlineSt->SetStatus(((AliTOFChannelOnlineStatus*)currentCalStatus->At(ich))->GetStatus()); | |
582 | } | |
583 | } | |
584 | ||
585 | // processing noise | |
586 | ||
587 | TFile * daqFile=0x0; | |
588 | TH1F * h1=0x0; | |
589 | ||
590 | //retrieving Noise data | |
591 | TList* listNoise = GetFileSources(kDAQ, "NOISE"); | |
592 | if (listNoise !=0x0 && listNoise->GetEntries()!=0) | |
593 | { | |
594 | AliInfo("The following sources produced files with the id NOISE"); | |
595 | listNoise->Print(); | |
596 | for (Int_t jj=0;jj<listNoise->GetEntries();jj++){ | |
597 | TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj)); | |
598 | AliInfo(Form("found source %s", str->String().Data())); | |
599 | // file to be stored run per run | |
600 | TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName()); | |
601 | if (fileNameNoise.Length()>0){ | |
602 | // storing refernce data | |
603 | AliInfo(Form("Got the file %s, now we can store the Reference Data for noise for the current Run.", fileNameNoise.Data())); | |
604 | daqFile = new TFile(fileNameNoise.Data(),"READ"); | |
605 | h1 = (TH1F*) daqFile->Get("hTOFnoise"); | |
606 | for (Int_t ibin=0;ibin<kSize;ibin++){ | |
607 | if ((h1->GetBinContent(ibin+1))!=-1){ | |
608 | if ((htofNoise->GetBinContent(ibin+1))==-1){ | |
609 | htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)); | |
610 | } | |
611 | else { | |
612 | Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin)); | |
613 | } | |
614 | } | |
615 | } | |
616 | // elaborating infos | |
617 | for (Int_t ich =0;ich<fNChannels;ich++){ | |
618 | AliTOFChannelOnlineStatus * chSt = (AliTOFChannelOnlineStatus *)fCalStatus->At(ich); | |
619 | if (h1->GetBinContent(ich+1)==-1) continue; | |
620 | AliDebug(1,Form( " channel %i",ich)); | |
621 | AliDebug(1,Form( " channel status before noise = %i",(Int_t)chSt->GetStatus())); | |
622 | ||
623 | /* check whether channel has been read out during current run. | |
624 | * if the status is bad it means it has not been read out. | |
625 | * in this case skip channel in order to leave its status | |
626 | * unchanged */ | |
627 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ich))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
628 | continue; | |
629 | ||
630 | if (h1->GetBinContent(ich+1)>=1){ // setting limit for noise to 1 kHz | |
631 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFNoiseBad); // bad status for noise | |
632 | AliDebug(1,Form( " channel status after noise = %i",(Int_t)chSt->GetStatus())); | |
633 | } | |
634 | else { | |
635 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFNoiseOk); // bad status for noise | |
636 | AliDebug(1,Form(" channel status after noise = %i",(Int_t)chSt->GetStatus())); | |
637 | } | |
638 | } | |
639 | ||
640 | daqFile->Close(); | |
641 | delete daqFile; | |
642 | delete h1; | |
643 | ||
644 | } | |
645 | ||
646 | else{ | |
647 | Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle "); | |
648 | return 13;//return error code for failure in retrieving Ref Data | |
649 | } | |
650 | ||
651 | } | |
652 | delete listNoise; | |
653 | } | |
654 | else{ | |
655 | Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle "); | |
656 | return 13;//return error code for failure in retrieving Ref Data | |
657 | } | |
658 | ||
659 | daqFile=0; | |
660 | ||
661 | //storing in OCDB | |
662 | ||
663 | AliCDBMetaData metaData; | |
664 | metaData.SetBeamPeriod(0); | |
665 | metaData.SetResponsible("Chiara Zampolli"); | |
666 | metaData.SetComment("This preprocessor fills a TObjArray object for Noise data."); | |
667 | AliInfo("Storing Calibration Data from Noise Run"); | |
668 | resultNoise = Store("Calib","Noise",fCalStatus, &metaData,0,kTRUE); | |
669 | if(!resultNoise){ | |
670 | Log("Some problems occurred while storing online object resulting from Noise data processing"); | |
671 | return 14;//return error code for problems in storing Noise data | |
672 | } | |
673 | ||
674 | if(fStoreRefData){ | |
675 | ||
676 | AliCDBMetaData metaDataHisto; | |
677 | metaDataHisto.SetBeamPeriod(0); | |
678 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
679 | char comment[200]; | |
680 | sprintf(comment,"This preprocessor stores the result of the noise run, TOF exiting from Shuttle "); | |
681 | metaDataHisto.SetComment(comment); | |
682 | AliInfo("Storing Reference Data"); | |
683 | resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto); | |
684 | if (!resultNoiseRef){ | |
685 | Log("some problems occurred::No Reference Data for noise stored"); | |
686 | return 12;//return error code for failure in storing Ref Data | |
687 | } | |
688 | } | |
689 | ||
690 | return 0; | |
691 | } | |
692 | //_____________________________________________________________________________ | |
693 | ||
694 | UInt_t AliTOFPreprocessor::ProcessFEEData() | |
695 | { | |
696 | // Processing Pulser Run data for TOF channel status | |
697 | // dummy for the time being | |
698 | ||
699 | Log("Processing FEE"); | |
700 | ||
701 | Bool_t updateOCDB = kFALSE; | |
702 | AliTOFFEEReader feeReader; | |
703 | AliTOFChannelOnlineStatus *currentChannel = NULL, *storedChannel = NULL; | |
704 | TObjArray *currentFEE = fFEEStatus; | |
705 | ||
706 | TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels); | |
707 | ||
708 | /* load current TOF FEE config from DCS FXS, parse, | |
709 | * fill current FEE histogram and set FEE status */ | |
710 | ||
711 | const char * nameFile = GetFile(kDCS,"TofFeeMap",""); | |
712 | AliInfo(Form("nameFile = %s",nameFile)); | |
713 | if (nameFile == NULL) { | |
714 | return 15; | |
715 | } | |
716 | feeReader.LoadFEEConfig(nameFile); | |
717 | feeReader.ParseFEEConfig(); | |
718 | /* loop over channels */ | |
719 | for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++) { | |
720 | currentChannel = (AliTOFChannelOnlineStatus *)currentFEE->At(iChannel); | |
721 | if (!currentChannel) | |
722 | continue; | |
723 | /* channel enabled. set FEE channel status ok */ | |
724 | if (feeReader.IsChannelEnabled(iChannel)) { | |
725 | currentChannel->SetStatus(AliTOFChannelOnlineStatus::kTOFHWOk); | |
726 | hCurrentFEE.SetBinContent(iChannel + 1, 1); | |
727 | } | |
728 | /* channel disabled. set FEE channel status bad */ | |
729 | else { | |
730 | currentChannel->SetStatus(AliTOFChannelOnlineStatus::kTOFHWBad); | |
731 | } | |
732 | } | |
733 | ||
734 | /* load stored TOF FEE from OCDB and compare it with current FEE. | |
735 | * if stored FEE is different from current FEE set update flag. | |
736 | * if there is no stored FEE in OCDB set update flag */ | |
737 | ||
738 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","FEE"); | |
739 | /* no CDB entry found. set update flag */ | |
740 | if (cdbEntry == NULL) { | |
741 | updateOCDB = kTRUE; | |
742 | } | |
743 | /* CDB entry OK. loop over channels */ | |
744 | else { | |
745 | TObjArray *storedFEE = (TObjArray *)cdbEntry->GetObject(); | |
746 | for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){ | |
747 | currentChannel = (AliTOFChannelOnlineStatus *)currentFEE->At(iChannel); | |
748 | storedChannel = (AliTOFChannelOnlineStatus *)storedFEE->At(iChannel); | |
749 | /* compare current FEE channel status with stored one | |
750 | * if different set update flag and break loop */ | |
751 | if (currentChannel->GetStatus() != storedChannel->GetStatus()) { | |
752 | updateOCDB = kTRUE; | |
753 | break; | |
754 | } | |
755 | } | |
756 | } | |
757 | ||
758 | /* check whether we don't have to store reference data. | |
759 | * in this case we return without errors. */ | |
760 | if (fStoreRefData) { | |
761 | /* store reference data */ | |
762 | AliCDBMetaData metaDataHisto; | |
763 | metaDataHisto.SetBeamPeriod(0); | |
764 | metaDataHisto.SetResponsible("Roberto Preghenella"); | |
765 | metaDataHisto.SetComment("This preprocessor stores the FEE referece data of the current run."); | |
766 | AliInfo("Storing FEE reference data"); | |
767 | /* store FEE reference data */ | |
768 | if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) { | |
769 | /* failed */ | |
770 | Log("problems while storing FEE reference data"); | |
771 | return 18; /* error return code for problems while storing FEE reference data */ | |
772 | } | |
773 | } | |
774 | ||
775 | /* check whether we don't need to update OCDB. | |
776 | * in this case we can return without errors and | |
777 | * the current FEE is stored in the fFEEStatus TObjArray. */ | |
778 | if (!updateOCDB) { | |
779 | AliInfo("TOF FEE config has not changed. Do not overwrite stored file."); | |
780 | return 0; /* return ok */ | |
781 | } | |
782 | ||
783 | /* update the OCDB with the current FEE since even | |
784 | * a little difference has been detected. */ | |
785 | ||
786 | AliCDBMetaData metaData; | |
787 | metaData.SetBeamPeriod(0); | |
788 | metaData.SetResponsible("Roberto Preghenella"); | |
789 | metaData.SetComment("This preprocessor fills a TObjArray object for FEE data."); | |
790 | AliInfo("Storing FEE data from current run"); | |
791 | /* store FEE data */ | |
792 | if (!Store("Calib", "FEE", fFEEStatus, &metaData, 0, kTRUE)) { | |
793 | /* failed */ | |
794 | Log("problems while storing FEE data object"); | |
795 | return 17; /* return error code for problems while storing FEE data */ | |
796 | } | |
797 | ||
798 | /* everything fine. return */ | |
799 | ||
800 | return 0; | |
801 | ||
802 | } | |
803 | ||
804 | //_____________________________________________________________________________ | |
805 | ||
806 | UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap) | |
807 | { | |
808 | // | |
809 | // | |
810 | // | |
811 | ||
812 | TString runType = GetRunType(); | |
813 | Log(Form("RunType %s",runType.Data())); | |
814 | ||
815 | // processing | |
816 | ||
817 | /* always process FEE data */ | |
818 | Int_t iresultFEE = ProcessFEEData(); | |
819 | if (iresultFEE != 0) | |
820 | return iresultFEE; | |
821 | ||
822 | if (runType == "PULSER") { | |
823 | Int_t iresultPulser = ProcessPulserData(); | |
824 | return iresultPulser; | |
825 | } | |
826 | ||
827 | if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined | |
828 | Int_t iresultNoise = ProcessNoiseData(); | |
829 | return iresultNoise; | |
830 | } | |
831 | ||
832 | if (runType == "PHYSICS") { | |
833 | Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap); | |
834 | if (iresultDCS != 0) { | |
835 | return iresultDCS; | |
836 | } | |
837 | else { | |
838 | Int_t iresultDAQ = ProcessOnlineDelays(); | |
839 | return iresultDAQ; | |
840 | } | |
841 | } | |
842 | ||
843 | // storing | |
844 | return 0; | |
845 | } | |
846 | ||
847 |