1 #ifndef ALIHLTMUONDATABLOCKREADER_H
2 #define ALIHLTMUONDATABLOCKREADER_H
3 /**************************************************************************
4 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
21 * @file AliHLTMUONDataBlockReader.h
22 * @author Artur Szostak <artursz@iafrica.com>
24 * @brief Definition of a reader class for internal dimuon HLT raw data blocks.
27 #include "AliHLTMUONDataTypes.h"
30 #include "AliHLTMUONTriggerRecordsBlockStruct.h"
31 #include "AliHLTMUONTrigRecsDebugBlockStruct.h"
32 #include "AliHLTMUONTriggerChannelsBlockStruct.h"
33 #include "AliHLTMUONRecHitsBlockStruct.h"
34 #include "AliHLTMUONClustersBlockStruct.h"
35 #include "AliHLTMUONChannelsBlockStruct.h"
36 #include "AliHLTMUONMansoTracksBlockStruct.h"
37 #include "AliHLTMUONMansoCandidatesBlockStruct.h"
38 #include "AliHLTMUONSinglesDecisionBlockStruct.h"
39 #include "AliHLTMUONPairsDecisionBlockStruct.h"
42 * A light weight class for reading the contents of an internal dimuon HLT
44 * Suppose we are given a pointer 'buffer' to the buffer where a data block is
45 * stored in memory and the size of the data block is given by the variable 'size'.
46 * The data block is of type 'block_type' and the data block entries are of type
47 * 'entries_type'. The data block can be accessed in the following way:
49 * void* buffer = somebuffer;
50 * AliHLTUInt32_t size = somebuffer_size;
52 * // Initialise the data block reader.
53 * AliHLTMUONDataBlockReader<block_type, entries_type> block(buffer, size);
55 * // Check that the buffer has the expected size.
56 * if (not block.BufferSizeOk())
61 * // Find the number of entries in the data block.
62 * AliHLTUInt32_t nentries = block.Nentries();
64 * // Loop over all entries in the data block.
65 * for (AliHLTUInt32_t i = 0; i < nentries; i++)
67 * const entries_type& entry = block[i];
68 * // Do something with the entry...
71 template <class DataBlockType, class DataElementType>
72 class AliHLTMUONDataBlockReader
75 typedef DataBlockType HeaderType;
76 typedef DataElementType ElementType;
79 * Constructor that sets the internal pointer to the start of the data
80 * block and the total size of the block in bytes.
81 * @param buffer The pointer to the first byte of the block in memory.
82 * @param size The total size of the data block in bytes.
84 AliHLTMUONDataBlockReader(const void* buffer, AliHLTUInt32_t size) :
86 fBlock(reinterpret_cast<const DataBlockType*>(buffer)),
87 fData(reinterpret_cast<const DataElementType*>(
88 reinterpret_cast<const DataBlockType*>(buffer) + 1
91 assert( buffer != NULL );
95 * Checks that the size of the buffer storing the data block is correct.
96 * Basic sanity checks are performed such as seeing if the data block
97 * size corresponds to the number of reconstructed hits stored and that
98 * the size of the buffer is at least sizeof(DataBlockType) bytes big.
100 bool BufferSizeOk() const
102 // The block size must be at least sizeof(DataBlockType) bytes.
103 if (fSize < sizeof(DataBlockType)) return false;
105 // Now check if the size of the data block corresponds to the
106 // number of entries it claims to contain.
107 AliHLTUInt32_t arraysize = fSize - sizeof(DataBlockType);
108 return arraysize == Nentries() * sizeof(DataElementType);
112 * Returns the common data block header.
114 const AliHLTMUONDataBlockHeader& CommonBlockHeader() const
116 return fBlock->fHeader;
120 * Returns the whole data block header.
122 const DataBlockType& BlockHeader() const
128 * Returns the total number of entries in the data block.
130 AliHLTUInt32_t Nentries() const { return fBlock->fHeader.fNrecords; }
133 * Returns a pointer to the i'th entry.
134 * If the index 'i' is out of bounds then NULL is returned.
135 * This is a safe access method because it does bounds checking but is
136 * a little slower than the array operator.
137 * @param i The index number of the entry to be returned.
138 * @return A pointer to the entry or NULL.
140 const DataElementType* Entry(AliHLTUInt32_t i) const
142 return (i < Nentries()) ? &fData[i] : NULL;
146 * Array operator for accessing the data entries directly.
147 * The index variable 'i' is not checked (except in debug compilations)
148 * so one should make sure they are within the valid range.
150 const DataElementType& operator [] (AliHLTUInt32_t i) const
152 assert( i < Nentries() );
157 * Returns a pointer to the array of elements in the data block.
158 * Care must be taken not to read beyond the array limits given by
161 const DataElementType* GetArray() const { return fData; }
163 AliHLTUInt32_t BufferSize() { return fSize; }
167 AliHLTUInt32_t fSize; // Size of the data block in bytes.
168 const DataBlockType* fBlock; // Pointer to the data block buffer.
169 const DataElementType* fData; // Pointer to the data array.
173 // We now define the reader classes for the various data block types from the
174 // template class AliHLTMUONDataBlockReader.
176 typedef AliHLTMUONDataBlockReader<
177 AliHLTMUONTriggerRecordsBlockStruct,
178 AliHLTMUONTriggerRecordStruct
179 > AliHLTMUONTriggerRecordsBlockReader;
181 typedef AliHLTMUONDataBlockReader<
182 AliHLTMUONTrigRecsDebugBlockStruct,
183 AliHLTMUONTrigRecInfoStruct
184 > AliHLTMUONTrigRecsDebugBlockReader;
186 typedef AliHLTMUONDataBlockReader<
187 AliHLTMUONTriggerChannelsBlockStruct,
188 AliHLTMUONTriggerChannelStruct
189 > AliHLTMUONTriggerChannelsBlockReader;
191 typedef AliHLTMUONDataBlockReader<
192 AliHLTMUONRecHitsBlockStruct,
193 AliHLTMUONRecHitStruct
194 > AliHLTMUONRecHitsBlockReader;
196 typedef AliHLTMUONDataBlockReader<
197 AliHLTMUONClustersBlockStruct,
198 AliHLTMUONClusterStruct
199 > AliHLTMUONClustersBlockReader;
201 typedef AliHLTMUONDataBlockReader<
202 AliHLTMUONChannelsBlockStruct,
203 AliHLTMUONChannelStruct
204 > AliHLTMUONChannelsBlockReader;
206 typedef AliHLTMUONDataBlockReader<
207 AliHLTMUONMansoTracksBlockStruct,
208 AliHLTMUONMansoTrackStruct
209 > AliHLTMUONMansoTracksBlockReader;
211 typedef AliHLTMUONDataBlockReader<
212 AliHLTMUONMansoCandidatesBlockStruct,
213 AliHLTMUONMansoCandidateStruct
214 > AliHLTMUONMansoCandidatesBlockReader;
216 typedef AliHLTMUONDataBlockReader<
217 AliHLTMUONSinglesDecisionBlockStruct,
218 AliHLTMUONTrackDecisionStruct
219 > AliHLTMUONSinglesDecisionBlockReader;
221 typedef AliHLTMUONDataBlockReader<
222 AliHLTMUONPairsDecisionBlockStruct,
223 AliHLTMUONPairDecisionStruct
224 > AliHLTMUONPairsDecisionBlockReader;
226 #endif // ALIHLTMUONDATABLOCKREADER_H