* provided "as is" without express or implied warranty. *
**************************************************************************/
-/* $Id$ */
+// $Id$
/**
* @file AliHLTMUONDataBlockWriter.h
* @author Artur Szostak <artursz@iafrica.com>
- * @date
+ * @date 19 May 2007
* @brief Definition of a writer 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"
/**
* A light weight class for writing an internal dimuon HLT data block.
* variable 'size'. The data block is of type 'block_type', the data block entries
* are of type 'entries_type' and the data block type code is 'type_code'.
* The data block can be written in the following way:
- *
+ * \code
* void* buffer = somebuffer;
* AliHLTUInt32_t size = somebuffer_size;
*
* block(buffer, size);
*
* // Initialise the block header
- * if (not block.InitHeader())
+ * if (not block.InitCommonHeader())
* {
* // handle error and exit...
* }
* // fill the new entry...
* entry.somefield = somevalue;
* }
- *
+ * \endcode
* The slightly slower but safer method is to do the following:
- *
+ * \code
* AliHLTMUONDataBlockWriter<block_type, entries_type, type_code>
* block(buffer, size);
- * if (not block.InitHeader())
+ * if (not block.InitCommonHeader())
* {
* // handle error and exit...
* }
* while (HaveMoreEntries())
* {
* entries_type* entry = block.AddEntry();
+ * if (entry == NULL)
+ * {
+ * // handle buffer overflow and exit...
+ * }
* // fill the new entry...
* entry->somefield = somevalue;
* }
+ * \endcode
*/
template <
class DataBlockType,
class AliHLTMUONDataBlockWriter
{
public:
+ typedef DataBlockType HeaderType;
+ typedef DataElementType ElementType;
/**
* Constructor that sets the internal pointer to the start of the buffer
*/
AliHLTMUONDataBlockWriter(void* buffer, AliHLTUInt32_t size) :
fSize(size),
- fMaxArraySize(size - sizeof(DataBlockType)),
+ fMaxArraySize(size > sizeof(DataBlockType) ? size - sizeof(DataBlockType) : 0),
fBlock(reinterpret_cast<DataBlockType*>(buffer)),
fData(reinterpret_cast<DataElementType*>(
reinterpret_cast<DataBlockType*>(buffer) + 1
{
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.
+ */
+ AliHLTMUONDataBlockWriter(const AliHLTMUONDataBlockWriter& writer)
+ {
+ fSize = writer.fSize;
+ fMaxArraySize = writer.fMaxArraySize;
+ fBlock = writer.fBlock;
+ fData = writer.fData;
+ }
+
+ /**
+ * Assignment operator performs a shallow copy.
+ * This is OK because this class does not take direct ownership of the
+ * output memory buffer.
+ */
+ AliHLTMUONDataBlockWriter& operator = (const AliHLTMUONDataBlockWriter& writer)
+ {
+ fSize = writer.fSize;
+ fMaxArraySize = writer.fMaxArraySize;
+ fBlock = writer.fBlock;
+ fData = writer.fData;
+ return *this;
+ }
/**
- * Initialises the data block header by setting the type and record width
- * fields. If the buffer size was to small to create the header then this
- * method returns false, otherwise true on success.
+ * Initialises the common data block header by setting the type and record
+ * width fields. If the buffer size was to small to create the header then
+ * this method returns false, otherwise true on success.
*/
- bool InitHeader() const
+ bool InitCommonHeader() const
{
// The block size must be at least sizeof(DataBlockType) bytes.
if (fSize < sizeof(DataBlockType)) return false;
}
/**
- * Returns the data block header.
+ * Returns the common data block header.
*/
- const AliHLTMUONDataBlockHeader& BlockHeader() const
+ const AliHLTMUONDataBlockHeader& CommonBlockHeader() const
{
return fBlock->fHeader;
}
+ /**
+ * Returns the whole data block header.
+ */
+ DataBlockType& BlockHeader()
+ {
+ return *fBlock;
+ }
+
+ const DataBlockType& BlockHeader() const
+ {
+ return *fBlock;
+ }
+
/**
* Returns a pointer to the next location where a data entry can be
* written and increments the number of entries.
{
if (n * sizeof(DataElementType) > fMaxArraySize) return false;
fBlock->fHeader.fNrecords = n;
+ return true;
}
/**
/**
* Calculates the number of bytes used for the data block in the buffer.
- * This value will only make sense if a call to InitHeader() was made
- * and it returned true.
+ * This value will only make sense if a call to InitCommonHeader() was
+ * made and it returned true.
*/
AliHLTUInt32_t BytesUsed() const
{
- assert( Nentries() * sizeof(DataElementType)
- == Nentries() * fBlock->fHeader.fRecordWidth
- );
-
+ assert( sizeof(DataElementType) == fBlock->fHeader.fRecordWidth);
return sizeof(DataBlockType) + Nentries() * sizeof(DataElementType);
}
return fMaxArraySize / sizeof(DataElementType);
}
+ AliHLTUInt32_t BufferSize() { return fSize; }
+
private:
AliHLTUInt32_t fSize; // Size of the buffer in bytes.
kTrigRecsDebugDataBlock
> AliHLTMUONTrigRecsDebugBlockWriter;
-typedef AliHLTMUONDataBlockWriter<
- AliHLTMUONTriggerChannelsBlockStruct,
- AliHLTMUONTriggerChannelStruct,
- kTriggerChannelsDataBlock
- > AliHLTMUONTriggerChannelsBlockWriter;
-
typedef AliHLTMUONDataBlockWriter<
AliHLTMUONRecHitsBlockStruct,
AliHLTMUONRecHitStruct,
kChannelsDataBlock
> AliHLTMUONChannelsBlockWriter;
+typedef AliHLTMUONDataBlockWriter<
+ AliHLTMUONMansoTracksBlockStruct,
+ AliHLTMUONMansoTrackStruct,
+ kMansoTracksDataBlock
+ > AliHLTMUONMansoTracksBlockWriter;
+
+typedef AliHLTMUONDataBlockWriter<
+ AliHLTMUONMansoCandidatesBlockStruct,
+ AliHLTMUONMansoCandidateStruct,
+ kMansoCandidatesDataBlock
+ > AliHLTMUONMansoCandidatesBlockWriter;
+
+typedef AliHLTMUONDataBlockWriter<
+ AliHLTMUONTracksBlockStruct,
+ AliHLTMUONTrackStruct,
+ kTracksDataBlock
+ > AliHLTMUONTracksBlockWriter;
+
+typedef AliHLTMUONDataBlockWriter<
+ AliHLTMUONSinglesDecisionBlockStruct,
+ AliHLTMUONTrackDecisionStruct,
+ kSinglesDecisionDataBlock
+ > AliHLTMUONSinglesDecisionBlockWriter;
+
+typedef AliHLTMUONDataBlockWriter<
+ AliHLTMUONPairsDecisionBlockStruct,
+ AliHLTMUONPairDecisionStruct,
+ kPairsDecisionDataBlock
+ > AliHLTMUONPairsDecisionBlockWriter;
+
#endif // ALIHLTMUONDATABLOCKWRITER_H