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