]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFPreprocessor.cxx
1-pass reference to aod branch to the frame, not the pointer; 2-track references...
[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
a174d599 18//#include <Riostream.h>
19//#include <stdio.h>
20//#include <stdlib.h>
c9fe8530 21
9edefa04 22#include <TFile.h>
9edefa04 23#include <TH2S.h>
24#include <TMath.h>
25#include <TObjArray.h>
26#include <TObjString.h>
27#include <TTimeStamp.h>
c9fe8530 28
29#include "AliCDBMetaData.h"
7fffa85b 30#include "AliCDBEntry.h"
c9fe8530 31#include "AliLog.h"
17149e6b 32#include "AliTOFChannelOnlineArray.h"
33#include "AliTOFChannelOnlineStatusArray.h"
9edefa04 34#include "AliTOFDataDCS.h"
10056aa6 35#include "AliTOFGeometry.h"
9edefa04 36#include "AliTOFPreprocessor.h"
db83b789 37#include "AliTOFFEEReader.h"
c9fe8530 38
c9fe8530 39// TOF preprocessor class.
40// It takes data from DCS and passes them to the class AliTOFDataDCS, which
41// processes them. The result is then written to the CDB.
17149e6b 42// Analogously, it takes data form DAQ (both at Run level and inclusive -
c9fe8530 43// of all the runs - level, processes them, and stores both Reference Data
44// and Online Calibration files in the CDB.
17149e6b 45// Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
7fffa85b 46
47// return codes:
48// return=0 : all ok
49// return=1 : no DCS input data Map
50// return=2 : no DCS input data processing
51// return=3 : no DCS processed data was stored in Ref Data
52// return=4 : no DAQ input for Ref Data
53// return=5 : failed to store DAQ Ref Data
54// return=6 : failed to retrieve DAQ data for calibration
55// return=7 : problems in processing histos in the input DAQ file
56// return=8 : failed to store Online Delays
57// return=9 : failed to store Reference Data for Pulser
58// return=10: failed to retrieve Pulser data
59// return=11: failed to store Pulser map in OCDB
60// return=12: failed to store Reference Data for Noise
61// return=13: failed to retrieve Noise data
62// return=14: failed to store Noise map in OCDB
db83b789 63// return=15: failed to retrieve FEE data from FXS
64// return=16: failed to retrieve FEE data from OCDB
65// return=17: failed to store FEE data in OCDB
66// return=18: failed to store FEE reference data in OCDB
17149e6b 67// return=20: failed in retrieving status variable
c9fe8530 68
69ClassImp(AliTOFPreprocessor)
70
7fffa85b 71const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
72const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
73const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
c9fe8530 74
75//_____________________________________________________________________________
76
708db10b 77AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
78 AliPreprocessor("TOF", shuttle),
c9fe8530 79 fData(0),
c9fe8530 80 fCal(0),
10056aa6 81 fNChannels(0),
7fffa85b 82 fStoreRefData(kTRUE),
17149e6b 83 fFDRFlag(kFALSE),
84 fStatus(0)
c9fe8530 85{
86 // constructor
370aeff7 87 AddRunType("PHYSICS");
88 AddRunType("PULSER");
89 AddRunType("NOISE");
10056aa6 90
c9fe8530 91}
92
93//_____________________________________________________________________________
94
95AliTOFPreprocessor::~AliTOFPreprocessor()
96{
97 // destructor
98}
99
100//______________________________________________________________________________
101void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
102 UInt_t endTime)
103{
104 // Creates AliTOFDataDCS object
105
106 AliPreprocessor::Initialize(run, startTime, endTime);
107
108 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
109 TTimeStamp(startTime).AsString(),
110 TTimeStamp(endTime).AsString()));
111
112 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
10056aa6 113 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
c9fe8530 114}
7fffa85b 115//_____________________________________________________________________________
116Bool_t AliTOFPreprocessor::ProcessDCS(){
117
118 // check whether DCS should be processed or not...
c9fe8530 119
7fffa85b 120 TString runType = GetRunType();
121 Log(Form("RunType %s",runType.Data()));
122
55454922 123 if (runType != "PHYSICS"){
7fffa85b 124 return kFALSE;
125 }
126
127 return kTRUE;
128}
c9fe8530 129//_____________________________________________________________________________
130
ee3e792b 131UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
c9fe8530 132{
133 // Fills data into a AliTOFDataDCS object
134
7fffa85b 135
136 Log("Processing DCS DP");
708db10b 137 TH1::AddDirectory(0);
5936ab02 138
7885c291 139 Bool_t resultDCSMap=kFALSE;
140 Bool_t resultDCSStore=kFALSE;
c9fe8530 141
142 // processing DCS
143
144 if (!dcsAliasMap){
5936ab02 145 Log("No DCS map found: TOF exiting from Shuttle");
e88f3330 146 if (fData){
147 delete fData;
148 fData = 0;
149 }
5936ab02 150 return 1;// return error Code for DCS input data not found
c9fe8530 151 }
152 else {
153 // The processing of the DCS input data is forwarded to AliTOFDataDCS
7885c291 154 resultDCSMap=fData->ProcessData(*dcsAliasMap);
155 if(!resultDCSMap){
156 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
e88f3330 157 if (fData){
158 delete fData;
159 fData = 0;
160 }
5936ab02 161 return 2;// return error Code for processed DCS data not stored
c9fe8530 162 }
7885c291 163 else{
164 AliCDBMetaData metaDataDCS;
165 metaDataDCS.SetBeamPeriod(0);
166 metaDataDCS.SetResponsible("Chiara Zampolli");
167 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
168 AliInfo("Storing DCS Data");
b0d8f3fc 169 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
7885c291 170 if (!resultDCSStore){
b0d8f3fc 171 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
e88f3330 172 if (fData){
173 delete fData;
174 fData = 0;
175 }
7885c291 176 return 3;// return error Code for processed DCS data not stored
b0d8f3fc 177 // in reference data
7885c291 178
179 }
180 }
c9fe8530 181 }
e88f3330 182 if (fData){
183 delete fData;
184 fData = 0;
185 }
186
ee3e792b 187 return 0;
188}
189//_____________________________________________________________________________
190
191UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
192{
7fffa85b 193 // Processing data from DAQ for online calibration
194
195 Log("Processing DAQ delays");
ee3e792b 196
17149e6b 197 // reading configuration map
198 TString compDelays = "kFALSE";
199 Int_t deltaStartingRun = fRun;
200 Int_t startingRun = fRun-deltaStartingRun;
201 Int_t binRangeAve = fgkBinRangeAve;
202 Double_t integralThr = fgkIntegralThr;
203 Double_t thrPar = fgkThrPar;
204
205 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
206 if (!cdbEntry) {
207 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
208 }
209 else {
210 TMap *configMap = (TMap*)cdbEntry->GetObject();
211 if (!configMap){
212 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
213 }
214 else{
215 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
216 if (strDelays) {
217 compDelays = (TString) strDelays->GetString();
218 }
219 else {
220 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
221 }
222 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
223 if (strRun) {
224 TString tmpstr = strRun->GetString();
225 startingRun = tmpstr.Atoi();
226 deltaStartingRun = fRun - startingRun;
227 }
228 else {
229 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
230 }
231 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
232 if (strBinRangeAve) {
233 TString tmpstr = strBinRangeAve->GetString();
234 binRangeAve = tmpstr.Atoi();
235 }
236 else {
237 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
238 }
239 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
240 if (strIntegralThr) {
241 TString tmpstr = strIntegralThr->GetString();
242 integralThr = tmpstr.Atof();
243 }
244 else {
245 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
246 }
247 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
248 if (strThrPar) {
249 TString tmpstr = strThrPar->GetString();
250 thrPar = tmpstr.Atof();
251 }
252 else {
253 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
254 }
255 }
256 }
257 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
258 else fFDRFlag = kTRUE;
259
38fd83e4 260 fData->SetFDRFlag(fFDRFlag);
261
e88f3330 262 delete cdbEntry;
263 cdbEntry = 0x0;
264
17149e6b 265 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
266
267 fCal = new AliTOFChannelOnlineArray(fNChannels);
268
ee3e792b 269 TH1::AddDirectory(0);
270
271 Bool_t resultDAQRef=kFALSE;
7fffa85b 272 Bool_t resultTOFPP=kFALSE;
e88f3330 273 TH2S *h2 = 0x0;
c9fe8530 274 // processing DAQ
7885c291 275
c9fe8530 276 TFile * daqFile=0x0;
7885c291 277
5936ab02 278 if(fStoreRefData){
279 //retrieving data at Run level
17149e6b 280 TList* list = GetFileSources(kDAQ, "RUNLevel");
281 if (list !=0x0 && list->GetEntries()!=0)
282 {
283 AliInfo("The following sources produced files with the id RUNLevel");
284 list->Print();
285 for (Int_t jj=0;jj<list->GetEntries();jj++){
286 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
287 AliInfo(Form("found source %s", str->String().Data()));
288 // file to be stored run per run
289 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
290 if (fileNameRun.Length()>0){
291 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
292 daqFile = new TFile(fileNameRun.Data(),"READ");
e88f3330 293 h2 = (TH2S*) daqFile->Get("htof");
17149e6b 294 AliCDBMetaData metaDataHisto;
295 metaDataHisto.SetBeamPeriod(0);
296 metaDataHisto.SetResponsible("Chiara Zampolli");
297 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
298 AliInfo("Storing Reference Data");
e88f3330 299 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
17149e6b 300 if (!resultDAQRef){
301 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
e88f3330 302 delete h2;
303 delete list;
304 delete fCal;
305 fCal=0x0;
17149e6b 306 return 5;//return error code for failure in storing Ref Data
307 }
308 daqFile->Close();
309 delete daqFile;
310 }
311
312 else{
313 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
e88f3330 314 delete list;
315 delete fCal;
316 fCal=0x0;
17149e6b 317 return 4;//return error code for failure in retrieving Ref Data
318 }
319 }
320 delete list;
321 }
5936ab02 322 else{
17149e6b 323 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
e88f3330 324 delete fCal;
325 fCal=0x0;
17149e6b 326 return 4;//return error code for failure in retrieving Ref Data
327 }
9bc469d1 328 }
329
9bc469d1 330
17149e6b 331 //Total files, with cumulative histos
5936ab02 332
9bc469d1 333 TList* listTot = GetFileSources(kDAQ, "DELAYS");
bf76be9c 334 if (listTot !=0x0 && listTot->GetEntries()!=0)
17149e6b 335 {
336 AliInfo("The following sources produced files with the id DELAYS");
337 listTot->Print();
338 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
339 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
340 AliInfo(Form("found source %s", str->String().Data()));
341
342 // file with summed histos, to extract calib params
343 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
344 if (fileName.Length()>0){
345 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
346
347 daqFile = new TFile(fileName.Data(),"READ");
e88f3330 348 if (h2) delete h2;
349 h2 = (TH2S*) daqFile->Get("htoftot");
350 if (!h2){
17149e6b 351 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
e88f3330 352 delete listTot;
17149e6b 353 delete daqFile;
e88f3330 354 delete fCal;
355 fCal=0x0;
17149e6b 356 return 7; //return error code for histograms not existing/junky
357 }
358 else {
e88f3330 359 static const Int_t kSize=h2->GetNbinsX();
360 static const Int_t kNBins=h2->GetNbinsY();
361 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
17149e6b 362 if (kSize != fNChannels){
363 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
e88f3330 364 delete listTot;
365 delete h2;
17149e6b 366 delete daqFile;
e88f3330 367 delete fCal;
368 fCal=0x0;
17149e6b 369 return 7; //return error code for histograms not existing/junky
370 }
371 Int_t nNotStatistics = 0; // number of channel with not enough statistics
372 if (fFDRFlag) Log(" Not computing delays according to flag set in Config entry in OCDB!");
373
374 else { // computing delays if not in FDR runs
375 for (Int_t ich=0;ich<kSize;ich++){
376 /* check whether channel has been read out during current run.
377 * if the status is bad it means it has not been read out.
378 * in this case skip channel in order to not affect the mean */
379 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
380 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
381 continue;
382 }
383 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
384 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
385 for (Int_t ibin=0;ibin<kNBins;ibin++){
e88f3330 386 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
17149e6b 387 }
388 if(h1->Integral()<integralThr) {
389 nNotStatistics++;
390 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
391 delete h1;
392 h1=0x0;
393 continue;
394 }
395 Bool_t found=kFALSE;
396 Float_t minContent=h1->Integral()*thrPar;
397 Int_t nbinsX = h1->GetNbinsX();
398 Int_t startBin=1;
399 for (Int_t j=1; j<=nbinsX; j++){
400 if ((
401 h1->GetBinContent(j) +
402 h1->GetBinContent(j+1)+
403 h1->GetBinContent(j+2)+
404 h1->GetBinContent(j+3))>minContent){
405 found=kTRUE;
406 startBin=j;
407 break;
408 }
409 }
410 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
411 // Now calculate the mean over the interval.
412 Double_t mean = 0;
413 Double_t sumw2 = 0;
414 Double_t nent = 0;
415 for(Int_t k=0;k<binRangeAve;k++){
416 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
417 nent=nent+h1->GetBinContent(startBin+k);
418 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
419 }
420 mean= mean/nent; //<x>
421 sumw2=sumw2/nent; //<x^2>
422 Double_t rmsmean= 0;
423 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
424 if (ich<fNChannels) {
425 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
426 fCal->SetDelay(ich,delay); // delay in ns
427 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
428 }
429 delete h1;
430 h1=0x0;
431 }
432 }
433 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
434 }
e88f3330 435 delete h2;
17149e6b 436 daqFile->Close();
437 delete daqFile;
438 }
439 else{
440 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
e88f3330 441 delete listTot;
442 delete fCal;
443 fCal=0x0;
17149e6b 444 return 6;//return error code for problems in retrieving DAQ data
445 }
7fffa85b 446 }
17149e6b 447 delete listTot;
c9fe8530 448 }
c9fe8530 449 else{
9d883ed9 450 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
e88f3330 451 delete fCal;
452 fCal=0x0;
7885c291 453 return 6; //return error code for problems in retrieving DAQ data
c9fe8530 454 }
455
c9fe8530 456 daqFile=0;
7fffa85b 457 AliCDBMetaData metaData;
458 metaData.SetBeamPeriod(0);
459 metaData.SetResponsible("Chiara Zampolli");
17149e6b 460 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
7fffa85b 461 AliInfo("Storing Calibration Data");
17149e6b 462 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
7fffa85b 463 if(!resultTOFPP){
464 Log("Some problems occurred while storing online object resulting from DAQ data processing");
e88f3330 465 delete fCal;
466 fCal=0x0;
7fffa85b 467 return 8;//return error code for problems in storing DAQ data
468 }
9d883ed9 469
e88f3330 470 if (fCal){
471 delete fCal;
472 fCal = 0;
473 }
474
5936ab02 475 return 0;
c9fe8530 476}
ee3e792b 477//_____________________________________________________________________________
478
479UInt_t AliTOFPreprocessor::ProcessPulserData()
480{
7fffa85b 481 // Processing Pulser Run data for TOF channel status
482
483 Log("Processing Pulser");
ee3e792b 484
17149e6b 485 if (fStatus==0x0){
486 AliError("No valid fStatus found, some errors must have occurred!!");
487 return 20;
488 }
ee3e792b 489
17149e6b 490 TH1::AddDirectory(0);
491
ee3e792b 492 Bool_t resultPulserRef=kFALSE;
7fffa85b 493 Bool_t resultPulser=kFALSE;
17149e6b 494
a174d599 495 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
496 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
497 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 498 htofPulser->SetBinContent(ibin,-1);
7fffa85b 499 }
17149e6b 500
ee3e792b 501 // processing pulser
502
503 TFile * daqFile=0x0;
504 TH1S *h1=0x0;
505
506 //retrieving Pulser data
507 TList* listPulser = GetFileSources(kDAQ, "PULSER");
bf76be9c 508 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
e88f3330 509 {
510 AliInfo("The following sources produced files with the id PULSER");
511 listPulser->Print();
512 Int_t nPulser = 0;
513 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
514 Int_t nPulserSource = 0;
515 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
516 AliInfo(Form("found source %s", str->String().Data()));
517 // file to be stored run per run
518 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
519 if (fileNamePulser.Length()>0){
520 // storing refernce data
521 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
522 daqFile = new TFile(fileNamePulser.Data(),"READ");
523 h1 = (TH1S*) daqFile->Get("hTOFpulser");
524 for (Int_t ibin=0;ibin<kSize;ibin++){
525 if ((h1->GetBinContent(ibin+1))!=-1){
526 if ((htofPulser->GetBinContent(ibin+1))==-1){
527 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
528 }
529 else {
530 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
531 }
532 }
533 }
534
535 // elaborating infos
536 Double_t mean =0;
537 Int_t nread=0;
538 Int_t nreadNotEmpty=0;
539 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
540
541 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)));
542 /* check whether channel has been read out during current run.
543 * if the status is bad it means it has not been read out.
544 * in this case skip channel in order to not affect the mean */
545 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
546 continue;
547 nPulser++;
548 nPulserSource++;
549 if (h1->GetBinContent(ientry)==-1) continue;
550 else {
551 if (h1->GetBinContent(ientry)>0) {
552 nreadNotEmpty++;
553 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
554 }
555 mean+=h1->GetBinContent(ientry);
556 nread++;
557 }
558 }
559 if (nread!=0) {
560 mean/=nread;
561 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
562 for (Int_t ich =0;ich<fNChannels;ich++){
563 if (h1->GetBinContent(ich+1)==-1) continue;
564 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
565
566 /* check whether channel has been read out during current run.
567 * if the status is bad it means it has not been read out.
568 * in this case skip channel in order to leave its status
569 * unchanged */
570 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
571 continue;
572
573 if (h1->GetBinContent(ich+1)<0.05*mean){
574 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
575 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)));
576 }
577 else {
578 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
579 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)));
580 }
581 }
582 }
583 else {
584 Log("No channels read!! No action taken, keeping old status");
585 }
586
587 daqFile->Close();
588 delete daqFile;
589 delete h1;
17149e6b 590 }
1a1486e7 591
e88f3330 592 else{
593 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
594 delete listPulser;
595 delete htofPulser;
596 htofPulser = 0x0;
597 if (fStatus){
598 delete fStatus;
599 fStatus = 0;
600 }
601 return 10;//return error code for failure in retrieving Ref Data
1a1486e7 602 }
e88f3330 603 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1a1486e7 604 }
e88f3330 605 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
606 delete listPulser;
ee3e792b 607 }
7fffa85b 608
ee3e792b 609 else{
17149e6b 610 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
e88f3330 611 delete htofPulser;
612 htofPulser = 0x0;
613 if (fStatus){
614 delete fStatus;
615 fStatus = 0;
616 }
17149e6b 617 return 10;//return error code for failure in retrieving Ref Data
ee3e792b 618 }
17149e6b 619
7fffa85b 620 //storing in OCDB
17149e6b 621
7fffa85b 622 AliCDBMetaData metaData;
623 metaData.SetBeamPeriod(0);
624 metaData.SetResponsible("Chiara Zampolli");
17149e6b 625 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
7fffa85b 626 AliInfo("Storing Calibration Data from Pulser Run");
17149e6b 627 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 628 if(!resultPulser){
629 Log("Some problems occurred while storing online object resulting from Pulser data processing");
e88f3330 630 delete htofPulser;
631 htofPulser = 0x0;
632 if (fStatus){
633 delete fStatus;
634 fStatus = 0;
635 }
7fffa85b 636 return 11;//return error code for problems in storing Pulser data
637 }
638
ee3e792b 639 if(fStoreRefData){
640
641 AliCDBMetaData metaDataHisto;
642 metaDataHisto.SetBeamPeriod(0);
643 metaDataHisto.SetResponsible("Chiara Zampolli");
644 char comment[200];
17149e6b 645 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
ee3e792b 646 metaDataHisto.SetComment(comment);
647 AliInfo("Storing Reference Data");
db83b789 648 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
ee3e792b 649 if (!resultPulserRef){
7fffa85b 650 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
e88f3330 651 delete htofPulser;
652 htofPulser = 0x0;
653 if (fStatus){
654 delete fStatus;
655 fStatus = 0;
656 }
7fffa85b 657 return 9;//return error code for failure in storing Ref Data
ee3e792b 658 }
659 }
660
661 daqFile=0;
662
e88f3330 663 delete htofPulser;
664 htofPulser = 0x0;
665
666 if (fStatus){
667 delete fStatus;
668 fStatus = 0;
669 }
670
ee3e792b 671 return 0;
672}
673//_____________________________________________________________________________
674
675UInt_t AliTOFPreprocessor::ProcessNoiseData()
676{
7fffa85b 677
678 // Processing Noise Run data for TOF channel status
679
680 Log("Processing Noise");
ee3e792b 681
17149e6b 682 if (fStatus==0x0){
683 AliError("No valid fStatus found, some errors must have occurred!!");
684 return 20;
685 }
686
ee3e792b 687 TH1::AddDirectory(0);
688
689 Bool_t resultNoiseRef=kFALSE;
7fffa85b 690 Bool_t resultNoise=kFALSE;
ee3e792b 691
a174d599 692 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
17149e6b 693 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
a174d599 694 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 695 htofNoise->SetBinContent(ibin,-1);
ee3e792b 696 }
17149e6b 697
ee3e792b 698 // processing noise
699
700 TFile * daqFile=0x0;
701 TH1F * h1=0x0;
702
703 //retrieving Noise data
704 TList* listNoise = GetFileSources(kDAQ, "NOISE");
bf76be9c 705 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
e88f3330 706 {
707 AliInfo("The following sources produced files with the id NOISE");
708 listNoise->Print();
709 Int_t nNoise = 0;
710 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
711 Int_t nNoiseSource = 0;
712 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
713 AliInfo(Form("found source %s", str->String().Data()));
714 // file to be stored run per run
715 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
716 if (fileNameNoise.Length()>0){
717 // storing reference data
718 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
719 daqFile = new TFile(fileNameNoise.Data(),"READ");
720 h1 = (TH1F*) daqFile->Get("hTOFnoise");
721 for (Int_t ibin=0;ibin<kSize;ibin++){
722 if ((h1->GetBinContent(ibin+1))!=-1){
723 if ((htofNoise->GetBinContent(ibin+1))==-1){
724 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
725 }
726 else {
727 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
728 }
729 }
730 }
731 // elaborating infos
732 for (Int_t ich =0;ich<fNChannels;ich++){
733 if (h1->GetBinContent(ich+1)==-1) continue;
734 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)));
735 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
736
737 /* check whether channel has been read out during current run.
738 * if the status is bad it means it has not been read out.
739 * in this case skip channel in order to leave its status
740 * unchanged */
741 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
742 continue;
743
744 nNoise++;
745 nNoiseSource++;
746 if (h1->GetBinContent(ich+1)>=1){ // setting limit for noise to 1 kHz
747 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
748 AliDebug(2,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
749 }
750 else {
751 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
752 AliDebug(2,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
753 }
754 }
755
756 daqFile->Close();
757 delete daqFile;
758 delete h1;
759
760 }
761
762 else{
763 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
764 delete listNoise;
765 delete htofNoise;
766 htofNoise = 0x0;
767 if (fStatus){
768 delete fStatus;
769 fStatus = 0;
770 }
771 return 13;//return error code for failure in retrieving Ref Data
772 }
773
774 AliDebug(2,Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
775 }
776 AliDebug(2,Form(" Number of channels processed during noise run = %i",nNoise));
777 delete listNoise;
ee3e792b 778 }
e88f3330 779 else{
780 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
781 delete htofNoise;
782 htofNoise = 0x0;
783 if (fStatus){
784 delete fStatus;
785 fStatus = 0;
ee3e792b 786 }
7fffa85b 787 return 13;//return error code for failure in retrieving Ref Data
ee3e792b 788 }
789
790 daqFile=0;
e88f3330 791
7fffa85b 792 //storing in OCDB
e88f3330 793
7fffa85b 794 AliCDBMetaData metaData;
795 metaData.SetBeamPeriod(0);
796 metaData.SetResponsible("Chiara Zampolli");
17149e6b 797 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
7fffa85b 798 AliInfo("Storing Calibration Data from Noise Run");
17149e6b 799 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 800 if(!resultNoise){
801 Log("Some problems occurred while storing online object resulting from Noise data processing");
e88f3330 802 delete htofNoise;
803 htofNoise = 0x0;
804 if (fStatus){
805 delete fStatus;
806 fStatus = 0;
807 }
7fffa85b 808 return 14;//return error code for problems in storing Noise data
809 }
810
ee3e792b 811 if(fStoreRefData){
812
813 AliCDBMetaData metaDataHisto;
814 metaDataHisto.SetBeamPeriod(0);
815 metaDataHisto.SetResponsible("Chiara Zampolli");
816 char comment[200];
17149e6b 817 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
ee3e792b 818 metaDataHisto.SetComment(comment);
819 AliInfo("Storing Reference Data");
db83b789 820 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
ee3e792b 821 if (!resultNoiseRef){
822 Log("some problems occurred::No Reference Data for noise stored");
e88f3330 823 delete htofNoise;
824 htofNoise = 0x0;
825 if (fStatus){
826 delete fStatus;
827 fStatus = 0;
828 }
7fffa85b 829 return 12;//return error code for failure in storing Ref Data
ee3e792b 830 }
831 }
832
e88f3330 833 delete htofNoise;
834 htofNoise = 0x0;
835
836 if (fStatus){
837 delete fStatus;
838 fStatus = 0;
839 }
840
ee3e792b 841 return 0;
842}
843//_____________________________________________________________________________
844
db83b789 845UInt_t AliTOFPreprocessor::ProcessFEEData()
ee3e792b 846{
7fffa85b 847 // Processing Pulser Run data for TOF channel status
848 // dummy for the time being
ee3e792b 849
db83b789 850 Log("Processing FEE");
851
852 Bool_t updateOCDB = kFALSE;
853 AliTOFFEEReader feeReader;
17149e6b 854
db83b789 855 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
856
857 /* load current TOF FEE config from DCS FXS, parse,
858 * fill current FEE histogram and set FEE status */
859
860 const char * nameFile = GetFile(kDCS,"TofFeeMap","");
861 AliInfo(Form("nameFile = %s",nameFile));
862 if (nameFile == NULL) {
863 return 15;
864 }
865 feeReader.LoadFEEConfig(nameFile);
17149e6b 866 Int_t parseFee = feeReader.ParseFEEConfig();
867 AliDebug(2,Form("%i enabled channels found in FEE configuration",parseFee));
db83b789 868 /* load stored TOF FEE from OCDB and compare it with current FEE.
869 * if stored FEE is different from current FEE set update flag.
870 * if there is no stored FEE in OCDB set update flag */
871
17149e6b 872 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
873 if (!cdbEntry) {
874 /* no CDB entry found. set update flag */
875 Log(" ************ WARNING ************");
876 Log("No CDB Status entry found, creating a new one!");
877 Log(" *********************************");
878 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
879 updateOCDB = kTRUE;
db83b789 880 }
db83b789 881 else {
e88f3330 882 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
17149e6b 883 /* CDB entry OK. loop over channels */
884 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
e88f3330 885 delete cdbEntry;
886 cdbEntry = 0x0;
db83b789 887 }
17149e6b 888 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
889 //AliDebug(2,Form("********** channel %i",iChannel));
890 /* compare current FEE channel status with stored one
891 * if different set update flag and break loop */
892 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
893 if (feeReader.IsChannelEnabled(iChannel)) {
894 hCurrentFEE.SetBinContent(iChannel + 1, 1);
895 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
896 updateOCDB = kTRUE;
897 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
898 AliDebug(2,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
899 }
900 }
901 else {
902 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
903 updateOCDB = kTRUE;
904 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
905 AliDebug(2,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
906 }
907 }
908 }
909
db83b789 910
911 /* check whether we don't have to store reference data.
912 * in this case we return without errors. */
913 if (fStoreRefData) {
914 /* store reference data */
915 AliCDBMetaData metaDataHisto;
916 metaDataHisto.SetBeamPeriod(0);
917 metaDataHisto.SetResponsible("Roberto Preghenella");
17149e6b 918 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
db83b789 919 AliInfo("Storing FEE reference data");
920 /* store FEE reference data */
921 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
922 /* failed */
923 Log("problems while storing FEE reference data");
e88f3330 924 if (fStatus){
925 delete fStatus;
926 fStatus = 0;
927 }
db83b789 928 return 18; /* error return code for problems while storing FEE reference data */
929 }
930 }
931
932 /* check whether we don't need to update OCDB.
933 * in this case we can return without errors and
17149e6b 934 * the current FEE is stored in the fStatus object. */
db83b789 935 if (!updateOCDB) {
936 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
937 return 0; /* return ok */
938 }
939
17149e6b 940 TString runType = GetRunType();
941 if (runType != "PHYSICS") {
942 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
943 return 0; /* return ok */
944 }
945
db83b789 946 /* update the OCDB with the current FEE since even
947 * a little difference has been detected. */
948
949 AliCDBMetaData metaData;
950 metaData.SetBeamPeriod(0);
951 metaData.SetResponsible("Roberto Preghenella");
17149e6b 952 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
953 AliInfo("Storing Status data from current run after FEE parsing");
db83b789 954 /* store FEE data */
17149e6b 955 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
db83b789 956 /* failed */
957 Log("problems while storing FEE data object");
e88f3330 958 if (fStatus){
959 delete fStatus;
960 fStatus = 0;
961 }
db83b789 962 return 17; /* return error code for problems while storing FEE data */
963 }
964
965 /* everything fine. return */
ee3e792b 966
e88f3330 967 if (fStatus){
968 delete fStatus;
969 fStatus = 0;
970 }
971
7fffa85b 972 return 0;
973
974}
975
976//_____________________________________________________________________________
977
978UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
979{
a174d599 980 //
981 //
982 //
7fffa85b 983
984 TString runType = GetRunType();
985 Log(Form("RunType %s",runType.Data()));
bf76be9c 986
ee3e792b 987 // processing
988
db83b789 989 /* always process FEE data */
990 Int_t iresultFEE = ProcessFEEData();
991 if (iresultFEE != 0)
992 return iresultFEE;
993
7fffa85b 994 if (runType == "PULSER") {
995 Int_t iresultPulser = ProcessPulserData();
996 return iresultPulser;
997 }
17149e6b 998
7fffa85b 999 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1000 Int_t iresultNoise = ProcessNoiseData();
1001 return iresultNoise;
1002 }
1003
1004 if (runType == "PHYSICS") {
1005 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1006 if (iresultDCS != 0) {
1007 return iresultDCS;
1008 }
1009 else {
1010 Int_t iresultDAQ = ProcessOnlineDelays();
1011 return iresultDAQ;
1012 }
ee3e792b 1013 }
1014
7fffa85b 1015 // storing
ee3e792b 1016 return 0;
1017}
c9fe8530 1018
1019