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-04-18 New version: MUONTRKPEDda.cxx,v 1.6
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 = 10; //below this nb_evt pedestal are not calculated and forced to 4085 (sigma)
148 // decode the input line
149 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
151 const char* arg = argv[i];
156 // If only one argument and no "-" => DA calling from ECS
172 shuttleFile = argv[i];
176 skipEvents=atoi(argv[i]);
180 sscanf(argv[i],"%d",&maxDateEvents);
184 sscanf(argv[i],"%d",&maxEvents);
188 printf("\n******************* %s usage **********************",argv[0]);
189 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
190 printf("\n%s can be used locally only with options (without DiMuon configuration file)",argv[0]);
191 printf("\n%s -options, the available options are :",argv[0]);
192 printf("\n-h help (this screen)");
195 printf("\n-f <raw data file> (default = %s)",inputFile.Data());
198 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
200 printf("\n Options");
201 printf("\n-m <max date events> (default = %d)",maxDateEvents);
202 printf("\n-s <skip events> (default = %d)",skipEvents);
203 printf("\n-n <max events> (default = %d)",maxEvents);
208 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
209 argc = 2; exit(-1); // exit if error
213 // decoding the events
220 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
221 muonPedestal->SetprefixDA(prefixDA);
223 Char_t dbfile[256]="";
224 // nConfig=1 : Reading configuration (or not) status via "mutrkpedvalues" file located in DetDB
227 sprintf(dbfile,"mutrkpedvalues");
228 status=daqDA_DB_getFile(dbfile,dbfile);
229 if(status) {printf(" !!! Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; }
230 ifstream filein(dbfile,ios::in);
232 // filein >> nEvthreshold;
234 else printf(" *** Config= %d: no configuration ascii file is used \n",nConfig);
235 muonPedestal->SetconfigDA(nConfig);
236 muonPedestal->SetnEvthreshold(nEvthreshold);
238 // nConfig=1: configuration ascii file config_$DATE_ROLE_NAME read from DetDB
241 sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME"));
242 status=daqDA_DB_getFile(dbfile,dbfile);
243 if(status) {printf(" !!! Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; }
244 // else printf(" *** Copy ascii config file: %s from DetDB to working directory and reading ...*** \n",dbfile);
245 muonPedestal->LoadConfig(dbfile);
248 // Rawdeader, RawStreamHP
249 AliRawReader* rawReader = AliRawReader::Create(inputFile);
250 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
251 // rawStream->DisableWarnings();
252 rawStream->EnabbleErrorLogger();
254 // kLowErrorDetail, /// Logs minimal information in the error messages.
255 // kMediumErrorDetail, /// Logs a medium level of detail in the error messages.
256 // kHighErrorDetail /// Logs maximum information in the error messages.
257 // rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kLowErrorDetail);
258 rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
259 // rawStream->SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kHighErrorDetail);
261 printf("\n %s : Reading data from file %s\n",prefixDA,inputFile.Data());
263 Int_t tabTokenError[20][14];
264 for ( Int_t i=0 ; i<20 ; i++) { for ( Int_t j=0 ; j<14 ; j++) { tabTokenError[i][j]=0;} }
266 while (rawReader->NextEvent())
268 if (nDateEvents >= maxDateEvents) break;
269 if (nEvents >= maxEvents) break;
270 if (nDateEvents>0 && nDateEvents % 100 == 0)
271 cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
273 // check shutdown condition
274 if (daqDA_checkShutdown())
279 rawReader->NextEvent();
282 Int_t eventType = rawReader->GetType();
283 runNumber = rawReader->GetRunNumber();
285 // Output log file initialisations
288 sprintf(flatFile,"%s.log",prefixDA);
289 logOutputFile=flatFile;
290 AliLog::SetStreamOutput(&filcout); // Print details on logfile
291 filcout.open(logOutputFile.Data());
292 filcout<<"//=================================================" << endl;
293 filcout<<"// " << prefixDA << " for run = " << runNumber << endl;
294 filcout<<"//=================================================" << endl;
295 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
296 cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " ********\n" << endl;
297 cout<<" * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
301 muonPedestal->SetAlifilcout(&filcout);
304 if (eventType != PHYSICS_EVENT)
305 continue; // for the moment
307 const char* detail = "";
308 // First lopp over DDL's to find good events
309 // Error counters per event (counters in the decoding lib are for each DDL)
310 Bool_t eventIsErrorMessage = kFALSE;
311 int eventGlitchErrors = 0;
312 int eventParityErrors = 0;
313 int eventPaddingErrors = 0;
314 int eventTokenlostErrors = 0;
318 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
319 eventGlitchErrors += rawStream->GetGlitchErrors();
320 eventParityErrors += rawStream->GetParityErrors();
321 eventPaddingErrors += rawStream->GetPaddingErrors();
322 eventTokenlostErrors += rawStream->GetTokenLostErrors();
323 if (rawStream->GetTokenLostErrors())
326 const AliMUONRawStreamTrackerHP::AliBlockHeader* blkHeader = 0x0;
327 const AliMUONRawStreamTrackerHP::AliDspHeader* dspHeader = 0x0;
328 Int_t nBlock = rawStream->GetBlockCount();
329 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++)
331 blkHeader = rawStream->GetBlockHeader(iBlock);
332 // printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
333 Int_t nDsp = rawStream->GetDspCount(iBlock);
334 // printf("Block %d DSP %d\n",iBlock,nDsp);
335 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++)
337 dspHeader = blkHeader->GetDspHeader(iDsp);
338 // printf("Dsp %d Add %X\n",iDsp,dspHeader);
339 if (dspHeader->GetErrorWord())
341 Int_t ddl = rawStream->GetDDL() ;
342 // Int_t ddl = AliDAQ::DdlID("MUONTRK", rawStream->GetDDL()) - 2560 ; // format 2560 + ddl
343 Int_t frt = (dspHeader->GetErrorWord() & 0xFFFF0000) >> 16 ; // 4*4bits right shift
344 tabTokenError[ddl][frt]++;
345 // printf(" DDL %d error word %X %d %d\n",ddl,dspHeader->GetErrorWord(),frt,tabTokenError[8][4]);
351 } while(rawStream->NextDDL());
353 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
354 if (!eventIsErrorMessage)
356 // Good events (no error) -> compute pedestal for all channels
359 muonPedestal->SetAliNCurrentEvents(nEvents);
360 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
362 for(int i = 0; i < busPatch->GetLength(); ++i)
364 busPatch->GetData(i, manuId, channelId, charge);
365 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
371 // Events with errors
372 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
374 filcout << " ----------- Date Event recovered = " << nDateEvents << " ----------------" << endl;
375 // Recover parity errors -> compute pedestal for all good buspatches
376 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
379 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
380 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
381 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
385 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
386 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
387 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
391 muonPedestal->SetAliNCurrentEvents(nEvents);
392 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
394 // Check the buspatch -> if error not use it in the pedestal calculation
396 for(int i = 0; i < busPatch->GetLength(); ++i)
398 if (!busPatch->IsParityOk(i)) errorCount++;
403 for(int i = 0; i < busPatch->GetLength(); ++i)
405 busPatch->GetData(i, manuId, channelId, charge);
406 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
411 AliMUONErrorCounter* errorCounter;
412 // Bad buspatch -> not used (just print)
413 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
414 <<" parity errors "<<errorCount<<endl;
415 // Number of events where this buspatch is missing
416 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(busPatch->GetBusPatchId()))))
419 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
420 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
425 errorCounter->Increment();
427 // errorCounter->Print();
428 } // end of if (!errorCount)
429 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
432 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
435 // Fatal errors reject the event
436 detail = Form(" ----------- Date Event rejected = %d ----------------",nDateEvents);
437 filcout << detail << endl;
438 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
441 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
442 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
443 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
447 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
448 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
449 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
452 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
453 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
454 <<" Parity "<<eventParityErrors
455 <<" Padding "<<eventPaddingErrors
456 <<" Token lost "<<eventTokenlostErrors<<endl;
458 } // end of if (!rawStream->IsErrorMessage())
460 if (eventGlitchErrors) nGlitchErrors++;
461 if (eventParityErrors) nParityErrors++;
462 if (eventPaddingErrors) nPaddingErrors++;
463 // if (eventTokenlostErrors) nTokenlostErrors++;
464 // muonPedestal->SetAliNCurrentEvents(nEvents);
466 } // while (rawReader->NextEvent())
470 sprintf(flatFile,"%s.ped",prefixDA);
471 if(shuttleFile.IsNull())shuttleFile=flatFile;
472 muonPedestal->SetAliNEvents(nEvents);
473 muonPedestal->SetAliRunNumber(runNumber);
475 muonPedestal->Finalize();
476 muonPedestal->MakeControlHistos();
477 if (!shuttleFile.IsNull())
479 ofstream out(shuttleFile.Data());
480 muonPedestal->MakeASCIIoutput(out);
484 //Send objects to the AMORE DB
486 ostringstream stringout;
487 muonPedestal->MakeASCIIoutput(stringout);
489 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
490 TObjString peddata(stringout.str().c_str());
491 Int_t amoreStatus = amoreDA.Send("Pedestals",&peddata);
493 cout << "Warning: Failed to write Pedestals in the AMORE database : " << amoreStatus << endl;
495 cout << "amoreDA.Send(Pedestals) ok" << endl;
497 cout << "Warning: MCH DA not compiled with AMORE support" << endl;
502 // writing some counters
504 cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
505 cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
506 cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
507 cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
508 cout << prefixDA << " : Nb of Token lost errors = " << nTokenlostErrors << endl;
509 cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
510 cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
511 cout << prefixDA << " : Nb of events used = " << nEvents << endl;
514 filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
515 filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
516 filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
517 filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
518 filcout << prefixDA << " : Nb of Token lost errors = " << nTokenlostErrors << endl;
519 filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
520 filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
521 filcout << prefixDA << " : Nb of events used = " << nEvents << endl;
525 cout << prefixDA << " : Output logfile : " << logOutputFile << endl;
526 cout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
527 cout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
529 // Writing Token Error table
532 char* detail=Form("\nWarning: Token Lost occurence \n");
535 for ( Int_t i=0 ; i<20 ; i++)
537 for ( Int_t j=4 ; j<14 ; j++)
539 if(tabTokenError[i][j]>0)
541 Int_t tab=tabTokenError[i][j];
543 Int_t station = i/4 +1;
544 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);
545 else detail=Form(" in DDL= %d (station %d) and FRT%d (Down) => %d Token errors (address = 0x%X0000)",2560+i,station,frt,tab,j);
546 printf("%s\n",detail);
547 filcout << detail << endl;
554 filcout << prefixDA << " : Output logfile : " << logOutputFile << endl;
555 filcout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
556 filcout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
558 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
560 dir= getenv("DAQ_DETDB_LOCAL");
561 unsigned int nLastVersions=50;
562 cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl;
563 status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
564 if(status)printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
565 status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
566 if(status)printf(" Store file : %s status = %d\n",shuttleFile.Data(),status);
567 status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
568 if(status)printf(" Store file : %s status = %d\n",logOutputFile.Data(),status);
572 // Transferring to FES (be sure that env variable DAQDALIB_PATH is set)
573 printf("\n ***** STORE Pedestal FILE in FES ****** \n");
574 status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
575 if (status) { printf(" !!! Failed to export file : %s , status = %d\n",shuttleFile.Data(),status); return -1; }
576 // else printf(" %s successfully exported to FES \n",shuttleFile.Data());
578 // Transferring to FES (be sure that env variable DAQDALIB_PATH is set)
579 printf("\n ***** STORE Configuration FILE in FES ****** \n");
580 status = daqDA_FES_storeFile(dbfile,"CONFIG");
581 if (status) { printf(" !!! Failed to export file : %s , status = %d\n",dbfile,status); return -1; }
582 // else printf(" %s successfully exported to FES \n",dbfile);
585 printf("\n ######## End execution : %s ######## \n",prefixDA);
587 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());