- cleaning up debug output
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTCaloClusterReader.cxx
CommitLineData
7fc04b67 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Authors: Oystein Djuvsland *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16#include "AliHLTCaloClusterReader.h"
17#include "AliHLTCaloClusterDataStruct.h"
b4479a87 18#include "AliHLTCaloDigitDataStruct.h"
7fc04b67 19
20AliHLTCaloClusterReader::AliHLTCaloClusterReader():
21 fCurrentClusterPtr(0),
22 fIsSetMemory(false),
23 fMaxCnt(0),
24 fCurrentCnt(0)
25{
26 //See header file for documentation
27}
28
29
30AliHLTCaloClusterReader::~AliHLTCaloClusterReader()
31{
32 //See header file for documentation
33}
34
35
36AliHLTCaloClusterDataStruct*
37AliHLTCaloClusterReader::NextCluster()
38{
39 // See header file for documentation
40 AliHLTCaloClusterDataStruct* tmpChannelPtr = 0;
41
42 // Check if we have set our memory buffer
43 if(fIsSetMemory == false)
44 {
45 return 0;
46 }
47
48 // Check if we don't read more clusters than we have
49 if(fCurrentCnt < fMaxCnt)
50 {
51 // So, we get our cluster
52 tmpChannelPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>(fCurrentClusterPtr);
53
54 // increment the number of clusters read
55 fCurrentCnt++;
56
57 // Move our cluster pointer to give us a cluster next time
58 // The increment is defined as the size of the cluster data struct
59 // + the number of cells minus the one already included in the struct
60 // times the amount of data for each cell (absolute ID (short) and amplitude fraction (float))
61 fCurrentClusterPtr = (AliHLTCaloClusterDataStruct*)((UChar_t*)fCurrentClusterPtr
ba340030 62 + sizeof(AliHLTCaloClusterDataStruct)
63 + (fCurrentClusterPtr->fNCells-1)*(sizeof(Float_t) + sizeof(Short_t)));
7fc04b67 64 // return the cluster
65 return tmpChannelPtr;
66 }
67 // if we have read our clusters we reset our memory pointer and returns 0;
68 else
69 {
70 Reset();
71 return 0;
72 }
73
74 // will never happen, but anyway...
75 return 0;
76}
77
78bool
79AliHLTCaloClusterReader::GetCell(AliHLTCaloClusterDataStruct *clusterPtr, UShort_t &cellId, Double32_t &cellAmp, UInt_t index)
80{
81 // See header file for documentation
82
83 // check if the index is within bounds
84 if(index < clusterPtr->fNCells)
85 {
86 // the absolute ID is located in the memory address of the first ID plus the size of the pair of cell properties times the index
87 cellId = *(UShort_t*)((UChar_t*)(&(clusterPtr->fCellsAbsId)) + index * (sizeof(Short_t) + sizeof(Float_t)));
88 // the amplitude fraction is located in the memory address of the first ID plus the size of the pair of cell properties times the index
89 cellAmp = *(Float_t*)((UChar_t*)(&(clusterPtr->fCellsAmpFraction)) + index * (sizeof(Short_t) + sizeof(Float_t)));
90 return true;
91 }
92 else return false;
93}
94
95void
96AliHLTCaloClusterReader::SetMemory(const AliHLTCaloClusterHeaderStruct* clusterHeaderPtr)
97{
98 //See header file for documentation
b4479a87 99
7fc04b67 100 fMaxCnt = clusterHeaderPtr->fNClusters;
b4479a87 101 fCurrentClusterPtr = reinterpret_cast<AliHLTCaloClusterDataStruct*>((UChar_t*)(clusterHeaderPtr) + sizeof(AliHLTCaloClusterHeaderStruct) + sizeof(AliHLTCaloDigitDataStruct)*clusterHeaderPtr->fNDigits);
7fc04b67 102 fIsSetMemory = true;
103}
104
105
106void
107AliHLTCaloClusterReader::Reset()
108{
109 //See header file for documentation
110 fCurrentCnt = 0;
111 fIsSetMemory = false;
112}