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