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>
92 #include "AliMUONPedestal.h"
93 #include "AliMUONErrorCounter.h"
97 int main(Int_t argc, Char_t **argv)
104 // needed for streamer application
105 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
111 // needed for Minuit plugin
112 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
116 "TMinuitMinimizer(const char*)");
118 Char_t prefixDA[256]="MUONTRKPEDda"; // program prefix
121 Int_t skipEvents = 0;
122 Int_t maxEvents = 1000000;
123 Int_t maxDateEvents = 1000000;
124 Char_t inputFile[256]="";
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;
142 // Int_t nIndex = -1;
144 // decode the input line
145 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
152 // If only one argument and no "-" => DA calling from ECS
155 sprintf(inputFile,argv[i]);
163 sprintf(inputFile,argv[i]);
167 shuttleFile = argv[i];
171 skipEvents=atoi(argv[i]);
175 sscanf(argv[i],"%d",&maxDateEvents);
179 sscanf(argv[i],"%d",&maxEvents);
183 // sscanf(argv[i],"%d",&recoverParityErrors);
187 printf("\n******************* %s usage **********************",argv[0]);
188 printf("\nOnline (called from ECS) : %s <raw data file> (no inline options)\n",argv[0]);
189 printf("\n%s -options, the available options are :",argv[0]);
190 printf("\n-h help (this screen)");
193 printf("\n-f <raw data file> (default = %s)",inputFile);
196 printf("\n-a <Flat ASCII file> (default = %s)",shuttleFile.Data());
198 printf("\n Options");
199 printf("\n-m <max date events> (default = %d)",maxDateEvents);
200 printf("\n-s <skip events> (default = %d)",skipEvents);
201 printf("\n-n <max events> (default = %d)",maxEvents);
202 // printf("\n-p <Recover parity errors> (default = %d)",recoverParityErrors);
207 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
208 argc = 2; exit(-1); // exit if error
212 // decoding the events
219 AliMUONPedestal* muonPedestal = new AliMUONPedestal();
220 muonPedestal->SetprefixDA(prefixDA);
222 // Rawdeader, RawStreamHP
223 AliRawReader* rawReader = AliRawReader::Create(inputFile);
224 AliMUONRawStreamTrackerHP* rawStream = new AliMUONRawStreamTrackerHP(rawReader);
225 rawStream->DisableWarnings();
226 rawStream->EnabbleErrorLogger();
228 cout << "\n" << prefixDA << " : Reading data from file " << inputFile << endl;
230 while (rawReader->NextEvent())
232 if (nDateEvents >= maxDateEvents) break;
233 if (nEvents >= maxEvents) break;
234 if (nDateEvents>0 && nDateEvents % 100 == 0)
235 cout<<"Cumulated: DATE events = " << nDateEvents << " Used events = " << nEvents << endl;
237 // check shutdown condition
238 if (daqDA_checkShutdown())
244 rawReader->NextEvent();
248 Int_t eventType = rawReader->GetType();
249 runNumber = rawReader->GetRunNumber();
251 // Output log file initialisations
254 sprintf(flatFile,"%s.log",prefixDA);
255 logOutputFile=flatFile;
257 filcout.open(logOutputFile.Data());
258 filcout<<"//=================================================" << endl;
259 filcout<<"// " << prefixDA << " for run = " << runNumber << endl;
260 filcout<<"//=================================================" << endl;
261 filcout<<"// * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
262 cout<<"\n ******** " << prefixDA << " for run = " << runNumber << " ********\n" << endl;
263 cout<<" * Date : " << muonPedestal->GetDate()->AsString("l") << "\n" << endl;
267 muonPedestal->SetAlifilcout(&filcout);
270 if (eventType != PHYSICS_EVENT)
271 continue; // for the moment
273 // First lopp over DDL's to find good events
274 // Error counters per event (counters in the decoding lib are for each DDL)
275 Bool_t eventIsErrorMessage = kFALSE;
276 int eventGlitchErrors = 0;
277 int eventParityErrors = 0;
278 int eventPaddingErrors = 0;
282 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
283 eventGlitchErrors += rawStream->GetGlitchErrors();
284 eventParityErrors += rawStream->GetParityErrors();
285 eventPaddingErrors += rawStream->GetPaddingErrors();
286 } while(rawStream->NextDDL());
288 AliMUONRawStreamTrackerHP::AliBusPatch* busPatch;
289 if (!eventIsErrorMessage)
291 // Good events (no error) -> compute pedestal for all channels
293 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
295 for(int i = 0; i < busPatch->GetLength(); ++i)
297 if (nEvents == 0) nChannel++;
298 busPatch->GetData(i, manuId, channelId, charge);
299 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
306 // Events with errors
307 if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
309 // Recover parity errors -> compute pedestal for all good buspatches
310 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
313 filcout <<"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
314 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
315 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
319 filcout <<"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
320 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
321 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
324 while( (busPatch = (AliMUONRawStreamTrackerHP::AliBusPatch*) rawStream->Next()))
326 // Check the buspatch -> if error not use it in the pedestal calculation
328 for(int i = 0; i < busPatch->GetLength(); ++i)
330 if (!busPatch->IsParityOk(i)) errorCount++;
335 for(int i = 0; i < busPatch->GetLength(); ++i)
337 if (nEvents == 0) nChannel++;
338 busPatch->GetData(i, manuId, channelId, charge);
339 // if (busPatch->GetBusPatchId()==1719 && manuId == 1 && channelId == 0) cout <<"Recovered charge "<<charge<<endl;
340 muonPedestal->MakePed(busPatch->GetBusPatchId(), (Int_t)manuId, (Int_t)channelId, (Int_t)charge);
346 AliMUONErrorCounter* errorCounter;
347 // Bad buspatch -> not used (just print)
348 filcout<<"bpId "<<busPatch->GetBusPatchId()<<" words "<<busPatch->GetLength()
349 <<" parity errors "<<errorCount<<endl;
350 // Number of events where this buspatch is missing
351 sprintf(bpname,"bp%d",busPatch->GetBusPatchId());
352 if (!(errorCounter = (AliMUONErrorCounter*) (muonPedestal->GetErrorBuspatchTable()->FindObject(bpname))))
355 errorCounter = new AliMUONErrorCounter(busPatch->GetBusPatchId());
356 errorCounter->SetName(bpname);
357 muonPedestal->GetErrorBuspatchTable()->Add(errorCounter);
362 errorCounter->Increment();
364 // errorCounter->Print();
365 } // end of if (!errorCount)
366 } // end of while( (busPatch = (AliMUONRawStreamTrackerHP ...
369 } //end of if (recoverParityErrors && eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
372 // Fatal errors reject the event
373 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
376 filcout <<"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
377 <<" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
378 <<" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
382 filcout <<"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
383 <<" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
384 <<" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
387 } // end of if (!rawStream->GetGlitchErrors() && !rawStream->GetPaddingErrors() ...
388 filcout<<"Number of errors : Glitch "<<eventGlitchErrors
389 <<" Parity "<<eventParityErrors
390 <<" Padding "<<eventPaddingErrors<<endl;
392 } // end of if (!rawStream->IsErrorMessage())
394 if (eventGlitchErrors) nGlitchErrors++;
395 if (eventParityErrors) nParityErrors++;
396 if (eventPaddingErrors) nPaddingErrors++;
398 } // while (rawReader->NextEvent())
402 sprintf(flatFile,"%s.ped",prefixDA);
403 if(shuttleFile.IsNull())shuttleFile=flatFile;
404 muonPedestal->SetAliNEvents(nEvents);
405 muonPedestal->SetAliRunNumber(runNumber);
406 muonPedestal->SetAliNChannel(nChannel);
408 muonPedestal->Finalize();
409 muonPedestal->MakeControlHistos();
410 if (!shuttleFile.IsNull())
412 ofstream out(shuttleFile.Data());
413 muonPedestal->MakeASCIIoutput(out);
417 //Send objects to the AMORE DB
419 ostringstream stringout;
420 muonPedestal->MakeASCIIoutput(stringout);
422 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
423 TObjString peddata(stringout.str().c_str());
425 status = amoreDA.Send("Pedestals",&peddata);
427 cout << "Warning: Failed to write Pedestals in the AMORE database : " << status << endl;
429 cout << "amoreDA.Send(Pedestals) ok" << endl;
431 cout << "Warning: MCH DA not compiled with AMORE support" << endl;
436 // writing some counters
438 cout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
439 cout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
440 cout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
441 cout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
442 cout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
443 cout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
444 cout << prefixDA << " : Nb of events used = " << nEvents << endl;
447 filcout << prefixDA << " : Nb of DATE events = " << nDateEvents << endl;
448 filcout << prefixDA << " : Nb of Glitch errors = " << nGlitchErrors << endl;
449 filcout << prefixDA << " : Nb of Parity errors = " << nParityErrors << endl;
450 filcout << prefixDA << " : Nb of Padding errors = " << nPaddingErrors << endl;
451 filcout << prefixDA << " : Nb of events recovered = " << nEventsRecovered<< endl;
452 filcout << prefixDA << " : Nb of events without errors = " << nEvents-nEventsRecovered<< endl;
453 filcout << prefixDA << " : Nb of events used = " << nEvents << endl;
457 cout << prefixDA << " : Output logfile : " << logOutputFile << endl;
458 cout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
459 cout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
462 filcout << prefixDA << " : Output logfile : " << logOutputFile << endl;
463 filcout << prefixDA << " : Pedestal Histo file : " << muonPedestal->GetHistoFileName() << endl;
464 filcout << prefixDA << " : Ped. file (to SHUTTLE) : " << shuttleFile << endl;
466 // Copying files to local DB folder defined by DAQ_DETDB_LOCAL
468 dir= getenv("DAQ_DETDB_LOCAL");
469 unsigned int nLastVersions=90;
470 cout << "\n *** Local DataBase: " << dir << " (Max= " << nLastVersions << ") ***" << endl;
471 status = daqDA_localDB_storeFile(muonPedestal->GetHistoFileName(),nLastVersions);
472 // if (!status) printf(" Failed to store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
473 printf(" Store file : %s status = %d\n",muonPedestal->GetHistoFileName(),status);
474 status = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
475 // if (!status) printf(" Failed to store file : %s status = %d\n",shuttleFile.Data(),status);
476 printf(" Store file : %s status = %d\n",shuttleFile.Data(),status);
477 status = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
478 // if (!status) printf(" Failed to store file : %s status = %d\n",logOutputFile.Data(),status);
479 printf(" Store file : %s status = %d\n",logOutputFile.Data(),status);
481 // Transferring to OCDB via the SHUTTLE
482 printf("\n ***** STORE FILE in FES ****** \n");
484 // be sure that env variable DAQDALIB_PATH is set in script file
485 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
487 status = daqDA_FES_storeFile(shuttleFile.Data(),"PEDESTALS");
490 printf(" Failed to export file : %d\n",status);
492 else printf(" %s successfully exported to FES \n",shuttleFile.Data());
496 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());