]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONRawStreamTracker.C
Add option to run on some local files with test mode using the alien plugin
[u/mrichter/AliRoot.git] / MUON / MUONRawStreamTracker.C
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17
18 /// \ingroup macros
19 /// \file MUONRawStreamTracker.C
20 /// \brief Macro for reading tracker raw data
21 ///
22 /// \author Ch. Finck, Subatech Febuary
23 ///
24 /// Added example routines to show how to use the interface of the high
25 /// performance decoder AliMUONRawStreamTrackerHP.
26 /// by  Artur Szostak <artursz@iafrica.com>
27 ///
28 /// This macro is interfaced with AliRawReader for RAW
29 ///
30 /// There are 2 ways of reading the data: 
31 /// - one where each intermediate structure (block, dsp, buspatch) is looped over
32 /// - and one, using an iterator, where we're directly accessing the pad informations 
33 /// (charge).
34 ///
35
36
37 #if !defined(__CINT__) || defined(__MAKECINT__)
38
39 // RAW includes
40 #include "AliRawReader.h"
41
42 // MUON includes
43 #include "AliMUONRawStreamTrackerHP.h"
44 #include "TStopwatch.h"
45 #include "AliRawDataErrorLog.h"
46 #include "Riostream.h"
47 #include "AliMUONLogger.h"
48
49 #endif
50
51 void MUONRawStreamTrackerExpert(TString fileName = "./", Int_t maxEvent = 1000,  
52                                 Int_t minDDL = 0, Int_t maxDDL = 19)
53 {
54   /// This routine shows how to use the decoder's expert interface.
55   
56   TStopwatch timer;
57   timer.Start(kTRUE);
58   
59   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
60   
61   // raw stream
62   AliMUONRawStreamTrackerHP rawStream(rawReader);
63   
64   // light weight interfaces to headers
65   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
66   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
67   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
68   
69   //   Loop over events  
70   Int_t iEvent = 0;
71   Int_t dataSize;
72   
73   while (rawReader->NextEvent()) {
74     
75     if (iEvent == maxEvent)
76       break;
77     
78     printf("Event %d\n",iEvent++);
79     
80     // read DDL while < 20 DDL
81     while(rawStream.NextDDL()) {
82       
83       if (rawStream.GetDDL() < minDDL || rawStream.GetDDL() > maxDDL)
84         continue;
85       
86       printf("\niDDL %d\n", rawStream.GetDDL());
87       
88       // loop over block structure
89       Int_t nBlock = rawStream.GetBlockCount();
90       for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
91         
92         blkHeader = rawStream.GetBlockHeader(iBlock);
93         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
94        
95         // loop over DSP structure
96         Int_t nDsp = rawStream.GetDspCount(iBlock);
97         for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
98           
99           dspHeader =  blkHeader->GetDspHeader(iDsp);
100           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
101           
102           // loop over BusPatch structure
103           Int_t nBusPatch = rawStream.GetBusPatchCount(iBlock, iDsp);
104           for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
105             
106             busStruct = dspHeader->GetBusPatch(iBusPatch);
107             
108             // loop over data
109             dataSize = busStruct->GetLength();
110             for (Int_t iData = 0; iData < dataSize; iData++) {
111               
112               Int_t  manuId    = busStruct->GetManuId(iData);
113               Int_t  channelId = busStruct->GetChannelId(iData);
114               Int_t  charge    = busStruct->GetCharge(iData);
115               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
116                      busStruct->GetBusPatchId(),
117                      manuId, 
118                      channelId, charge);
119             } // iData
120           } // iBusPatch
121         } // iDsp
122       } // iBlock
123     } // NextDDL
124   }// NextEvent
125   
126   delete rawReader;
127   timer.Print();
128 }
129
130
131 void MUONRawStreamTrackerExpert2(TString fileName = "./", Int_t maxEvent = 1000,  
132                                 Int_t minDDL = 0, Int_t maxDDL = 19)
133 {
134   /// This routine shows an alternate way to iterate over the DDL structures
135   /// compared to MUONRawStreamTrackerExpert().
136   
137   TStopwatch timer;
138   timer.Start(kTRUE);
139   
140   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
141   
142   // raw stream
143   AliMUONRawStreamTrackerHP rawStream(rawReader);
144   
145   // light weight interfaces to headers
146   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
147   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
148   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
149   
150   //   Loop over events  
151   Int_t iEvent = 0;
152   Int_t dataSize;
153   
154   while (rawReader->NextEvent()) {
155     
156     if (iEvent == maxEvent)
157       break;
158     
159     printf("Event %d\n",iEvent++);
160     
161     // read DDL while < 20 DDL
162     while(rawStream.NextDDL()) {
163       
164       if (rawStream.GetDDL() < minDDL || rawStream.GetDDL() > maxDDL)
165         continue;
166       
167       printf("\niDDL %d\n", rawStream.GetDDL());
168       
169       // loop over block structure
170       Int_t nBlock = rawStream.GetBlockCount();
171       for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
172         
173         blkHeader = rawStream.GetBlockHeader(iBlock);
174         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
175        
176         // loop over DSP structure
177         Int_t nDsp = rawStream.GetDspCount(iBlock);
178         for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
179           
180           dspHeader =  rawStream.GetDspHeader(iBlock, iDsp);
181           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
182           
183           // loop over BusPatch structure
184           Int_t nBusPatch = rawStream.GetBusPatchCount(iBlock, iDsp);
185           for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
186             
187             busStruct = rawStream.GetBusPatch(iBlock, iDsp, iBusPatch);
188             
189             // loop over data
190             dataSize = busStruct->GetLength();
191             for (Int_t iData = 0; iData < dataSize; iData++) {
192               
193               Int_t  manuId    = busStruct->GetManuId(iData);
194               Int_t  channelId = busStruct->GetChannelId(iData);
195               Int_t  charge    = busStruct->GetCharge(iData);
196               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
197                      busStruct->GetBusPatchId(),
198                      manuId, 
199                      channelId, charge);
200             } // iData
201           } // iBusPatch
202         } // iDsp
203       } // iBlock
204     } // NextDDL
205   }// NextEvent
206   
207   delete rawReader;
208   timer.Print();
209 }
210
211
212 void MUONRawStreamTrackerExpert3(TString fileName = "./", Int_t maxEvent = 1000,  
213                                 Int_t minDDL = 0, Int_t maxDDL = 19)
214 {
215   /// This routine shows yet another alternate way to iterate over the DDL
216   /// structures compared to MUONRawStreamTrackerExpert().
217   
218   TStopwatch timer;
219   timer.Start(kTRUE);
220   
221   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
222   
223   // raw stream
224   AliMUONRawStreamTrackerHP rawStream(rawReader);
225   
226   // light weight interfaces to headers
227   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
228   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
229   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
230   
231   //   Loop over events  
232   Int_t iEvent = 0;
233   Int_t dataSize;
234   
235   while (rawReader->NextEvent()) {
236     
237     if (iEvent == maxEvent)
238       break;
239     
240     printf("Event %d\n",iEvent++);
241     
242     // read DDL while < 20 DDL
243     while(rawStream.NextDDL()) {
244       
245       if (rawStream.GetDDL() < minDDL || rawStream.GetDDL() > maxDDL)
246         continue;
247       
248       printf("\niDDL %d\n", rawStream.GetDDL());
249       
250       // loop over block structure
251       Int_t iBlock = 0;
252       blkHeader = rawStream.GetFirstBlockHeader();
253       while (blkHeader != NULL)
254       {
255         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
256        
257         // loop over DSP structure
258         Int_t iDsp = 0;
259         dspHeader = blkHeader->GetFirstDspHeader();
260         while (dspHeader != NULL)
261         {
262           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
263           
264           // loop over BusPatch structure
265           Int_t iBusPatch = 0;
266           busStruct = dspHeader->GetFirstBusPatch();
267           while (busStruct != NULL)
268           {
269             // loop over data
270             dataSize = busStruct->GetLength();
271             for (Int_t iData = 0; iData < dataSize; iData++) {
272               
273               Int_t  manuId    = busStruct->GetManuId(iData);
274               Int_t  channelId = busStruct->GetChannelId(iData);
275               Int_t  charge    = busStruct->GetCharge(iData);
276               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
277                      busStruct->GetBusPatchId(),
278                      manuId, 
279                      channelId, charge);
280             } // iData
281             busStruct = busStruct->Next();
282             iBusPatch++;
283           } // iBusPatch
284           dspHeader = dspHeader->Next();
285           iDsp++;
286         } // iDsp
287         blkHeader = blkHeader->Next();
288         iBlock++;
289       } // iBlock
290     } // NextDDL
291   }// NextEvent
292   
293   delete rawReader;
294   timer.Print();
295 }
296
297
298 void MUONRawStreamTrackerSimple(TString fileName = "./", Int_t maxEvent = 1000)
299 {
300   /// This routine shows how to use the high performance decoder's simple interface.
301
302   TStopwatch timer;
303   timer.Start(kTRUE);
304   
305   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
306   
307   // raw stream
308   AliMUONRawStreamTrackerHP rawStream(rawReader);    
309   
310   //   Loop over events  
311   Int_t iEvent = 0;
312   
313   while (rawReader->NextEvent()) {
314     
315     if (iEvent == maxEvent)
316       break;
317     
318     printf("Event %d\n",iEvent++);
319     
320     Int_t busPatch;
321     UShort_t manuId, adc;
322     UChar_t manuChannel;
323     
324     rawStream.First();
325     
326     while ( rawStream.Next(busPatch,manuId,manuChannel,adc) )
327     {      
328       printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
329              busPatch,manuId,manuChannel, adc);
330     }
331   }
332   
333   delete rawReader;
334   timer.Print();
335 }
336
337
338 void ShowErrors(const AliRawReader& rawReader)
339 {
340   for ( Int_t i = 0; i < rawReader.GetNumberOfErrorLogs(); ++i )
341   {
342     AliRawDataErrorLog* error = rawReader.GetErrorLog(i);
343     error->Print();
344   }
345
346   cout << Form("Number of error logs : %d (%d events)",
347                rawReader.GetNumberOfErrorLogs(),
348                rawReader.GetNumberOfEvents()) << endl;
349 }
350
351
352 void MUONRawStreamTrackerSimple2(TString fileName = "./", Int_t maxEvent = 1000)
353 {
354   /// This routine is an alternative to MUONRawStreamTrackerSimple() which is even faster.
355
356   TStopwatch timer;
357   timer.Start(kTRUE);
358   
359   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
360   
361   // raw stream
362   AliMUONRawStreamTrackerHP rawStream(rawReader);
363   rawStream.EnableRawReaderErrorLogger();
364   
365   //   Loop over events  
366   Int_t iEvent = 0;
367   
368   while (rawReader->NextEvent()) {
369     
370     if (iEvent == maxEvent)
371       break;
372     
373     printf("Event %d\n",iEvent++);
374     
375     UShort_t manuId, adc;
376     UChar_t manuChannel;
377     
378     rawStream.First();
379     const AliMUONRawStreamTrackerHP::AliBusPatch* buspatch = NULL;
380     while ((buspatch = rawStream.Next()) != NULL)
381     {
382       for (UInt_t i = 0; i < buspatch->GetDataCount(); i++)
383       {
384         buspatch->GetData(i, manuId, manuChannel, adc);
385         printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
386                buspatch->GetBusPatchId(), manuId, manuChannel, adc);
387       }
388     }
389   }
390
391   ShowErrors(*rawReader);
392   
393   delete rawReader;
394   timer.Print();
395 }
396
397 void MUONRawStreamTrackerErrorCount(TString fileName = "collection://filelist", Int_t maxEvent = -1)
398 {
399   /// This routine is just a loop to get the error log at the end
400   
401   TStopwatch timer;
402   timer.Start(kTRUE);
403   
404   AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
405   
406   // raw stream
407   AliMUONRawStreamTrackerHP rawStream(rawReader);
408   rawStream.DisableWarnings();    
409
410   AliMUONLogger logger;
411   
412   rawStream.EnableMUONErrorLogger();  
413   rawStream.SetMUONErrorLogger(&logger);    
414   rawStream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
415   
416   //   Loop over events  
417   Int_t iEvent = 0;
418   
419   while (rawReader->NextEvent()) 
420   {    
421     if (iEvent == maxEvent) break;
422     
423     rawStream.First();
424
425     const AliMUONRawStreamTrackerHP::AliBusPatch* buspatch = NULL;
426     
427     while ((buspatch = rawStream.Next()) != NULL)
428     {
429     }
430     
431     ++iEvent;
432   }
433   
434   logger.Print();
435   
436 //  ShowErrors(*rawReader);
437
438   delete rawReader;
439   timer.Print();
440 }
441