]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/misc/AliHLTDDLRawReader.cxx
L3 becomes HLT
[u/mrichter/AliRoot.git] / HLT / misc / AliHLTDDLRawReader.cxx
CommitLineData
240d63be 1// @(#) $Id$
2
3// Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4//*-- Copyright &copy ALICE HLT Group
5
4aa41877 6#include "AliHLTRootTypes.h"
7#include "AliHLTStandardIncludes.h"
8#include "AliHLTLogging.h"
240d63be 9
4aa41877 10#include "AliHLTDDLRawReader.h"
240d63be 11
5929c18d 12#if __GNUC__ >= 3
13using namespace std;
14#endif
15
240d63be 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
4aa41877 31/** \class AliHLTDDLRawReader
240d63be 32<pre>
33//_____________________________________________________________
4aa41877 34// AliHLTDDLRawReader (taken from the offline AliROOT code,
240d63be 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
4aa41877 42ClassImp(AliHLTDDLRawReader)
240d63be 43
4aa41877 44AliHLTDDLRawReader::AliHLTDDLRawReader()
240d63be 45{
46 fMiniHeader = NULL;
47 fCount = 0;
48 fSelectDetectorID = -1;
49 fSelectMinDDLID = -1;
50 fSelectMaxDDLID = -1;
51}
52
4aa41877 53AliHLTDDLRawReader::~AliHLTDDLRawReader()
240d63be 54{
55}
56
4aa41877 57void AliHLTDDLRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
240d63be 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
4aa41877 68Bool_t AliHLTDDLRawReader::IsSelected() const
240d63be 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
4aa41877 82Bool_t AliHLTDDLRawReader::CheckMiniHeader() const
240d63be 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)) {
4aa41877 89 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::CheckMiniHeader","MH")
240d63be 90 <<"DDL mini header has wrong magic word!"<<ENDLOG;
91 return kFALSE;
92 }
93 return kTRUE;
94}
95
4aa41877 96Bool_t AliHLTDDLRawReader::ReadNextInt(UInt_t& data)
240d63be 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)) {
4aa41877 105 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::ReadNextInt","Data")
106 <<AliHLTLog::kDec<<"Too few data left ("<<fCount<<") to read UInt_t!"<<ENDLOG;
240d63be 107 return kFALSE;
108 }
109 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
4aa41877 110 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::ReadNextInt","Data")
240d63be 111 <<"Could not read data."<<ENDLOG;
112 return kFALSE;
113 }
114 return kTRUE;
115}
116
4aa41877 117Bool_t AliHLTDDLRawReader::ReadNextShort(UShort_t& data)
240d63be 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)) {
4aa41877 126 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::ReadNextShort","Data")
127 <<AliHLTLog::kDec<<"Too few data left ("<<fCount<<") to read UShort_t!"<<ENDLOG;
240d63be 128 return kFALSE;
129 }
130 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
4aa41877 131 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::ReadNextShort","Data")
240d63be 132 <<"Could not read data."<<ENDLOG;
133 return kFALSE;
134 }
135 return kTRUE;
136}
137
4aa41877 138Bool_t AliHLTDDLRawReader::ReadNextChar(UChar_t& data)
240d63be 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))) {
4aa41877 147 LOG(AliHLTLog::kError,"AliHLTDDLRawReader::ReadNextChar","Data")
240d63be 148 <<"Could not read data."<<ENDLOG;
149 return kFALSE;
150 }
151 return kTRUE;
152}
153