]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliRawReader.cxx
Concomitant clusterisation and trigger reconstruction
[u/mrichter/AliRoot.git] / STEER / AliRawReader.cxx
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 ///////////////////////////////////////////////////////////////////////////////
17 //
18 // This is the base class for reading raw data and providing
19 // information about digits
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "AliRawReader.h"
24
25
26 ClassImp(AliRawReader)
27
28
29 AliRawReader::AliRawReader()
30 {
31   fMiniHeader = NULL;
32   fCount = 0;
33
34   fSelectDetectorID = -1;
35   fSelectMinDDLID = -1;
36   fSelectMaxDDLID = -1;
37 }
38
39
40 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
41 {
42 // read only data of the detector with the given ID and in the given
43 // range of DDLs (minDDLID <= DDLID < maxDDLID).
44 // no selection is applied if a value < 0 is used.
45
46   fSelectDetectorID = detectorID;
47   fSelectMinDDLID = minDDLID;
48   fSelectMaxDDLID = maxDDLID;
49 }
50
51 Bool_t AliRawReader::IsSelected()
52 {
53 // apply the selection (if any)
54
55   if (fSelectDetectorID >= 0) {
56     if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
57     if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
58       return kFALSE;
59     if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
60       return kFALSE;
61   }
62   return kTRUE;
63 }
64
65
66 Bool_t AliRawReader::CheckMiniHeader()
67 {
68 // check the magic number of the mini header
69
70   if ((fMiniHeader->fMagicWord[2] != 0x12) ||
71       (fMiniHeader->fMagicWord[1] != 0x34) ||
72       (fMiniHeader->fMagicWord[0] != 0x56)) {
73     Error("CheckMiniHeader", "wrong magic word!");
74     return kFALSE;
75   }
76   return kTRUE;
77 }
78
79 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
80 {
81 // reads the next 4 bytes at the current position
82 // returns kFALSE if the data could not be read
83
84   while (fCount == 0) {
85     if (!ReadMiniHeader()) return kFALSE;
86   }
87   if (fCount < (Int_t) sizeof(data)) {
88     Error("ReadNextInt", 
89           "too few data left (%d bytes) to read an UInt_t!", fCount);
90     return kFALSE;
91   }
92   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
93     Error("ReadNextInt", "could not read data!");
94     return kFALSE;
95   }
96   return kTRUE;
97 }
98
99 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
100 {
101 // reads the next 2 bytes at the current position
102 // returns kFALSE if the data could not be read
103
104   while (fCount == 0) {
105     if (!ReadMiniHeader()) return kFALSE;
106   }
107   if (fCount < (Int_t) sizeof(data)) {
108     Error("ReadNextShort", 
109           "too few data left (%d bytes) to read an UShort_t!", fCount);
110     return kFALSE;
111   }
112   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
113     Error("ReadNextShort", "could not read data!");
114     return kFALSE;
115   }
116   return kTRUE;
117 }
118
119 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
120 {
121 // reads the next 1 byte at the current stream position
122 // returns kFALSE if the data could not be read
123
124   while (fCount == 0) {
125     if (!ReadMiniHeader()) return kFALSE;
126   }
127   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
128     Error("ReadNextChar", "could not read data!");
129     return kFALSE;
130   }
131   return kTRUE;
132 }
133