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