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