]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSPDErrorLog.cxx
Minor changes - acceptance cut
[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   //  (could be replaced by calls to 'StartEvent' and 'EndEvent')
322   ProcessEvent(eventNum);
323   ResetEvent();
324 }
325 //________________________________________________________________________________________________
326 void AliITSRawStreamSPDErrorLog::SetByteOffset(UInt_t eq, Int_t size) {
327   // set byte offset (equipment header size)
328   if (eq<20) {
329     fByteOffset[eq]=size;
330   }
331   else {
332     AliWarning(Form("Equipment number (%d) out of range",eq));
333   }
334 }
335 //________________________________________________________________________________________________
336 void AliITSRawStreamSPDErrorLog::SuppressErrorMessages(UInt_t errorCode, Bool_t suppr) {
337   // suppress error messages for specific error code
338   if (errorCode<kNrErrorCodes) {
339     fSuppressMess[errorCode] = suppr;
340   }
341   else {
342     AliWarning(Form("Error code (%d) out of range",errorCode));
343   }
344 }
345 //________________________________________________________________________________________________
346 void AliITSRawStreamSPDErrorLog::SuppressErrorEq(UInt_t eq, Bool_t suppr) {
347   // suppress error messages for specific equipment
348   if (eq<20) {
349     fSuppressEq[eq] = suppr;
350   }
351   else {
352     AliWarning(Form("Eq id (%d) out of range",eq));
353   }
354 }
355 //________________________________________________________________________________________________
356 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrors(UInt_t errorCode, UInt_t eq) {
357   // returns the number of errors for this event for a specific error code and equipment
358   if (errorCode<kNrErrorCodes && eq<20) return fNErrors[errorCode][eq];
359   else {
360     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
361     return 0;
362   }
363 }
364 //________________________________________________________________________________________________
365 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsAllEq(UInt_t errorCode) {
366   // returns the number of errors for this event for a specific error code and all equipments
367   if (errorCode<kNrErrorCodes) {
368     UInt_t returnval=0;
369     for (UInt_t eq=0; eq<20; eq++) {
370       returnval += fNErrors[errorCode][eq];
371     }
372     return returnval;
373   }
374   else {
375     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
376     return 0;
377   }
378 }
379 //________________________________________________________________________________________________
380 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotal(UInt_t errorCode, UInt_t eq) {
381   // returns the total number of errors for a specific error code and equipment
382   if (errorCode<kNrErrorCodes && eq<20) {
383     return fNErrorsTotal[errorCode][eq];
384     //    return (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
385   }
386   else {
387     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
388     return 0;
389   }
390 }
391 //________________________________________________________________________________________________
392 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotalAllEq(UInt_t errorCode) {
393   // returns the total number of errors for a specific error code and for all equipments
394   if (errorCode<kNrErrorCodes) {
395     UInt_t returnval=0;
396     for (UInt_t eq=0; eq<20; eq++) {
397       returnval += fNErrorsTotal[errorCode][eq];
398       //      returnval += (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
399     }
400     return returnval;
401   }
402   else {
403     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
404     return 0;
405   }
406 }
407 //________________________________________________________________________________________________
408 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrEvent(UInt_t errorCode, UInt_t eq) {
409   // returns a pointer to the graph
410   if (errorCode<kNrErrorCodes && eq<20) return fConsErrEvent[errorCode][eq];
411   else {
412     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
413     return NULL;
414   }
415 }
416 //________________________________________________________________________________________________
417 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrType(UInt_t eq) {
418   // returns a pointer to the histogram
419   if (eq<20) return fConsErrType[eq];
420   else {
421     AliWarning(Form("Eq nr (%d) out of bounds",eq));
422     return NULL;
423   }
424 }
425 //________________________________________________________________________________________________
426 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFraction(UInt_t eq) {
427   // creates a new histogram and returns a pointer to it. 
428   // NB!!! Take care of deleting this object later
429   if (eq<20) {
430     TH1F* returnhisto = (TH1F*)(fConsErrFraction[eq]->Clone());
431     if (fNEvents[eq]!=0) returnhisto->Scale(1./fNEvents[eq]);
432     //    returnhisto->SetMaximum(1.);
433     return returnhisto;
434   }
435   else {
436     AliWarning(Form("Eq nr (%d) out of bounds",eq));
437     return NULL;
438   }
439 }
440 //________________________________________________________________________________________________
441 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFractionUnScaled(UInt_t eq) {
442   // returns a pointer to the histogram
443   if (eq<20) return fConsErrFraction[eq];
444   else {
445     AliWarning(Form("Eq nr (%d) out of bounds",eq));
446     return NULL;
447   }
448 }
449 //________________________________________________________________________________________________
450 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrPos(UInt_t errorCode, UInt_t eq) {
451   // returns a pointer to the histogram
452   if (errorCode<kNrErrorCodes && eq<20) return fConsErrPos[errorCode][eq];
453   else {
454     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
455     return NULL;
456   }
457 }
458 //________________________________________________________________________________________________
459 UInt_t AliITSRawStreamSPDErrorLog::GetEventErrPosCounter(UInt_t errorCode, UInt_t eq) {
460   // returns the number of errors with bytes information for current event
461   if (errorCode<kNrErrorCodes && eq<20) return fErrPosTMPCounter[errorCode][eq];
462   else {
463     AliError(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
464     return 0;
465   }
466 }
467 //________________________________________________________________________________________________
468 UInt_t AliITSRawStreamSPDErrorLog::GetEventErrPos(UInt_t index, UInt_t errorCode, UInt_t eq) {
469   // returns the bytes read for the index'th error of current event
470   if (errorCode<kNrErrorCodes && eq<20) {
471     if (index<fErrPosTMPCounter[errorCode][eq]) {
472       Double_t x,y;
473       fConsErrPosTMP[errorCode][eq]->GetPoint(index,x,y);
474       return (UInt_t) y;
475     }
476     else {
477       AliError(Form("Index %d out of range, returning 0",index));
478     return 0;
479     }
480   }
481   else {
482     AliError(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
483     return 0;
484   }
485
486 }