* provided "as is" without express or implied warranty. *
**************************************************************************/
-/* $Id$ */
+// $Id$
/**
* @file AliHLTMUONDataBlockReader.h
* @author Artur Szostak <artursz@iafrica.com>
- * @date
+ * @date 19 May 2007
* @brief Definition of a reader class for internal dimuon HLT raw data blocks.
*/
#include "AliHLTMUONTriggerRecordsBlockStruct.h"
#include "AliHLTMUONTrigRecsDebugBlockStruct.h"
-#include "AliHLTMUONTriggerChannelsBlockStruct.h"
#include "AliHLTMUONRecHitsBlockStruct.h"
#include "AliHLTMUONClustersBlockStruct.h"
#include "AliHLTMUONChannelsBlockStruct.h"
#include "AliHLTMUONMansoTracksBlockStruct.h"
#include "AliHLTMUONMansoCandidatesBlockStruct.h"
+#include "AliHLTMUONTracksBlockStruct.h"
#include "AliHLTMUONSinglesDecisionBlockStruct.h"
#include "AliHLTMUONPairsDecisionBlockStruct.h"
* stored in memory and the size of the data block is given by the variable 'size'.
* The data block is of type 'block_type' and the data block entries are of type
* 'entries_type'. The data block can be accessed in the following way:
- *
+ * \code
* void* buffer = somebuffer;
* AliHLTUInt32_t size = somebuffer_size;
*
* const entries_type& entry = block[i];
* // Do something with the entry...
* }
+ * \endcode
*/
template <class DataBlockType, class DataElementType>
class AliHLTMUONDataBlockReader
{
public:
+ typedef DataBlockType HeaderType;
+ typedef DataElementType ElementType;
/**
* Constructor that sets the internal pointer to the start of the data
{
assert( buffer != NULL );
}
+
+ /**
+ * Copy constructor that performs a shallow copy.
+ * Since this class does not take direct ownership of the buffer, never
+ * allocates or deallocates memory, this can be allowed.
+ */
+ AliHLTMUONDataBlockReader(const AliHLTMUONDataBlockReader& reader)
+ {
+ fSize = reader.fSize;
+ fBlock = reader.fBlock;
+ fData = reader.fData;
+ }
+
+ /**
+ * Assignment operator performs a shallow copy.
+ * This is OK because this class does not take direct ownership of the
+ * output memory buffer.
+ */
+ AliHLTMUONDataBlockReader& operator = (const AliHLTMUONDataBlockReader& reader)
+ {
+ fSize = reader.fSize;
+ fBlock = reader.fBlock;
+ fData = reader.fData;
+ return *this;
+ }
/**
* Checks that the size of the buffer storing the data block is correct.
bool BufferSizeOk() const
{
// The block size must be at least sizeof(DataBlockType) bytes.
+ // Do not try read the header otherwise, because we could get a
+ // seg fault.
if (fSize < sizeof(DataBlockType)) return false;
// Now check if the size of the data block corresponds to the
*/
const DataBlockType& BlockHeader() const
{
- return fBlock;
+ return *fBlock;
}
/**
*/
const DataElementType* GetArray() const { return fData; }
+ /**
+ * Calculates the number of bytes used for the data block in the buffer.
+ * This value should be the same as what is returned by BufferSize()
+ * unless too much buffer space was allocated.
+ */
+ AliHLTUInt32_t BytesUsed() const
+ {
+ assert( sizeof(DataElementType) == fBlock->fHeader.fRecordWidth);
+ return sizeof(DataBlockType) + Nentries() * sizeof(DataElementType);
+ }
+
+ AliHLTUInt32_t BufferSize() const { return fSize; }
+
private:
AliHLTUInt32_t fSize; // Size of the data block in bytes.
AliHLTMUONTrigRecInfoStruct
> AliHLTMUONTrigRecsDebugBlockReader;
-typedef AliHLTMUONDataBlockReader<
- AliHLTMUONTriggerChannelsBlockStruct,
- AliHLTMUONTriggerChannelStruct
- > AliHLTMUONTriggerChannelsBlockReader;
-
typedef AliHLTMUONDataBlockReader<
AliHLTMUONRecHitsBlockStruct,
AliHLTMUONRecHitStruct
AliHLTMUONMansoCandidateStruct
> AliHLTMUONMansoCandidatesBlockReader;
+typedef AliHLTMUONDataBlockReader<
+ AliHLTMUONTracksBlockStruct,
+ AliHLTMUONTrackStruct
+ > AliHLTMUONTracksBlockReader;
+
typedef AliHLTMUONDataBlockReader<
AliHLTMUONSinglesDecisionBlockStruct,
AliHLTMUONTrackDecisionStruct