2 Contact: Jean-Luc Charvet <jean-luc.charvet@cea.fr>
3 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_Mchda
6 Number of events needed: 400 events for pedestal run
7 Input Files: Rawdata file (DATE format)
8 Output Files: local dir (not persistent) -> MUONTRKPEDda_<run#>.ped
9 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-06-18 New version: MUONTRKPEDda.cxx,v 1.2
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
51 #include <Riostream.h>
58 #include "AliMUONRawStreamTrackerHP.h"
59 #include "AliRawReader.h"
60 #include "AliMUONVStore.h"
61 #include "AliMUON2DMap.h"
62 #include "AliMUONCalibParamND.h"
63 #include "AliMpIntPair.h"
64 #include "AliMpConstants.h"
65 #include "AliRawDataErrorLog.h"
66 #include "AliMUONTrackerIO.h"
74 #include "TStopwatch.h"
76 #include "TTimeStamp.h"
77 #include "TGraphErrors.h"
80 #include "TPluginManager.h"
82 #include "TObjString.h"
83 #include "THashTable.h"
84 #include <THashList.h>
86 #include "AliMUONPedestal.h"
87 #include "AliMUONErrorCounter.h"
91 int main(Int_t argc, Char_t **argv)
98 // needed for streamer application
99 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
105 // needed for Minuit plugin
106 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
110 "TMinuitMinimizer(const char*)");
112 Char_t prefixDA[256]="MUONTRKPEDda"; // program prefix
115 Int_t skipEvents = 0;
116 Int_t maxEvents = 1000000;
117 Int_t maxDateEvents = 1000000;
118 Char_t inputFile[256]="";
120 Int_t nDateEvents = 0;
121 Int_t nGlitchErrors= 0;
122 Int_t nParityErrors= 0;
123 Int_t nPaddingErrors= 0;
124 Int_t recoverParityErrors = 1;
126 TString logOutputFile;
128 Char_t flatFile[256]="";
131 Int_t nEventsRecovered = 0;
133 UInt_t runNumber = 0;
136 // Int_t nIndex = -1;
138 // decode the input line
139 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
146 // If only one argument and no "-" => DA calling from ECS
149 sprintf(inputFile,argv[i]);
157 sprintf(inputFile,argv[i]);
161 shuttleFile = argv[i];
165 skipEvents=atoi(argv[i]);
169 sscanf(argv[i],"%d",&maxDateEvents);
173 sscanf(argv[i],"%d",&maxEvents);
177 // sscanf(argv[i],"%d",&recoverParityErrors);
181 printf("\n******************* %s usage **********************",argv[0]);
182 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
183 printf("\n%s -options, the available options are :",argv[0]);
184 printf("\n-h help (this screen)");
187 printf("\n-f <raw data file> (default = %s)",inputFile);
190 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
192 printf("\n Options");
193 printf("\n-m <max date events> (default = %d)",maxDateEvents);
194 printf("\n-s <skip events> (default = %d)",skipEvents);
195 printf("\n-n <max events> (default = %d)",maxEvents);
196 // printf("\n-p <Recover parity errors> (default = %d)",recoverParityErrors);
201 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
202 argc = 2; exit(-1); // exit if error
206 // decoding the events
213 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
214 muonPedestal->SetprefixDA(prefixDA);
216 // Rawdeader, RawStreamHP
217 AliRawReader* rawReader = AliRawReader::Create(inputFile);
218 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
219 rawStream->DisableWarnings();
220 rawStream->EnabbleErrorLogger();
222 cout << "\n" << prefixDA << " : Reading data from file " << inputFile << endl;
224 while (rawReader->NextEvent())
226 if (nDateEvents >= maxDateEvents) break;
227 if (nEvents >= maxEvents) break;
228 if (nDateEvents>0 && nDateEvents % 100 == 0)
229 cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
231 // check shutdown condition
232 if (daqDA_checkShutdown())
238 rawReader->NextEvent();
242 Int_t eventType = rawReader->GetType();
243 runNumber = rawReader->GetRunNumber();
245 // Output log file initialisations
248 sprintf(flatFile,"%s.log",prefixDA);
249 logOutputFile=flatFile;
251 filcout.open(logOutputFile.Data());
252 filcout<<"//=================================================" << endl;
253 filcout<<"// " << prefixDA << " for run = " << runNumber << endl;
254 filcout<<"//=================================================" << endl;
255 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
256 cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " ********\n" << endl;
257 cout<<" * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
261 muonPedestal->SetAlifilcout(&filcout);
264 if (eventType != PHYSICS_EVENT)
265 continue; // for the moment
267 // First lopp over DDL's to find good events
268 // Error counters per event (counters in the decoding lib are for each DDL)
269 Bool_t eventIsErrorMessage = kFALSE;
270 int eventGlitchErrors = 0;
271 int eventParityErrors = 0;
272 int eventPaddingErrors = 0;
276 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
277 eventGlitchErrors += rawStream->GetGlitchErrors();
278 eventParityErrors += rawStream->GetParityErrors();
279 eventPaddingErrors += rawStream->GetPaddingErrors();
280 } while(rawStream->NextDDL());
282 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
283 if (!eventIsErrorMessage)
285 // Good events (no error) -> compute pedestal for all channels
287 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
289 for(int i = 0; i < busPatch->GetLength(); ++i)
291 if (nEvents == 0) nChannel++;
292 busPatch->GetData(i, manuId, channelId, charge);
293 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
300 // Events with errors
301 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
303 // Recover parity errors -> compute pedestal for all good buspatches
304 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
307 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
308 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
309 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
313 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
314 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
315 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
318 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
320 // Check the buspatch -> if error not use it in the pedestal calculation
322 for(int i = 0; i < busPatch->GetLength(); ++i)
324 if (!busPatch->IsParityOk(i)) errorCount++;
329 for(int i = 0; i < busPatch->GetLength(); ++i)
331 if (nEvents == 0) nChannel++;
332 busPatch->GetData(i, manuId, channelId, charge);
333 // if (busPatch->GetBusPatchId()==1719 && manuId == 1 && channelId == 0) cout <<"Recovered charge "<<charge<<endl;
334 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
340 AliMUONErrorCounter* errorCounter;
341 // Bad buspatch -> not used (just print)
342 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
343 <<" parity errors "<<errorCount<<endl;
344 // Number of events where this buspatch is missing
345 sprintf(bpname,"bp%d",busPatch->GetBusPatchId());
346 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(bpname))))
349 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
350 errorCounter->SetName(bpname);
351 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
356 errorCounter->Increment();
358 // errorCounter->Print();
359 } // end of if (!errorCount)
360 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
363 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
366 // Fatal errors reject the event
367 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
370 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
371 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
372 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
376 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
377 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
378 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
381 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
382 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
383 <<" Parity "<<eventParityErrors
384 <<" Padding "<<eventPaddingErrors<<endl;
386 } // end of if (!rawStream->IsErrorMessage())
388 if (eventGlitchErrors) nGlitchErrors++;
389 if (eventParityErrors) nParityErrors++;
390 if (eventPaddingErrors) nPaddingErrors++;
392 } // while (rawReader->NextEvent())
396 sprintf(flatFile,"%s.ped",prefixDA);
397 if(shuttleFile.IsNull())shuttleFile=flatFile;
398 muonPedestal->SetAliNEvents(nEvents);
399 muonPedestal->SetAliRunNumber(runNumber);
400 muonPedestal->SetAliNChannel(nChannel);
401 muonPedestal->MakePedStore(shuttleFile);
403 // writing some counters
405 cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
406 cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
407 cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
408 cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
409 cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
410 cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
411 cout << prefixDA << " : Nb of events used = " << nEvents << endl;
414 filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
415 filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
416 filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
417 filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
418 filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
419 filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
420 filcout << prefixDA << " : Nb of events used = " << nEvents << endl;
424 cout << prefixDA << " : Output logfile : " << logOutputFile << endl;
425 cout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
426 cout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
429 filcout << prefixDA << " : Output logfile : " << logOutputFile << endl;
430 filcout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
431 filcout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
433 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
435 dir= getenv("DAQ_DETDB_LOCAL");
436 unsigned int nLastVersions=90;
437 cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl;
438 status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
439 // if (!status) printf(" Failed to store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
440 printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
441 status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
442 // if (!status) printf(" Failed to store file : %s status = %d\n",shuttleFile.Data(),status);
443 printf(" Store file : %s status = %d\n",shuttleFile.Data(),status);
444 status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
445 // if (!status) printf(" Failed to store file : %s status = %d\n",logOutputFile.Data(),status);
446 printf(" Store file : %s status = %d\n",logOutputFile.Data(),status);
448 // Transferring to OCDB via the SHUTTLE
449 printf("\n ***** STORE FILE in FES ****** \n");
451 // be sure that env variable DAQDALIB_PATH is set in script file
452 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
454 status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
457 printf(" Failed to export file : %d\n",status);
459 else printf(" %s successfully exported to FES \n",shuttleFile.Data());
463 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());