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