]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/misc/AliL3DDLRawReader.cxx
New version of SPD raw-data reconstruction. The format now correponds to the actual...
[u/mrichter/AliRoot.git] / HLT / misc / AliL3DDLRawReader.cxx
1 // @(#) $Id$
2
3 // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright &copy ALICE HLT Group
5
6 #include "AliL3RootTypes.h"
7 #include "AliL3StandardIncludes.h"
8 #include "AliL3Logging.h"
9
10 #include "AliL3DDLRawReader.h"
11
12 #if __GNUC__ >= 3
13 using namespace std;
14 #endif
15
16 /**************************************************************************
17  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
18  *                                                                        *
19  * Author: The ALICE Off-line Project.                                    *
20  * Contributors are mentioned in the code where appropriate.              *
21  *                                                                        *
22  * Permission to use, copy, modify and distribute this software and its   *
23  * documentation strictly for non-commercial purposes is hereby granted   *
24  * without fee, provided that the above copyright notice appears in all   *
25  * copies and that both the copyright notice and this permission notice   *
26  * appear in the supporting documentation. The authors make no claims     *
27  * about the suitability of this software for any purpose. It is          *
28  * provided "as is" without express or implied warranty.                  *
29  **************************************************************************/
30
31 /** \class AliL3DDLRawReader
32 <pre>
33 //_____________________________________________________________
34 // AliL3DDLRawReader (taken from the offline AliROOT code,
35 // original authors: D.Favretto and A.K.Mohanty)
36 //
37 // This is the base class for reading ddl raw data 
38 // and providing information about digits
39 </pre>
40 */
41
42 ClassImp(AliL3DDLRawReader)
43
44 AliL3DDLRawReader::AliL3DDLRawReader()
45 {
46   fMiniHeader = NULL;
47   fCount = 0;
48   fSelectDetectorID = -1;
49   fSelectMinDDLID = -1;
50   fSelectMaxDDLID = -1;
51 }
52
53 AliL3DDLRawReader::~AliL3DDLRawReader()
54 {
55 }
56
57 void AliL3DDLRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
58 {
59   // read only data of the detector with the given ID and in the given
60   // range of DDLs (minDDLID <= DDLID < maxDDLID).
61   // no selection is applied if a value < 0 is used.
62
63   fSelectDetectorID = detectorID;
64   fSelectMinDDLID = minDDLID;
65   fSelectMaxDDLID = maxDDLID;
66 }
67
68 Bool_t AliL3DDLRawReader::IsSelected() const
69 {
70   // apply the selection (if any)
71
72   if (fSelectDetectorID >= 0) {
73     if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
74     if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
75       return kFALSE;
76     if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
77       return kFALSE;
78   }
79   return kTRUE;
80 }
81
82 Bool_t AliL3DDLRawReader::CheckMiniHeader() const
83 {
84   // check the magic number of the mini header
85
86   if ((fMiniHeader->fMagicWord[2] != 0x12) ||
87       (fMiniHeader->fMagicWord[1] != 0x34) ||
88       (fMiniHeader->fMagicWord[0] != 0x56)) {
89     LOG(AliL3Log::kError,"AliL3DDLRawReader::CheckMiniHeader","MH")
90       <<"DDL mini header has wrong magic word!"<<ENDLOG;
91     return kFALSE;
92   }
93   return kTRUE;
94 }
95
96 Bool_t AliL3DDLRawReader::ReadNextInt(UInt_t& data)
97 {
98   // reads the next 4 bytes at the current position
99   // returns kFALSE if the data could not be read
100
101   while (fCount == 0) {
102     if (!ReadMiniHeader()) return kFALSE;
103   }
104   if (fCount < (Int_t) sizeof(data)) {
105     LOG(AliL3Log::kError,"AliL3DDLRawReader::ReadNextInt","Data")
106       <<AliL3Log::kDec<<"Too few data left ("<<fCount<<") to read UInt_t!"<<ENDLOG;
107     return kFALSE;
108   }
109   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
110     LOG(AliL3Log::kError,"AliL3DDLRawReader::ReadNextInt","Data")
111       <<"Could not read data."<<ENDLOG;
112     return kFALSE;
113   }
114   return kTRUE;
115 }
116
117 Bool_t AliL3DDLRawReader::ReadNextShort(UShort_t& data)
118 {
119   // reads the next 2 bytes at the current position
120   // returns kFALSE if the data could not be read
121
122   while (fCount == 0) {
123     if (!ReadMiniHeader()) return kFALSE;
124   }
125   if (fCount < (Int_t) sizeof(data)) {
126     LOG(AliL3Log::kError,"AliL3DDLRawReader::ReadNextShort","Data")
127       <<AliL3Log::kDec<<"Too few data left ("<<fCount<<") to read UShort_t!"<<ENDLOG;
128     return kFALSE;
129   }
130   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
131     LOG(AliL3Log::kError,"AliL3DDLRawReader::ReadNextShort","Data")
132       <<"Could not read data."<<ENDLOG;
133     return kFALSE;
134   }
135   return kTRUE;
136 }
137
138 Bool_t AliL3DDLRawReader::ReadNextChar(UChar_t& data)
139 {
140   // reads the next 1 byte at the current stream position
141   // returns kFALSE if the data could not be read
142
143   while (fCount == 0) {
144     if (!ReadMiniHeader()) return kFALSE;
145   }
146   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
147     LOG(AliL3Log::kError,"AliL3DDLRawReader::ReadNextChar","Data")
148       <<"Could not read data."<<ENDLOG;
149     return kFALSE;
150   }
151   return kTRUE;
152 }
153