]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSRawStreamSPDErrorLog.cxx
Modifications by H. Tydesio:
[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     }
30   }
31   for (UInt_t err=0; err<kNrErrorCodes; err++) {
32     fSuppressMess[err] = kFALSE;
33   }
34   InitHistograms();
35 }
36 //________________________________________________________________________________________________
37 AliITSRawStreamSPDErrorLog::AliITSRawStreamSPDErrorLog(const AliITSRawStreamSPDErrorLog& logger) :
38   TObject(logger), fText(NULL), fTextTmpGeneral(NULL)
39 {
40   // copy constructor
41   for (UInt_t eq=0; eq<20; eq++) {
42     for (UInt_t err=0; err<kNrErrorCodes; err++) {
43       fNErrors[err][eq] = logger.fNErrors[err][eq];
44       fErrEventCounter[err][eq] = logger.fErrEventCounter[err][eq];
45     }
46     fNEvents[eq] = logger.fNEvents[eq];
47     fByteOffset[eq] = logger.fByteOffset[eq];
48     fSuppressEq[eq] = logger.fSuppressEq[eq];
49   }
50   for (UInt_t err=0; err<kNrErrorCodes; err++) {
51     fSuppressMess[err] = logger.fSuppressMess[err];
52   }
53   
54   fText = new TGText(logger.fText);
55   fTextTmpGeneral = new TGText(logger.fTextTmpGeneral);
56   for (UInt_t eq=0; eq<20; eq++) {
57     fTextTmp[eq] = new TGText(logger.fTextTmp[eq]);
58   }
59   
60   for (UInt_t eq=0; eq<20; eq++) {
61     for (UInt_t err=0; err<kNrErrorCodes; err++) {
62       fConsErrEvent[err][eq] = new TGraph(*logger.fConsErrEvent[err][eq]);
63       fConsErrPos[err][eq] = new TGraph(*logger.fConsErrPos[err][eq]);
64     }
65     fConsErrType[eq] = new TH1F(*logger.fConsErrType[eq]);
66     fConsErrFraction[eq] = new TH1F(*logger.fConsErrFraction[eq]);
67   }
68   
69 }
70 //________________________________________________________________________________________________
71 AliITSRawStreamSPDErrorLog& AliITSRawStreamSPDErrorLog::operator=(const AliITSRawStreamSPDErrorLog& logger) {
72   // assignment operator
73   if (this!=&logger) {
74     delete fText;
75     delete fTextTmpGeneral;
76     delete[] fTextTmp;
77     this->DeleteHistograms();
78
79     for (UInt_t eq=0; eq<20; eq++) {
80       for (UInt_t err=0; err<kNrErrorCodes; err++) {
81         fNErrors[err][eq] = logger.fNErrors[err][eq];
82         fErrEventCounter[err][eq] = logger.fErrEventCounter[err][eq];
83       }
84       fNEvents[eq] = logger.fNEvents[eq];
85       fByteOffset[eq] = logger.fByteOffset[eq];
86       fSuppressEq[eq] = logger.fSuppressEq[eq];
87     }
88     for (UInt_t err=0; err<kNrErrorCodes; err++) {
89       fSuppressMess[err] = logger.fSuppressMess[err];
90     }
91
92     fText = new TGText(logger.fText);
93     fTextTmpGeneral = new TGText(logger.fTextTmpGeneral);
94     for (UInt_t eq=0; eq<20; eq++) {
95       fTextTmp[eq] = new TGText(logger.fTextTmp[eq]);
96     }
97     
98     for (UInt_t eq=0; eq<20; eq++) {
99       for (UInt_t err=0; err<kNrErrorCodes; err++) {
100         fConsErrEvent[err][eq] = new TGraph(*logger.fConsErrEvent[err][eq]);
101         fConsErrPos[err][eq] = new TGraph(*logger.fConsErrPos[err][eq]);
102       }
103       fConsErrType[eq] = new TH1F(*logger.fConsErrType[eq]);
104       fConsErrFraction[eq] = new TH1F(*logger.fConsErrFraction[eq]);
105     }
106
107   }
108   return *this;
109   
110 }
111 //________________________________________________________________________________________________
112 AliITSRawStreamSPDErrorLog::~AliITSRawStreamSPDErrorLog() {
113   // destructor
114   DeleteHistograms();
115   delete fText;
116   delete fTextTmpGeneral;
117   delete[] fTextTmp;
118 }
119 //________________________________________________________________________________________________
120 void AliITSRawStreamSPDErrorLog::InitHistograms() {
121   // initialize histograms
122   for (UInt_t eq=0; eq<20; eq++) {
123     TString histName, histTitle;
124     histName = Form("ConsErrType %d",eq);
125     histTitle = Form("Distribution of errors, eq %d",eq);
126     fConsErrType[eq]=new TH1F(histName.Data(),histTitle.Data(),kNrErrorCodes,-0.5,kNrErrorCodes-0.5);
127     fConsErrType[eq]->SetXTitle("Error Code");
128     fConsErrType[eq]->SetYTitle("Nr Errors");
129     
130     histName = Form("ConsErrFraction %d",eq);
131     histTitle = Form("Fraction of events with errors, eq %d",eq);
132     fConsErrFraction[eq]=new TH1F(histName.Data(),histTitle.Data(),kNrErrorCodes,-0.5,kNrErrorCodes-0.5);
133     fConsErrFraction[eq]->SetXTitle("Error Code");
134     fConsErrFraction[eq]->SetYTitle("Fraction");
135     
136     for (UInt_t err=0; err<kNrErrorCodes; err++) {
137       fConsErrEvent[err][eq]=new TGraph();
138       fConsErrPos[err][eq]=new TGraph();
139       fConsErrPosTMP[err][eq]=new TGraph();
140       fErrEventCounter[err][eq] = 0;
141       fErrPosCounter[err][eq] = 0;
142       fErrPosTMPCounter[err][eq] = 0;
143     }
144   }
145 }
146 //________________________________________________________________________________________________
147 void AliITSRawStreamSPDErrorLog::DeleteHistograms() const {
148   // delete histograms
149   for (UInt_t eq=0; eq<20; eq++) {
150     delete fConsErrType[eq];
151     delete fConsErrFraction[eq];
152     for (UInt_t err=0; err<kNrErrorCodes; err++) {
153       delete fConsErrEvent[err][eq];
154       delete fConsErrPos[err][eq];
155       delete fConsErrPosTMP[err][eq];
156     }
157   }
158 }
159 //________________________________________________________________________________________________
160 void AliITSRawStreamSPDErrorLog::Reset() {
161   // Reset
162   fText->Clear();
163   for (UInt_t eq=0; eq<20; eq++) {
164     fTextTmp[eq]->Clear();
165     fConsErrType[eq]->Reset();
166     fConsErrFraction[eq]->Reset();
167     fNEvents[eq] = 0;
168     for (UInt_t err=0; err<kNrErrorCodes; err++) {
169       fNErrors[err][eq] = 0;
170       delete fConsErrEvent[err][eq];
171       delete fConsErrPos[err][eq];
172       delete fConsErrPosTMP[err][eq];
173       fErrEventCounter[err][eq] = 0;
174       fErrPosCounter[err][eq] = 0;
175       fErrPosTMPCounter[err][eq] = 0;
176       fConsErrEvent[err][eq] = new TGraph();
177       fConsErrPos[err][eq] = new TGraph();
178       fConsErrPosTMP[err][eq] = new TGraph();
179     }
180   }
181 }
182 //________________________________________________________________________________________________
183 void AliITSRawStreamSPDErrorLog::ProcessError(UInt_t errorCode, UInt_t eq, Int_t bytesRead, Int_t headersRead, const Char_t *errMess) {
184   // Process an error
185   if (eq>=20) {
186     AliWarning(Form("Equipment number (%d) out of bounds",eq));
187     return;
188   }
189   // check if we want to exclude the error...
190   if (!(fSuppressMess[errorCode] || fSuppressEq[eq])) {
191     fNErrors[errorCode][eq]++;
192     if (errorCode!=kTotal) fNErrors[kTotal][eq]++;
193
194     if (bytesRead>=0) {
195       fConsErrPosTMP[errorCode][eq]->SetPoint(fErrPosTMPCounter[errorCode][eq],0,bytesRead+fByteOffset[eq]);
196       fErrPosTMPCounter[errorCode][eq]++;
197       if (errorCode!=kTotal) {
198         fConsErrPosTMP[kTotal][eq]->SetPoint(fErrPosTMPCounter[kTotal][eq],0,bytesRead+fByteOffset[eq]);
199         fErrPosTMPCounter[kTotal][eq]++;
200       }
201     }
202
203     TString msg;
204     if (bytesRead<0) {
205       msg = Form("%s",errMess);
206     }
207     else {
208       msg = Form("%s (%d bytes read, %d chip headers read)",errMess,bytesRead+fByteOffset[eq],headersRead);
209     }
210     fTextTmp[eq]->InsLine(fTextTmp[eq]->RowCount(),msg.Data());
211   }
212 }
213 //________________________________________________________________________________________________
214 void AliITSRawStreamSPDErrorLog::AddMessage(const Char_t *errMess) {
215   // add a general message to the buffer
216   fTextTmpGeneral->InsLine(fTextTmpGeneral->RowCount(),errMess);
217 }
218 //________________________________________________________________________________________________
219 void AliITSRawStreamSPDErrorLog::SummarizeEvent(UInt_t eventNum) {
220   // summarize the information for the current event
221   TString msg;
222   if (fText->RowCount()>5000) {
223     fText->Clear();
224     msg = "*** previous errors cleared ***";
225     fText->InsLine(fText->RowCount(),msg.Data());
226   }
227   if (fTextTmpGeneral->RowCount()>1) {
228     msg = Form("*** Event %d , General Errors: ***",eventNum);
229     fText->InsLine(fText->RowCount(),msg.Data());
230     fText->AddText(fTextTmpGeneral);
231     fTextTmpGeneral->Clear();
232   }
233   for (UInt_t eq=0; eq<20; eq++) {
234     for (UInt_t err=0; err<kNrErrorCodes; err++) {
235       fConsErrType[eq]->Fill(err,fNErrors[err][eq]);
236       if (fNErrors[err][eq]>0){
237         fConsErrEvent[err][eq]->SetPoint(fErrEventCounter[err][eq],eventNum,fNErrors[err][eq]);
238         fErrEventCounter[err][eq]++;
239         fConsErrFraction[eq]->Fill(err);
240       }
241       for (UInt_t pind=0; pind<fErrPosTMPCounter[err][eq]; pind++) {
242         Double_t x,y;
243         fConsErrPosTMP[err][eq]->GetPoint(pind,x,y);
244         fConsErrPos[err][eq]->SetPoint(fErrPosCounter[err][eq],eventNum,y);
245         fErrPosCounter[err][eq]++;
246       }
247     }
248
249     fNEvents[eq]++;
250     if (fNErrors[kTotal][eq]>0) {
251       msg = Form("*** Event %d , Eq %d: ***",eventNum,eq);
252       fText->InsLine(fText->RowCount(),msg.Data());
253       fText->AddText(fTextTmp[eq]);
254       fText->InsLine(fText->RowCount()," ");
255     }
256     fByteOffset[eq]=0;
257     fTextTmp[eq]->Clear();
258     for (UInt_t err=0; err<kNrErrorCodes; err++) {
259       fNErrors[err][eq]=0;
260     }
261   }
262
263   for (UInt_t eq=0; eq<20; eq++) {
264     for (UInt_t err=0; err<kNrErrorCodes; err++) {
265       delete fConsErrPosTMP[err][eq];
266       fErrPosTMPCounter[err][eq] = 0;
267       fConsErrPosTMP[err][eq] = new TGraph();
268     }
269   }
270 }
271 //________________________________________________________________________________________________
272 void AliITSRawStreamSPDErrorLog::SetByteOffset(UInt_t eq, Int_t size) {
273   // set byte offset (equipment header size)
274   if (eq<20) {
275     fByteOffset[eq]=size;
276   }
277   else {
278     AliWarning(Form("Equipment number (%d) out of range",eq));
279   }
280 }
281 //________________________________________________________________________________________________
282 void AliITSRawStreamSPDErrorLog::SuppressErrorMessages(UInt_t errorCode, Bool_t suppr) {
283   // suppress error messages for specific error code
284   if (errorCode<kNrErrorCodes) {
285     fSuppressMess[errorCode] = suppr;
286   }
287   else {
288     AliWarning(Form("Error code (%d) out of range",errorCode));
289   }
290 }
291 //________________________________________________________________________________________________
292 void AliITSRawStreamSPDErrorLog::SuppressErrorEq(UInt_t eq, Bool_t suppr) {
293   // suppress error messages for specific equipment
294   if (eq<20) {
295     fSuppressEq[eq] = suppr;
296   }
297   else {
298     AliWarning(Form("Eq id (%d) out of range",eq));
299   }
300 }
301 //________________________________________________________________________________________________
302 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrors(UInt_t errorCode, UInt_t eq) {
303   // returns the number of errors for this event for a specific error code and equipment
304   if (errorCode<kNrErrorCodes && eq<20) return fNErrors[errorCode][eq];
305   else {
306     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
307     return 0;
308   }
309 }
310 //________________________________________________________________________________________________
311 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsAllEq(UInt_t errorCode) {
312   // returns the number of errors for this event for a specific error code and all equipments
313   if (errorCode<kNrErrorCodes) {
314     UInt_t returnval=0;
315     for (UInt_t eq=0; eq<20; eq++) {
316       returnval += fNErrors[errorCode][eq];
317     }
318     return returnval;
319   }
320   else {
321     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
322     return 0;
323   }
324 }
325 //________________________________________________________________________________________________
326 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotal(UInt_t errorCode, UInt_t eq) {
327   // returns the total number of errors for a specific error code and equipment
328   if (errorCode<kNrErrorCodes && eq<20) {
329     return (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
330   }
331   else {
332     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning 0",errorCode,eq));
333     return 0;
334   }
335 }
336 //________________________________________________________________________________________________
337 UInt_t AliITSRawStreamSPDErrorLog::GetNrErrorsTotalAllEq(UInt_t errorCode) {
338   // returns the total number of errors for a specific error code and for all equipment
339   if (errorCode<kNrErrorCodes) {
340     UInt_t returnval=0;
341     for (UInt_t eq=0; eq<20; eq++) {
342       returnval += (UInt_t) fConsErrType[eq]->GetBinContent(errorCode+1);
343     }
344     return returnval;
345   }
346   else {
347     AliWarning(Form("Error code (%d) out of range, returning 0",errorCode));
348     return 0;
349   }
350 }
351 //________________________________________________________________________________________________
352 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrEvent(UInt_t errorCode, UInt_t eq) {
353   // returns a pointer to the graph
354   if (errorCode<kNrErrorCodes && eq<20) return fConsErrEvent[errorCode][eq];
355   else {
356     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
357     return NULL;
358   }
359 }
360 //________________________________________________________________________________________________
361 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrType(UInt_t eq) {
362   // returns a pointer to the histogram
363   if (eq<20) return fConsErrType[eq];
364   else {
365     AliWarning(Form("Eq nr (%d) out of bounds",eq));
366     return NULL;
367   }
368 }
369 //________________________________________________________________________________________________
370 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFraction(UInt_t eq) {
371   // creates a new histogram and returns a pointer to it. 
372   // NB!!! Take care of deleting this object later
373   if (eq<20) {
374     TH1F* returnhisto = (TH1F*)(fConsErrFraction[eq]->Clone());
375     if (fNEvents[eq]!=0) returnhisto->Scale(1./fNEvents[eq]);
376     //    returnhisto->SetMaximum(1.);
377     return returnhisto;
378   }
379   else {
380     AliWarning(Form("Eq nr (%d) out of bounds",eq));
381     return NULL;
382   }
383 }
384 //________________________________________________________________________________________________
385 TH1F* AliITSRawStreamSPDErrorLog::GetConsErrFractionUnScaled(UInt_t eq) {
386   // returns a pointer to the histogram
387   if (eq<20) return fConsErrFraction[eq];
388   else {
389     AliWarning(Form("Eq nr (%d) out of bounds",eq));
390     return NULL;
391   }
392 }
393 //________________________________________________________________________________________________
394 TGraph* AliITSRawStreamSPDErrorLog::GetConsErrPos(UInt_t errorCode, UInt_t eq) {
395   // returns a pointer to the histogram
396   if (errorCode<kNrErrorCodes && eq<20) return fConsErrPos[errorCode][eq];
397   else {
398     AliWarning(Form("Error code (%d) or equipment (%d) out of range, returning NULL",errorCode,eq));
399     return NULL;
400   }
401 }