]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloSharedMemoryInterfacev2.cxx
f7ccdce269f6cc3bf653fd281d0a4dc5e33225dc
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloSharedMemoryInterfacev2.cxx
1 // $Id: AliHLTCaloSharedMemoryInterfacev2.cxx 35071 2009-09-29 05:26:09Z phille $
2
3 /**************************************************************************
4  * This file is property of and copyright by the Experimental Nuclear     *
5  * Physics Group, Dep. of Physics                                         *
6  * University of Oslo, Norway, 2007                                       *
7  *                                                                        *
8  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
9  * Contributors are mentioned in the code where appropriate.              *
10  * Please report bugs to perthi@fys.uio.no                                *
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          *
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21
22 #include "AliHLTCaloSharedMemoryInterfacev2.h"
23 #include "AliHLTCaloChannelDataHeaderStruct.h"
24 #include "AliHLTCaloChannelDataStruct.h"
25 #include "AliHLTLogging.h"
26 #include "AliHLTCaloMapper.h"
27 #include "AliHLTCaloConstants.h"
28
29
30 AliHLTCaloSharedMemoryInterfacev2::AliHLTCaloSharedMemoryInterfacev2(): fCurrentChannel(0),
31                                                                         fChannelDataPtr(0),
32                                                                         fIsSetMemory(false),
33                                                                         fHasRawData(false),
34                                                                         fMaxCnt(0),
35                                                                         fCurrentCnt(0), 
36                                                                         fRawDataPtr(0),
37                                                                         fRawData()
38                                                                         //      fSpecification(0)
39 {
40   //  GetSpecFromDDLIndex
41   //  AliHLTCaloMapper  *fMapperPtr[32];
42
43   /*
44   for(int i=0; i < 32; i++)
45     {
46       fMapperPtr[i] = new AliHLTCaloMapper( AliHLTCaloMapper::GetSpecFromDDLIndex(i) ) ;
47     }
48   */
49 }
50
51
52
53 AliHLTCaloSharedMemoryInterfacev2::~AliHLTCaloSharedMemoryInterfacev2()
54 {
55
56 }
57
58
59 /*
60 struct AliHLTCaloChannelDataStruct
61 {
62   Float_t fEnergy;
63   Float_t fTime;
64   UShort_t fChannelID;
65   Short_t fCrazyness;
66   //  Short_t fRawDataSize; //the size of the raw data
67 };
68 */
69
70 AliHLTCaloChannelDataStruct*   
71 AliHLTCaloSharedMemoryInterfacev2::NextChannel()
72 {
73   // Comment
74   AliHLTCaloChannelDataStruct* tmpChannelPtr = 0;
75   if(fCurrentCnt < fMaxCnt)
76     {
77       tmpChannelPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(fChannelDataPtr);
78       fCurrentCnt++;
79       fChannelDataPtr += sizeof(AliHLTCaloChannelDataStruct);
80       if(fHasRawData == true)
81         {
82           fRawData.fEnergy = tmpChannelPtr->fEnergy;
83           fRawData.fTime = tmpChannelPtr->fTime;
84           fRawData.fChannelID = tmpChannelPtr->fChannelID; 
85           fRawData.fCrazyness  = tmpChannelPtr->fCrazyness; 
86           Reset(fRawData);
87           //AliHLTCaloMapper::ChannelId2Coordinate(const UShort_t channelId,    AliHLTCaloCoordinate &channelCoord) 
88
89           
90           AliHLTCaloMapper::ChannelId2Coordinate( fRawData.fChannelID, fRawData.fCoordinate);
91           
92           
93           
94
95           
96           if( fRawData.fChannelID ==  fRawDataPtr[0]  )
97             {
98               Reset(fRawData);
99               //      cout << __FILE__ << __LINE__ << "fRawData.fChannelID ==  fRawDataPtr[0] =  " << fRawDataPtr[0]  << endl;
100               //    cout << "  copying raw dat not yet implemnted " << endl;
101               UShort_t tmpTotSize =  fRawDataPtr[1];
102               UShort_t tmpStartBin   =  fRawDataPtr[2];
103               UShort_t tmpBunchtSize =  fRawDataPtr[3];
104               //    fRawDataPtr
105               UShort_t tmpSamplesLeft = tmpTotSize -4; 
106
107               fRawData.nSamplesUsed =  tmpTotSize +  tmpStartBin;
108
109               while(tmpSamplesLeft > 0)
110                 {
111                   for(int i=0; i < tmpBunchtSize; i++ )
112                     {
113                       fRawData.fDataPtr[i + tmpStartBin] = fRawDataPtr[ i+ 4];
114                       tmpSamplesLeft --;
115                     }
116                 }
117               fRawDataPtr+= tmpTotSize;
118               
119             }
120           else
121             {
122               //              cout << __FILE__ << __LINE__ << "ERROR! fRawData.fChannelID = "<<  fRawData.fChannelID  << "  but  fRawDataPtr[0] =  " << fRawDataPtr[0]  << endl;
123             }
124           
125
126           //      HLTDebug("Raw data interface not yet implemented, ignoring raw data");
127         }
128       return tmpChannelPtr;
129     }
130   else
131     {
132       Reset();
133       return 0;
134     }
135   return 0;
136 }
137
138
139 void  
140 AliHLTCaloSharedMemoryInterfacev2::NextRawChannel( )
141 {
142   if(fHasRawData == false )
143     {
144       cout << __FILE__ << __LINE__<< "ERROR: no raw data present" << endl;
145     }
146   else
147     {
148       for(int i = 0; i <  200 ; i++ )
149
150         {
151           cout << fRawDataPtr[i] << "\t";
152           if(i%16 == 0)
153             {
154               cout << endl;
155             }
156         }
157     }
158 }
159
160
161 void
162 //AliHLTCaloSharedMemoryInterfacev2::SetMemory(AliHLTCaloChannelDataHeaderStruct* channelDataHeaderPtr,  const unsigned long specification)
163 AliHLTCaloSharedMemoryInterfacev2::SetMemory(AliHLTCaloChannelDataHeaderStruct* channelDataHeaderPtr)
164 {
165   //  fSpecification = specification;
166
167   //Shutting up rule checker
168   fHasRawData = channelDataHeaderPtr->fHasRawData; 
169   fMaxCnt = channelDataHeaderPtr->fNChannels;
170   fChannelDataPtr = reinterpret_cast<AliHLTUInt8_t*>(channelDataHeaderPtr) + sizeof(AliHLTCaloChannelDataHeaderStruct);
171   
172
173   if(fHasRawData == true)
174     {
175       fRawDataPtr = reinterpret_cast<  UShort_t* >(channelDataHeaderPtr); 
176       int inc =  sizeof (AliHLTCaloChannelDataHeaderStruct) +  fMaxCnt*sizeof(AliHLTCaloChannelDataStruct);
177       fRawDataPtr += inc/sizeof(UShort_t );
178     }
179
180     fIsSetMemory = true;
181 }
182
183
184 void
185 AliHLTCaloSharedMemoryInterfacev2::Reset()
186 {
187   //Shutting up rule checker
188   fCurrentCnt = 0;
189   fIsSetMemory = false;
190   fHasRawData = false;
191 }
192
193  
194 void 
195 AliHLTCaloSharedMemoryInterfacev2::Reset(AliHLTCaloChannelRawDataStruct &str)
196 {
197   for(int i=0; i< ALTROMAXSAMPLES; i++ )
198     {
199       str.fDataPtr[i] = 0;
200     }
201  
202 }