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