]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFPreprocessor.cxx
Moving classes from graphics to rec
[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),
708db10b 80 fh2(0),
c9fe8530 81 fCal(0),
10056aa6 82 fNChannels(0),
7fffa85b 83 fStoreRefData(kTRUE),
17149e6b 84 fFDRFlag(kFALSE),
85 fStatus(0)
c9fe8530 86{
87 // constructor
370aeff7 88 AddRunType("PHYSICS");
89 AddRunType("PULSER");
90 AddRunType("NOISE");
10056aa6 91
c9fe8530 92}
93
94//_____________________________________________________________________________
95
96AliTOFPreprocessor::~AliTOFPreprocessor()
97{
98 // destructor
7981612d 99 if (fData){
100 delete fData;
101 fData = 0;
102 }
103 if (fh2){
104 delete fh2;
105 fh2 = 0;
106 }
107 if (fCal){
64f2148a 108 // fCal->Clear();
7981612d 109 delete fCal;
110 fCal = 0;
111 }
17149e6b 112 if (fStatus){
113 delete fStatus;
114 fStatus = 0;
db83b789 115 }
c9fe8530 116}
117
118//______________________________________________________________________________
119void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
120 UInt_t endTime)
121{
122 // Creates AliTOFDataDCS object
123
124 AliPreprocessor::Initialize(run, startTime, endTime);
125
126 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
127 TTimeStamp(startTime).AsString(),
128 TTimeStamp(endTime).AsString()));
129
130 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
7fffa85b 131 fData->SetFDRFlag(fFDRFlag);
708db10b 132 fh2 = 0x0;
10056aa6 133 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
c9fe8530 134}
7fffa85b 135//_____________________________________________________________________________
136Bool_t AliTOFPreprocessor::ProcessDCS(){
137
138 // check whether DCS should be processed or not...
c9fe8530 139
7fffa85b 140 TString runType = GetRunType();
141 Log(Form("RunType %s",runType.Data()));
142
55454922 143 if (runType != "PHYSICS"){
7fffa85b 144 return kFALSE;
145 }
146
147 return kTRUE;
148}
c9fe8530 149//_____________________________________________________________________________
150
ee3e792b 151UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
c9fe8530 152{
153 // Fills data into a AliTOFDataDCS object
154
7fffa85b 155
156 Log("Processing DCS DP");
708db10b 157 TH1::AddDirectory(0);
5936ab02 158
7885c291 159 Bool_t resultDCSMap=kFALSE;
160 Bool_t resultDCSStore=kFALSE;
c9fe8530 161
162 // processing DCS
163
164 if (!dcsAliasMap){
5936ab02 165 Log("No DCS map found: TOF exiting from Shuttle");
166 return 1;// return error Code for DCS input data not found
c9fe8530 167 }
168 else {
169 // The processing of the DCS input data is forwarded to AliTOFDataDCS
7885c291 170 resultDCSMap=fData->ProcessData(*dcsAliasMap);
171 if(!resultDCSMap){
172 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
5936ab02 173 return 2;// return error Code for processed DCS data not stored
c9fe8530 174 }
7885c291 175 else{
176 AliCDBMetaData metaDataDCS;
177 metaDataDCS.SetBeamPeriod(0);
178 metaDataDCS.SetResponsible("Chiara Zampolli");
179 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
180 AliInfo("Storing DCS Data");
b0d8f3fc 181 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
7885c291 182 if (!resultDCSStore){
b0d8f3fc 183 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
7885c291 184 return 3;// return error Code for processed DCS data not stored
b0d8f3fc 185 // in reference data
7885c291 186
187 }
188 }
c9fe8530 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
263 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
264
265 fCal = new AliTOFChannelOnlineArray(fNChannels);
266
ee3e792b 267 TH1::AddDirectory(0);
268
269 Bool_t resultDAQRef=kFALSE;
7fffa85b 270 Bool_t resultTOFPP=kFALSE;
c9fe8530 271 // processing DAQ
7885c291 272
c9fe8530 273 TFile * daqFile=0x0;
7885c291 274
5936ab02 275 if(fStoreRefData){
276 //retrieving data at Run level
17149e6b 277 TList* list = GetFileSources(kDAQ, "RUNLevel");
278 if (list !=0x0 && list->GetEntries()!=0)
279 {
280 AliInfo("The following sources produced files with the id RUNLevel");
281 list->Print();
282 for (Int_t jj=0;jj<list->GetEntries();jj++){
283 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
284 AliInfo(Form("found source %s", str->String().Data()));
285 // file to be stored run per run
286 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
287 if (fileNameRun.Length()>0){
288 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
289 daqFile = new TFile(fileNameRun.Data(),"READ");
290 fh2 = (TH2S*) daqFile->Get("htof");
291 AliCDBMetaData metaDataHisto;
292 metaDataHisto.SetBeamPeriod(0);
293 metaDataHisto.SetResponsible("Chiara Zampolli");
294 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
295 AliInfo("Storing Reference Data");
296 resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
297 if (!resultDAQRef){
298 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
299 return 5;//return error code for failure in storing Ref Data
300 }
301 daqFile->Close();
302 delete daqFile;
303 }
304
305 else{
306 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
307 return 4;//return error code for failure in retrieving Ref Data
308 }
309 }
310 delete list;
311 }
5936ab02 312 else{
17149e6b 313 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
314 return 4;//return error code for failure in retrieving Ref Data
315 }
9bc469d1 316 }
317
9bc469d1 318
17149e6b 319 //Total files, with cumulative histos
5936ab02 320
9bc469d1 321 TList* listTot = GetFileSources(kDAQ, "DELAYS");
bf76be9c 322 if (listTot !=0x0 && listTot->GetEntries()!=0)
17149e6b 323 {
324 AliInfo("The following sources produced files with the id DELAYS");
325 listTot->Print();
326 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
327 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
328 AliInfo(Form("found source %s", str->String().Data()));
329
330 // file with summed histos, to extract calib params
331 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
332 if (fileName.Length()>0){
333 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
334
335 daqFile = new TFile(fileName.Data(),"READ");
336 if (fh2) delete fh2;
337 fh2 = (TH2S*) daqFile->Get("htoftot");
338 if (!fh2){
339 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
340 delete daqFile;
341 return 7; //return error code for histograms not existing/junky
342 }
343 else {
344 static const Int_t kSize=fh2->GetNbinsX();
345 static const Int_t kNBins=fh2->GetNbinsY();
346 static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1);
347 if (kSize != fNChannels){
348 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
349 delete daqFile;
350 return 7; //return error code for histograms not existing/junky
351 }
352 Int_t nNotStatistics = 0; // number of channel with not enough statistics
353 if (fFDRFlag) Log(" Not computing delays according to flag set in Config entry in OCDB!");
354
355 else { // computing delays if not in FDR runs
356 for (Int_t ich=0;ich<kSize;ich++){
357 /* check whether channel has been read out during current run.
358 * if the status is bad it means it has not been read out.
359 * in this case skip channel in order to not affect the mean */
360 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
361 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
362 continue;
363 }
364 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
365 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
366 for (Int_t ibin=0;ibin<kNBins;ibin++){
367 h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1));
368 }
369 if(h1->Integral()<integralThr) {
370 nNotStatistics++;
371 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
372 delete h1;
373 h1=0x0;
374 continue;
375 }
376 Bool_t found=kFALSE;
377 Float_t minContent=h1->Integral()*thrPar;
378 Int_t nbinsX = h1->GetNbinsX();
379 Int_t startBin=1;
380 for (Int_t j=1; j<=nbinsX; j++){
381 if ((
382 h1->GetBinContent(j) +
383 h1->GetBinContent(j+1)+
384 h1->GetBinContent(j+2)+
385 h1->GetBinContent(j+3))>minContent){
386 found=kTRUE;
387 startBin=j;
388 break;
389 }
390 }
391 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
392 // Now calculate the mean over the interval.
393 Double_t mean = 0;
394 Double_t sumw2 = 0;
395 Double_t nent = 0;
396 for(Int_t k=0;k<binRangeAve;k++){
397 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
398 nent=nent+h1->GetBinContent(startBin+k);
399 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
400 }
401 mean= mean/nent; //<x>
402 sumw2=sumw2/nent; //<x^2>
403 Double_t rmsmean= 0;
404 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
405 if (ich<fNChannels) {
406 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
407 fCal->SetDelay(ich,delay); // delay in ns
408 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
409 }
410 delete h1;
411 h1=0x0;
412 }
413 }
414 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
415 }
416 daqFile->Close();
417 delete daqFile;
418 }
419 else{
420 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
421 return 6;//return error code for problems in retrieving DAQ data
422 }
7fffa85b 423 }
17149e6b 424 delete listTot;
c9fe8530 425 }
c9fe8530 426 else{
9d883ed9 427 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
7885c291 428 return 6; //return error code for problems in retrieving DAQ data
c9fe8530 429 }
430
c9fe8530 431 daqFile=0;
7fffa85b 432 AliCDBMetaData metaData;
433 metaData.SetBeamPeriod(0);
434 metaData.SetResponsible("Chiara Zampolli");
17149e6b 435 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
7fffa85b 436 AliInfo("Storing Calibration Data");
17149e6b 437 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
7fffa85b 438 if(!resultTOFPP){
439 Log("Some problems occurred while storing online object resulting from DAQ data processing");
440 return 8;//return error code for problems in storing DAQ data
441 }
9d883ed9 442
5936ab02 443 return 0;
c9fe8530 444}
ee3e792b 445//_____________________________________________________________________________
446
447UInt_t AliTOFPreprocessor::ProcessPulserData()
448{
7fffa85b 449 // Processing Pulser Run data for TOF channel status
450
451 Log("Processing Pulser");
ee3e792b 452
17149e6b 453 if (fStatus==0x0){
454 AliError("No valid fStatus found, some errors must have occurred!!");
455 return 20;
456 }
ee3e792b 457
17149e6b 458 TH1::AddDirectory(0);
459
ee3e792b 460 Bool_t resultPulserRef=kFALSE;
7fffa85b 461 Bool_t resultPulser=kFALSE;
17149e6b 462
a174d599 463 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
464 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
465 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 466 htofPulser->SetBinContent(ibin,-1);
7fffa85b 467 }
17149e6b 468
ee3e792b 469 // processing pulser
470
471 TFile * daqFile=0x0;
472 TH1S *h1=0x0;
473
474 //retrieving Pulser data
475 TList* listPulser = GetFileSources(kDAQ, "PULSER");
bf76be9c 476 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
ee3e792b 477 {
478 AliInfo("The following sources produced files with the id PULSER");
479 listPulser->Print();
17149e6b 480 Int_t nPulser = 0;
ee3e792b 481 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
17149e6b 482 Int_t nPulserSource = 0;
ee3e792b 483 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
484 AliInfo(Form("found source %s", str->String().Data()));
485 // file to be stored run per run
486 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
487 if (fileNamePulser.Length()>0){
488 // storing refernce data
1a1486e7 489 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
ee3e792b 490 daqFile = new TFile(fileNamePulser.Data(),"READ");
491 h1 = (TH1S*) daqFile->Get("hTOFpulser");
a174d599 492 for (Int_t ibin=0;ibin<kSize;ibin++){
ee3e792b 493 if ((h1->GetBinContent(ibin+1))!=-1){
494 if ((htofPulser->GetBinContent(ibin+1))==-1){
495 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
496 }
497 else {
498 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
499 }
500 }
501 }
1a1486e7 502
ee3e792b 503 // elaborating infos
504 Double_t mean =0;
505 Int_t nread=0;
506 Int_t nreadNotEmpty=0;
507 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
db83b789 508
17149e6b 509 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)));
db83b789 510 /* check whether channel has been read out during current run.
511 * if the status is bad it means it has not been read out.
512 * in this case skip channel in order to not affect the mean */
17149e6b 513 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
514 continue;
515 nPulser++;
516 nPulserSource++;
517 if (h1->GetBinContent(ientry)==-1) continue;
518 else {
519 if (h1->GetBinContent(ientry)>0) {
520 nreadNotEmpty++;
521 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
522 }
523 mean+=h1->GetBinContent(ientry);
524 nread++;
525 }
ee3e792b 526 }
1a1486e7 527 if (nread!=0) {
528 mean/=nread;
17149e6b 529 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
1a1486e7 530 for (Int_t ich =0;ich<fNChannels;ich++){
1a1486e7 531 if (h1->GetBinContent(ich+1)==-1) continue;
17149e6b 532 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
1a1486e7 533
534 /* check whether channel has been read out during current run.
535 * if the status is bad it means it has not been read out.
536 * in this case skip channel in order to leave its status
537 * unchanged */
17149e6b 538 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
539 continue;
1a1486e7 540
541 if (h1->GetBinContent(ich+1)<0.05*mean){
17149e6b 542 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
543 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)));
1a1486e7 544 }
545 else {
17149e6b 546 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
547 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)));
1a1486e7 548 }
549 }
ee3e792b 550 }
1a1486e7 551 else {
552 Log("No channels read!! No action taken, keeping old status");
553 }
17149e6b 554
ee3e792b 555 daqFile->Close();
556 delete daqFile;
557 delete h1;
558 }
559
560 else{
17149e6b 561 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
562 return 10;//return error code for failure in retrieving Ref Data
ee3e792b 563 }
17149e6b 564 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
ee3e792b 565
566 }
17149e6b 567 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
ee3e792b 568 delete listPulser;
569 }
7fffa85b 570
ee3e792b 571 else{
17149e6b 572 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
573 return 10;//return error code for failure in retrieving Ref Data
ee3e792b 574 }
17149e6b 575
7fffa85b 576 //storing in OCDB
17149e6b 577
7fffa85b 578 AliCDBMetaData metaData;
579 metaData.SetBeamPeriod(0);
580 metaData.SetResponsible("Chiara Zampolli");
17149e6b 581 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
7fffa85b 582 AliInfo("Storing Calibration Data from Pulser Run");
17149e6b 583 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 584 if(!resultPulser){
585 Log("Some problems occurred while storing online object resulting from Pulser data processing");
586 return 11;//return error code for problems in storing Pulser data
587 }
588
ee3e792b 589 if(fStoreRefData){
590
591 AliCDBMetaData metaDataHisto;
592 metaDataHisto.SetBeamPeriod(0);
593 metaDataHisto.SetResponsible("Chiara Zampolli");
594 char comment[200];
17149e6b 595 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
ee3e792b 596 metaDataHisto.SetComment(comment);
597 AliInfo("Storing Reference Data");
db83b789 598 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
ee3e792b 599 if (!resultPulserRef){
7fffa85b 600 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
601 return 9;//return error code for failure in storing Ref Data
ee3e792b 602 }
603 }
604
605 daqFile=0;
606
607 return 0;
608}
609//_____________________________________________________________________________
610
611UInt_t AliTOFPreprocessor::ProcessNoiseData()
612{
7fffa85b 613
614 // Processing Noise Run data for TOF channel status
615
616 Log("Processing Noise");
ee3e792b 617
17149e6b 618 if (fStatus==0x0){
619 AliError("No valid fStatus found, some errors must have occurred!!");
620 return 20;
621 }
622
ee3e792b 623 TH1::AddDirectory(0);
624
625 Bool_t resultNoiseRef=kFALSE;
7fffa85b 626 Bool_t resultNoise=kFALSE;
ee3e792b 627
a174d599 628 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
17149e6b 629 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
a174d599 630 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 631 htofNoise->SetBinContent(ibin,-1);
ee3e792b 632 }
17149e6b 633
ee3e792b 634 // processing noise
635
636 TFile * daqFile=0x0;
637 TH1F * h1=0x0;
638
639 //retrieving Noise data
640 TList* listNoise = GetFileSources(kDAQ, "NOISE");
bf76be9c 641 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
ee3e792b 642 {
643 AliInfo("The following sources produced files with the id NOISE");
644 listNoise->Print();
17149e6b 645 Int_t nNoise = 0;
ee3e792b 646 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
17149e6b 647 Int_t nNoiseSource = 0;
ee3e792b 648 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
649 AliInfo(Form("found source %s", str->String().Data()));
650 // file to be stored run per run
651 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
652 if (fileNameNoise.Length()>0){
17149e6b 653 // storing reference data
1a1486e7 654 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
ee3e792b 655 daqFile = new TFile(fileNameNoise.Data(),"READ");
656 h1 = (TH1F*) daqFile->Get("hTOFnoise");
a174d599 657 for (Int_t ibin=0;ibin<kSize;ibin++){
ee3e792b 658 if ((h1->GetBinContent(ibin+1))!=-1){
659 if ((htofNoise->GetBinContent(ibin+1))==-1){
660 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
661 }
662 else {
663 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
664 }
665 }
666 }
667 // elaborating infos
668 for (Int_t ich =0;ich<fNChannels;ich++){
ee3e792b 669 if (h1->GetBinContent(ich+1)==-1) continue;
17149e6b 670 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)));
671 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
db83b789 672
673 /* check whether channel has been read out during current run.
674 * if the status is bad it means it has not been read out.
675 * in this case skip channel in order to leave its status
676 * unchanged */
17149e6b 677 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
db83b789 678 continue;
679
17149e6b 680 nNoise++;
681 nNoiseSource++;
ee3e792b 682 if (h1->GetBinContent(ich+1)>=1){ // setting limit for noise to 1 kHz
17149e6b 683 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
684 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)));
ee3e792b 685 }
686 else {
17149e6b 687 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
688 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)));
ee3e792b 689 }
690 }
691
692 daqFile->Close();
693 delete daqFile;
7fffa85b 694 delete h1;
695
ee3e792b 696 }
697
698 else{
7fffa85b 699 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
700 return 13;//return error code for failure in retrieving Ref Data
ee3e792b 701 }
702
17149e6b 703 AliDebug(2,Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
ee3e792b 704 }
17149e6b 705 AliDebug(2,Form(" Number of channels processed during noise run = %i",nNoise));
ee3e792b 706 delete listNoise;
707 }
708 else{
7fffa85b 709 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
710 return 13;//return error code for failure in retrieving Ref Data
ee3e792b 711 }
712
713 daqFile=0;
714
7fffa85b 715 //storing in OCDB
716
717 AliCDBMetaData metaData;
718 metaData.SetBeamPeriod(0);
719 metaData.SetResponsible("Chiara Zampolli");
17149e6b 720 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
7fffa85b 721 AliInfo("Storing Calibration Data from Noise Run");
17149e6b 722 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 723 if(!resultNoise){
724 Log("Some problems occurred while storing online object resulting from Noise data processing");
725 return 14;//return error code for problems in storing Noise data
726 }
727
ee3e792b 728 if(fStoreRefData){
729
730 AliCDBMetaData metaDataHisto;
731 metaDataHisto.SetBeamPeriod(0);
732 metaDataHisto.SetResponsible("Chiara Zampolli");
733 char comment[200];
17149e6b 734 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
ee3e792b 735 metaDataHisto.SetComment(comment);
736 AliInfo("Storing Reference Data");
db83b789 737 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
ee3e792b 738 if (!resultNoiseRef){
739 Log("some problems occurred::No Reference Data for noise stored");
7fffa85b 740 return 12;//return error code for failure in storing Ref Data
ee3e792b 741 }
742 }
743
744 return 0;
745}
746//_____________________________________________________________________________
747
db83b789 748UInt_t AliTOFPreprocessor::ProcessFEEData()
ee3e792b 749{
7fffa85b 750 // Processing Pulser Run data for TOF channel status
751 // dummy for the time being
ee3e792b 752
db83b789 753 Log("Processing FEE");
754
755 Bool_t updateOCDB = kFALSE;
756 AliTOFFEEReader feeReader;
17149e6b 757
db83b789 758 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
759
760 /* load current TOF FEE config from DCS FXS, parse,
761 * fill current FEE histogram and set FEE status */
762
763 const char * nameFile = GetFile(kDCS,"TofFeeMap","");
764 AliInfo(Form("nameFile = %s",nameFile));
765 if (nameFile == NULL) {
766 return 15;
767 }
768 feeReader.LoadFEEConfig(nameFile);
17149e6b 769 Int_t parseFee = feeReader.ParseFEEConfig();
770 AliDebug(2,Form("%i enabled channels found in FEE configuration",parseFee));
db83b789 771 /* load stored TOF FEE from OCDB and compare it with current FEE.
772 * if stored FEE is different from current FEE set update flag.
773 * if there is no stored FEE in OCDB set update flag */
774
17149e6b 775 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
776 if (!cdbEntry) {
777 /* no CDB entry found. set update flag */
778 Log(" ************ WARNING ************");
779 Log("No CDB Status entry found, creating a new one!");
780 Log(" *********************************");
781 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
782 updateOCDB = kTRUE;
db83b789 783 }
db83b789 784 else {
17149e6b 785 /* CDB entry OK. loop over channels */
786 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
db83b789 787 }
17149e6b 788 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
789 //AliDebug(2,Form("********** channel %i",iChannel));
790 /* compare current FEE channel status with stored one
791 * if different set update flag and break loop */
792 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
793 if (feeReader.IsChannelEnabled(iChannel)) {
794 hCurrentFEE.SetBinContent(iChannel + 1, 1);
795 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
796 updateOCDB = kTRUE;
797 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
798 AliDebug(2,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
799 }
800 }
801 else {
802 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
803 updateOCDB = kTRUE;
804 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
805 AliDebug(2,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
806 }
807 }
808 }
809
db83b789 810
811 /* check whether we don't have to store reference data.
812 * in this case we return without errors. */
813 if (fStoreRefData) {
814 /* store reference data */
815 AliCDBMetaData metaDataHisto;
816 metaDataHisto.SetBeamPeriod(0);
817 metaDataHisto.SetResponsible("Roberto Preghenella");
17149e6b 818 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
db83b789 819 AliInfo("Storing FEE reference data");
820 /* store FEE reference data */
821 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
822 /* failed */
823 Log("problems while storing FEE reference data");
824 return 18; /* error return code for problems while storing FEE reference data */
825 }
826 }
827
828 /* check whether we don't need to update OCDB.
829 * in this case we can return without errors and
17149e6b 830 * the current FEE is stored in the fStatus object. */
db83b789 831 if (!updateOCDB) {
832 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
833 return 0; /* return ok */
834 }
835
17149e6b 836 TString runType = GetRunType();
837 if (runType != "PHYSICS") {
838 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
839 return 0; /* return ok */
840 }
841
db83b789 842 /* update the OCDB with the current FEE since even
843 * a little difference has been detected. */
844
845 AliCDBMetaData metaData;
846 metaData.SetBeamPeriod(0);
847 metaData.SetResponsible("Roberto Preghenella");
17149e6b 848 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
849 AliInfo("Storing Status data from current run after FEE parsing");
db83b789 850 /* store FEE data */
17149e6b 851 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
db83b789 852 /* failed */
853 Log("problems while storing FEE data object");
854 return 17; /* return error code for problems while storing FEE data */
855 }
856
857 /* everything fine. return */
ee3e792b 858
7fffa85b 859 return 0;
860
861}
862
863//_____________________________________________________________________________
864
865UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
866{
a174d599 867 //
868 //
869 //
7fffa85b 870
871 TString runType = GetRunType();
872 Log(Form("RunType %s",runType.Data()));
bf76be9c 873
ee3e792b 874 // processing
875
db83b789 876 /* always process FEE data */
877 Int_t iresultFEE = ProcessFEEData();
878 if (iresultFEE != 0)
879 return iresultFEE;
880
7fffa85b 881 if (runType == "PULSER") {
882 Int_t iresultPulser = ProcessPulserData();
883 return iresultPulser;
884 }
17149e6b 885
7fffa85b 886 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
887 Int_t iresultNoise = ProcessNoiseData();
888 return iresultNoise;
889 }
890
891 if (runType == "PHYSICS") {
892 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
893 if (iresultDCS != 0) {
894 return iresultDCS;
895 }
896 else {
897 Int_t iresultDAQ = ProcessOnlineDelays();
898 return iresultDAQ;
899 }
ee3e792b 900 }
901
7fffa85b 902 // storing
ee3e792b 903 return 0;
904}
c9fe8530 905
906