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