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