2 Contact: Jean-Luc Charvet <jean-luc.charvet@cern.ch>
3 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mchda.html
4 Reference Run: 109302 (station 3 only)
7 Number of events needed: 400 events for pedestal run
8 Input Files: mutrkpedvalues and config_ldc-MTRK-S3-0 in path : /afs/cern.ch/user/j/jcharvet/public/DA_validation
9 Output Files: local dir (not persistent) -> MUONTRKPEDda.ped FXS -> run<#>_MCH_<ldc>_PEDESTALS
13 /**************************************************************************
14 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
16 * Author: The ALICE Off-line Project. *
17 * Contributors are mentioned in the code where appropriate. *
19 * Permission to use, copy, modify and distribute this software and its *
20 * documentation strictly for non-commercial purposes is hereby granted *
21 * without fee, provided that the above copyright notice appears in all *
22 * copies and that both the copyright notice and this permission notice *
23 * appear in the supporting documentation. The authors make no claims *
24 * about the suitability of this software for any purpose. It is *
25 * provided "as is" without express or implied warranty. *
26 **************************************************************************/
31 -------------------------------------------------------------------------
32 2012-02-16 New version: MUONTRKPEDda.cxx,v 1.8
33 -------------------------------------------------------------------------
35 Version for MUONTRKPEDda MUON tracking
36 (A. Baldisseri, J.-L. Charvet)
39 Rem: AliMUON2DMap stores all channels, even those which are not connected
40 if pedMean == -1, channel not connected to a pad
52 #include <Riostream.h>
59 #include "AliMUONRawStreamTrackerHP.h"
60 #include "AliRawReader.h"
61 #include "AliMUONVStore.h"
62 #include "AliMUON2DMap.h"
63 #include "AliMUONCalibParamND.h"
64 #include "AliMpIntPair.h"
65 #include "AliMpConstants.h"
66 #include "AliRawDataErrorLog.h"
67 #include "AliMUONTrackerIO.h"
69 #include "AliMUONDspHeader.h"
78 #include "TStopwatch.h"
80 #include "TTimeStamp.h"
81 #include "TGraphErrors.h"
84 #include "TPluginManager.h"
86 #include "TObjString.h"
87 #include "THashTable.h"
88 #include <THashList.h>
96 #include "AliMUONPedestal.h"
97 #include "AliMUONErrorCounter.h"
101 int main(Int_t argc, const char **argv)
103 Int_t status=0, status1=0;
107 // Needed for streamer application
108 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
113 // needed for Minuit plugin
114 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
118 "TMinuitMinimizer(const char*)");
121 Int_t skipEvents = 0;
122 Int_t maxEvents = 1000000;
123 Int_t maxDateEvents = 1000000;
124 Int_t errorDetail = 1;
125 Int_t checkTokenlost = 0;
129 Int_t nDateEvents = 0;
130 Int_t nDateRejEvents = 0;
131 Int_t nGlitchErrors= 0;
132 Int_t nParityErrors= 0;
133 Int_t nPaddingErrors= 0;
134 Int_t nTokenlostErrors= 0;
135 Int_t recoverParityErrors = 1;
137 TString logOutputFile;
139 Char_t flatFile[256]="";
143 Int_t nEventsRecovered = 0;
145 UInt_t runNumber = 0;
147 Int_t nEvthreshold = 100; //below this nb_evt pedestal are not calculated and forced to 4085 (sigma)
148 Int_t nSorting = 1 ; // pedestal sorting (ON by default)
149 Int_t statusDA = 0 ; // DA return code
152 // decode the input line
153 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
155 const char* arg = argv[i];
160 // If only one argument and no "-" => DA calling from ECS
178 shuttleFile = argv[i];
182 skipEvents=atoi(argv[i]);
186 sscanf(argv[i],"%d",&maxDateEvents);
190 sscanf(argv[i],"%d",&maxEvents);
194 sscanf(argv[i],"%d",&errorDetail);
198 sscanf(argv[i],"%d",&checkTokenlost);
202 printf("\n******************* %s usage **********************",argv[0]);
203 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
204 printf("\n%s can be used locally only with options (without DiMuon configuration file: nConfig=%d)",argv[0],nConfig);
205 printf("\n%s -options, the available options are :",argv[0]);
206 printf("\n-h help (this screen)");
209 printf("\n-f <raw data file> (default = %s)",inputFile.Data());
212 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
214 printf("\n Options");
215 printf("\n-m <max date events> (default = %d)",maxDateEvents);
216 printf("\n-s <skip events> (default = %d)",skipEvents);
217 printf("\n-n <max events> (default = %d)",maxEvents);
218 printf("\n-v <error detail> (default = %d : 0=low 1=medium 2=high)",errorDetail);
219 printf("\n-t <token lost check> (default = %d : 0=no , 1=yes)",checkTokenlost);
224 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
225 argc = 2; exit(-1); // exit if error
233 const char* prefixDA = "MUONTRKPEDda"; // program prefix
234 const char* prefixLDC = getenv("DATE_ROLE_NAME"); // LDC name
235 if(prefixLDC == NULL) prefixLDC ="MCH" ;
236 printf("%s : -------- Begin execution : %s -------- \n",prefixLDC,prefixDA);
239 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
240 muonPedestal->SetprefixDA(prefixDA);
241 muonPedestal->SetprefixLDC(prefixLDC);
242 muonPedestal->SetStatusDA(statusDA);
244 // Output log file initialisations
245 sprintf(flatFile,"%s.log",prefixDA);
246 logOutputFile=flatFile;
247 AliLog::SetStreamOutput(&filcout); // Print details on logfile
248 filcout.open(logOutputFile.Data());
249 filcout<<"//=================================================" << endl;
250 filcout<<"//" << prefixLDC << " " << prefixDA << endl;
251 filcout<<"//=================================================" << endl;
252 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
254 muonPedestal->SetAlifilcout(&filcout);
255 cout<<prefixLDC << " : Date: " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
258 Char_t dbfile[256]="";
259 // nConfig=1 : Reading configuration (or not) status via "mutrkpedvalues" file located in DetDB
262 Int_t flag_hist, nEvthres,maxEvts;
264 sprintf(dbfile,"mutrkpedvalues");
265 status=daqDA_DB_getFile(dbfile,dbfile);
266 if(status) {printf(" !!! Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; }
267 ifstream filein(dbfile,ios::in);
268 filein >> line >> nConfig ; cout << "mutrkpedvalues: " << line << nConfig << " " ;
269 filein >> line >> nEvthres ; if(nEvthres !=0)nEvthreshold=nEvthres; cout << line << nEvthreshold << " " ;
270 filein >> line >> checkTokenlost ; cout << line << checkTokenlost << " " ;
271 filein >> line >> flag_histo ; if(flag_histo !=0) cout << line << flag_histo << " " ;
272 filein >> line >> maxEvts ; if(maxEvts!=0){maxEvents=maxEvts; cout << line << maxEvents;}
273 // filein >> line >> errorDetail ; cout << line << errorDetail << " " ;
274 // filein >> line >> nSorting ; cout << line << nSorting << " " ;
277 if(!nConfig) printf("%s : *** Config= %d: no configuration ascii file is used \n",prefixLDC,nConfig);
278 muonPedestal->SetconfigDA(nConfig);
279 muonPedestal->SetnEvthreshold(nEvthreshold);
280 muonPedestal->SetnSorting(nSorting);
282 // nConfig=1: configuration ascii file config_$DATE_ROLE_NAME read from DetDB
285 sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME"));
286 status=daqDA_DB_getFile(dbfile,dbfile);
287 if(status) {printf(" !!! Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; }
288 muonPedestal->LoadConfig(dbfile);
291 // Rawdeader, RawStreamHP
292 AliRawReader* rawReader = AliRawReader::Create(inputFile);
293 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
294 // rawStream->DisableWarnings();
295 rawStream->EnabbleErrorLogger();
299 case 0: rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kLowErrorDetail); break;/// Logs minimal information in the error messages.
300 case 1: rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail); break;/// Logs a medium level of detail in the error messages.
301 case 2: rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kHighErrorDetail); break;/// Logs a medium level of detail in the error messages.
302 default: rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail); break;
305 printf("\n%s : Reading data from file %s\n",prefixLDC,inputFile.Data());
307 Int_t tabTokenError[20][14];
308 for ( Int_t i=0 ; i<20 ; i++) { for ( Int_t j=0 ; j<14 ; j++) { tabTokenError[i][j]=0;} }
310 while (rawReader->NextEvent())
312 Int_t eventType = rawReader->GetType();
313 runNumber = rawReader->GetRunNumber();
314 if(nDateEvents==0) { filcout<<"// ----> RUN = " << runNumber << "\n" << endl;}
315 if (nDateEvents >= maxDateEvents) break;
316 if (nEvents >= maxEvents) break;
317 if (nDateEvents>0 && nDateEvents % 100 == 0)
318 cout<< prefixLDC << " : DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
320 // check shutdown condition
321 if (daqDA_checkShutdown()) break;
325 rawReader->NextEvent();
329 if (eventType != PHYSICS_EVENT)
330 continue; // for the moment
332 // const char* detail = "";
333 // First lopp over DDL's to find good events
334 // Error counters per event (counters in the decoding lib are for each DDL)
335 Bool_t eventIsErrorMessage = kFALSE;
336 int eventGlitchErrors = 0;
337 int eventParityErrors = 0;
338 int eventPaddingErrors = 0;
339 int eventTokenlostErrors = 0;
343 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
344 eventGlitchErrors += rawStream->GetGlitchErrors();
345 eventParityErrors += rawStream->GetParityErrors();
346 eventPaddingErrors += rawStream->GetPaddingErrors();
347 eventTokenlostErrors += rawStream->GetTokenLostErrors();
348 // cout << nDateEvents << " " << rawStream->GetDDL() << " " << eventTokenlostErrors << endl;
349 if (rawStream->GetTokenLostErrors())
352 const AliMUONRawStreamTrackerHP::AliBlockHeader* blkHeader = 0x0;
353 const AliMUONRawStreamTrackerHP::AliDspHeader* dspHeader = 0x0;
354 Int_t nBlock = rawStream->GetBlockCount();
355 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++)
357 blkHeader = rawStream->GetBlockHeader(iBlock);
358 // printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
359 Int_t nDsp = rawStream->GetDspCount(iBlock);
360 // printf("Block %d DSP %d\n",iBlock,nDsp);
361 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++)
363 dspHeader = blkHeader->GetDspHeader(iDsp);
364 // printf("Dsp %d Add %X\n",iDsp,dspHeader);
365 if (dspHeader->GetErrorWord())
367 Int_t ddl = rawStream->GetDDL() ;
368 // Int_t ddl = AliDAQ::DdlID("MUONTRK", rawStream->GetDDL()) - 2560 ; // format 2560 + ddl
369 Int_t frt = (dspHeader->GetErrorWord() & 0xFFFF0000) >> 16 ; // 4*4bits right shift
370 tabTokenError[ddl][frt]++;
371 // printf(" DDL %d error word %X %d %d\n",ddl,dspHeader->GetErrorWord(),frt,tabTokenError[8][4]);
377 } while(rawStream->NextDDL());
379 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
380 if (!eventIsErrorMessage)
382 // Good events (no error) -> compute pedestal for all channels
385 muonPedestal->SetAliNCurrentEvents(nEvents);
386 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
388 for(int i = 0; i < busPatch->GetLength(); ++i)
390 busPatch->GetData(i, manuId, channelId, charge);
391 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
397 // Events with errors
398 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors && !eventPaddingErrors && !(eventTokenlostErrors && checkTokenlost))
400 filcout << " ----------- Date Event recovered = " << nDateEvents << " ----------------" << endl;
401 // Recover parity errors -> compute pedestal for all good buspatches
402 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
405 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
406 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
407 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
411 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
412 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
413 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
417 muonPedestal->SetAliNCurrentEvents(nEvents);
418 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
420 // Check the buspatch -> if error not use it in the pedestal calculation
422 for(int i = 0; i < busPatch->GetLength(); ++i)
424 if (!busPatch->IsParityOk(i)) errorCount++;
429 for(int i = 0; i < busPatch->GetLength(); ++i)
431 busPatch->GetData(i, manuId, channelId, charge);
432 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
437 AliMUONErrorCounter* errorCounter;
438 // Bad buspatch -> not used (just print)
439 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
440 <<" parity errors "<<errorCount<<endl;
441 // Number of events where this buspatch is missing
442 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(busPatch->GetBusPatchId()))))
445 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
446 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
451 errorCounter->Increment();
453 // errorCounter->Print();
454 } // end of if (!errorCount)
455 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
458 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
461 // Fatal errors reject the event
462 detail = Form(" ----------- Date Event rejected = %d ----------------",nDateEvents);
464 filcout << detail << endl;
465 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
468 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
469 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
470 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
474 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
475 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
476 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
479 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
480 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
481 <<" Parity "<<eventParityErrors
482 <<" Padding "<<eventPaddingErrors
483 <<" Token lost "<<eventTokenlostErrors<<endl;
485 } // end of if (!rawStream->IsErrorMessage())
487 if (eventGlitchErrors) nGlitchErrors++;
488 if (eventParityErrors) nParityErrors++;
489 if (eventPaddingErrors) nPaddingErrors++;
491 } // while (rawReader->NextEvent())
495 sprintf(flatFile,"%s.ped",prefixDA);
496 if(shuttleFile.IsNull())shuttleFile=flatFile;
497 muonPedestal->SetAliNEvents(nEvents);
498 muonPedestal->SetAliRunNumber(runNumber);
500 muonPedestal->Finalize();
501 status = muonPedestal->GetStatusDA() ;
503 // writing some counters
504 detail=Form("\n%s : Nb of DATE events = %d",prefixLDC,nDateEvents) ; cout << detail; filcout << detail ;
505 detail=Form("\n%s : Nb of Glitch errors = %d",prefixLDC,nGlitchErrors) ; cout << detail; filcout << detail ;
506 detail=Form("\n%s : Nb of Parity errors = %d",prefixLDC,nParityErrors) ; cout << detail; filcout << detail ;
507 detail=Form("\n%s : Nb of Token lost errors = %d",prefixLDC,nTokenlostErrors) ; cout << detail; filcout << detail ;
508 detail=Form("\n%s : Nb of Rejected DATE events = %d",prefixLDC,nDateRejEvents) ; cout << detail; filcout << detail ;
509 detail=Form("\n%s : Nb of recovered events = %d",prefixLDC,nEventsRecovered) ; cout << detail; filcout << detail ;
510 detail=Form("\n%s : Nb of events without errors = %d",prefixLDC,nEvents-nEventsRecovered) ; cout << detail; filcout << detail ;
511 detail=Form("\n%s : Nb of used events = %d (threshold= %d)\n\n",prefixLDC,nEvents,nEvthreshold); cout << detail; filcout << detail ;
513 // Writing Token Error table
516 detail=Form("%s : Warning: Token Lost occurence \n",prefixLDC);
519 for ( Int_t i=0 ; i<20 ; i++)
521 for ( Int_t j=4 ; j<14 ; j++)
523 if(tabTokenError[i][j]>0)
525 Int_t tab=tabTokenError[i][j];
527 Int_t station = i/4 +1;
528 if( j % 2 == 0)detail=Form("%s : in DDL= %d (station %d) and FRT%d ( Up ) => %d Token errors (address = 0x%X0000)",prefixLDC,2560+i,station,frt,tab,j);
529 else detail=Form("%s : in DDL= %d (station %d) and FRT%d (Down) => %d Token errors (address = 0x%X0000)",prefixLDC,2560+i,station,frt,tab,j);
530 printf("%s\n",detail);
531 filcout << detail << endl;
537 if (!shuttleFile.IsNull())
539 ofstream out(shuttleFile.Data());
540 muonPedestal->MakeASCIIoutput(out); /// Generate pedestal output file
542 detail=Form("%s : Pedestal file (to SHUTTLE) : %s\n",prefixLDC,shuttleFile.Data());
543 cout << detail; filcout << detail ;
545 if(flag_histo) /// Generate pedestal histo rootfile
547 muonPedestal->MakeControlHistos();
548 detail=Form("%s : Pedestal Histo file : %s\n",prefixLDC,muonPedestal->GetHistoFileName());
549 cout << detail; filcout << detail ;
552 detail=Form("%s : Output logfile : %s\n",prefixLDC,logOutputFile.Data());
553 cout << detail; filcout << detail ;
556 // Transferring pedestal file to FES (be sure that env variable DAQDALIB_PATH is set)
558 status1 = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
559 if (status1) { detail=Form("%s: !!! ERROR: Failed to export pedestal file : %s to FES \n",prefixLDC,shuttleFile.Data());
560 printf("%s",detail); filcout << detail ; status= -1; }
561 //else { detail=Form("%s : ***** STORE Pedestal FILE in FES : OK ****** \n",prefixLDC); printf("%s",detail); filcout << detail ;}
563 // Transferring configuration file to FES (be sure that env variable DAQDALIB_PATH is set)
566 status1 = daqDA_FES_storeFile(dbfile,"CONFIG");
567 if (status1) { detail=Form("%s: !!! ERROR: Failed to export configuration file : %s to FES \n",prefixLDC,dbfile);
568 printf("%s",detail); filcout << detail ; status=-1; }
569 // else {detail=Form("%s : ***** STORE Configuration FILE in FES : OK ****** \n",prefixLDC); printf("%s",detail); filcout << detail ;}
572 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
574 unsigned int nLastVersions=50;
575 dir= getenv("DAQ_DETDB_LOCAL");
577 unsigned int nLastVersions=50;
578 printf("\n%s : --- Local DataBase: %s (Max= %d) ---\n",prefixLDC,dir,nLastVersions);
579 if(!shuttleFile.IsNull())status1 = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
580 if(flag_histo)status1 = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
581 status1 = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
589 //Send objects to the AMORE DB
591 ostringstream stringout;
592 muonPedestal->MakeASCIIoutput(stringout);
594 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
595 TObjString peddata(stringout.str().c_str());
596 Int_t amoreStatus = amoreDA.Send("Pedestals",&peddata);
598 {cout << prefixLDC << " : !!! ERROR: Failed to write Pedestals in the AMORE database : " << amoreStatus << endl ; status=-1 ;}
600 cout << prefixLDC << " : amoreDA.Send(Pedestals) ok" << endl;
602 cout << prefixLDC << " : Warning: MCH DA not compiled with AMORE support" << endl;
607 if(!status)printf("\n%s : -------- End execution : %s -------- (status= %d) \n",prefixLDC,prefixDA,status);
608 else { printf("\n%s : -------- %s ending in ERROR !!!! -------- (status= %d) \n",prefixLDC,prefixDA,status);}
610 printf("\n Execution time : R:%7.2fs C:%7.2fs\n",timers.RealTime(), timers.CpuTime());