2 Contact: Jean-Luc Charvet <jean-luc.charvet@cern.ch>
3 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mchda.html
7 Number of events needed: 400 events for pedestal run
8 Input Files: mutrkpedvalues and config_ldc-MTRK-S3-0
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 2009-11-05 New version: MUONTRKPEDda.cxx,v 1.4
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"
75 #include "TStopwatch.h"
77 #include "TTimeStamp.h"
78 #include "TGraphErrors.h"
81 #include "TPluginManager.h"
83 #include "TObjString.h"
84 #include "THashTable.h"
85 #include <THashList.h>
93 #include "AliMUONPedestal.h"
94 #include "AliMUONErrorCounter.h"
98 int main(Int_t argc, const char **argv)
104 const char* prefixDA = "MUONTRKPEDda"; // program prefix
105 printf(" ######## Begin execution : %s ######## \n\n",prefixDA);
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;
126 Int_t nDateEvents = 0;
127 Int_t nGlitchErrors= 0;
128 Int_t nParityErrors= 0;
129 Int_t nPaddingErrors= 0;
130 Int_t recoverParityErrors = 1;
132 TString logOutputFile;
134 Char_t flatFile[256]="";
137 Int_t nEventsRecovered = 0;
139 UInt_t runNumber = 0;
143 // decode the input line
144 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
146 const char* arg = argv[i];
151 // If only one argument and no "-" => DA calling from ECS
167 shuttleFile = argv[i];
171 skipEvents=atoi(argv[i]);
175 sscanf(argv[i],"%d",&maxDateEvents);
179 sscanf(argv[i],"%d",&maxEvents);
183 printf("\n******************* %s usage **********************",argv[0]);
184 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
185 printf("\n%s can be used locally only with options (without DiMuon configuration file)",argv[0]);
186 printf("\n%s -options, the available options are :",argv[0]);
187 printf("\n-h help (this screen)");
190 printf("\n-f <raw data file> (default = %s)",inputFile.Data());
193 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
195 printf("\n Options");
196 printf("\n-m <max date events> (default = %d)",maxDateEvents);
197 printf("\n-s <skip events> (default = %d)",skipEvents);
198 printf("\n-n <max events> (default = %d)",maxEvents);
203 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
204 argc = 2; exit(-1); // exit if error
208 // decoding the events
215 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
216 muonPedestal->SetprefixDA(prefixDA);
218 Char_t dbfile[256]="";
219 // nConfig=1 : Reading configuration (or not) status via "mutrkpedvalues" file located in DetDB
222 sprintf(dbfile,"mutrkpedvalues");
223 status=daqDA_DB_getFile(dbfile,dbfile);
224 if(status) {printf(" Failed : input file %s is missing, status = %d\n",dbfile,status); return -1; }
225 ifstream filein(dbfile,ios::in);
227 printf(" *** Copy: %s from DetDB to working directory *** Config= %d\n",dbfile,nConfig);
231 printf(" *** Config= %d: no configuration ascii file is used \n",nConfig);
233 muonPedestal->SetconfigDA(nConfig);
235 // nConfig=1: configuration ascii file read from DetDB
238 // MuonTrk Configuration ascii file (initCROCUS.dat -> ascii file = config_$DATE_ROLE_NAME)
239 sprintf(dbfile,"config_%s",getenv("DATE_ROLE_NAME"));
240 status=daqDA_DB_getFile(dbfile,dbfile);
241 if(status) {printf(" Failed : Configuration file %s is missing, status = %d\n",dbfile,status); return -1; }
242 else printf(" *** Copy ascii config file: %s from DetDB to working directory and reading ...*** \n",dbfile);
243 muonPedestal->LoadConfig(dbfile);
246 // Rawdeader, RawStreamHP
247 AliRawReader* rawReader = AliRawReader::Create(inputFile);
248 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
249 rawStream->DisableWarnings();
250 rawStream->EnabbleErrorLogger();
252 printf("\n %s : Reading data from file %s\n",prefixDA,inputFile.Data());
254 while (rawReader->NextEvent())
256 if (nDateEvents >= maxDateEvents) break;
257 if (nEvents >= maxEvents) break;
258 if (nDateEvents>0 && nDateEvents % 100 == 0)
259 cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
261 // check shutdown condition
262 if (daqDA_checkShutdown())
268 rawReader->NextEvent();
272 Int_t eventType = rawReader->GetType();
273 runNumber = rawReader->GetRunNumber();
275 // Output log file initialisations
278 sprintf(flatFile,"%s.log",prefixDA);
279 logOutputFile=flatFile;
281 filcout.open(logOutputFile.Data());
282 filcout<<"//=================================================" << endl;
283 filcout<<"// " << prefixDA << " for run = " << runNumber << endl;
284 filcout<<"//=================================================" << endl;
285 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
286 cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " ********\n" << endl;
287 cout<<" * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
291 muonPedestal->SetAlifilcout(&filcout);
294 if (eventType != PHYSICS_EVENT)
295 continue; // for the moment
297 // First lopp over DDL's to find good events
298 // Error counters per event (counters in the decoding lib are for each DDL)
299 Bool_t eventIsErrorMessage = kFALSE;
300 int eventGlitchErrors = 0;
301 int eventParityErrors = 0;
302 int eventPaddingErrors = 0;
306 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
307 eventGlitchErrors += rawStream->GetGlitchErrors();
308 eventParityErrors += rawStream->GetParityErrors();
309 eventPaddingErrors += rawStream->GetPaddingErrors();
310 } while(rawStream->NextDDL());
312 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
313 if (!eventIsErrorMessage)
315 // Good events (no error) -> compute pedestal for all channels
317 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
319 for(int i = 0; i < busPatch->GetLength(); ++i)
321 busPatch->GetData(i, manuId, channelId, charge);
322 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
329 // Events with errors
330 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
332 // Recover parity errors -> compute pedestal for all good buspatches
333 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
336 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
337 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
338 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
342 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
343 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
344 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
347 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
349 // Check the buspatch -> if error not use it in the pedestal calculation
351 for(int i = 0; i < busPatch->GetLength(); ++i)
353 if (!busPatch->IsParityOk(i)) errorCount++;
358 for(int i = 0; i < busPatch->GetLength(); ++i)
360 busPatch->GetData(i, manuId, channelId, charge);
361 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
366 AliMUONErrorCounter* errorCounter;
367 // Bad buspatch -> not used (just print)
368 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
369 <<" parity errors "<<errorCount<<endl;
370 // Number of events where this buspatch is missing
371 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(busPatch->GetBusPatchId()))))
374 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
375 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
380 errorCounter->Increment();
382 // errorCounter->Print();
383 } // end of if (!errorCount)
384 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
387 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
390 // Fatal errors reject the event
391 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
394 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
395 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
396 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
400 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
401 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
402 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
405 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
406 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
407 <<" Parity "<<eventParityErrors
408 <<" Padding "<<eventPaddingErrors<<endl;
410 } // end of if (!rawStream->IsErrorMessage())
412 if (eventGlitchErrors) nGlitchErrors++;
413 if (eventParityErrors) nParityErrors++;
414 if (eventPaddingErrors) nPaddingErrors++;
416 } // while (rawReader->NextEvent())
420 sprintf(flatFile,"%s.ped",prefixDA);
421 if(shuttleFile.IsNull())shuttleFile=flatFile;
422 muonPedestal->SetAliNEvents(nEvents);
423 muonPedestal->SetAliRunNumber(runNumber);
425 muonPedestal->Finalize();
426 muonPedestal->MakeControlHistos();
427 if (!shuttleFile.IsNull())
429 ofstream out(shuttleFile.Data());
430 muonPedestal->MakeASCIIoutput(out);
434 //Send objects to the AMORE DB
436 ostringstream stringout;
437 muonPedestal->MakeASCIIoutput(stringout);
439 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
440 TObjString peddata(stringout.str().c_str());
442 status = amoreDA.Send("Pedestals",&peddata);
444 cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
446 cout << "amoreDA.Send(Pedestals) ok" << endl;
448 cout << "Warning: MCH DA not compiled with AMORE support" << endl;
453 // writing some counters
455 cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
456 cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
457 cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
458 cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
459 cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
460 cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
461 cout << prefixDA << " : Nb of events used = " << nEvents << endl;
464 filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
465 filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
466 filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
467 filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
468 filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
469 filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
470 filcout << prefixDA << " : Nb of events used = " << nEvents << endl;
474 cout << prefixDA << " : Output logfile : " << logOutputFile << endl;
475 cout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
476 cout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
479 filcout << prefixDA << " : Output logfile : " << logOutputFile << endl;
480 filcout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
481 filcout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
483 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
485 dir= getenv("DAQ_DETDB_LOCAL");
486 unsigned int nLastVersions=90;
487 cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl;
488 status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
489 if(status)printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
490 status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
491 if(status)printf(" Store file : %s status = %d\n",shuttleFile.Data(),status);
492 status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
493 if(status)printf(" Store file : %s status = %d\n",logOutputFile.Data(),status);
497 // Transferring to OCDB via the SHUTTLE (be sure that env variable DAQDALIB_PATH is set)
498 printf("\n ***** STORE FILE in FES ****** \n");
499 status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
500 if (status) { printf(" Failed to export file : %s , status = %d\n",shuttleFile.Data(),status); return -1; }
501 else printf(" %s successfully exported to FES \n",shuttleFile.Data());
503 printf("\n ######## End execution : %s ######## \n",prefixDA);
505 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());