]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloSharedMemoryInterfacev2.cxx
implementing the short info option which includes a TNames array instead of input...
[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 AliHLTCaloChannelDataStruct*
70 AliHLTCaloSharedMemoryInterfacev2::NextChannel()
71 {
72   // Comment
73   AliHLTCaloChannelDataStruct* tmpChannelPtr = 0;
74   if(fCurrentCnt < fMaxCnt)
75     {
76       tmpChannelPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(fChannelDataPtr);
77       fCurrentCnt++;
78       fChannelDataPtr += sizeof(AliHLTCaloChannelDataStruct);
79       
80       if(fHasRawData == true)
81       //     if( false )        
82         {
83           fRawData.fEnergy = tmpChannelPtr->fEnergy;
84           fRawData.fTime = tmpChannelPtr->fTime;
85           fRawData.fChannelID = tmpChannelPtr->fChannelID;
86           fRawData.fCrazyness = tmpChannelPtr->fCrazyness;
87           Reset(fRawData);
88           //AliHLTCaloMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTCaloCoordinate &channelCoord)
89  
90  
91           AliHLTCaloMapper::ChannelId2Coordinate( fRawData.fChannelID, fRawData.fCoordinate);
92           
93           if( fRawData.fChannelID == fRawDataPtr[0] )
94             {
95               Reset(fRawData);
96               // cout << __FILE__ << __LINE__ << "fRawData.fChannelID == fRawDataPtr[0] = " << fRawDataPtr[0] << endl;
97               // cout << " copying raw dat not yet implemnted " << endl;
98               UShort_t tmpTotSize = fRawDataPtr[1];
99               UShort_t tmpStartBin = fRawDataPtr[2];
100               UShort_t tmpBunchtSize = fRawDataPtr[3];
101               // fRawDataPtr
102               //     UShort_t tmpSamplesLeft = tmpTotSize -4;
103               int tmpSamplesLeft = tmpTotSize -4;
104
105               fRawData.nSamplesUsed = tmpTotSize + tmpStartBin;
106
107               if(tmpSamplesLeft > 0 )
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   AliHLTCaloChannelDataStruct*   
140   AliHLTCaloSharedMemoryInterfacev2::NextChannel()
141   {
142   cout << __FILE__ << __LINE__ << " TP0" << endl;
143
144   AliHLTCaloChannelDataStruct* tmpChannelPtr = 0;
145   if(fCurrentCnt < fMaxCnt)
146   {
147   cout << __FILE__ << __LINE__ << " TP1" << endl;  
148   tmpChannelPtr = reinterpret_cast<AliHLTCaloChannelDataStruct*>(fChannelDataPtr);
149   fCurrentCnt++;
150   fChannelDataPtr += sizeof(AliHLTCaloChannelDataStruct);
151    
152   //    if(fHasRawData == true)
153   if(false)     
154   {
155   cout << __FILE__ << __LINE__ << " TP2" << endl; 
156   fRawData.fEnergy = tmpChannelPtr->fEnergy;
157   fRawData.fTime = tmpChannelPtr->fTime;
158   fRawData.fChannelID = tmpChannelPtr->fChannelID; 
159   fRawData.fCrazyness  = tmpChannelPtr->fCrazyness; 
160   Reset(fRawData);
161   AliHLTCaloMapper::ChannelId2Coordinate( fRawData.fChannelID, fRawData.fCoordinate);
162   cout << __FILE__ << __LINE__ << " TP3" << endl; 
163   if( fRawData.fChannelID ==  fRawDataPtr[0]  )
164   {
165   cout << __FILE__ << __LINE__ << " TP4" << endl; 
166   Reset(fRawData);
167   cout << __FILE__ << __LINE__ << " TP5" << endl; 
168   UShort_t tmpTotSize =  fRawDataPtr[1];
169   UShort_t tmpStartBin   =  fRawDataPtr[2];
170   UShort_t tmpBunchtSize =  fRawDataPtr[3];
171   UShort_t tmpSamplesLeft = tmpTotSize -4; 
172   fRawData.nSamplesUsed =  tmpTotSize +  tmpStartBin;
173   cout << __FILE__ << __LINE__ << " TP6" << endl; 
174
175   while(tmpSamplesLeft > 0)
176   {
177   if ( (tmpBunchtSize <  ( ALTROMAXSAMPLES +4)) && tmpBunchtSize > 0   )
178   {
179   cout << __FILE__ << __LINE__ << " TP7" << endl; 
180   for(int i=0; i < tmpBunchtSize; i++ )
181   {
182   cout << __FILE__ << __LINE__ << "  TMP tot size =" <<  tmpBunchtSize <<  tmpTotSize  << endl;
183   cout << __FILE__ << __LINE__ << "  TMP bunch size =" <<  tmpTotSize  << endl;
184   cout << __FILE__ << __LINE__ << " TP8, i=" << i <<", tmpStartBin = "<< tmpStartBin  << " fCurrentCnt = "<< fCurrentCnt << endl; 
185   cout << __FILE__ << __LINE__ << " acessing fRawData.fDataPtr["<<  i + tmpStartBin  << "]" << endl; 
186   fRawData.fDataPtr[ i + tmpStartBin ] = fRawDataPtr[ i+ 4];
187   //                        cout << __FILE__ << __LINE__ << " acessing fRawData.fDataPtr["<<  i + tmpStartBin  << "]" << endl; 
188   tmpSamplesLeft --;
189   }
190   fRawDataPtr+= tmpTotSize;
191   }
192   else
193   {
194   tmpSamplesLeft = -1;
195   }
196   }
197   }
198   }
199   return tmpChannelPtr;
200   } 
201   else
202   {
203   Reset();
204   return 0;
205   }
206   return 0;
207   //   }
208   }
209 */
210
211
212 void  
213 AliHLTCaloSharedMemoryInterfacev2::NextRawChannel( )
214 {
215   if(fHasRawData == false )
216     {
217       cout << __FILE__ << __LINE__<< "ERROR: no raw data present" << endl;
218     }
219   else
220     {
221       for(int i = 0; i <  200 ; i++ )
222
223         {
224           cout << fRawDataPtr[i] << "\t";
225           if(i%16 == 0)
226             {
227               cout << endl;
228             }
229         }
230     }
231 }
232
233
234 void
235 //AliHLTCaloSharedMemoryInterfacev2::SetMemory(AliHLTCaloChannelDataHeaderStruct* channelDataHeaderPtr,  const unsigned long specification)
236 AliHLTCaloSharedMemoryInterfacev2::SetMemory(AliHLTCaloChannelDataHeaderStruct* channelDataHeaderPtr)
237 {
238   //  fSpecification = specification;
239
240   //Shutting up rule checker
241   fHasRawData = channelDataHeaderPtr->fHasRawData; 
242   fMaxCnt = channelDataHeaderPtr->fNChannels;
243   fChannelDataPtr = reinterpret_cast<AliHLTUInt8_t*>(channelDataHeaderPtr) + sizeof(AliHLTCaloChannelDataHeaderStruct);
244   
245
246   if(fHasRawData == true)
247     {
248       fRawDataPtr = reinterpret_cast<  UShort_t* >(channelDataHeaderPtr); 
249       int inc =  sizeof (AliHLTCaloChannelDataHeaderStruct) +  fMaxCnt*sizeof(AliHLTCaloChannelDataStruct);
250       fRawDataPtr += inc/sizeof(UShort_t );
251     }
252
253     fIsSetMemory = true;
254 }
255
256
257 void
258 AliHLTCaloSharedMemoryInterfacev2::Reset()
259 {
260   //Shutting up rule checker
261   fCurrentCnt = 0;
262   fIsSetMemory = false;
263   fHasRawData = false;
264 }
265
266  
267 void 
268 AliHLTCaloSharedMemoryInterfacev2::Reset(AliHLTCaloChannelRawDataStruct &str)
269 {
270   for(int i=0; i< ALTROMAXSAMPLES; i++ )
271     {
272       str.fDataPtr[i] = 0;
273     }
274  
275 }