Line data Source code
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 :
19 : //#include <Riostream.h>
20 : //#include <stdio.h>
21 : //#include <stdlib.h>
22 :
23 : #include <TFile.h>
24 : #include <TH2S.h>
25 : #include <TH1F.h>
26 : #include <TCanvas.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 "AliTOFChannelOnlineArray.h"
36 : #include "AliTOFChannelOnlineStatusArray.h"
37 : #include "AliTOFDataDCS.h"
38 : #include "AliTOFDCSmaps.h"
39 : #include "AliTOFLvHvDataPoints.h"
40 : #include "AliTOFGeometry.h"
41 : #include "AliTOFPreprocessor.h"
42 : #include "AliTOFFEEReader.h"
43 : #include "AliTOFRawStream.h"
44 : #include "AliTOFCableLengthMap.h"
45 : #include "AliTOFcalibHisto.h"
46 : #include "AliTOFFEEDump.h"
47 : #include "TChain.h"
48 : #include "AliTOFDeltaBCOffset.h"
49 : #include "AliTOFCTPLatency.h"
50 : #include "AliTOFRunParams.h"
51 : #include "AliTOFT0FillOnlineCalib.h"
52 : #include "AliTOFHitField.h"
53 : #include "AliTOFChannelOffline.h"
54 : #include "TF1.h"
55 : #include "TGeoManager.h"
56 : #include "AliGeomManager.h"
57 : #include "AliTOFReadoutInfo.h"
58 :
59 : // TOF preprocessor class.
60 : // It takes data from DCS and passes them to the class AliTOFDataDCS, which
61 : // processes them. The result is then written to the CDB.
62 : // Analogously, it takes data form DAQ (both at Run level and inclusive -
63 : // of all the runs - level, processes them, and stores both Reference Data
64 : // and Online Calibration files in the CDB.
65 : // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
66 :
67 : // return codes:
68 : // return=0 : all ok
69 : // return=1 : no DCS input data Map
70 : // return=2 : no DCS input data processing
71 : // return=3 : no DCS processed data was stored in Ref Data
72 : // return=4 : no DAQ input for Ref Data
73 : // return=5 : failed to store DAQ Ref Data
74 : // return=6 : failed to retrieve DAQ data for calibration
75 : // return=7 : problems in processing histos in the input DAQ file
76 : // return=8 : failed to store Online Delays
77 : // return=9 : failed to store Reference Data for Pulser
78 : // return=10: failed to retrieve Pulser data
79 : // return=11: failed to store Pulser map in OCDB
80 : // return=12: failed to store Reference Data for Noise
81 : // return=13: failed to retrieve Noise data
82 : // return=14: failed to store Noise map in OCDB
83 : // return=15: failed to retrieve FEE data from FXS
84 : // return=16: failed to retrieve FEE data from OCDB
85 : // return=17: failed to store FEE data in OCDB
86 : // return=18: failed to store FEE reference data in OCDB
87 : // return=20: failed in retrieving status variable
88 : // return=100 : no DCS input data Map (HV and LV status)
89 : // return=200 : no DCS input data processing (HV and LV status)
90 : // return=300 : no DCS processed data was stored in Ref Data (HV and LV status)
91 :
92 26 : ClassImp(AliTOFPreprocessor)
93 :
94 : const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
95 : const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
96 : const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
97 :
98 : //_____________________________________________________________________________
99 :
100 : AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
101 0 : AliPreprocessor("TOF", shuttle),
102 0 : fData(0),
103 0 : fHVLVmaps(0),
104 0 : fCal(0),
105 0 : fNChannels(0),
106 0 : fStoreRefData(kTRUE),
107 0 : fFDRFlag(kFALSE),
108 0 : fStatus(0),
109 0 : fMatchingWindow(0),
110 0 : fLatencyWindow(0),
111 0 : fIsStatusMapChanged(0)
112 0 : {
113 : // constructor
114 0 : AddRunType("PHYSICS");
115 0 : AddRunType("PULSER");
116 0 : AddRunType("NOISE");
117 :
118 0 : }
119 :
120 : //_____________________________________________________________________________
121 :
122 : AliTOFPreprocessor::~AliTOFPreprocessor()
123 0 : {
124 : // destructor
125 0 : }
126 :
127 : //______________________________________________________________________________
128 : void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
129 : UInt_t endTime)
130 : {
131 : // Creates AliTOFDataDCS object
132 :
133 0 : AliPreprocessor::Initialize(run, startTime, endTime);
134 :
135 0 : AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
136 : TTimeStamp(startTime).AsString(),
137 : TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
138 :
139 0 : fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
140 0 : fHVLVmaps = new AliTOFLvHvDataPoints(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
141 0 : fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
142 0 : }
143 : //_____________________________________________________________________________
144 : Bool_t AliTOFPreprocessor::ProcessDCS(){
145 :
146 : // check whether DCS should be processed or not...
147 :
148 0 : TString runType = GetRunType();
149 0 : Log(Form("RunType %s",runType.Data()));
150 :
151 0 : if (runType != "PHYSICS"){
152 0 : return kFALSE;
153 : }
154 :
155 0 : return kTRUE;
156 0 : }
157 : //_____________________________________________________________________________
158 :
159 : UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
160 : {
161 : // Fills data into a AliTOFDataDCS object
162 :
163 :
164 0 : Log("Processing DCS DP");
165 0 : TH1::AddDirectory(0);
166 :
167 : Bool_t resultDCSMap=kFALSE;
168 : Bool_t resultDCSStore=kFALSE;
169 :
170 : // processing DCS
171 :
172 0 : if (!dcsAliasMap){
173 0 : Log("No DCS map found: TOF exiting from Shuttle");
174 0 : if (fData) {
175 0 : delete fData;
176 0 : fData = 0;
177 0 : }
178 0 : return 1;// return error Code for DCS input data not found
179 : }
180 : else {
181 :
182 0 : if (!fData) {
183 0 : Log("No DCSdata map initialized: TOF exiting from Shuttle");
184 0 : return 0;// return error Code for DCS data map not initialized
185 : }
186 :
187 0 : fData->SetFDRFlag(fFDRFlag);
188 :
189 : // The processing of the DCS input data is forwarded to AliTOFDataDCS
190 0 : resultDCSMap=fData->ProcessData(*dcsAliasMap);
191 0 : if(!resultDCSMap){
192 0 : Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
193 0 : if (fData) {
194 0 : delete fData;
195 0 : fData = 0;
196 0 : }
197 0 : return 2;// return error Code for processed DCS data not stored
198 : }
199 : else{
200 0 : AliCDBMetaData metaDataDCS;
201 0 : metaDataDCS.SetBeamPeriod(0);
202 0 : metaDataDCS.SetResponsible("Chiara Zampolli");
203 0 : metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
204 0 : AliInfo("Storing DCS Data");
205 0 : resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
206 0 : if (!resultDCSStore){
207 0 : Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
208 0 : if (fData){
209 0 : delete fData;
210 0 : fData = 0;
211 0 : }
212 0 : return 3;// return error Code for processed DCS data not stored
213 : // in reference data
214 :
215 : }
216 0 : }
217 : }
218 0 : if (fData){
219 0 : delete fData;
220 0 : fData = 0;
221 0 : }
222 :
223 0 : return 0;
224 0 : }
225 : //_____________________________________________________________________________
226 :
227 : UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
228 : {
229 : //
230 : //Fills data into a AliTOFLvHvDataPoints object
231 : // Merges fStatus object with LV and HV status at SOR
232 : // Updates fStatus object with LV and HV status
233 : // at EOR in case of correct end of run
234 : // at last but two value in case of end-of-run caused by TOF detector.
235 : //
236 :
237 0 : Log("Processing HV and LV DCS DPs");
238 0 : TH1::AddDirectory(0);
239 :
240 : Bool_t resultDCSMap=kFALSE;
241 :
242 : // processing DCS HV and LV data points
243 :
244 0 : if (!dcsAliasMap){
245 0 : Log("No DCS map found: TOF exiting from Shuttle");
246 0 : if (fHVLVmaps){
247 0 : delete fHVLVmaps;
248 0 : fHVLVmaps = 0;
249 0 : }
250 0 : return 100;// return error Code for DCS input data not found
251 : }
252 : else {
253 :
254 0 : if (!fHVLVmaps) {
255 0 : Log("No HVLVdata map initialized: TOF exiting from Shuttle");
256 0 : return 200;// return error Code for HVLV data map not initialized
257 : }
258 :
259 0 : fHVLVmaps->SetFDRFlag(fFDRFlag);
260 :
261 : // The processing of the DCS input data is forwarded to AliTOFDataDCS
262 :
263 0 : resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
264 0 : if (!resultDCSMap) {
265 0 : Log("Some problems occurred while processing DCS data for HV and LV, TOF exiting from Shuttle");
266 0 : if (fHVLVmaps) {
267 0 : delete fHVLVmaps;
268 0 : fHVLVmaps = 0;
269 0 : }
270 0 : return 200;// return error Code for processed DCS data not stored
271 : }
272 : else {
273 :
274 : // check with plots. Start...
275 : /*
276 : TH1F *hROsor = new TH1F("hROsor","RO status map at SOR",91*96*18,-0.5,91*96*18-0.5);
277 : for (Int_t ii=1; ii<=91*96*18; ii++) hROsor->SetBinContent(ii,-1);
278 : for (Int_t ii=0; ii<91*96*18; ii++) {
279 : if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
280 : hROsor->SetBinContent(ii+1,0);
281 : else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
282 : hROsor->SetBinContent(ii+1,1);
283 : }
284 :
285 : TH1F *hROandHVandLVsor = new TH1F("hROandHVandLVsor","RO.and.HV.andLV status map at SOR",91*96*18,-0.5,91*96*18-0.5);
286 : for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVsor->SetBinContent(ii,-1);
287 : TH1F *hROandHVandLVeor = new TH1F("hROandHVandLVeor","RO.and.HV.andLV status map at EOR",91*96*18,-0.5,91*96*18-0.5);
288 : for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVeor->SetBinContent(ii,-1);
289 : */
290 :
291 0 : AliTOFDCSmaps * lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtSOR(); // Get LV.and.HV status map at SOR
292 0 : for (Int_t index=0; index<fNChannels; index++) {
293 0 : if ( ( lvANDhvMap->GetCellValue(index)==0 &&
294 0 : fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
295 0 : ( lvANDhvMap->GetCellValue(index)==1 &&
296 0 : fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
297 0 : fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
298 0 : fIsStatusMapChanged=kTRUE;
299 0 : }
300 : }
301 :
302 : // check with plots. Start...
303 : /*
304 : for (Int_t ii=0; ii<91*96*18; ii++) {
305 : if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
306 : hROandHVandLVsor->SetBinContent(ii+1,0);
307 : else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
308 : hROandHVandLVsor->SetBinContent(ii+1,1);
309 : }
310 : */
311 :
312 0 : lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtEOR(); // Get LV.and.HV status map at EOR
313 0 : for (Int_t index=0; index<fNChannels; index++) {
314 0 : if ( ( lvANDhvMap->GetCellValue(index)==0 &&
315 0 : fStatus->GetHWStatus(index)!=AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
316 0 : ( lvANDhvMap->GetCellValue(index)==1 &&
317 0 : fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
318 0 : fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
319 0 : fIsStatusMapChanged=kTRUE;
320 0 : }
321 : }
322 :
323 : // check with plots. Start...
324 : /*
325 : for (Int_t ii=0; ii<91*96*18; ii++) {
326 : if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
327 : hROandHVandLVeor->SetBinContent(ii+1,0);
328 : else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
329 : hROandHVandLVeor->SetBinContent(ii+1,1);
330 : }
331 :
332 : TCanvas *canvas = new TCanvas("canvas","",10,10,1000,1000);
333 : canvas->SetFillColor(0);
334 : canvas->Divide(2,2);
335 : canvas->cd(1);
336 : hROsor->SetLineWidth(2);
337 : hROsor->Draw();
338 : canvas->cd(2);
339 : hROandHVandLVsor->SetLineWidth(2);
340 : hROandHVandLVsor->Draw();
341 : canvas->cd(3);
342 : hROandHVandLVeor->SetLineWidth(2);
343 : hROandHVandLVeor->Draw();
344 : canvas->cd();
345 : */
346 :
347 : }
348 :
349 : }
350 :
351 :
352 : /* check whether we don't need to update OCDB.
353 : * in this case we can return without errors. */
354 :
355 0 : if (!fIsStatusMapChanged) {
356 0 : AliInfo("TOF HW status config has not changed. Do not overwrite stored file.");
357 0 : return 0; // return ok
358 : }
359 :
360 0 : TString runType = GetRunType();
361 0 : if (runType != "PHYSICS") {
362 0 : AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
363 0 : return 0; // return ok
364 : }
365 :
366 : // update the OCDB with the current FEE.and.HV.and.LV
367 : // since even a little difference has been detected.
368 :
369 0 : AliCDBMetaData metaData;
370 0 : metaData.SetBeamPeriod(0);
371 0 : metaData.SetResponsible("Roberto Preghenella");
372 0 : metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE.and.HV.and.LV data.");
373 0 : AliInfo("Storing Status data from current run. Collected RO.and.HV.and.LV infos @ EOR");
374 : // store TOF channel status
375 0 : if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
376 : // failed
377 0 : Log("problems while storing RO.and.HV.and.LV Status data object");
378 0 : if (fStatus){
379 0 : delete fStatus;
380 0 : fStatus = 0;
381 0 : }
382 0 : if (fHVLVmaps) {
383 0 : delete fHVLVmaps;
384 0 : fHVLVmaps = 0;
385 0 : }
386 0 : return 17; // return error code for problems while TOF channel status
387 : }
388 :
389 : // everything fine. return
390 :
391 0 : if (fStatus){
392 0 : delete fStatus;
393 0 : fStatus = 0;
394 0 : }
395 :
396 0 : if (fHVLVmaps) {
397 0 : delete fHVLVmaps;
398 0 : fHVLVmaps = 0;
399 0 : }
400 :
401 0 : return 0;
402 0 : }
403 :
404 : //_____________________________________________________________________________
405 :
406 : UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
407 : {
408 : // Processing data from DAQ for online calibration
409 :
410 : Bool_t updateOCDB = kFALSE;
411 0 : Log("Processing DAQ delays");
412 :
413 : // reading configuration map
414 0 : TString compDelays = "kFALSE";
415 0 : Int_t deltaStartingRun = fRun;
416 : Int_t startingRun = fRun-deltaStartingRun;
417 : Int_t binRangeAve = fgkBinRangeAve;
418 : Double_t integralThr = fgkIntegralThr;
419 : Double_t thrPar = fgkThrPar;
420 :
421 0 : AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
422 0 : if (!cdbEntry) {
423 0 : Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
424 : }
425 : else {
426 0 : TMap *configMap = (TMap*)cdbEntry->GetObject();
427 0 : if (!configMap){
428 0 : Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
429 : }
430 : else{
431 0 : TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
432 0 : if (strDelays) {
433 0 : compDelays = (TString) strDelays->GetString();
434 0 : }
435 : else {
436 0 : Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
437 : }
438 0 : TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
439 0 : if (strRun) {
440 0 : TString tmpstr = strRun->GetString();
441 0 : startingRun = tmpstr.Atoi();
442 0 : deltaStartingRun = fRun - startingRun;
443 0 : }
444 : else {
445 0 : Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
446 : }
447 0 : TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
448 0 : if (strBinRangeAve) {
449 0 : TString tmpstr = strBinRangeAve->GetString();
450 0 : binRangeAve = tmpstr.Atoi();
451 0 : }
452 : else {
453 0 : Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
454 : }
455 0 : TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
456 0 : if (strIntegralThr) {
457 0 : TString tmpstr = strIntegralThr->GetString();
458 0 : integralThr = tmpstr.Atof();
459 0 : }
460 : else {
461 0 : Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %f",integralThr));
462 : }
463 0 : TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
464 0 : if (strThrPar) {
465 0 : TString tmpstr = strThrPar->GetString();
466 0 : thrPar = tmpstr.Atof();
467 0 : }
468 : else {
469 0 : Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %f",thrPar));
470 : }
471 : }
472 : }
473 0 : if (compDelays == "kTRUE") fFDRFlag = kFALSE;
474 0 : else fFDRFlag = kTRUE;
475 :
476 0 : delete cdbEntry;
477 : cdbEntry = 0x0;
478 :
479 0 : Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
480 :
481 : /* init array with current calibration, if any */
482 0 : fCal = new AliTOFChannelOnlineArray(fNChannels);
483 : AliTOFChannelOnlineArray *curCal = NULL;
484 :
485 0 : AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
486 0 : if (!cdbEntry2 || !cdbEntry2->GetObject()) {
487 : /* no CDB entry found. set update flag */
488 0 : Log(" ************ WARNING ************");
489 0 : Log("No CDB ParOnlineDelay entry found, creating a new one!");
490 0 : Log(" *********************************");
491 : updateOCDB = kTRUE;
492 0 : }
493 : else {
494 0 : Log("Found previous ParOnlineDelay entry. Using it to init calibration");
495 0 : curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
496 0 : for (Int_t i = 0; i < fNChannels; i++)
497 0 : fCal->SetDelay(i, curCal->GetDelay(i));
498 : }
499 :
500 :
501 0 : TH1::AddDirectory(0);
502 :
503 : Bool_t resultDAQRef=kFALSE;
504 : Bool_t resultTOFPP=kFALSE;
505 : TH2S *h2 = 0x0;
506 : // processing DAQ
507 :
508 : TFile * daqFile=0x0;
509 :
510 0 : if(fStoreRefData){
511 : //retrieving data at Run level
512 0 : TList* list = GetFileSources(kDAQ, "RUNLevel");
513 0 : if (list !=0x0 && list->GetEntries()!=0)
514 : {
515 0 : AliInfo("The following sources produced files with the id RUNLevel");
516 0 : list->Print();
517 0 : for (Int_t jj=0;jj<list->GetEntries();jj++){
518 0 : TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
519 0 : if (!str) {
520 0 : AliError("dynamic_cast returned NULL");
521 0 : return 4;
522 : }
523 0 : AliInfo(Form("found source %s", str->String().Data()));
524 : // file to be stored run per run
525 0 : TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
526 0 : if (fileNameRun.Length()>0){
527 0 : AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
528 0 : daqFile = new TFile(fileNameRun.Data(),"READ");
529 0 : h2 = (TH2S*) daqFile->Get("htof");
530 0 : AliCDBMetaData metaDataHisto;
531 0 : metaDataHisto.SetBeamPeriod(0);
532 0 : metaDataHisto.SetResponsible("Chiara Zampolli");
533 0 : metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
534 0 : AliInfo("Storing Reference Data");
535 0 : resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
536 0 : if (!resultDAQRef){
537 0 : Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
538 0 : delete h2;
539 0 : delete list;
540 0 : delete fCal;
541 0 : fCal=0x0;
542 0 : return 5;//return error code for failure in storing Ref Data
543 : }
544 0 : daqFile->Close();
545 0 : delete daqFile;
546 0 : }
547 :
548 : else{
549 0 : Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
550 0 : delete list;
551 0 : delete fCal;
552 0 : fCal=0x0;
553 0 : return 4;//return error code for failure in retrieving Ref Data
554 : }
555 0 : }
556 0 : delete list;
557 : }
558 : else{
559 0 : Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
560 0 : delete fCal;
561 0 : fCal=0x0;
562 0 : return 4;//return error code for failure in retrieving Ref Data
563 : }
564 0 : }
565 :
566 :
567 : //Total files, with cumulative histos
568 :
569 0 : TList* listTot = GetFileSources(kDAQ, "DELAYS");
570 0 : if (listTot !=0x0 && listTot->GetEntries()!=0)
571 : {
572 0 : AliInfo("The following sources produced files with the id DELAYS");
573 0 : listTot->Print();
574 0 : for (Int_t jj=0;jj<listTot->GetEntries();jj++){
575 0 : TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
576 0 : if (!str) {
577 0 : AliError("dynamic_cast returned NULL");
578 0 : return 4;
579 : }
580 0 : AliInfo(Form("found source %s", str->String().Data()));
581 :
582 : // file with summed histos, to extract calib params
583 0 : TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
584 0 : if (fileName.Length()>0){
585 0 : AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
586 :
587 0 : daqFile = new TFile(fileName.Data(),"READ");
588 0 : if (h2) delete h2;
589 0 : h2 = (TH2S*) daqFile->Get("htoftot");
590 0 : if (!h2){
591 0 : Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
592 0 : delete listTot;
593 0 : delete daqFile;
594 0 : delete fCal;
595 0 : fCal=0x0;
596 0 : return 7; //return error code for histograms not existing/junky
597 : }
598 : else {
599 0 : static const Int_t kSize=h2->GetNbinsX();
600 0 : static const Int_t kNBins=h2->GetNbinsY();
601 0 : static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
602 0 : if (kSize != fNChannels){
603 0 : Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
604 0 : delete listTot;
605 0 : delete h2;
606 0 : delete daqFile;
607 0 : delete fCal;
608 0 : fCal=0x0;
609 0 : return 7; //return error code for histograms not existing/junky
610 : }
611 : Int_t nNotStatistics = 0; // number of channel with not enough statistics
612 :
613 : /* FDR flag set. do not compute delays, use nominal cable delays */
614 0 : if (fFDRFlag) {
615 :
616 0 : Log(" Not computing delays according to flag set in Config entry in OCDB!");
617 0 : FillWithCosmicCalibration(fCal);
618 :
619 : /* check whether the new calibration is different from the previous one */
620 0 : if (curCal) { /* well, check also whether we have a previous calibration */
621 0 : for (Int_t i = 0; i < fNChannels; i++) {
622 0 : if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
623 : updateOCDB = kTRUE;
624 0 : break;
625 : }
626 : }
627 0 : }
628 : else /* otherwise update OCDB */
629 : updateOCDB = kTRUE;
630 :
631 : }
632 :
633 : else { // computing delays if not in FDR runs
634 :
635 : updateOCDB = kTRUE; /* always update OCDB when computing delays */
636 :
637 0 : for (Int_t ich=0;ich<kSize;ich++){
638 : /* check whether channel has been read out during current run.
639 : * if the status is bad it means it has not been read out.
640 : * in this case skip channel in order to not affect the mean */
641 0 : if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
642 0 : AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
643 : continue;
644 : }
645 0 : AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
646 0 : TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
647 0 : for (Int_t ibin=0;ibin<kNBins;ibin++){
648 0 : h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
649 : }
650 0 : if(h1->Integral()<integralThr) {
651 0 : nNotStatistics++;
652 0 : Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
653 0 : delete h1;
654 : h1=0x0;
655 0 : continue;
656 : }
657 : Bool_t found=kFALSE;
658 0 : Float_t minContent=h1->Integral()*thrPar;
659 0 : Int_t nbinsX = h1->GetNbinsX();
660 : Int_t startBin=1;
661 0 : for (Int_t j=1; j<=nbinsX; j++){
662 0 : if ((
663 0 : h1->GetBinContent(j) +
664 0 : h1->GetBinContent(j+1)+
665 0 : h1->GetBinContent(j+2)+
666 0 : h1->GetBinContent(j+3))>minContent){
667 : found=kTRUE;
668 : startBin=j;
669 0 : break;
670 : }
671 : }
672 0 : if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
673 : // Now calculate the mean over the interval.
674 : Double_t mean = 0;
675 : Double_t sumw2 = 0;
676 : Double_t nent = 0;
677 0 : for(Int_t k=0;k<binRangeAve;k++){
678 0 : mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
679 0 : nent=nent+h1->GetBinContent(startBin+k);
680 0 : sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
681 : }
682 0 : mean= mean/nent; //<x>
683 : sumw2=sumw2/nent; //<x^2>
684 : //Double_t rmsmean= 0; // not used for the time being
685 : //rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
686 0 : if (ich<fNChannels) {
687 0 : Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
688 0 : fCal->SetDelay(ich,delay); // delay in ns
689 0 : AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
690 0 : }
691 0 : delete h1;
692 : h1=0x0;
693 0 : }
694 : }
695 0 : if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
696 : }
697 0 : delete h2;
698 0 : daqFile->Close();
699 0 : delete daqFile;
700 : }
701 : else{
702 0 : Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
703 0 : delete listTot;
704 0 : delete fCal;
705 0 : fCal=0x0;
706 0 : return 6;//return error code for problems in retrieving DAQ data
707 : }
708 0 : }
709 0 : delete listTot;
710 : }
711 : else{
712 0 : Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
713 0 : delete fCal;
714 0 : fCal=0x0;
715 0 : return 6; //return error code for problems in retrieving DAQ data
716 : }
717 :
718 : /* check whether we don't need to update OCDB.
719 : * in this case we can return without errors and
720 : * the current FEE is stored in the fStatus object. */
721 0 : if (!updateOCDB) {
722 0 : AliInfo("update OCDB flag not set. Do not overwrite stored file.");
723 0 : return 0; /* return ok */
724 : }
725 :
726 : daqFile=0;
727 0 : AliCDBMetaData metaData;
728 0 : metaData.SetBeamPeriod(0);
729 0 : metaData.SetResponsible("Chiara Zampolli");
730 0 : metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
731 0 : AliInfo("Storing Calibration Data");
732 0 : resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
733 0 : if(!resultTOFPP){
734 0 : Log("Some problems occurred while storing online object resulting from DAQ data processing");
735 0 : delete fCal;
736 0 : fCal=0x0;
737 0 : return 8;//return error code for problems in storing DAQ data
738 : }
739 :
740 0 : if (fCal){
741 0 : delete fCal;
742 0 : fCal = 0;
743 0 : }
744 :
745 0 : return 0;
746 0 : }
747 :
748 : //_____________________________________________________________________________
749 :
750 : UInt_t
751 : AliTOFPreprocessor::ProcessT0Fill()
752 : {
753 : // Processing data from DAQ for T0-fill measurement
754 :
755 0 : Log("Processing T0-fill");
756 :
757 : #if 0
758 : /* instance and setup CDB manager */
759 : AliCDBManager *cdb = AliCDBManager::Instance();
760 : /* load geometry */
761 : if (!gGeoManager) AliGeomManager::LoadGeometry();
762 : #endif
763 :
764 : /* get params from OCDB */
765 : AliCDBEntry *cdbe = NULL;
766 :
767 : /*
768 : * check UseLHCClockPhase flag in RunParams.
769 : * if set do nothing and return successfully
770 : */
771 0 : cdbe = GetFromOCDB("Calib", "RunParams");
772 0 : if (!cdbe) {
773 0 : Log("cannot get \"RunParams\" entry from OCDB");
774 0 : return 21;
775 : }
776 0 : AliTOFRunParams *runparams = (AliTOFRunParams *)cdbe->GetObject();
777 0 : if (runparams->GetUseLHCClockPhase()) {
778 0 : Log("UseLHCClockPhase flag is set in RunParams: online T0-fill not computed");
779 0 : return 0;
780 : }
781 :
782 : /*
783 : * at this stage status object is not on OCDB yet
784 : * since it will be stored later. nevertheless we
785 : * should have the array in memory since it has been
786 : * already setup by ProcessFEF.
787 : */
788 :
789 : /* check status and latency window available */
790 0 : if (!fStatus || !fLatencyWindow){
791 0 : AliError("No valid fStatus or fLatencyWindow found, some errors must have occurred!!");
792 0 : return 21;
793 : }
794 :
795 : /* get offline calibration from OCDB */
796 0 : cdbe = GetFromOCDB("Calib", "ParOffline");
797 0 : if (!cdbe) {
798 0 : Log("cannot get \"ParOffline\" entry from OCDB");
799 0 : return 21;
800 : }
801 0 : TObjArray *offlineArray = (TObjArray *)cdbe->GetObject();
802 : AliTOFChannelOffline *channelOffline;
803 0 : if (!offlineArray) {
804 0 : Log("cannot get \"ParOffline\" object from CDB entry");
805 0 : return 21;
806 : }
807 0 : Log("got \"ParOffline\" object");
808 :
809 : /* get deltaBC offset from OCDB */
810 0 : cdbe = GetFromOCDB("Calib", "DeltaBCOffset");
811 0 : if (!cdbe) {
812 0 : Log("cannot get \"DeltaBCOffset\" entry from OCDB");
813 0 : return 21;
814 : }
815 0 : AliTOFDeltaBCOffset *deltaBCOffsetObject = (AliTOFDeltaBCOffset *)cdbe->GetObject();
816 0 : if (!deltaBCOffsetObject) {
817 0 : Log("cannot get \"DeltaBCOffset\" object from CDB entry");
818 0 : return 21;
819 : }
820 0 : Int_t deltaBCOffset = deltaBCOffsetObject->GetDeltaBCOffset();
821 0 : Log(Form("got \"DeltaBCOffset\" object: deltaBCOffset=%d (BC bins)", deltaBCOffset));
822 :
823 : /* get CTP latency from OCDB */
824 0 : cdbe = GetFromOCDB("Calib", "CTPLatency");
825 0 : if (!cdbe) {
826 0 : Log("cannot get \"CTPLatency\" entry from OCDB");
827 0 : return 21;
828 : }
829 0 : AliTOFCTPLatency *ctpLatencyObject = (AliTOFCTPLatency *)cdbe->GetObject();
830 0 : if (!ctpLatencyObject) {
831 0 : Log("cannot get \"CTPLatency\" object from CDB entry");
832 0 : return 21;
833 : }
834 0 : Float_t ctpLatency = ctpLatencyObject->GetCTPLatency();
835 0 : Log(Form("got \"CTPLatency\" object: ctpLatency=%f (ps)", ctpLatency));
836 :
837 : /* get file sources from FXS */
838 0 : TList *fileList = GetFileSources(kDAQ, "HITS");
839 0 : if (!fileList || fileList->GetEntries() == 0) {
840 0 : Log("cannot get DAQ source file list or empty list");
841 0 : return 21;
842 : }
843 0 : Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
844 0 : fileList->Print();
845 :
846 : /* create tree chain using file sources */
847 0 : TChain chain("hitTree");
848 0 : for (Int_t ifile = 0; ifile < fileList->GetEntries(); ifile++) {
849 0 : TObjString *str = (TObjString *)fileList->At(ifile);
850 0 : TString filename = GetFile(kDAQ, "HITS", str->GetName());
851 0 : chain.Add(filename);
852 0 : Log(Form("file added to input chain: source=%s, filename=%s", str->String().Data(), filename.Data()));
853 0 : }
854 0 : Int_t nhits = chain.GetEntries();
855 0 : Log(Form("input chain ready: %d hits", nhits));
856 :
857 : /* setup input chain */
858 0 : AliTOFHitField *hit = new AliTOFHitField();
859 0 : chain.SetBranchAddress("hit", &hit);
860 :
861 : /* create calib histo and geometry */
862 0 : AliTOFcalibHisto calibHisto;
863 0 : calibHisto.LoadCalibHisto();
864 0 : AliTOFGeometry tofGeo;
865 :
866 : /* constants */
867 0 : Float_t c = TMath::C() * 1.e2 / 1.e12; /* cm/ps */
868 0 : Float_t c_1 = 1. / c;
869 : /* variables */
870 0 : Int_t index, timebin, totbin, deltaBC, l0l1latency, det[5];
871 0 : Float_t timeps, totns, corrps, length, timeexp, timezero, pos[3], latencyWindow;
872 :
873 : /* histos */
874 0 : TH1F *hT0Fill = new TH1F("hT0Fill", "T0 fill;t - t_{exp}^{(c)} (ps);", 2000, -24400., 24400.);
875 :
876 : /* loop over hits */
877 0 : for (Int_t ihit = 0; ihit < nhits; ihit++) {
878 :
879 : /* get entry */
880 0 : chain.GetEntry(ihit);
881 :
882 : /* get hit info */
883 0 : index = hit->GetIndex();
884 0 : timebin = hit->GetTimeBin();
885 0 : totbin = hit->GetTOTBin();
886 0 : deltaBC = hit->GetDeltaBC();
887 0 : l0l1latency = hit->GetL0L1Latency();
888 0 : latencyWindow = fLatencyWindow[index] * 1.e3;
889 :
890 : /* convert time in ps and tot in ns */
891 0 : timeps = timebin * AliTOFGeometry::TdcBinWidth();
892 0 : totns = totbin * AliTOFGeometry::ToTBinWidth() * 1.e-3;
893 : /* get calibration correction in ps */
894 :
895 :
896 0 : channelOffline = (AliTOFChannelOffline *)offlineArray->At(index);
897 0 : if (totns < AliTOFGeometry::SlewTOTMin()) totns = AliTOFGeometry::SlewTOTMin();
898 0 : if (totns > AliTOFGeometry::SlewTOTMax()) totns = AliTOFGeometry::SlewTOTMax();
899 : corrps = 0.;
900 0 : for (Int_t ipar = 0; ipar < 6; ipar++) corrps += channelOffline->GetSlewPar(ipar) * TMath::Power(totns, ipar);
901 0 : corrps *= 1.e3;
902 : /* perform time correction */
903 : // timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps; /* deltaBC correction removed for the time being */
904 0 : timeps = timeps + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
905 : /* compute length and expected time */
906 0 : tofGeo.GetVolumeIndices(index, det);
907 0 : tofGeo.GetPosPar(det, pos);
908 : length = 0.;
909 0 : for (Int_t i = 0; i < 3; i++) length += pos[i] * pos[i];
910 0 : length = TMath::Sqrt(length);
911 0 : timeexp = length * c_1;
912 : /* compute time zero */
913 0 : timezero = timeps - timeexp;
914 :
915 : /* fill histos */
916 0 : hT0Fill->Fill(timezero);
917 : }
918 :
919 : /* rebin until maximum bin has required minimum entries */
920 0 : Int_t maxBin = hT0Fill->GetMaximumBin();
921 0 : Float_t maxBinContent = hT0Fill->GetBinContent(maxBin);
922 0 : Float_t binWidth = hT0Fill->GetBinWidth(maxBin);
923 0 : while (maxBinContent < 400 && binWidth < 90.) {
924 0 : hT0Fill->Rebin(2);
925 0 : maxBin = hT0Fill->GetMaximumBin();
926 0 : maxBinContent = hT0Fill->GetBinContent(maxBin);
927 0 : binWidth = hT0Fill->GetBinWidth(maxBin);
928 : }
929 0 : Float_t maxBinCenter = hT0Fill->GetBinCenter(maxBin);
930 :
931 : /* rough fit of the edge */
932 0 : TF1 *gaus = (TF1 *)gROOT->GetFunction("gaus");
933 0 : gaus->SetParameter(1, maxBinCenter);
934 0 : Float_t fitMin = maxBinCenter - 1000.; /* fit from 1 ns before max */
935 0 : Float_t fitMax = maxBinCenter + 1000.; /* fit until 1 ns above max */
936 0 : hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
937 : /* better fit of the edge */
938 : Float_t mean, sigma;
939 0 : for (Int_t istep = 0; istep < 10; istep++) {
940 0 : mean = gaus->GetParameter(1);
941 0 : sigma = gaus->GetParameter(2);
942 0 : fitMin = mean - 3. * sigma;
943 : fitMax = mean;
944 0 : hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
945 : }
946 : /* print params */
947 0 : mean = gaus->GetParameter(1);
948 0 : sigma = gaus->GetParameter(2);
949 0 : Float_t meane = gaus->GetParError(1);
950 0 : Float_t sigmae = gaus->GetParError(2);
951 0 : Log(Form("edge fit: mean = %f +- %f ps", mean, meane));
952 0 : Log(Form("edge fit: sigma = %f +- %f ps", sigma, sigmae));
953 : /* check error */
954 0 : if (meane > 300.) {
955 0 : Log("error on mean is large: store default T0-fill value (0 ps)");
956 : mean = 0.;
957 0 : }
958 0 : if (sigmae > 300.) {
959 0 : Log("error on sigma is large: store default TOFreso value (200 ps)");
960 : sigma = 200.;
961 0 : }
962 :
963 : /* scratch values from the fit and use max bin center as t0-fill */
964 : mean = maxBinCenter;
965 : sigma = -1.;
966 0 : Log(Form("do not care about fitted value, just use max bin as t0-fill: %f ps", mean));
967 :
968 : /* create RunParams object */
969 0 : UInt_t timestamp[1] = {0};
970 0 : Float_t t0[1] = {mean};
971 0 : Float_t tofReso[1] = {sigma};
972 0 : Float_t t0Spread[1] = {-1.};
973 0 : AliTOFRunParams *runParamsObject = new AliTOFRunParams(1);
974 0 : runParamsObject->SetTimestamp(timestamp);
975 0 : runParamsObject->SetT0(t0);
976 0 : runParamsObject->SetTOFResolution(tofReso);
977 0 : runParamsObject->SetT0Spread(t0Spread);
978 0 : runParamsObject->SetUseLHCClockPhase(kFALSE);
979 :
980 : /* store reference data */
981 0 : if(fStoreRefData){
982 0 : AliCDBMetaData metaDataHisto;
983 0 : metaDataHisto.SetBeamPeriod(0);
984 0 : metaDataHisto.SetResponsible("Roberto Preghenella");
985 0 : metaDataHisto.SetComment("online T0-fill histogram");
986 0 : if (!StoreReferenceData("Calib","T0Fill", hT0Fill, &metaDataHisto)) {
987 0 : Log("error while storing reference data");
988 0 : delete hT0Fill;
989 0 : delete hit;
990 0 : delete runParamsObject;
991 0 : return 21;
992 : }
993 0 : Log("reference data successfully stored");
994 0 : }
995 :
996 0 : AliCDBMetaData metaData;
997 0 : metaData.SetBeamPeriod(0);
998 0 : metaData.SetResponsible("Roberto Preghenella");
999 0 : metaData.SetComment("online RunParams measurement");
1000 0 : if (!Store("Calib", "RunParams", runParamsObject, &metaData, 0, kFALSE)) {
1001 0 : Log("error while storing RunParams object");
1002 0 : delete hT0Fill;
1003 0 : delete hit;
1004 0 : delete runParamsObject;
1005 0 : return 21;
1006 : }
1007 0 : Log("RunParams object successfully stored");
1008 :
1009 0 : delete hT0Fill;
1010 0 : delete hit;
1011 0 : delete runParamsObject;
1012 0 : return 0;
1013 :
1014 0 : }
1015 :
1016 : //_____________________________________________________________________________
1017 :
1018 : UInt_t
1019 : AliTOFPreprocessor::ProcessNoiseCalibTrg()
1020 : {
1021 : // Processing data from DAQ using calibration triggers for noise measurement
1022 :
1023 0 : Log("Processing Noise (calibration trigger)");
1024 :
1025 : /* check status and matching window available */
1026 0 : if (!fStatus || !fMatchingWindow){
1027 0 : AliError("No valid fStatus or fMatchingWindow found, some errors must have occurred!!");
1028 0 : return 22;
1029 : }
1030 :
1031 : Float_t noiseThr = 1000.; // setting default threshold for noise to 1000 Hz
1032 : // reading config map
1033 0 : AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1034 0 : if (!cdbEntry) Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1035 : else {
1036 0 : TMap *configMap = (TMap*)cdbEntry->GetObject();
1037 0 : if (!configMap) Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1038 : else {
1039 0 : TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1040 0 : if (strNoiseThr) {
1041 0 : TString tmpstr = strNoiseThr->GetString();
1042 0 : noiseThr = tmpstr.Atoi();
1043 0 : }
1044 0 : else Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1045 : }
1046 : }
1047 :
1048 : /* get file sources from FXS */
1049 0 : TList *fileList = GetFileSources(kDAQ, "CALIB");
1050 0 : if (!fileList || fileList->GetEntries() == 0) {
1051 0 : Log("cannot get DAQ source file list or empty list");
1052 0 : return 22;
1053 : }
1054 0 : Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1055 0 : fileList->Print();
1056 :
1057 : /* open input file (only one expected) */
1058 0 : TObjString *str = (TObjString *)fileList->At(0);
1059 0 : TString filename = GetFile(kDAQ, "CALIB", str->GetName());
1060 0 : Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1061 0 : TFile *filein = TFile::Open(filename.Data());
1062 0 : if (!filein || !filein->IsOpen()) {
1063 0 : Log("cannot open input file");
1064 0 : return 22;
1065 : }
1066 :
1067 : /* get histo from input file */
1068 0 : TH1F *hCalibHit = (TH1F *)filein->Get("hCalibHit");
1069 0 : if (!hCalibHit) {
1070 0 : Log("cannot get \"hCalibHit\" histo");
1071 0 : return 22;
1072 : }
1073 :
1074 : /* create and set noise rate histo and check rate */
1075 0 : TH1F *hNoiseRate = new TH1F("hNoiseRate", ";index;rate (Hz)", fNChannels, 0., fNChannels);
1076 : Float_t rate, rate_err;
1077 0 : for (Int_t ich = 0; ich < fNChannels; ich++) {
1078 : /* check channel enabled */
1079 0 : if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad) continue;
1080 : /* set noise rate histo */
1081 0 : rate = hCalibHit->GetBinContent(ich + 1);
1082 0 : rate_err = hCalibHit->GetBinError(ich + 1);
1083 0 : rate /= fMatchingWindow[ich] * 1.e-9;
1084 0 : rate_err /= fMatchingWindow[ich] * 1.e-9;
1085 0 : hNoiseRate->SetBinContent(ich + 1, rate);
1086 0 : hNoiseRate->SetBinError(ich + 1, rate_err);
1087 : /* check error */
1088 0 : if (rate_err == 0.) continue;
1089 : /* check noise rate and set noise flags */
1090 0 : if ((rate - 3. * rate_err) > noiseThr) {
1091 0 : Log(Form("channel %d detected as noisy: rate = (%f +- %f) Hz", ich, rate, rate_err));
1092 0 : if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseOk) {
1093 0 : Log(Form("channel %d noise status changed from Ok to Bad", ich));
1094 0 : fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseBad);
1095 0 : fIsStatusMapChanged = kTRUE;
1096 0 : }
1097 0 : else Log(Form("channel %d noise status unchanged", ich));
1098 : }
1099 0 : else if ((rate + 3. * rate_err) < noiseThr) {
1100 0 : if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) {
1101 0 : Log(Form("channel %d noise status changed from Bad to Ok", ich));
1102 0 : fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseOk);
1103 0 : fIsStatusMapChanged = kTRUE;
1104 0 : }
1105 : }
1106 : }
1107 :
1108 : /* store reference data */
1109 0 : if(fStoreRefData){
1110 0 : AliCDBMetaData metaDataHisto;
1111 0 : metaDataHisto.SetBeamPeriod(0);
1112 0 : metaDataHisto.SetResponsible("Roberto Preghenella");
1113 0 : metaDataHisto.SetComment("calibration trigger noise rate histogram");
1114 0 : if (!StoreReferenceData("Calib","CalibNoise", hNoiseRate, &metaDataHisto)) {
1115 0 : Log("error while storing reference data");
1116 0 : delete hNoiseRate;
1117 0 : filein->Close();
1118 0 : return 22;
1119 : }
1120 0 : Log("reference data successfully stored");
1121 0 : }
1122 :
1123 0 : delete hNoiseRate;
1124 0 : filein->Close();
1125 0 : return 0;
1126 0 : }
1127 :
1128 : //_____________________________________________________________________________
1129 :
1130 : UInt_t
1131 : AliTOFPreprocessor::ProcessReadout()
1132 : {
1133 : // Processing data from DAQ to compute reaodut efficiency
1134 :
1135 0 : Log("Processing Readout");
1136 :
1137 : /* get file sources from FXS */
1138 0 : TList *fileList = GetFileSources(kDAQ, "READOUT");
1139 0 : if (!fileList || fileList->GetEntries() == 0) {
1140 0 : Log("cannot get DAQ source file list or empty list");
1141 0 : return 22;
1142 : }
1143 0 : Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1144 0 : fileList->Print();
1145 :
1146 : /* open input file (only one expected) */
1147 0 : TObjString *str = (TObjString *)fileList->At(0);
1148 0 : TString filename = GetFile(kDAQ, "READOUT", str->GetName());
1149 0 : Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1150 0 : TFile *filein = TFile::Open(filename.Data());
1151 0 : if (!filein || !filein->IsOpen()) {
1152 0 : Log("cannot open input file");
1153 0 : return 23;
1154 : }
1155 :
1156 : /* get histo from input file */
1157 0 : TH1F *hChainEfficiency = (TH1F *)filein->Get("hChainEfficiency");
1158 0 : if (!hChainEfficiency) {
1159 0 : Log("cannot get \"hChainEfficiency\" histo");
1160 0 : return 23;
1161 : }
1162 :
1163 : /* fill channel efficiency histo */
1164 :
1165 : /* temporarly disable warnings */
1166 0 : AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1167 0 : AliLog::SetGlobalLogLevel(AliLog::kError);
1168 :
1169 0 : TH1F *hChannelEfficiency = new TH1F("hChannelEfficiency", "Channel readout efficiency;index;efficiency", fNChannels, 0., fNChannels);
1170 0 : Int_t chainIndex, det[5], dummy, index;
1171 : Float_t effi, effi_err;
1172 : /* loop over DDLs */
1173 0 : for (Int_t iddl = 0; iddl < 72; iddl++) {
1174 : /* loop over TRMs */
1175 0 : for (Int_t itrm = 0; itrm < 10; itrm++) {
1176 : /* loop over chains */
1177 0 : for (Int_t ichain = 0; ichain < 2; ichain++) {
1178 0 : chainIndex = ichain + 2 * itrm + 20 * iddl;
1179 0 : effi = hChainEfficiency->GetBinContent(chainIndex + 1);
1180 0 : effi_err = hChainEfficiency->GetBinError(chainIndex + 1);
1181 : /* loop over TDCs */
1182 0 : for (Int_t itdc = 0; itdc < 15; itdc++) {
1183 : /* loop over channels */
1184 0 : for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1185 :
1186 : /* get channel index */
1187 0 : AliTOFRawStream::EquipmentId2VolumeId(iddl, itrm + 3, ichain, itdc, ichannel, det);
1188 0 : dummy = det[4];
1189 0 : det[4] = det[3];
1190 0 : det[3] = dummy;
1191 : /* check valid index */
1192 0 : if (det[0] < 0 || det[0] > 17 ||
1193 0 : det[1] < 0 || det[1] > 5 ||
1194 0 : det[2] < 0 || det[2] > 18 ||
1195 0 : det[3] < 0 || det[3] > 1 ||
1196 0 : det[4] < 0 || det[4] > 47) continue;
1197 0 : index = AliTOFGeometry::GetIndex(det);
1198 :
1199 : /* set channel efficiency */
1200 0 : hChannelEfficiency->SetBinContent(index + 1, effi);
1201 0 : hChannelEfficiency->SetBinError(index + 1, effi_err);
1202 :
1203 : }
1204 : }
1205 : }
1206 : }
1207 : }
1208 :
1209 : /* re-enable warnings */
1210 0 : AliLog::SetGlobalLogLevel(logLevel);
1211 :
1212 : /* store reference data */
1213 0 : if(fStoreRefData){
1214 : /* setup TOF readout info object */
1215 0 : AliTOFReadoutInfo readoutInfo;
1216 0 : readoutInfo.SetChainEfficiency((TH1F *)filein->Get("hChainEfficiency"));
1217 0 : readoutInfo.SetTRMData((TH1F *)filein->Get("hTRMData"));
1218 0 : readoutInfo.SetTRMEmptyEvent((TH1F *)filein->Get("hTRMEmptyEvent"));
1219 0 : readoutInfo.SetTRMBadEventCounter((TH1F *)filein->Get("hTRMBadEventCounter"));
1220 0 : readoutInfo.SetTRMBadCRC((TH1F *)filein->Get("hTRMBadCRC"));
1221 0 : readoutInfo.SetChainData((TH1F *)filein->Get("hChainData"));
1222 0 : readoutInfo.SetChainBadStatus((TH1F *)filein->Get("hChainBadStatus"));
1223 0 : readoutInfo.SetChainBadEventCounter((TH1F *)filein->Get("hChainBadEventCounter"));
1224 0 : readoutInfo.SetTDCError((TH1F *)filein->Get("hTDCError"));
1225 0 : readoutInfo.SetTDCErrorFlags((TH2F *)filein->Get("hTDCErrorFlags"));
1226 :
1227 0 : AliCDBMetaData metaDataHisto;
1228 0 : metaDataHisto.SetBeamPeriod(0);
1229 0 : metaDataHisto.SetResponsible("Roberto Preghenella");
1230 0 : metaDataHisto.SetComment("readout info data");
1231 0 : if (!StoreReferenceData("Calib","ReadoutInfo", &readoutInfo, &metaDataHisto)) {
1232 0 : Log("error while storing reference data");
1233 0 : filein->Close();
1234 0 : return 23;
1235 : }
1236 0 : Log("reference data successfully stored");
1237 0 : }
1238 :
1239 0 : AliCDBMetaData metaData;
1240 0 : metaData.SetBeamPeriod(0);
1241 0 : metaData.SetResponsible("Roberto Preghenella");
1242 0 : metaData.SetComment("online ReadoutEfficiency measurement");
1243 0 : if (!Store("Calib", "ReadoutEfficiency", hChannelEfficiency, &metaData, 0, kFALSE)) {
1244 0 : Log("error while storing ReadoutEfficiency object");
1245 0 : delete hChannelEfficiency;
1246 0 : filein->Close();
1247 0 : return 23;
1248 : }
1249 0 : Log("ReadoutEfficiency object successfully stored");
1250 :
1251 0 : delete hChannelEfficiency;
1252 0 : filein->Close();
1253 0 : return 0;
1254 0 : }
1255 :
1256 : //_____________________________________________________________________________
1257 :
1258 : UInt_t AliTOFPreprocessor::ProcessPulserData()
1259 : {
1260 : // Processing Pulser Run data for TOF channel status
1261 :
1262 0 : Log("Processing Pulser");
1263 :
1264 0 : if (fStatus==0x0){
1265 0 : AliError("No valid fStatus found, some errors must have occurred!!");
1266 0 : return 20;
1267 : }
1268 :
1269 0 : TH1::AddDirectory(0);
1270 :
1271 : Bool_t resultPulserRef=kFALSE;
1272 : Bool_t resultPulser=kFALSE;
1273 :
1274 0 : static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1275 0 : TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
1276 0 : for (Int_t ibin =1;ibin<=kSize;ibin++){
1277 0 : htofPulser->SetBinContent(ibin,-1);
1278 : }
1279 :
1280 : // processing pulser
1281 :
1282 : TFile * daqFile=0x0;
1283 : TH1S *h1=0x0;
1284 :
1285 : //retrieving Pulser data
1286 0 : TList* listPulser = GetFileSources(kDAQ, "PULSER");
1287 0 : if (listPulser !=0x0 && listPulser->GetEntries()!=0)
1288 : {
1289 0 : AliInfo("The following sources produced files with the id PULSER");
1290 0 : listPulser->Print();
1291 : Int_t nPulser = 0;
1292 0 : for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
1293 : Int_t nPulserSource = 0;
1294 0 : TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
1295 0 : if (!str) {
1296 0 : AliError("dynamic_cast returned NULL");
1297 0 : return 4;
1298 : }
1299 0 : AliInfo(Form("found source %s", str->String().Data()));
1300 : // file to be stored run per run
1301 0 : TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
1302 0 : if (fileNamePulser.Length()>0){
1303 : // storing refernce data
1304 0 : AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
1305 0 : daqFile = new TFile(fileNamePulser.Data(),"READ");
1306 0 : h1 = (TH1S*) daqFile->Get("hTOFpulser");
1307 0 : for (Int_t ibin=0;ibin<kSize;ibin++){
1308 0 : if ((h1->GetBinContent(ibin+1))!=-1){
1309 0 : if ((htofPulser->GetBinContent(ibin+1))==-1){
1310 0 : htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
1311 : }
1312 : else {
1313 0 : Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
1314 : }
1315 : }
1316 : }
1317 :
1318 : // elaborating infos
1319 : Double_t mean =0;
1320 : Int_t nread=0;
1321 : Int_t nreadNotEmpty=0;
1322 0 : for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
1323 :
1324 0 : AliDebug(3,Form(" channel %i pulser status before pulser = %i, with global status = %i",ientry,(Int_t)fStatus->GetPulserStatus(ientry),(Int_t)fStatus->GetStatus(ientry)));
1325 : /* check whether channel has been read out during current run.
1326 : * if the status is bad it means it has not been read out.
1327 : * in this case skip channel in order to not affect the mean */
1328 0 : if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1329 : continue;
1330 0 : nPulser++;
1331 0 : nPulserSource++;
1332 0 : if (h1->GetBinContent(ientry)==-1) continue;
1333 : else {
1334 0 : if (h1->GetBinContent(ientry)>0) {
1335 0 : nreadNotEmpty++;
1336 0 : AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
1337 : }
1338 0 : mean+=h1->GetBinContent(ientry);
1339 0 : nread++;
1340 : }
1341 0 : }
1342 0 : if (nread!=0) {
1343 0 : mean/=nread;
1344 0 : AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
1345 0 : for (Int_t ich =0;ich<fNChannels;ich++){
1346 0 : if (h1->GetBinContent(ich+1)==-1) continue;
1347 0 : AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
1348 :
1349 : /* check whether channel has been read out during current run.
1350 : * if the status is bad it means it has not been read out.
1351 : * in this case skip channel in order to leave its status
1352 : * unchanged */
1353 0 : if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1354 : continue;
1355 :
1356 0 : if (h1->GetBinContent(ich+1)<0.05*mean){
1357 0 : fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
1358 0 : AliDebug(2,Form( " channel %i pulser status after pulser = %i (bad, content = %f), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),h1->GetBinContent(ich+1),(Int_t)fStatus->GetStatus(ich)));
1359 : }
1360 : else {
1361 0 : fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
1362 0 : AliDebug(2,Form( " channel %i pulser status after pulser = %i (good), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1363 : }
1364 : }
1365 0 : }
1366 : else {
1367 0 : Log("No channels read!! No action taken, keeping old status");
1368 : }
1369 :
1370 0 : daqFile->Close();
1371 0 : delete daqFile;
1372 0 : delete h1;
1373 : }
1374 :
1375 : else{
1376 0 : Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1377 0 : delete listPulser;
1378 0 : delete htofPulser;
1379 : htofPulser = 0x0;
1380 0 : if (fStatus){
1381 0 : delete fStatus;
1382 0 : fStatus = 0;
1383 0 : }
1384 0 : return 10;//return error code for failure in retrieving Ref Data
1385 : }
1386 0 : AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1387 0 : }
1388 0 : AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
1389 0 : delete listPulser;
1390 0 : }
1391 :
1392 : else{
1393 0 : Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1394 0 : delete htofPulser;
1395 : htofPulser = 0x0;
1396 0 : if (fStatus){
1397 0 : delete fStatus;
1398 0 : fStatus = 0;
1399 0 : }
1400 0 : return 10;//return error code for failure in retrieving Ref Data
1401 : }
1402 :
1403 : //storing in OCDB
1404 :
1405 0 : AliCDBMetaData metaData;
1406 0 : metaData.SetBeamPeriod(0);
1407 0 : metaData.SetResponsible("Chiara Zampolli");
1408 0 : metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
1409 0 : AliInfo("Storing Calibration Data from Pulser Run");
1410 0 : resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1411 0 : if(!resultPulser){
1412 0 : Log("Some problems occurred while storing online object resulting from Pulser data processing");
1413 0 : delete htofPulser;
1414 : htofPulser = 0x0;
1415 0 : if (fStatus){
1416 0 : delete fStatus;
1417 0 : fStatus = 0;
1418 0 : }
1419 0 : return 11;//return error code for problems in storing Pulser data
1420 : }
1421 :
1422 0 : if(fStoreRefData){
1423 :
1424 0 : AliCDBMetaData metaDataHisto;
1425 0 : metaDataHisto.SetBeamPeriod(0);
1426 0 : metaDataHisto.SetResponsible("Chiara Zampolli");
1427 0 : metaDataHisto.SetComment("This preprocessor stores the Ref data from a pulser run.");
1428 0 : AliInfo("Storing Reference Data");
1429 0 : resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
1430 0 : if (!resultPulserRef){
1431 0 : Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
1432 0 : delete htofPulser;
1433 : htofPulser = 0x0;
1434 0 : if (fStatus){
1435 0 : delete fStatus;
1436 0 : fStatus = 0;
1437 0 : }
1438 0 : return 9;//return error code for failure in storing Ref Data
1439 : }
1440 0 : }
1441 :
1442 : daqFile=0;
1443 :
1444 0 : delete htofPulser;
1445 : htofPulser = 0x0;
1446 :
1447 0 : if (fStatus){
1448 0 : delete fStatus;
1449 0 : fStatus = 0;
1450 0 : }
1451 :
1452 0 : return 0;
1453 0 : }
1454 : //_____________________________________________________________________________
1455 :
1456 : UInt_t AliTOFPreprocessor::ProcessNoiseData()
1457 : {
1458 :
1459 : // Processing Noise Run data for TOF channel status
1460 :
1461 0 : Log("Processing Noise");
1462 :
1463 0 : if (fStatus==0x0){
1464 0 : AliError("No valid fStatus found, some errors must have occurred!!");
1465 0 : return 20;
1466 : }
1467 :
1468 : Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
1469 : // reading config map
1470 0 : AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1471 0 : if (!cdbEntry) {
1472 0 : Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1473 0 : }
1474 : else {
1475 0 : TMap *configMap = (TMap*)cdbEntry->GetObject();
1476 0 : if (!configMap){
1477 0 : Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1478 0 : }
1479 : else{
1480 0 : TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1481 0 : if (strNoiseThr) {
1482 0 : TString tmpstr = strNoiseThr->GetString();
1483 0 : noiseThr = tmpstr.Atoi();
1484 0 : }
1485 : else {
1486 0 : Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1487 : }
1488 : }
1489 : }
1490 :
1491 0 : delete cdbEntry;
1492 : cdbEntry = 0x0;
1493 :
1494 0 : TH1::AddDirectory(0);
1495 :
1496 : Bool_t resultNoiseRef=kFALSE;
1497 : Bool_t resultNoise=kFALSE;
1498 :
1499 0 : static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1500 0 : TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
1501 0 : for (Int_t ibin =1;ibin<=kSize;ibin++){
1502 0 : htofNoise->SetBinContent(ibin,-1);
1503 : }
1504 :
1505 : // processing noise
1506 :
1507 : TFile * daqFile=0x0;
1508 : TH1F * h1=0x0;
1509 :
1510 : // useful counters
1511 : Int_t nNoise = 0;
1512 : Int_t nNoisyChannels = 0;
1513 : Int_t nNotNoisyChannels = 0;
1514 : Int_t nChannelsFromDA = 0;
1515 : Int_t nMatchingWindowNullNonZero = 0;
1516 : Int_t nMatchingWindowNullEqualZero = 0;
1517 :
1518 : // retrieving Noise data
1519 0 : TList* listNoise = GetFileSources(kDAQ, "NOISE");
1520 0 : if (listNoise !=0x0 && listNoise->GetEntries()!=0)
1521 : {
1522 0 : AliInfo("The following sources produced files with the id NOISE");
1523 0 : listNoise->Print();
1524 0 : for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
1525 : Int_t nNoiseSource = 0;
1526 0 : TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
1527 0 : if (!str) {
1528 0 : AliError("dynamic_cast returned NULL");
1529 0 : return 4;
1530 : }
1531 0 : AliInfo(Form("found source %s", str->String().Data()));
1532 : // file to be stored run per run
1533 0 : TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
1534 0 : if (fileNameNoise.Length()>0){
1535 : // storing reference data
1536 0 : AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
1537 0 : daqFile = new TFile(fileNameNoise.Data(),"READ");
1538 0 : h1 = (TH1F*) daqFile->Get("hTOFnoise");
1539 0 : for (Int_t ibin=0;ibin<kSize;ibin++){
1540 0 : if ((h1->GetBinContent(ibin+1))!=-1){
1541 0 : nNoiseSource++;
1542 : // checking the matching window for current channel
1543 0 : if (fMatchingWindow[ibin] == 0){
1544 0 : Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
1545 0 : if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
1546 0 : if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
1547 : continue;
1548 : }
1549 0 : if ((htofNoise->GetBinContent(ibin+1))==-1){
1550 0 : htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
1551 0 : if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
1552 : }
1553 : else {
1554 0 : Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
1555 : }
1556 : }
1557 : }
1558 :
1559 0 : Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
1560 0 : daqFile->Close();
1561 0 : delete daqFile;
1562 0 : delete h1;
1563 : daqFile = 0x0;
1564 : h1 = 0x0;
1565 :
1566 : }
1567 : else{
1568 0 : Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
1569 0 : delete listNoise;
1570 : listNoise = 0x0;
1571 0 : delete htofNoise;
1572 : htofNoise = 0x0;
1573 0 : if (fStatus){
1574 0 : delete fStatus;
1575 0 : fStatus = 0;
1576 0 : }
1577 0 : if (fMatchingWindow){
1578 0 : delete [] fMatchingWindow;
1579 0 : fMatchingWindow = 0;
1580 0 : }
1581 0 : return 13;//return error code for failure in retrieving Ref Data
1582 : }
1583 0 : }
1584 : }
1585 :
1586 : else{
1587 0 : Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
1588 0 : delete htofNoise;
1589 : htofNoise = 0x0;
1590 0 : if (fStatus){
1591 0 : delete fStatus;
1592 0 : fStatus = 0;
1593 0 : }
1594 0 : if (fMatchingWindow){
1595 0 : delete [] fMatchingWindow;
1596 0 : fMatchingWindow = 0;
1597 0 : }
1598 0 : return 13;//return error code for failure in retrieving Ref Data
1599 : }
1600 :
1601 : // elaborating infos to set NOISE status
1602 0 : for (Int_t ich =0;ich<fNChannels;ich++){
1603 0 : if (htofNoise->GetBinContent(ich+1)== -1) continue;
1604 :
1605 0 : nChannelsFromDA++;
1606 :
1607 0 : AliDebug(3,Form(" channel %i noise status before noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1608 : //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
1609 :
1610 : /* check whether channel has been read out during current run.
1611 : * if the status is bad it means it has not been read out.
1612 : * in this case skip channel in order to leave its status
1613 : * unchanged */
1614 :
1615 0 : if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1616 : continue;
1617 :
1618 0 : nNoise++;
1619 0 : if (htofNoise->GetBinContent(ich+1) >= noiseThr){
1620 0 : fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
1621 0 : AliDebug(3,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1622 0 : nNoisyChannels++;
1623 0 : }
1624 : else {
1625 0 : fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
1626 0 : AliDebug(3,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
1627 0 : nNotNoisyChannels++;
1628 : }
1629 : }
1630 :
1631 0 : Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
1632 0 : Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
1633 0 : Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
1634 0 : Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
1635 0 : Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
1636 0 : Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
1637 :
1638 0 : delete listNoise;
1639 :
1640 : //daqFile=0;
1641 :
1642 : //storing in OCDB
1643 :
1644 0 : AliCDBMetaData metaData;
1645 0 : metaData.SetBeamPeriod(0);
1646 0 : metaData.SetResponsible("Chiara Zampolli");
1647 0 : metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
1648 0 : AliInfo("Storing Calibration Data from Noise Run");
1649 0 : resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1650 0 : if(!resultNoise){
1651 0 : Log("Some problems occurred while storing online object resulting from Noise data processing");
1652 0 : delete htofNoise;
1653 : htofNoise = 0x0;
1654 0 : if (fStatus){
1655 0 : delete fStatus;
1656 0 : fStatus = 0;
1657 0 : }
1658 0 : if (fMatchingWindow){
1659 0 : delete [] fMatchingWindow;
1660 0 : fMatchingWindow = 0;
1661 0 : }
1662 0 : return 14;//return error code for problems in storing Noise data
1663 : }
1664 :
1665 0 : if(fStoreRefData){
1666 :
1667 0 : AliCDBMetaData metaDataHisto;
1668 0 : metaDataHisto.SetBeamPeriod(0);
1669 0 : metaDataHisto.SetResponsible("Chiara Zampolli");
1670 0 : metaDataHisto.SetComment("This preprocessor stores the Ref data from a noise run. ");
1671 0 : AliInfo("Storing Reference Data");
1672 0 : resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
1673 0 : if (!resultNoiseRef){
1674 0 : Log("some problems occurred::No Reference Data for noise stored");
1675 0 : delete htofNoise;
1676 : htofNoise = 0x0;
1677 0 : if (fStatus){
1678 0 : delete fStatus;
1679 0 : fStatus = 0;
1680 0 : }
1681 0 : if (fMatchingWindow){
1682 0 : delete [] fMatchingWindow;
1683 0 : fMatchingWindow = 0;
1684 0 : }
1685 0 : return 12;//return error code for failure in storing Ref Data
1686 : }
1687 0 : }
1688 :
1689 0 : delete htofNoise;
1690 : htofNoise = 0x0;
1691 :
1692 0 : if (fStatus){
1693 0 : delete fStatus;
1694 0 : fStatus = 0;
1695 0 : }
1696 :
1697 0 : if (fMatchingWindow){
1698 0 : delete [] fMatchingWindow;
1699 0 : fMatchingWindow = 0;
1700 0 : }
1701 :
1702 0 : return 0;
1703 0 : }
1704 : //_____________________________________________________________________________
1705 :
1706 : UInt_t AliTOFPreprocessor::ProcessFEEData()
1707 : {
1708 : // Processing Pulser Run data for TOF channel status
1709 : // dummy for the time being
1710 :
1711 0 : Log("Processing FEE");
1712 :
1713 : //Bool_t updateOCDB = kFALSE;
1714 0 : AliTOFFEEReader feeReader;
1715 :
1716 0 : TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
1717 :
1718 : /* load current TOF FEE(dump) from DCS FXS,
1719 : * setup TOFFEEdump object */
1720 :
1721 0 : const char * toffeeFileName = GetFile(kDCS,"TofFeeMap","");
1722 0 : AliInfo(Form("toffee file name = %s", toffeeFileName));
1723 0 : if (toffeeFileName == NULL) {
1724 0 : return 15;
1725 : }
1726 0 : AliTOFFEEDump feedump;
1727 0 : feedump.ReadFromFile(toffeeFileName);
1728 :
1729 : /* load current TOF FEE(light) config from DCS FXS, parse,
1730 : * fill current FEE histogram and set FEE status */
1731 :
1732 0 : const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
1733 0 : AliInfo(Form("toffeeLight file name = %s",nameFile));
1734 0 : if (nameFile == NULL) {
1735 0 : return 15;
1736 : }
1737 0 : feeReader.LoadFEElightConfig(nameFile);
1738 0 : Int_t parseFee = feeReader.ParseFEElightConfig();
1739 0 : AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1740 : /* load stored TOF FEE from OCDB and compare it with current FEE.
1741 : * if stored FEE is different from current FEE set update flag.
1742 : * if there is no stored FEE in OCDB set update flag */
1743 :
1744 0 : fMatchingWindow = new Int_t[fNChannels];
1745 0 : fLatencyWindow = new Int_t[fNChannels];
1746 :
1747 0 : AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1748 0 : if (!cdbEntry) {
1749 : /* no CDB entry found. set update flag */
1750 0 : Log(" ************ WARNING ************");
1751 0 : Log("No CDB Status entry found, creating a new one!");
1752 0 : Log(" *********************************");
1753 0 : fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1754 : //updateOCDB = kTRUE;
1755 0 : fIsStatusMapChanged = kTRUE;
1756 0 : }
1757 : else {
1758 0 : if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1759 : /* CDB entry OK. loop over channels */
1760 0 : fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1761 0 : delete cdbEntry;
1762 : cdbEntry = 0x0;
1763 : /* cehck whether status object has latency window data */
1764 0 : if (!fStatus->HasLatencyWindow()) {
1765 : /* create new status object and update OCDB */
1766 0 : Log(" ************ WARNING ************");
1767 0 : Log("CDB Status entry found but has no latency window data, creating a new one!");
1768 0 : Log(" *********************************");
1769 0 : delete fStatus;
1770 0 : fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1771 : //updateOCDB = kTRUE;
1772 0 : fIsStatusMapChanged = kTRUE;
1773 0 : }
1774 : }
1775 0 : for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1776 : //AliDebug(2,Form("********** channel %i",iChannel));
1777 : /* compare current FEE channel status with stored one
1778 : * if different set update flag and break loop */
1779 : //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1780 0 : fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1781 0 : fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1782 0 : if (feeReader.IsChannelEnabled(iChannel)) {
1783 0 : hCurrentFEE.SetBinContent(iChannel + 1, 1);
1784 0 : if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1785 : //updateOCDB = kTRUE;
1786 0 : fIsStatusMapChanged = kTRUE;
1787 0 : fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1788 0 : AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1789 : }
1790 0 : if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1791 : //updateOCDB = kTRUE;
1792 0 : fIsStatusMapChanged = kTRUE;
1793 0 : fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1794 0 : AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1795 : }
1796 : }
1797 : else {
1798 0 : if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1799 : //updateOCDB = kTRUE;
1800 0 : fIsStatusMapChanged = kTRUE;
1801 0 : fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1802 0 : AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1803 : }
1804 : }
1805 : }
1806 :
1807 :
1808 : /* check whether we don't have to store reference data.
1809 : * in this case we return without errors. */
1810 0 : if (fStoreRefData) {
1811 : /* store reference data */
1812 0 : AliCDBMetaData metaDataHisto;
1813 0 : metaDataHisto.SetBeamPeriod(0);
1814 0 : metaDataHisto.SetResponsible("Roberto Preghenella");
1815 0 : metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1816 0 : AliInfo("Storing FEE reference data");
1817 : /* store FEE reference data */
1818 0 : if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1819 : /* failed */
1820 0 : Log("problems while storing FEE reference data");
1821 0 : if (fStatus){
1822 0 : delete fStatus;
1823 0 : fStatus = 0;
1824 0 : }
1825 0 : return 18; /* error return code for problems while storing FEE reference data */
1826 : }
1827 :
1828 : /* store TOF FEE dump reference data */
1829 0 : AliCDBMetaData metaDatadump;
1830 0 : metaDatadump.SetBeamPeriod(0);
1831 0 : metaDatadump.SetResponsible("Roberto Preghenella");
1832 0 : metaDatadump.SetComment("This preprocessor stores the TOF FEE dump Ref data of the current run.");
1833 0 : AliInfo("Storing TOF FEE dump reference data");
1834 : /* store FEE reference data */
1835 0 : if (!StoreReferenceData("Calib", "FEEDump", &feedump, &metaDatadump)) {
1836 : /* failed */
1837 0 : Log("problems while storing TOF FEE dump reference data");
1838 0 : return 18; /* error return code for problems while storing FEE reference data */
1839 : }
1840 0 : }
1841 :
1842 0 : return 0;
1843 :
1844 0 : }
1845 :
1846 : //_____________________________________________________________________________
1847 :
1848 : UInt_t AliTOFPreprocessor::Process(TMap *dcsAliasMap)
1849 : {
1850 : //
1851 : // Main AliTOFPreprocessor method called by SHUTTLE
1852 : //
1853 :
1854 0 : TString runType = GetRunType();
1855 0 : Log(Form("RunType %s",runType.Data()));
1856 :
1857 : // processing
1858 :
1859 : /* always process FEE data */
1860 0 : Int_t iresultFEE = ProcessFEEData();
1861 0 : if (iresultFEE != 0)
1862 0 : return iresultFEE;
1863 :
1864 0 : if (runType == "PULSER") {
1865 0 : Int_t iresultPulser = ProcessPulserData();
1866 : return iresultPulser;
1867 : }
1868 :
1869 0 : if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1870 0 : Int_t iresultNoise = ProcessNoiseData();
1871 : return iresultNoise;
1872 : }
1873 :
1874 0 : if (runType == "PHYSICS") {
1875 : // Int_t iresultDAQ = ProcessOnlineDelays();
1876 0 : Int_t iresultDAQ = ProcessT0Fill();
1877 0 : Int_t iresultNoiseCalib = ProcessNoiseCalibTrg();
1878 0 : Int_t iresultReadout = ProcessReadout();
1879 0 : Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1880 0 : Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
1881 0 : Int_t totResult = iresultDAQ + iresultNoiseCalib + iresultDCS + iResultHVandLVdps + iresultReadout;
1882 0 : Log(Form("Processing PHYSICS, returning %d (iresultDAQ = %d, iresultNoiseCalib = %d, iresultDCS = %d, iResultHVandLVdps = %d, iresultReadout = %d)", totResult, iresultDAQ, iresultNoiseCalib, iresultDCS, iResultHVandLVdps, iresultReadout));
1883 : return totResult;
1884 : }
1885 :
1886 : // storing
1887 0 : return 0;
1888 0 : }
1889 :
1890 :
1891 : //_____________________________________________________________________________
1892 :
1893 : void
1894 : AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1895 : {
1896 : /*
1897 : * fill with cosmic calibration
1898 : */
1899 :
1900 0 : Log(" Using cosmic-ray calibration.");
1901 :
1902 0 : AliTOFcalibHisto calibHisto;
1903 0 : calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1904 0 : Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1905 0 : Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1906 0 : calibHisto.LoadCalibPar();
1907 :
1908 : /* loop over channel index */
1909 0 : for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1910 0 : cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1911 : }
1912 :
1913 0 : }
1914 :
1915 : //_____________________________________________________________________________
1916 :
1917 : void
1918 : AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1919 : {
1920 : /*
1921 : * fill with cosmic calibration
1922 : */
1923 :
1924 0 : Log(" Using cable-length map.");
1925 0 : AliTOFRawStream tofrs;
1926 0 : Int_t det[5], dummy, index;
1927 : Float_t cableTimeShift;
1928 :
1929 : /* temporarly disable warnings */
1930 0 : AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1931 0 : AliLog::SetGlobalLogLevel(AliLog::kError);
1932 :
1933 : /* loop over EO indeces */
1934 0 : for (Int_t iddl = 0; iddl < 72; iddl++)
1935 0 : for (Int_t islot = 3; islot <= 12; islot++)
1936 0 : for (Int_t ichain = 0; ichain < 2; ichain++)
1937 0 : for (Int_t itdc = 0; itdc < 15; itdc++)
1938 0 : for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1939 :
1940 : /* get DO index */
1941 0 : tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1942 :
1943 : /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1944 0 : dummy = det[3];
1945 0 : det[3] = det[4];
1946 0 : det[4] = dummy;
1947 :
1948 : /* check DO index */
1949 0 : if (det[0] < 0 || det[0] > 17 ||
1950 0 : det[1] < 0 || det[1] > 4 ||
1951 0 : det[2] < 0 || det[2] > 18 ||
1952 0 : det[3] < 0 || det[3] > 1 ||
1953 0 : det[4] < 0 || det[4] > 47)
1954 : continue;
1955 :
1956 : /* get channel index */
1957 0 : index = AliTOFGeometry::GetIndex(det);
1958 0 : if (index < 0) continue;
1959 :
1960 : /* get cable time shift */
1961 0 : cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1962 :
1963 : /* set delay */
1964 0 : if (index<fNChannels) {
1965 0 : cal->SetDelay(index,cableTimeShift); // delay in ns
1966 0 : AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1967 : }
1968 :
1969 : } /* loop over EO indeces */
1970 :
1971 : /* re-enable warnings */
1972 0 : AliLog::SetGlobalLogLevel(logLevel);
1973 :
1974 0 : }
1975 :
1976 :
|