]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONRawStreamTracker.C
Revision of macros documentation
[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 /// The different stucture of the payload are readout and stored in TClonesArray
36 /// with AliMUONRawStreamTracker class.
37 /// The macro just simply reads again the TClonesArray contents.
38 /// The parameters of each structure could be seen in the container classes
39 /// AliMUONBlockHeader, AliMUONBlockHeader, AliMUONBusStruct.
40 /// The class AliMUONDDLTracker manages the structure containers.
41 /// The number of structures in the rawdata file could be set.
42
43
44 #if !defined(__CINT__) || defined(__MAKECINT__)
45
46 // RAW includes
47 #include "AliRawReaderDate.h"
48 #include "AliRawReaderFile.h"
49 #include "AliRawReaderRoot.h"
50
51 // MUON includes
52 #include "AliMUONRawStreamTracker.h"
53 #include "AliMUONRawStreamTrackerHP.h"
54 #include "AliMUONDspHeader.h"
55 #include "AliMUONBlockHeader.h"
56 #include "AliMUONBusStruct.h"
57 #include "AliMUONDDLTracker.h"
58
59 #include "TStopwatch.h"
60
61 #endif
62
63 void MUONRawStreamTrackerExpert(TString fileName = "./", Int_t maxEvent = 1000,  
64                                 Int_t minDDL = 0, Int_t maxDDL = 19)
65 {
66   /// Reads the data from fileName, using an "expert" mode where all substructures
67   /// are looped upon.
68   
69   TStopwatch timer;
70   timer.Start(kTRUE);
71   
72   AliRawReader* rawReader = 0x0;
73   
74   // check extention to choose the rawdata file format
75   if (fileName.EndsWith("/")) {
76     rawReader = new AliRawReaderFile(fileName); // DDL files
77   } else if (fileName.EndsWith(".root")) {
78     rawReader = new AliRawReaderRoot(fileName);
79   } else if (!fileName.IsNull()) {
80     rawReader = new AliRawReaderDate(fileName); // DATE file
81   }
82   
83   // raw stream
84   AliMUONRawStreamTracker* rawStream  = new AliMUONRawStreamTracker(rawReader);    
85   
86   // set the number of DDL block Dsp & buspatch structures that are PRESENT in the rawdata file
87   // it's NOT the number to be read.
88   // default wise set to 20, 2, 5 ans 5 respectively.
89   //    rawStream->SetMaxDDL(xx);
90   //    rawStream->SetMaxBlock(xx);
91   //    rawStream->SetMaxDsp(xx);
92   //    rawStream->SetMaxBus(xx);
93   
94   // containers
95   AliMUONDDLTracker*       ddlTracker = 0x0;
96   AliMUONBlockHeader*      blkHeader  = 0x0;
97   AliMUONDspHeader*        dspHeader  = 0x0;
98   AliMUONBusStruct*        busStruct  = 0x0;
99   
100   //   Loop over events  
101   Int_t iEvent = 0;
102   Int_t dataSize;
103   
104   while (rawReader->NextEvent()) {
105     
106     if (iEvent == maxEvent)
107       break;
108     
109     printf("Event %d\n",iEvent++);
110     
111     // read DDL while < 20 DDL
112     while(rawStream->NextDDL()) {
113       
114       if (rawStream->GetDDL() < minDDL || rawStream->GetDDL() > maxDDL)
115         continue;
116       
117       printf("\niDDL %d\n", rawStream->GetDDL());
118       
119       ddlTracker =  rawStream->GetDDLTracker();
120       
121       // loop over block structure
122       Int_t nBlock = ddlTracker->GetBlkHeaderEntries();
123       for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
124         
125         blkHeader = ddlTracker->GetBlkHeaderEntry(iBlock);
126         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
127        
128         // loop over DSP structure
129         Int_t nDsp = blkHeader->GetDspHeaderEntries();
130         for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
131           
132           dspHeader =  blkHeader->GetDspHeaderEntry(iDsp);
133           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
134           
135           // loop over BusPatch structure
136           Int_t nBusPatch = dspHeader->GetBusPatchEntries();
137           for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
138             
139             busStruct = dspHeader->GetBusPatchEntry(iBusPatch);
140             
141             //       printf("busPatchId %d", busStruct->GetBusPatchId());
142             //       printf(" BlockId %d", busStruct->GetBlockId());
143             //       printf(" DspId %d\n", busStruct->GetDspId());
144             
145             // loop over data
146             dataSize = busStruct->GetLength();
147             for (Int_t iData = 0; iData < dataSize; iData++) {
148               
149               Int_t  manuId    = busStruct->GetManuId(iData);
150               Int_t  channelId = busStruct->GetChannelId(iData);
151               Int_t  charge    = busStruct->GetCharge(iData);
152               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
153                      busStruct->GetBusPatchId(),
154                      manuId, 
155                      channelId, charge);
156             } // iData
157           } // iBusPatch
158         } // iDsp
159       } // iBlock
160     } // NextDDL
161   }// NextEvent
162   
163   delete rawReader;
164   delete rawStream;
165   timer.Print();
166 }
167
168
169 void MUONRawStreamTrackerHPExpert(TString fileName = "./", Int_t maxEvent = 1000,  
170                                 Int_t minDDL = 0, Int_t maxDDL = 19)
171 {
172   /// This routine shows how to use the high performance decoder's expert interface.
173   
174   TStopwatch timer;
175   timer.Start(kTRUE);
176   
177   AliRawReader* rawReader = 0x0;
178   
179   // check extention to choose the rawdata file format
180   if (fileName.EndsWith("/")) {
181     rawReader = new AliRawReaderFile(fileName); // DDL files
182   } else if (fileName.EndsWith(".root")) {
183     rawReader = new AliRawReaderRoot(fileName);
184   } else if (!fileName.IsNull()) {
185     rawReader = new AliRawReaderDate(fileName); // DATE file
186   }
187   
188   // raw stream
189   AliMUONRawStreamTrackerHP* rawStream  = new AliMUONRawStreamTrackerHP(rawReader);
190   
191   // light weight interfaces to headers
192   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
193   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
194   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
195   
196   //   Loop over events  
197   Int_t iEvent = 0;
198   Int_t dataSize;
199   
200   while (rawReader->NextEvent()) {
201     
202     if (iEvent == maxEvent)
203       break;
204     
205     printf("Event %d\n",iEvent++);
206     
207     // read DDL while < 20 DDL
208     while(rawStream->NextDDL()) {
209       
210       if (rawStream->GetDDL() < minDDL || rawStream->GetDDL() > maxDDL)
211         continue;
212       
213       printf("\niDDL %d\n", rawStream->GetDDL());
214       
215       // loop over block structure
216       Int_t nBlock = rawStream->GetBlockCount();
217       for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
218         
219         blkHeader = rawStream->GetBlockHeader(iBlock);
220         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
221        
222         // loop over DSP structure
223         Int_t nDsp = rawStream->GetDspCount(iBlock);
224         for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
225           
226           dspHeader =  blkHeader->GetDspHeader(iDsp);
227           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
228           
229           // loop over BusPatch structure
230           Int_t nBusPatch = rawStream->GetBusPatchCount(iBlock, iDsp);
231           for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
232             
233             busStruct = dspHeader->GetBusPatch(iBusPatch);
234             
235             // loop over data
236             dataSize = busStruct->GetLength();
237             for (Int_t iData = 0; iData < dataSize; iData++) {
238               
239               Int_t  manuId    = busStruct->GetManuId(iData);
240               Int_t  channelId = busStruct->GetChannelId(iData);
241               Int_t  charge    = busStruct->GetCharge(iData);
242               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
243                      busStruct->GetBusPatchId(),
244                      manuId, 
245                      channelId, charge);
246             } // iData
247           } // iBusPatch
248         } // iDsp
249       } // iBlock
250     } // NextDDL
251   }// NextEvent
252   
253   delete rawReader;
254   delete rawStream;
255   timer.Print();
256 }
257
258
259 void MUONRawStreamTrackerHPExpert2(TString fileName = "./", Int_t maxEvent = 1000,  
260                                 Int_t minDDL = 0, Int_t maxDDL = 19)
261 {
262   /// This routine shows an alternate way to iterate over the DDL structures
263   /// compared to MUONRawStreamTrackerHPExpert().
264   
265   TStopwatch timer;
266   timer.Start(kTRUE);
267   
268   AliRawReader* rawReader = 0x0;
269   
270   // check extention to choose the rawdata file format
271   if (fileName.EndsWith("/")) {
272     rawReader = new AliRawReaderFile(fileName); // DDL files
273   } else if (fileName.EndsWith(".root")) {
274     rawReader = new AliRawReaderRoot(fileName);
275   } else if (!fileName.IsNull()) {
276     rawReader = new AliRawReaderDate(fileName); // DATE file
277   }
278   
279   // raw stream
280   AliMUONRawStreamTrackerHP* rawStream  = new AliMUONRawStreamTrackerHP(rawReader);
281   
282   // light weight interfaces to headers
283   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
284   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
285   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
286   
287   //   Loop over events  
288   Int_t iEvent = 0;
289   Int_t dataSize;
290   
291   while (rawReader->NextEvent()) {
292     
293     if (iEvent == maxEvent)
294       break;
295     
296     printf("Event %d\n",iEvent++);
297     
298     // read DDL while < 20 DDL
299     while(rawStream->NextDDL()) {
300       
301       if (rawStream->GetDDL() < minDDL || rawStream->GetDDL() > maxDDL)
302         continue;
303       
304       printf("\niDDL %d\n", rawStream->GetDDL());
305       
306       // loop over block structure
307       Int_t nBlock = rawStream->GetBlockCount();
308       for(Int_t iBlock = 0; iBlock < nBlock ;iBlock++){
309         
310         blkHeader = rawStream->GetBlockHeader(iBlock);
311         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
312        
313         // loop over DSP structure
314         Int_t nDsp = rawStream->GetDspCount(iBlock);
315         for(Int_t iDsp = 0; iDsp < nDsp ;iDsp++){   //DSP loop
316           
317           dspHeader =  rawStream->GetDspHeader(iBlock, iDsp);
318           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
319           
320           // loop over BusPatch structure
321           Int_t nBusPatch = rawStream->GetBusPatchCount(iBlock, iDsp);
322           for(Int_t iBusPatch = 0; iBusPatch < nBusPatch; iBusPatch++) {  
323             
324             busStruct = rawStream->GetBusPatch(iBlock, iDsp, iBusPatch);
325             
326             // loop over data
327             dataSize = busStruct->GetLength();
328             for (Int_t iData = 0; iData < dataSize; iData++) {
329               
330               Int_t  manuId    = busStruct->GetManuId(iData);
331               Int_t  channelId = busStruct->GetChannelId(iData);
332               Int_t  charge    = busStruct->GetCharge(iData);
333               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
334                      busStruct->GetBusPatchId(),
335                      manuId, 
336                      channelId, charge);
337             } // iData
338           } // iBusPatch
339         } // iDsp
340       } // iBlock
341     } // NextDDL
342   }// NextEvent
343   
344   delete rawReader;
345   delete rawStream;
346   timer.Print();
347 }
348
349
350 void MUONRawStreamTrackerHPExpert3(TString fileName = "./", Int_t maxEvent = 1000,  
351                                 Int_t minDDL = 0, Int_t maxDDL = 19)
352 {
353   /// This routine shows yet another alternate way to iterate over the DDL
354   /// structures compared to MUONRawStreamTrackerHPExpert().
355   
356   TStopwatch timer;
357   timer.Start(kTRUE);
358   
359   AliRawReader* rawReader = 0x0;
360   
361   // check extention to choose the rawdata file format
362   if (fileName.EndsWith("/")) {
363     rawReader = new AliRawReaderFile(fileName); // DDL files
364   } else if (fileName.EndsWith(".root")) {
365     rawReader = new AliRawReaderRoot(fileName);
366   } else if (!fileName.IsNull()) {
367     rawReader = new AliRawReaderDate(fileName); // DATE file
368   }
369   
370   // raw stream
371   AliMUONRawStreamTrackerHP* rawStream  = new AliMUONRawStreamTrackerHP(rawReader);
372   
373   // light weight interfaces to headers
374   const AliMUONRawStreamTrackerHP::AliBlockHeader*      blkHeader  = 0x0;
375   const AliMUONRawStreamTrackerHP::AliDspHeader*        dspHeader  = 0x0;
376   const AliMUONRawStreamTrackerHP::AliBusPatch*         busStruct  = 0x0;
377   
378   //   Loop over events  
379   Int_t iEvent = 0;
380   Int_t dataSize;
381   
382   while (rawReader->NextEvent()) {
383     
384     if (iEvent == maxEvent)
385       break;
386     
387     printf("Event %d\n",iEvent++);
388     
389     // read DDL while < 20 DDL
390     while(rawStream->NextDDL()) {
391       
392       if (rawStream->GetDDL() < minDDL || rawStream->GetDDL() > maxDDL)
393         continue;
394       
395       printf("\niDDL %d\n", rawStream->GetDDL());
396       
397       // loop over block structure
398       Int_t iBlock = 0;
399       blkHeader = rawStream->GetFirstBlockHeader();
400       while (blkHeader != NULL)
401       {
402         printf("Block %d Total length %d\n",iBlock,blkHeader->GetTotalLength());
403        
404         // loop over DSP structure
405         Int_t iDsp = 0;
406         dspHeader = blkHeader->GetFirstDspHeader();
407         while (dspHeader != NULL)
408         {
409           printf("Dsp %d length %d error word %d\n",iDsp,dspHeader->GetTotalLength(), dspHeader->GetErrorWord());
410           
411           // loop over BusPatch structure
412           Int_t iBusPatch = 0;
413           busStruct = dspHeader->GetFirstBusPatch();
414           while (busStruct != NULL)
415           {
416             // loop over data
417             dataSize = busStruct->GetLength();
418             for (Int_t iData = 0; iData < dataSize; iData++) {
419               
420               Int_t  manuId    = busStruct->GetManuId(iData);
421               Int_t  channelId = busStruct->GetChannelId(iData);
422               Int_t  charge    = busStruct->GetCharge(iData);
423               printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
424                      busStruct->GetBusPatchId(),
425                      manuId, 
426                      channelId, charge);
427             } // iData
428             busStruct = busStruct->Next();
429             iBusPatch++;
430           } // iBusPatch
431           dspHeader = dspHeader->Next();
432           iDsp++;
433         } // iDsp
434         blkHeader = blkHeader->Next();
435         iBlock++;
436       } // iBlock
437     } // NextDDL
438   }// NextEvent
439   
440   delete rawReader;
441   delete rawStream;
442   timer.Print();
443 }
444
445
446 void MUONRawStreamTrackerSimple(TString fileName = "./", Int_t maxEvent = 1000)
447 {
448   /// Reads the raw data in fileName, using a simplified interface (iterator
449   /// over pads).
450   TStopwatch timer;
451   timer.Start(kTRUE);
452   
453   AliRawReader* rawReader = 0x0;
454   
455   // check extention to choose the rawdata file format
456   if (fileName.EndsWith("/")) {
457     rawReader = new AliRawReaderFile(fileName); // DDL files
458   } else if (fileName.EndsWith(".root")) {
459     rawReader = new AliRawReaderRoot(fileName);
460   } else if (!fileName.IsNull()) {
461     rawReader = new AliRawReaderDate(fileName); // DATE file
462   }
463   
464   // raw stream
465   AliMUONRawStreamTracker* rawStream  = new AliMUONRawStreamTracker(rawReader);    
466   
467   //   Loop over events  
468   Int_t iEvent = 0;
469   
470   while (rawReader->NextEvent()) {
471     
472     if (iEvent == maxEvent)
473       break;
474     
475     printf("Event %d\n",iEvent++);
476     
477     Int_t busPatch;
478     UShort_t manuId, adc;
479     UChar_t manuChannel;
480     
481     rawStream->First();
482     
483     while ( rawStream->Next(busPatch,manuId,manuChannel,adc) )
484     {      
485       printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
486              busPatch,manuId,manuChannel, adc);
487     }
488   }
489   
490   delete rawReader;
491   delete rawStream;
492   timer.Print();
493 }
494
495
496 void MUONRawStreamTrackerHPSimple(TString fileName = "./", Int_t maxEvent = 1000)
497 {
498   /// This routine shows how to use the high performance decoder's simple interface.
499
500   TStopwatch timer;
501   timer.Start(kTRUE);
502   
503   AliRawReader* rawReader = 0x0;
504   
505   // check extention to choose the rawdata file format
506   if (fileName.EndsWith("/")) {
507     rawReader = new AliRawReaderFile(fileName); // DDL files
508   } else if (fileName.EndsWith(".root")) {
509     rawReader = new AliRawReaderRoot(fileName);
510   } else if (!fileName.IsNull()) {
511     rawReader = new AliRawReaderDate(fileName); // DATE file
512   }
513   
514   // raw stream
515   AliMUONRawStreamTrackerHP* rawStream  = new AliMUONRawStreamTrackerHP(rawReader);    
516   
517   //   Loop over events  
518   Int_t iEvent = 0;
519   
520   while (rawReader->NextEvent()) {
521     
522     if (iEvent == maxEvent)
523       break;
524     
525     printf("Event %d\n",iEvent++);
526     
527     Int_t busPatch;
528     UShort_t manuId, adc;
529     UChar_t manuChannel;
530     
531     rawStream->First();
532     
533     while ( rawStream->Next(busPatch,manuId,manuChannel,adc) )
534     {      
535       printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
536              busPatch,manuId,manuChannel, adc);
537     }
538   }
539   
540   delete rawReader;
541   delete rawStream;
542   timer.Print();
543 }
544
545
546 void MUONRawStreamTrackerHPSimple2(TString fileName = "./", Int_t maxEvent = 1000)
547 {
548   /// This routine is an alternative to MUONRawStreamTrackerHPSimple() which is even faster.
549
550   TStopwatch timer;
551   timer.Start(kTRUE);
552   
553   AliRawReader* rawReader = 0x0;
554   
555   // check extention to choose the rawdata file format
556   if (fileName.EndsWith("/")) {
557     rawReader = new AliRawReaderFile(fileName); // DDL files
558   } else if (fileName.EndsWith(".root")) {
559     rawReader = new AliRawReaderRoot(fileName);
560   } else if (!fileName.IsNull()) {
561     rawReader = new AliRawReaderDate(fileName); // DATE file
562   }
563   
564   // raw stream
565   AliMUONRawStreamTrackerHP* rawStream  = new AliMUONRawStreamTrackerHP(rawReader);    
566   
567   //   Loop over events  
568   Int_t iEvent = 0;
569   
570   while (rawReader->NextEvent()) {
571     
572     if (iEvent == maxEvent)
573       break;
574     
575     printf("Event %d\n",iEvent++);
576     
577     UShort_t manuId, adc;
578     UChar_t manuChannel;
579     
580     rawStream->First();
581     const AliMUONRawStreamTrackerHP::AliBusPatch* buspatch = NULL;
582     while ((buspatch = rawStream->Next()) != NULL)
583     {
584       for (UInt_t i = 0; i < buspatch->GetDataCount(); i++)
585       {
586         buspatch->GetData(i, manuId, manuChannel, adc);
587         printf("buspatch %5d manuI %4d channel %3d charge %4d\n", 
588                buspatch->GetBusPatchId(), manuId, manuChannel, adc);
589       }
590     }
591   }
592   
593   delete rawReader;
594   delete rawStream;
595   timer.Print();
596 }
597