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 2010-07-09 New version: MUONTRKPEDda.cxx,v 1.7
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)
107 const char* prefixDA = "MUONTRKPEDda"; // program prefix
108 printf(" ######## Begin execution : %s ######## \n\n",prefixDA);
110 // needed for streamer application
111 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
116 // needed for Minuit plugin
117 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
121 "TMinuitMinimizer(const char*)");
124 Int_t skipEvents = 0;
125 Int_t maxEvents = 1000000;
126 Int_t maxDateEvents = 1000000;
129 Int_t nDateEvents = 0;
130 Int_t nGlitchErrors= 0;
131 Int_t nParityErrors= 0;
132 Int_t nPaddingErrors= 0;
133 Int_t nTokenlostErrors= 0;
134 Int_t recoverParityErrors = 1;
136 TString logOutputFile;
138 Char_t flatFile[256]="";
141 Int_t nEventsRecovered = 0;
143 UInt_t runNumber = 0;
145 Int_t nEvthreshold = 100; //below this nb_evt pedestal are not calculated and forced to 4085 (sigma)
146 Int_t nSorting = 0 ; // pedestal sorting (OFF by default)
149 // decode the input line
150 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
152 const char* arg = argv[i];
157 // If only one argument and no "-" => DA calling from ECS
173 shuttleFile = argv[i];
177 skipEvents=atoi(argv[i]);
181 sscanf(argv[i],"%d",&maxDateEvents);
185 sscanf(argv[i],"%d",&maxEvents);
189 printf("\n******************* %s usage **********************",argv[0]);
190 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
191 printf("\n%s can be used locally only with options (without DiMuon configuration file)",argv[0]);
192 printf("\n%s -options, the available options are :",argv[0]);
193 printf("\n-h help (this screen)");
196 printf("\n-f <raw data file> (default = %s)",inputFile.Data());
199 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
201 printf("\n Options");
202 printf("\n-m <max date events> (default = %d)",maxDateEvents);
203 printf("\n-s <skip events> (default = %d)",skipEvents);
204 printf("\n-n <max events> (default = %d)",maxEvents);
209 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
210 argc = 2; exit(-1); // exit if error
214 // decoding the events
221 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
222 muonPedestal->SetprefixDA(prefixDA);
224 Char_t dbfile[256]="";
225 // nConfig=1 : Reading configuration (or not) status via "mutrkpedvalues" file located in DetDB
229 sprintf(dbfile,"mutrkpedvalues");
230 status=daqDA_DB_getFile(dbfile,dbfile);
231 if(status) {printf(" !!! Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; }
232 ifstream filein(dbfile,ios::in);
235 // filein >> maxEvts;
236 // if(maxEvts!=0)maxEvents=maxEvts;
238 else printf(" *** Config= %d: no configuration ascii file is used \n",nConfig);
239 muonPedestal->SetconfigDA(nConfig);
240 muonPedestal->SetnEvthreshold(nEvthreshold);
241 muonPedestal->SetnSorting(nSorting);
243 // nConfig=1: configuration ascii file config_$DATE_ROLE_NAME read from DetDB
246 sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME"));
247 status=daqDA_DB_getFile(dbfile,dbfile);
248 if(status) {printf(" !!! Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; }
249 // else printf(" *** Copy ascii config file: %s from DetDB to working directory and reading ...*** \n",dbfile);
250 muonPedestal->LoadConfig(dbfile);
253 // Rawdeader, RawStreamHP
254 AliRawReader* rawReader = AliRawReader::Create(inputFile);
255 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
256 // rawStream->DisableWarnings();
257 rawStream->EnabbleErrorLogger();
259 // kLowErrorDetail, /// Logs minimal information in the error messages.
260 // kMediumErrorDetail, /// Logs a medium level of detail in the error messages.
261 // kHighErrorDetail /// Logs maximum information in the error messages.
262 // rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kLowErrorDetail);
263 rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
264 // rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kHighErrorDetail);
266 printf("\n %s : Reading data from file %s\n",prefixDA,inputFile.Data());
268 Int_t tabTokenError[20][14];
269 for ( Int_t i=0 ; i<20 ; i++) { for ( Int_t j=0 ; j<14 ; j++) { tabTokenError[i][j]=0;} }
271 while (rawReader->NextEvent())
273 if (nDateEvents >= maxDateEvents) break;
274 if (nEvents >= maxEvents) break;
275 if (nDateEvents>0 && nDateEvents % 100 == 0)
276 cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
278 // check shutdown condition
279 if (daqDA_checkShutdown())
284 rawReader->NextEvent();
287 Int_t eventType = rawReader->GetType();
288 runNumber = rawReader->GetRunNumber();
290 // Output log file initialisations
293 sprintf(flatFile,"%s.log",prefixDA);
294 logOutputFile=flatFile;
295 AliLog::SetStreamOutput(&filcout); // Print details on logfile
296 filcout.open(logOutputFile.Data());
297 filcout<<"//=================================================" << endl;
298 filcout<<"// " << prefixDA << " for run = " << runNumber << endl;
299 filcout<<"//=================================================" << endl;
300 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
301 cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " ********\n" << endl;
302 cout<<" * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
306 muonPedestal->SetAlifilcout(&filcout);
309 if (eventType != PHYSICS_EVENT)
310 continue; // for the moment
312 const char* detail = "";
313 // First lopp over DDL's to find good events
314 // Error counters per event (counters in the decoding lib are for each DDL)
315 Bool_t eventIsErrorMessage = kFALSE;
316 int eventGlitchErrors = 0;
317 int eventParityErrors = 0;
318 int eventPaddingErrors = 0;
319 int eventTokenlostErrors = 0;
323 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
324 eventGlitchErrors += rawStream->GetGlitchErrors();
325 eventParityErrors += rawStream->GetParityErrors();
326 eventPaddingErrors += rawStream->GetPaddingErrors();
327 eventTokenlostErrors += rawStream->GetTokenLostErrors();
328 if (rawStream->GetTokenLostErrors())
331 const AliMUONRawStreamTrackerHP::AliBlockHeader* blkHeader = 0x0;
332 const AliMUONRawStreamTrackerHP::AliDspHeader* dspHeader = 0x0;
333 Int_t nBlock = rawStream->GetBlockCount();
334 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++)
336 blkHeader = rawStream->GetBlockHeader(iBlock);
337 // printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
338 Int_t nDsp = rawStream->GetDspCount(iBlock);
339 // printf("Block %d DSP %d\n",iBlock,nDsp);
340 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++)
342 dspHeader = blkHeader->GetDspHeader(iDsp);
343 // printf("Dsp %d Add %X\n",iDsp,dspHeader);
344 if (dspHeader->GetErrorWord())
346 Int_t ddl = rawStream->GetDDL() ;
347 // Int_t ddl = AliDAQ::DdlID("MUONTRK", rawStream->GetDDL()) - 2560 ; // format 2560 + ddl
348 Int_t frt = (dspHeader->GetErrorWord() & 0xFFFF0000) >> 16 ; // 4*4bits right shift
349 tabTokenError[ddl][frt]++;
350 // printf(" DDL %d error word %X %d %d\n",ddl,dspHeader->GetErrorWord(),frt,tabTokenError[8][4]);
356 } while(rawStream->NextDDL());
358 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
359 if (!eventIsErrorMessage)
361 // Good events (no error) -> compute pedestal for all channels
364 muonPedestal->SetAliNCurrentEvents(nEvents);
365 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
367 for(int i = 0; i < busPatch->GetLength(); ++i)
369 busPatch->GetData(i, manuId, channelId, charge);
370 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
376 // Events with errors
377 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
379 filcout << " ----------- Date Event recovered = " << nDateEvents << " ----------------" << endl;
380 // Recover parity errors -> compute pedestal for all good buspatches
381 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
384 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
385 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
386 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
390 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
391 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
392 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
396 muonPedestal->SetAliNCurrentEvents(nEvents);
397 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
399 // Check the buspatch -> if error not use it in the pedestal calculation
401 for(int i = 0; i < busPatch->GetLength(); ++i)
403 if (!busPatch->IsParityOk(i)) errorCount++;
408 for(int i = 0; i < busPatch->GetLength(); ++i)
410 busPatch->GetData(i, manuId, channelId, charge);
411 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
416 AliMUONErrorCounter* errorCounter;
417 // Bad buspatch -> not used (just print)
418 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
419 <<" parity errors "<<errorCount<<endl;
420 // Number of events where this buspatch is missing
421 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(busPatch->GetBusPatchId()))))
424 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
425 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
430 errorCounter->Increment();
432 // errorCounter->Print();
433 } // end of if (!errorCount)
434 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
437 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
440 // Fatal errors reject the event
441 detail = Form(" ----------- Date Event rejected = %d ----------------",nDateEvents);
442 filcout << detail << endl;
443 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
446 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
447 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
448 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
452 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
453 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
454 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
457 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
458 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
459 <<" Parity "<<eventParityErrors
460 <<" Padding "<<eventPaddingErrors
461 <<" Token lost "<<eventTokenlostErrors<<endl;
463 } // end of if (!rawStream->IsErrorMessage())
465 if (eventGlitchErrors) nGlitchErrors++;
466 if (eventParityErrors) nParityErrors++;
467 if (eventPaddingErrors) nPaddingErrors++;
468 // if (eventTokenlostErrors) nTokenlostErrors++;
469 // muonPedestal->SetAliNCurrentEvents(nEvents);
471 } // while (rawReader->NextEvent())
475 sprintf(flatFile,"%s.ped",prefixDA);
476 if(shuttleFile.IsNull())shuttleFile=flatFile;
477 muonPedestal->SetAliNEvents(nEvents);
478 muonPedestal->SetAliRunNumber(runNumber);
480 muonPedestal->Finalize();
481 muonPedestal->MakeControlHistos();
482 if (!shuttleFile.IsNull())
484 ofstream out(shuttleFile.Data());
485 muonPedestal->MakeASCIIoutput(out);
489 //Send objects to the AMORE DB
491 ostringstream stringout;
492 muonPedestal->MakeASCIIoutput(stringout);
494 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
495 TObjString peddata(stringout.str().c_str());
496 Int_t amoreStatus = amoreDA.Send("Pedestals",&peddata);
498 cout << "Warning: Failed to write Pedestals in the AMORE database : " << amoreStatus << endl;
500 cout << "amoreDA.Send(Pedestals) ok" << endl;
502 cout << "Warning: MCH DA not compiled with AMORE support" << endl;
507 // writing some counters
509 cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
510 cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
511 cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
512 cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
513 cout << prefixDA << " : Nb of Token lost errors = " << nTokenlostErrors << endl;
514 cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
515 cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
516 cout << prefixDA << " : Nb of events used = " << nEvents << endl;
519 filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
520 filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
521 filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
522 filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
523 filcout << prefixDA << " : Nb of Token lost errors = " << nTokenlostErrors << endl;
524 filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
525 filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
526 filcout << prefixDA << " : Nb of events used = " << nEvents << endl;
530 cout << prefixDA << " : Output logfile : " << logOutputFile << endl;
531 cout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
532 cout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
534 // Writing Token Error table
537 char* detail=Form("\nWarning: Token Lost occurence \n");
540 for ( Int_t i=0 ; i<20 ; i++)
542 for ( Int_t j=4 ; j<14 ; j++)
544 if(tabTokenError[i][j]>0)
546 Int_t tab=tabTokenError[i][j];
548 Int_t station = i/4 +1;
549 if( j % 2 == 0)detail=Form(" in DDL= %d (station %d) and FRT%d ( Up ) => %d Token errors (address = 0x%X0000)",2560+i,station,frt,tab,j);
550 else detail=Form(" in DDL= %d (station %d) and FRT%d (Down) => %d Token errors (address = 0x%X0000)",2560+i,station,frt,tab,j);
551 printf("%s\n",detail);
552 filcout << detail << endl;
559 filcout << prefixDA << " : Output logfile : " << logOutputFile << endl;
560 filcout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
561 filcout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
563 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
565 dir= getenv("DAQ_DETDB_LOCAL");
566 unsigned int nLastVersions=50;
567 cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl;
568 status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
569 if(status)printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
570 status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
571 if(status)printf(" Store file : %s status = %d\n",shuttleFile.Data(),status);
572 status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
573 if(status)printf(" Store file : %s status = %d\n",logOutputFile.Data(),status);
577 // Transferring to FES (be sure that env variable DAQDALIB_PATH is set)
578 printf("\n ***** STORE Pedestal FILE in FES ****** \n");
579 status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
580 if (status) { printf(" !!! Failed to export file : %s , status = %d\n",shuttleFile.Data(),status); return -1; }
581 // else printf(" %s successfully exported to FES \n",shuttleFile.Data());
583 // Transferring to FES (be sure that env variable DAQDALIB_PATH is set)
584 printf("\n ***** STORE Configuration FILE in FES ****** \n");
585 status = daqDA_FES_storeFile(dbfile,"CONFIG");
586 if (status) { printf(" !!! Failed to export file : %s , status = %d\n",dbfile,status); return -1; }
587 // else printf(" %s successfully exported to FES \n",dbfile);
590 printf("\n ######## End execution : %s ######## \n",prefixDA);
592 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());