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