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