]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSPDErrorLog.cxx
Updating example reco macro for real data
[u/mrichter/AliRoot.git] / ITS / AliITSRawStreamSPDErrorLog.cxx
1 ///////////////////////////////////////////////////////////////////////
2 // Author: Henrik Tydesjo                                            //
3 // For easier handling of error messages from AliITSRawStreamSPD.    //
4 // The purpose of this class is to make possible the switch to the   //
5 // AliRoot raw data parsing routines in the onlinte monitoring       //
6 // programs, like SPD-MOOD, and still keep all the old functionality.//
7 ///////////////////////////////////////////////////////////////////////
8
9 #include "AliITSRawStreamSPDErrorLog.h"
10 #include "AliLog.h"
11
12 /* $Id$ */
13
14 ClassImp(AliITSRawStreamSPDErrorLog)
15 //________________________________________________________________________________________________
16 AliITSRawStreamSPDErrorLog::AliITSRawStreamSPDErrorLog() :
17   fText(NULL), fTextTmpGeneral(NULL)
18 {
19   // default constructor
20   fText=new TGText();
21   fTextTmpGeneral=new TGText();
22   for (UInt_t eq=0; eq<20; eq++) {
23     fTextTmp[eq] = new TGText();
24     fNEvents[eq] = 0;
25     fByteOffset[eq] = 0;
26     fSuppressEq[eq] = kFALSE;
27     for (UInt_t err=0; err<kNrErrorCodes; err++) {
28       fNErrors[err][eq] = 0;
29       fNErrorsTotal[err][eq] = 0;
30     }
31   }
32   for (UInt_t err=0; err<kNrErrorCodes; err++) {
33     fSuppressMess[err] = kFALSE;
34   }
35   InitHistograms();
36 }
37 //________________________________________________________________________________________________
38 AliITSRawStreamSPDErrorLog::AliITSRawStreamSPDErrorLog(const AliITSRawStreamSPDErrorLog& logger) :
39   TObject(logger), fText(NULL), fTextTmpGeneral(NULL)
40 {
41   // copy constructor
42   for (UInt_t eq=0; eq<20; eq++) {
43     for (UInt_t err=0; err<kNrErrorCodes; err++) {
44       fNErrors[err][eq] = logger.fNErrors[err][eq];
45       fNErrorsTotal[err][eq] = logger.fNErrorsTotal[err][eq];
46       fErrEventCounter[err][eq] = logger.fErrEventCounter[err][eq];
47     }
48     fNEvents[eq] = logger.fNEvents[eq];
49     fByteOffset[eq] = logger.fByteOffset[eq];
50     fSuppressEq[eq] = logger.fSuppressEq[eq];
51   }
52   for (UInt_t err=0; err<kNrErrorCodes; err++) {
53     fSuppressMess[err] = logger.fSuppressMess[err];
54   }
55   
56   fText = new TGText(logger.fText);
57   fTextTmpGeneral = new TGText(logger.fTextTmpGeneral);
58   for (UInt_t eq=0; eq<20; eq++) {
59     fTextTmp[eq] = new TGText(logger.fTextTmp[eq]);
60   }
61   
62   for (UInt_t eq=0; eq<20; eq++) {
63     for (UInt_t err=0; err<kNrErrorCodes; err++) {
64       fConsErrEvent[err][eq] = new TGraph(*logger.fConsErrEvent[err][eq]);
65       fConsErrPos[err][eq] = new TGraph(*logger.fConsErrPos[err][eq]);
66     }
67     fConsErrType[eq] = new TH1F(*logger.fConsErrType[eq]);
68     fConsErrFraction[eq] = new TH1F(*logger.fConsErrFraction[eq]);
69   }
70   
71 }
72 //________________________________________________________________________________________________
73 AliITSRawStreamSPDErrorLog& AliITSRawStreamSPDErrorLog::operator=(const AliITSRawStreamSPDErrorLog& logger) {
74   // assignment operator
75   if (this!=&logger) {
76     delete fText;
77     delete fTextTmpGeneral;
78     delete[] fTextTmp;
79     this->DeleteHistograms();
80
81     for (UInt_t eq=0; eq<20; eq++) {
82       for (UInt_t err=0; err<kNrErrorCodes; err++) {
83         fNErrors[err][eq] = logger.fNErrors[err][eq];
84         fNErrorsTotal[err][eq] = logger.fNErrorsTotal[err][eq];
85         fErrEventCounter[err][eq] = logger.fErrEventCounter[err][eq];
86       }
87       fNEvents[eq] = logger.fNEvents[eq];
88       fByteOffset[eq] = logger.fByteOffset[eq];
89       fSuppressEq[eq] = logger.fSuppressEq[eq];
90     }
91     for (UInt_t err=0; err<kNrErrorCodes; err++) {
92       fSuppressMess[err] = logger.fSuppressMess[err];
93     }
94
95     fText = new TGText(logger.fText);
96     fTextTmpGeneral = new TGText(logger.fTextTmpGeneral);
97     for (UInt_t eq=0; eq<20; eq++) {
98       fTextTmp[eq] = new TGText(logger.fTextTmp[eq]);
99     }
100     
101     for (UInt_t eq=0; eq<20; eq++) {
102       for (UInt_t err=0; err<kNrErrorCodes; err++) {
103         fConsErrEvent[err][eq] = new TGraph(*logger.fConsErrEvent[err][eq]);
104         fConsErrPos[err][eq] = new TGraph(*logger.fConsErrPos[err][eq]);
105       }
106       fConsErrType[eq] = new TH1F(*logger.fConsErrType[eq]);
107       fConsErrFraction[eq] = new TH1F(*logger.fConsErrFraction[eq]);
108     }
109
110   }
111   return *this;
112   
113 }
114 //________________________________________________________________________________________________
115 AliITSRawStreamSPDErrorLog::~AliITSRawStreamSPDErrorLog() {
116   // destructor
117   DeleteHistograms();
118   delete fText;
119   delete fTextTmpGeneral;
120   delete[] fTextTmp;
121 }
122 //________________________________________________________________________________________________
123 void AliITSRawStreamSPDErrorLog::InitHistograms() {
124   // initialize histograms
125   for (UInt_t eq=0; eq<20; eq++) {
126     TString histName, histTitle;
127     histName = Form("ConsErrType %d",eq);
128     histTitle = Form("Distribution of errors, eq %d",eq);
129     fConsErrType[eq]=new TH1F(histName.Data(),histTitle.Data(),kNrErrorCodes,-0.5,kNrErrorCodes-0.5);
130     fConsErrType[eq]->SetXTitle("Error Code");
131     fConsErrType[eq]->SetYTitle("Nr Errors");
132     
133     histName = Form("ConsErrFraction %d",eq);
134     histTitle = Form("Fraction of events with errors, eq %d",eq);
135     fConsErrFraction[eq]=new TH1F(histName.Data(),histTitle.Data(),kNrErrorCodes,-0.5,kNrErrorCodes-0.5);
136     fConsErrFraction[eq]->SetXTitle("Error Code");
137     fConsErrFraction[eq]->SetYTitle("Fraction");
138     
139     for (UInt_t err=0; err<kNrErrorCodes; err++) {
140       fConsErrEvent[err][eq]=new TGraph();
141       fConsErrPos[err][eq]=new TGraph();
142       fConsErrPosTMP[err][eq]=new TGraph();
143       fErrEventCounter[err][eq] = 0;
144       fErrPosCounter[err][eq] = 0;
145       fErrPosTMPCounter[err][eq] = 0;
146     }
147   }
148 }
149 //________________________________________________________________________________________________
150 void AliITSRawStreamSPDErrorLog::DeleteHistograms() const {
151   // delete histograms
152   for (UInt_t eq=0; eq<20; eq++) {
153     delete fConsErrType[eq];
154     delete fConsErrFraction[eq];
155     for (UInt_t err=0; err<kNrErrorCodes; err++) {
156       delete fConsErrEvent[err][eq];
157       delete fConsErrPos[err][eq];
158       delete fConsErrPosTMP[err][eq];
159     }
160   }
161 }
162 //________________________________________________________________________________________________
163 void AliITSRawStreamSPDErrorLog::Reset() {
164   // Reset
165   fText->Clear();
166   fTextTmpGeneral->Clear();
167   for (UInt_t eq=0; eq<20; eq++) {
168     fTextTmp[eq]->Clear();
169     fConsErrType[eq]->Reset();
170     fConsErrFraction[eq]->Reset();
171     fNEvents[eq] = 0;
172     for (UInt_t err=0; err<kNrErrorCodes; err++) {
173       fNErrors[err][eq] = 0;
174       fNErrorsTotal[err][eq] = 0;
175       delete fConsErrEvent[err][eq];
176       delete fConsErrPos[err][eq];
177       delete fConsErrPosTMP[err][eq];
178       fErrEventCounter[err][eq] = 0;
179       fErrPosCounter[err][eq] = 0;
180       fErrPosTMPCounter[err][eq] = 0;
181       fConsErrEvent[err][eq] = new TGraph();
182       fConsErrPos[err][eq] = new TGraph();
183       fConsErrPosTMP[err][eq] = new TGraph();
184     }
185   }
186 }
187 //________________________________________________________________________________________________
188 void AliITSRawStreamSPDErrorLog::ProcessError(UInt_t errorCode, UInt_t eq, Int_t bytesRead, Int_t headersRead, const Char_t *errMess) {
189   // Process an error
190   if (eq>=20) {
191     AliWarning(Form("Equipment number (%d) out of bounds",eq));
192     return;
193   }
194   // check if we want to exclude the error...
195   if (!(fSuppressMess[errorCode] || fSuppressEq[eq])) {
196     fNErrors[errorCode][eq]++;
197     fNErrorsTotal[errorCode][eq]++;
198     if (errorCode!=kTotal) {
199       fNErrors[kTotal][eq]++;
200       fNErrorsTotal[kTotal][eq]++;
201     }
202
203     if (bytesRead>=0) {
204       fConsErrPosTMP[errorCode][eq]->SetPoint(fErrPosTMPCounter[errorCode][eq],0,bytesRead+fByteOffset[eq]);
205       fErrPosTMPCounter[errorCode][eq]++;
206       if (errorCode!=kTotal) {
207         fConsErrPosTMP[kTotal][eq]->SetPoint(fErrPosTMPCounter[kTotal][eq],0,bytesRead+fByteOffset[eq]);
208         fErrPosTMPCounter[kTotal][eq]++;
209       }
210     }
211
212     TString msg;
213     if (bytesRead<0) {
214       msg = Form("%s",errMess);
215     }
216     else {
217       msg = Form("%s (%d bytes read, %d chip headers read)",errMess,bytesRead+fByteOffset[eq],headersRead);
218     }
219     fTextTmp[eq]->InsLine(fTextTmp[eq]->RowCount(),msg.Data());
220   }
221 }
222 //________________________________________________________________________________________________
223 void AliITSRawStreamSPDErrorLog::AddMessage(const Char_t *errMess) {
224   // add a general message to the buffer
225   fTextTmpGeneral->InsLine(fTextTmpGeneral->RowCount(),errMess);
226 }
227 //________________________________________________________________________________________________
228 void AliITSRawStreamSPDErrorLog::ResetEvent() {
229   // reset error counters for current event
230   for (UInt_t eq=0; eq<20; eq++) {
231     for (UInt_t err=0; err<kNrErrorCodes; err++) {
232       fNErrors[err][eq]=0;
233     }
234     fByteOffset[eq]=0;
235     fTextTmpGeneral->Clear();
236     fTextTmp[eq]->Clear();
237   }
238
239   for (UInt_t eq=0; eq<20; eq++) {
240     for (UInt_t err=0; err<kNrErrorCodes; err++) {
241       delete fConsErrPosTMP[err][eq];
242       fErrPosTMPCounter[err][eq] = 0;
243       fConsErrPosTMP[err][eq] = new TGraph();
244     }
245   }
246 }
247 //________________________________________________________________________________________________
248 void AliITSRawStreamSPDErrorLog::AddErrorMessagesFromCurrentEvent(UInt_t eventNum) {
249   TString msg;
250   if (fText->RowCount()>5000) {
251     fText->Clear();
252     msg = "*** previous errors cleared ***";
253     fText->InsLine(fText->RowCount(),msg.Data());
254   }
255   if (fTextTmpGeneral->RowCount()>1) {
256     msg = Form("*** Event %d , General Errors: ***",eventNum);
257     fText->InsLine(fText->RowCount(),msg.Data());
258     fText->AddText(fTextTmpGeneral);
259     //    fTextTmpGeneral->Clear();
260   }
261
262   for (UInt_t eq=0; eq<20; eq++) {
263     if (fNErrors[kTotal][eq]>0) {
264       msg = Form("*** Event %d , Eq %d: ***",eventNum,eq);
265       fText->InsLine(fText->RowCount(),msg.Data());
266       fText->AddText(fTextTmp[eq]);
267       fText->InsLine(fText->RowCount()," ");
268     }
269     //    fTextTmp[eq]->Clear();
270   }
271 }
272 //________________________________________________________________________________________________
273 void AliITSRawStreamSPDErrorLog::ProcessEvent(UInt_t eventNum) {
274   // summarize the information for the current event
275 //  TString msg;
276 //  if (fText->RowCount()>5000) {
277 //    fText->Clear();
278 //    msg = "*** previous errors cleared ***";
279 //    fText->InsLine(fText->RowCount(),msg.Data());
280 //  }
281 //  if (fTextTmpGeneral->RowCount()>1) {
282 //    msg = Form("*** Event %d , General Errors: ***",eventNum);
283 //    fText->InsLine(fText->RowCount(),msg.Data());
284 //    fText->AddText(fTextTmpGeneral);
285 //    fTextTmpGeneral->Clear();
286 //  }
287
288   AddErrorMessagesFromCurrentEvent(eventNum);
289
290   for (UInt_t eq=0; eq<20; eq++) {
291     for (UInt_t err=0; err<kNrErrorCodes; err++) {
292       fConsErrType[eq]->Fill(err,fNErrors[err][eq]);
293       if (fNErrors[err][eq]>0) {
294         fConsErrEvent[err][eq]->SetPoint(fErrEventCounter[err][eq],eventNum,fNErrors[err][eq]);
295         fErrEventCounter[err][eq]++;
296         fConsErrFraction[eq]->Fill(err);
297       }
298       for (UInt_t pind=0; pind<fErrPosTMPCounter[err][eq]; pind++) {
299         Double_t x,y;
300         fConsErrPosTMP[err][eq]->GetPoint(pind,x,y);
301         fConsErrPos[err][eq]->SetPoint(fErrPosCounter[err][eq],eventNum,y);
302         fErrPosCounter[err][eq]++;
303       }
304     }
305
306     fNEvents[eq]++;
307 //    if (fNErrors[kTotal][eq]>0) {
308 //      msg = Form("*** Event %d , Eq %d: ***",eventNum,eq);
309 //      fText->InsLine(fText->RowCount(),msg.Data());
310 //      fText->AddText(fTextTmp[eq]);
311 //      fText->InsLine(fText->RowCount()," ");
312 //    }
313 //    fByteOffset[eq]=0;
314 //    fTextTmp[eq]->Clear();
315   }
316
317 }
318 //________________________________________________________________________________________________
319 void AliITSRawStreamSPDErrorLog::SummarizeEvent(UInt_t eventNum) {
320   // summarize the information for the current event 
321   ProcessEvent(eventNum);
322   ResetEvent();
323 }
324 //________________________________________________________________________________________________
325 void AliITSRawStreamSPDErrorLog::SetByteOffset(UInt_t eq, Int_t size) {
326   // set byte offset (equipment header size)
327   if (eq<20) {
328     fByteOffset[eq]=size;
329   }
330   else {
331     AliWarning(Form("Equipment number (%d) out of range",eq));
332   }
333 }
334 //________________________________________________________________________________________________
335 void AliITSRawStreamSPDErrorLog::SuppressErrorMessages(UInt_t errorCode, Bool_t suppr) {
336   // suppress error messages for specific error code
337   if (errorCode<kNrErrorCodes) {
338     fSuppressMess[errorCode] = suppr;
339   }
340   else {
341     AliWarning(Form("Error code (%d) out of range",errorCode));
342   }
343 }
344 //________________________________________________________________________________________________
345 void AliITSRawStreamSPDErrorLog::SuppressErrorEq(UInt_t eq, Bool_t suppr) {
346   // suppress error messages for specific equipment
347   if (eq<20) {
348     fSuppressEq[eq] = suppr;
349   }
350   else {
351     AliWarning(Form("Eq id (%d) out of range",eq));
352   }
353 }
354 //________________________________________________________________________________________________
355 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrors(UInt_t errorCode, UInt_t eq) {
356   // returns the number of errors for this event for a specific error code and equipment
357   if (errorCode<kNrErrorCodes && eq<20) return fNErrors[errorCode][eq];
358   else {
359     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
360     return 0;
361   }
362 }
363 //________________________________________________________________________________________________
364 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsAllEq(UInt_t errorCode) {
365   // returns the number of errors for this event for a specific error code and all equipments
366   if (errorCode<kNrErrorCodes) {
367     UInt_t returnval=0;
368     for (UInt_t eq=0; eq<20; eq++) {
369       returnval += fNErrors[errorCode][eq];
370     }
371     return returnval;
372   }
373   else {
374     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
375     return 0;
376   }
377 }
378 //________________________________________________________________________________________________
379 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotal(UInt_t errorCode, UInt_t eq) {
380   // returns the total number of errors for a specific error code and equipment
381   if (errorCode<kNrErrorCodes && eq<20) {
382     return fNErrorsTotal[errorCode][eq];
383     //    return (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
384   }
385   else {
386     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
387     return 0;
388   }
389 }
390 //________________________________________________________________________________________________
391 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotalAllEq(UInt_t errorCode) {
392   // returns the total number of errors for a specific error code and for all equipments
393   if (errorCode<kNrErrorCodes) {
394     UInt_t returnval=0;
395     for (UInt_t eq=0; eq<20; eq++) {
396       returnval += fNErrorsTotal[errorCode][eq];
397       //      returnval += (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
398     }
399     return returnval;
400   }
401   else {
402     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
403     return 0;
404   }
405 }
406 //________________________________________________________________________________________________
407 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrEvent(UInt_t errorCode, UInt_t eq) {
408   // returns a pointer to the graph
409   if (errorCode<kNrErrorCodes && eq<20) return fConsErrEvent[errorCode][eq];
410   else {
411     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
412     return NULL;
413   }
414 }
415 //________________________________________________________________________________________________
416 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrType(UInt_t eq) {
417   // returns a pointer to the histogram
418   if (eq<20) return fConsErrType[eq];
419   else {
420     AliWarning(Form("Eq nr (%d) out of bounds",eq));
421     return NULL;
422   }
423 }
424 //________________________________________________________________________________________________
425 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFraction(UInt_t eq) {
426   // creates a new histogram and returns a pointer to it. 
427   // NB!!! Take care of deleting this object later
428   if (eq<20) {
429     TH1F* returnhisto = (TH1F*)(fConsErrFraction[eq]->Clone());
430     if (fNEvents[eq]!=0) returnhisto->Scale(1./fNEvents[eq]);
431     //    returnhisto->SetMaximum(1.);
432     return returnhisto;
433   }
434   else {
435     AliWarning(Form("Eq nr (%d) out of bounds",eq));
436     return NULL;
437   }
438 }
439 //________________________________________________________________________________________________
440 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFractionUnScaled(UInt_t eq) {
441   // returns a pointer to the histogram
442   if (eq<20) return fConsErrFraction[eq];
443   else {
444     AliWarning(Form("Eq nr (%d) out of bounds",eq));
445     return NULL;
446   }
447 }
448 //________________________________________________________________________________________________
449 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrPos(UInt_t errorCode, UInt_t eq) {
450   // returns a pointer to the histogram
451   if (errorCode<kNrErrorCodes && eq<20) return fConsErrPos[errorCode][eq];
452   else {
453     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
454     return NULL;
455   }
456 }
457 //________________________________________________________________________________________________
458 UInt_t AliITSRawStreamSPDErrorLog::GetEventErrPosCounter(UInt_t errorCode, UInt_t eq) {
459   // returns the number of errors with bytes information for current event
460   if (errorCode<kNrErrorCodes && eq<20) return fErrPosTMPCounter[errorCode][eq];
461   else {
462     AliError(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
463     return 0;
464   }
465 }
466 //________________________________________________________________________________________________
467 UInt_t AliITSRawStreamSPDErrorLog::GetEventErrPos(UInt_t index, UInt_t errorCode, UInt_t eq) {
468   // returns the bytes read for the index'th error of current event
469   if (errorCode<kNrErrorCodes && eq<20) {
470     if (index<fErrPosTMPCounter[errorCode][eq]) {
471       Double_t x,y;
472       fConsErrPosTMP[errorCode][eq]->GetPoint(index,x,y);
473       return (UInt_t) y;
474     }
475     else {
476       AliError(Form("Index %d out of range, returning 0",index));
477     return 0;
478     }
479   }
480   else {
481     AliError(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
482     return 0;
483   }
484
485 }
486