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