63 #include <Riostream.h>
71 #include "AliRawReader.h"
77 #include "AliRawDataErrorLog.h"
89 #include "TStopwatch.h"
91 #include "TTimeStamp.h"
92 #include "TGraphErrors.h"
95 #include "TPluginManager.h"
97 #include "TObjString.h"
98 #include "THashTable.h"
99 #include <THashList.h>
112 int main(Int_t argc,
const char** argv)
114 Int_t status=0 , status1=0 ;
118 const char* prefixDA =
"MUONTRKGAINda";
119 const char* prefixLDC = getenv(
"DATE_ROLE_NAME");
120 if(prefixLDC == NULL) prefixLDC =
"MCH" ;
121 printf(
"%s : -------- Begin execution : %s -------- \n",prefixLDC,prefixDA);
128 if (argc!=2) {
printf(
"Wrong number of arguments\n");
return -1; }
133 gROOT->GetPluginManager()->AddHandler(
"TVirtualStreamerInfo",
139 gROOT->GetPluginManager()->AddHandler(
"ROOT::Math::Minimizer",
143 "TMinuitMinimizer(const char*)");
144 Int_t skipEvents = 0;
145 Int_t maxEvents = 1000000;
146 Int_t maxDateEvents = 1000000;
147 Int_t errorDetail = 0;
149 Int_t nDateEvents = 0;
150 Int_t nDateRejEvents = 0;
151 Int_t nGlitchErrors= 0;
152 Int_t nParityErrors= 0;
153 Int_t nPaddingErrors= 0;
154 Int_t nTokenlostErrors= 0;
155 Int_t nEventsRecovered = 0;
157 Int_t nEvthreshold = 50;
160 TString logOutputFile;
162 Char_t flatFile[256]=
"";
165 UInt_t runNumber = 0;
170 Int_t nEntries = daqDA_ECS_getTotalIteration();
179 nIndex = daqDA_ECS_getCurrentIteration();
180 if(nIndex<0 || nIndex>nEntries) {
printf(
"\n Failed: nIndex = %d\n",nIndex);
return -1 ;}
190 sprintf(flatFile,
"%s.log",prefixDA);
191 logOutputFile=flatFile;
192 AliLog::SetStreamOutput(&filcout);
193 filcout.open(logOutputFile.Data());
194 filcout<<
"//=================================================" << endl;
195 filcout<<
"//" << prefixLDC <<
" " << prefixDA << endl;
196 filcout<<
"//=================================================" << endl;
197 filcout<<
"// * Date : " << muonGain->
GetDate()->AsString(
"l") <<
"\n" << endl;
200 cout<<prefixLDC <<
" : Date: " << muonGain->
GetDate()->AsString(
"l") <<
"\n" << endl;
212 Char_t dbfile[256]=
"";
215 sprintf(dbfile,
"mutrkcalibvalues");
216 status=daqDA_DB_getFile(dbfile,dbfile);
217 if(status) {
printf(
" Failed : input file %s is missing, status = %d\n",dbfile,status);
return -1; }
219 ifstream filein(dbfile,ios::in); Int_t k=0, kk;
220 while (k<nEntries ) { filein >> kk >> vDAC[k] ; k++; }
221 injCharge=vDAC[nIndex-1];
223 filein >> line >> nInit ; cout <<
"mutrkcalibvalues: " << line << nInit <<
" " ;
224 filein >> line >> nbpf1; cout << line << nbpf1 <<
" " ;
225 filein >> line >>
printLevel; cout << line << printLevel <<
" " ;
226 filein >> line >> plotLevel; cout << line << plotLevel <<
" " ;
227 filein >> line >> nConfig ; cout << line << nConfig <<
" " ;
228 filein >> line >> nEvthres ;
if(nEvthres !=0)nEvthreshold=nEvthres; cout << line << nEvthreshold <<
" " ;
229 filein >> line >> nbev ;
if(nbev !=0){maxEvents=nbev; cout << line << maxEvents <<
" " ;}
240 sprintf(dbfile,
"config_%s",getenv(
"DATE_ROLE_NAME"));
241 status=daqDA_DB_getFile(dbfile,dbfile);
242 if(status) {
printf(
" Failed : Configuration file %s is missing, status = %d\n",dbfile,status);
return -1; }
248 AliRawReader* rawReader = AliRawReader::Create(inputFile.Data());
251 rawStream->EnabbleErrorLogger();
260 printf(
"\n%s : Reading data from file %s\n",prefixLDC,inputFile.Data());
262 Int_t tabTokenError[20][14];
263 for ( Int_t i=0 ; i<20 ; i++) {
for ( Int_t j=0 ; j<14 ; j++) { tabTokenError[i][j]=0;} }
265 while (rawReader->NextEvent())
267 Int_t eventType = rawReader->GetType();
268 runNumber = rawReader->GetRunNumber();
269 if(nDateEvents==0) { filcout<<
"// ----> RUN = " << runNumber <<
"\n" << endl;}
270 if (nDateEvents >= maxDateEvents)
break;
271 if (nEvents >= maxEvents)
break;
272 if (nDateEvents>0 && nDateEvents % 100 == 0)
273 cout<< prefixLDC <<
" : DATE events = " << nDateEvents <<
" Used events = " << nEvents << endl;
276 if (daqDA_checkShutdown())
281 rawReader->NextEvent();
285 if (eventType != PHYSICS_EVENT)
288 const char* detail =
"";
291 Bool_t eventIsErrorMessage = kFALSE;
292 int eventGlitchErrors = 0;
293 int eventParityErrors = 0;
294 int eventPaddingErrors = 0;
295 int eventTokenlostErrors = 0;
299 if (rawStream->IsErrorMessage()) eventIsErrorMessage = kTRUE;
300 eventGlitchErrors += rawStream->GetGlitchErrors();
301 eventParityErrors += rawStream->GetParityErrors();
302 eventPaddingErrors += rawStream->GetPaddingErrors();
303 eventTokenlostErrors += rawStream->GetTokenLostErrors();
304 if (rawStream->GetTokenLostErrors())
309 Int_t nBlock = rawStream->GetBlockCount();
310 for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++)
312 blkHeader = rawStream->GetBlockHeader(iBlock);
316 for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++)
322 Int_t ddl = rawStream->GetDDL() ;
324 Int_t frt = (dspHeader->
GetErrorWord() & 0xFFFF0000) >> 16 ;
325 tabTokenError[ddl][frt]++;
332 }
while(rawStream->NextDDL());
335 if (!eventIsErrorMessage)
343 for(
int i = 0; i < busPatch->
GetLength(); ++i)
345 busPatch->
GetData(i, manuId, channelId, charge);
353 if (eventParityErrors && !eventGlitchErrors&& !eventPaddingErrors)
355 filcout <<
" ----------- Date Event recovered = " << nDateEvents <<
" ----------------" << endl;
357 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
360 filcout <<
"Event recovered -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
361 <<
" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
362 <<
" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
366 filcout <<
"Event recovered -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
367 <<
" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
368 <<
" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
377 for(
int i = 0; i < busPatch->
GetLength(); ++i)
384 for(
int i = 0; i < busPatch->
GetLength(); ++i)
386 busPatch->
GetData(i, manuId, channelId, charge);
396 <<
" parity errors "<<errorCount<<endl;
403 errorCounter->SetName(bpname);
420 detail = Form(
" ----------- Date Event rejected = %d ----------------",nDateEvents);
422 filcout << detail << endl;
423 if ( TEST_SYSTEM_ATTRIBUTE( rawReader->GetAttributes(),
426 filcout <<
"Event rejected -> Period:"<<EVENT_ID_GET_PERIOD( rawReader->GetEventId() )
427 <<
" Orbit:"<<EVENT_ID_GET_ORBIT( rawReader->GetEventId() )
428 <<
" BunchCrossing:"<<EVENT_ID_GET_BUNCH_CROSSING( rawReader->GetEventId() )<<endl;
432 filcout <<
"Event rejected -> nbInRun:"<<EVENT_ID_GET_NB_IN_RUN( rawReader->GetEventId() )
433 <<
" burstNb:"<<EVENT_ID_GET_BURST_NB( rawReader->GetEventId() )
434 <<
" nbInBurst:"<<EVENT_ID_GET_NB_IN_BURST( rawReader->GetEventId() )<<endl;
438 filcout<<
"Number of errors : Glitch "<<eventGlitchErrors
439 <<
" Parity "<<eventParityErrors
440 <<
" Padding "<<eventPaddingErrors
441 <<
" Token lost "<<eventTokenlostErrors<<endl;
445 if (eventGlitchErrors) nGlitchErrors++;
446 if (eventParityErrors) nParityErrors++;
447 if (eventPaddingErrors) nPaddingErrors++;
455 sprintf(flatFile,
"%s.par",prefixDA);
456 if(shuttleFile.IsNull())shuttleFile=flatFile;
457 injCharge=vDAC[nIndex-1];
465 detail=Form(
"\n%s : Nb of DATE events = %d",prefixLDC,nDateEvents) ; cout << detail; filcout << detail ;
466 detail=Form(
"\n%s : Nb of Glitch errors = %d",prefixLDC,nGlitchErrors) ; cout << detail; filcout << detail ;
467 detail=Form(
"\n%s : Nb of Parity errors = %d",prefixLDC,nParityErrors) ; cout << detail; filcout << detail ;
468 detail=Form(
"\n%s : Nb of Token lost errors = %d",prefixLDC,nTokenlostErrors) ; cout << detail; filcout << detail ;
469 detail=Form(
"\n%s : Nb of Rejected DATE events = %d",prefixLDC,nDateRejEvents) ; cout << detail; filcout << detail ;
470 detail=Form(
"\n%s : Nb of recovered events = %d",prefixLDC,nEventsRecovered) ; cout << detail; filcout << detail ;
471 detail=Form(
"\n%s : Nb of events without errors = %d",prefixLDC,nEvents-nEventsRecovered) ; cout << detail; filcout << detail ;
472 detail=Form(
"\n%s : Nb of used events = %d (threshold= %d)\n\n",prefixLDC,nEvents,nEvthreshold); cout << detail; filcout << detail ;
477 char* detail=Form(
"\nWarning: Token Lost occurence \n");
480 for ( Int_t i=0 ; i<20 ; i++)
482 for ( Int_t j=4 ; j<14 ; j++)
484 if(tabTokenError[i][j]>0)
486 Int_t tab=tabTokenError[i][j];
488 Int_t station = i/4 +1;
489 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);
490 else detail=Form(
" in DDL= %d (station %d) and FRT%d (Down) => %d Token errors (address = 0x%X0000)",2560+i,station,frt,tab,j);
492 filcout << detail << endl;
509 detail=Form(
"%s : Root data file : %s\n",prefixLDC,muonGain->
GetRootDataFileName()); filcout << detail ;
510 detail=Form(
"%s : Output logfile : %s\n",prefixLDC,logOutputFile.Data()); filcout << detail ;
511 detail=Form(
"%s : Gain Histo file : %s\n",prefixLDC,muonGain->
GetHistoFileName()); filcout << detail ;
512 detail=Form(
"%s : Gain file (to SHUTTLE) : %s\n",prefixLDC,shuttleFile.Data()); filcout << detail ;
516 unsigned int nLastVersions=50;
517 dir= getenv(
"DAQ_DETDB_LOCAL");
519 unsigned int nLastVersions=50;
520 printf(
"\n%s : --- Local DataBase: %s (Max= %d) ---\n",prefixLDC,dir,nLastVersions);
521 status1 = daqDA_localDB_storeFile(logOutputFile.Data(),nLastVersions);
526 status1 = daqDA_localDB_storeFile(muonGain->
GetHistoFileName(),nLastVersions);
527 status1 = daqDA_localDB_storeFile(shuttleFile.Data(),nLastVersions);
534 status1 = daqDA_FES_storeFile(shuttleFile.Data(),
"GAINS");
535 if (status1) { detail=Form(
"%s: !!! ERROR: Failed to export calibration file : %s to FES \n",prefixLDC,shuttleFile.Data());
536 printf(
"%s",detail); filcout << detail ; status= -1; }
542 std::ifstream in(shuttleFile.Data());
543 ostringstream stringout;
545 while ( in.getline(line,1024) )
546 stringout << line <<
"\n";
549 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
550 TObjString gaindata(stringout.str().c_str());
551 Int_t amoreStatus = amoreDA.Send(
"Gains",&gaindata);
553 {cout << prefixLDC <<
" : !!! ERROR: Failed to write Gains in the AMORE database : " << amoreStatus << endl ; status=-1 ;}
555 cout << prefixLDC <<
" : amoreDA.Send(Gains) ok" << endl;
557 cout << prefixLDC <<
" : Warning: MCH DA not compiled with AMORE support" << endl;
561 if(!status)
printf(
"\n%s : -------- End execution : %s -------- (status= %d) \n",prefixLDC,prefixDA,status);
562 else {
printf(
"\n%s : -------- %s ending in ERROR !!!! -------- (status= %d) \n",prefixLDC,prefixDA,status);}
565 printf(
"\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
A high performance stream decoder for muon tracking DDL streams.
Int_t GetStatusDA() const
get DA status (return code)
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TTimeStamp * GetDate() const
return date and time
Logs a medium level of detail in the error messages.
void Increment()
Increment nb of erroneous event.
int main(Int_t argc, const char **argv)
void SetAliIndex(Int_t ind)
set the index of calibration runs
void SetAliInjCharge(Int_t charge)
Set InjCharge = DAC value.
void SetAliRunNumber(Int_t run)
return the Run number
Int_t GetLength() const
Return length of raw data.
const char * GetHistoFileName() const
return the name of DAPedestal .root file
const char * GetRootDataFileName() const
Get filename of root file containing pedmean and sigma values.
void SetconfigDA(Int_t ind)
set config flag
void SetprefixDA(const char *folder)
set specific DA prefixname
void MakePedStoreForGain(TString flatfile)
Store Pedmean and sigma in pedestal-like ascii file.
void MakeGainStore(TString flatfile)
Computes gain parameters and store in an ascii file.
void SetAliRootDataFileName(const char *name="MUONTRKGAINda_data.root")
Set filename of root file containing pedmean and sigma values for each DAC value. ...
void SetAlifilcout(ofstream *stream)
output .log file of DAs
void SetAliNEvents(Int_t events)
return the number of events
Bool_t IsParityOk(UInt_t n) const
void SetAliNCurrentEvents(Int_t events)
return the number of current events
Int_t GetBusPatchId() const
Return bus patch id.
const UInt_t * GetData() const
Return raw digit data.
void SetAliPlotLevel(Int_t plo)
Set PlotLevel.
Implementation of the pedestal and gain computing.
void SetprefixLDC(const char *folder)
set specific LDC prefixname
Logs minimal information in the error messages.
void LoadConfig(const char *dbfile)
load MuonTrk configuration from ascii dbfile
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
void SetAliPrintLevel(Int_t pri)
Set PrintLevel.
void SetAliInit(Int_t ini)
Set fnInit (=1: first DAC=0 removed to compute the fit)
Light weight interface class to the bus patch data.
AliMUONVStore * GetErrorBuspatchTable() const
Count parity errors per Buspatch.
void SetAliNbpf1(Int_t nf1)
Set Nbpf1 = nb of DAC values for the linear fit.
void MakePed(Int_t bp, Int_t manu, Int_t ch, Int_t charge)
sum pedestal values for mean and sigma determination
void SetStatusDA(Int_t ind)
set DA status (return code)
Declaration of the high performance decoder for muon trigger chamber raw streams. ...
const AliBusPatch * Next() const
Return the next bus patch header.
void SetnEvthreshold(Int_t ind)
set Nb of evt threshold to calculate pedestal
virtual TObject * FindObject(const char *name) const
Find an object by name.
void SetAliEntries(Int_t ent)
Set nEntries = Nb of DAC values.