]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
468be4aa436d07cfe16abbdcffc55f7102074048
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
1 /**************************************************************************
2  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
3  *                                                                        *
4  * Author: Per Thomas Hille for the ALICE HLT Project.                    *
5  * Contributors are mentioned in the code where appropriate.              *
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 "AliHLTPHOSRawAnalyzerComponent.h"
17 #include <iostream>
18 #include "stdio.h"
19
20 #include "AliRawReaderMemory.h"
21 #include "AliCaloRawStream.h"
22 #include <cstdlib>
23 #include "AliHLTPHOSRcuCellEnergyData.h"
24
25
26 const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
27
28
29 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(),  fEventCount(0),  fEquippmentID(0), fPHOSRawStream(), fRawMemoryReader(0)
30 {
31
32
33
34 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
35 {
36   if(fRawMemoryReader != 0)
37     {
38       delete fRawMemoryReader;
39     }
40     if(fPHOSRawStream != 0)
41     {
42       delete fPHOSRawStream;
43     }
44
45 }
46
47
48
49 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(),  fEventCount(0),  fEquippmentID(0), fPHOSRawStream(),fRawMemoryReader(0)
50 {
51 }
52
53
54 int 
55 AliHLTPHOSRawAnalyzerComponent::Deinit()
56 {
57   return 0;
58 }
59
60 int 
61 AliHLTPHOSRawAnalyzerComponent::DoDeinit()
62 {
63   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
64
65   if(fRawMemoryReader !=0)
66     {
67       delete fRawMemoryReader;
68     }
69     
70   if(fPHOSRawStream != 0)
71     {
72       delete fPHOSRawStream;
73     }
74   return 0;
75
76 }
77
78 const char* 
79 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
80 {
81   return "AliPhosTestRaw";
82 }
83
84 void
85 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
86 {
87   const AliHLTComponentDataType* pType=inputDataTypes;
88   while (pType->fID!=0) {
89     list.push_back(*pType);
90     pType++;
91   }
92 }
93
94 AliHLTComponentDataType 
95 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
96 {
97   return AliHLTPHOSDefinitions::gkCellEnergyDataType;
98 }
99
100 void
101 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
102
103 {
104   constBase = 30;
105   inputMultiplier = 0.1;
106 }
107
108
109 int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
110                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
111                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
112 {
113   Int_t tmpMod  = 0;
114   Int_t tmpRow  = 0;
115   Int_t tmpCol  = 0;
116   Int_t tmpGain = 0;
117   Int_t processedChannels = 0;
118   UInt_t offset = 0; 
119   UInt_t mysize = 0;
120   UInt_t tSize  = 0;
121   AliHLTPHOSRcuCellEnergyData* outPtr; 
122   AliHLTUInt8_t* outBPtr;
123   outBPtr = outputPtr;
124   const AliHLTComponentBlockData* iter = NULL; 
125   unsigned long ndx;
126
127   Reset();
128
129   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
130     {
131       iter = blocks+ndx;
132       mysize = 0;
133       offset = tSize;
134
135
136       if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
137         {
138           cout << "Warning: data type = is nOT gkDDLPackedRawDataType " << endl;
139           continue;
140         }
141
142      fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
143      analyzerPtr->SetData(fTmpChannelData);
144
145      outPtr =  (AliHLTPHOSRcuCellEnergyData*)outBPtr;
146      mysize += sizeof(AliHLTPHOSRcuCellEnergyData);
147
148      outPtr->fRcuX = fRcuX;
149      outPtr->fRcuZ = fRcuZ;
150      outPtr->fModuleID = fModuleID;
151
152       while(fPHOSRawStream->Next())
153         {
154           if (fPHOSRawStream->IsNewHWAddress())
155             {
156               if(processedChannels > 0)
157                 {
158                   analyzerPtr->SetData(fTmpChannelData);
159                   analyzerPtr->Evaluate(0, 1008);
160                   fMaxValues[tmpMod][tmpRow][tmpCol][tmpGain] = analyzerPtr->GetEnergy();
161                   outPtr->fCellEnergies[tmpRow - fRcuRowOffeset][tmpCol - fRcuColOffeset][tmpGain] =  fMaxValues[tmpMod][tmpRow][tmpCol][tmpGain];
162                   ResetDataPtr(); 
163                 }
164
165               tmpMod  =  fPHOSRawStream->GetModule();
166               tmpRow  =  fPHOSRawStream->GetRow();
167               tmpCol  =  fPHOSRawStream->GetColumn();
168               tmpGain =  fPHOSRawStream->IsLowGain(); 
169               processedChannels ++;
170             }
171
172
173           fTmpChannelData[fPHOSRawStream->GetTime()] =  fPHOSRawStream->GetSignal();
174         }
175       
176  
177       AliHLTComponentBlockData bd;
178       FillBlockData( bd );
179       bd.fOffset = offset;
180       bd.fSize = mysize;
181       bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
182       bd.fSpecification = 0xFFFFFFFF;
183       outputBlocks.push_back( bd );
184       tSize += mysize;
185       outBPtr += mysize;
186       
187       if( tSize > size )
188         {
189           Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
190                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
191                    , tSize, size );
192           return EMSGSIZE;
193         }
194       
195     }
196
197   fEventCount++; 
198   size = tSize;
199   return 0;
200 }//end DoEvent
201
202
203
204 int
205 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
206 {
207   int equippmentID = atoi(argv[6]);
208   Reset();
209   fRawMemoryReader = new AliRawReaderMemory();
210   fPHOSRawStream = new  AliCaloRawStream(fRawMemoryReader,"PHOS");
211   fRawMemoryReader->SetEquipmentID(equippmentID); 
212   SetEquippmentID(equippmentID);
213   SetCoordinates(equippmentID);
214   if (argc==0 && argv==NULL) {
215     // this is currently just to get rid of the warning "unused parameter"
216   }
217   return 0;
218 }
219
220 void
221 AliHLTPHOSRawAnalyzerComponent::DumpData()
222 {
223   for(int mod = 0; mod <5; mod ++)
224     {
225       printf("\n ***********  MODULE %d ************\n", mod);
226       for(int row = 0; row < 64; row ++)
227         {
228           for(int col = 0; col < 56; col ++)
229             {
230               if( fMaxValues[mod][row][col][0] != 0)
231                 { 
232                   cout << fMaxValues[mod][row][col][0] << "\t";
233                 }
234             }
235         } 
236     }
237 }
238
239
240 void
241 AliHLTPHOSRawAnalyzerComponent::Reset()
242 {
243   for(int mod = 0; mod <5; mod ++)
244     {
245       for(int row = 0; row < 64; row ++)
246         {
247           for(int col = 0; col < 56; col ++)
248             {
249               for(int gain = 0; gain <2; gain ++ )
250                 {
251                   fMaxValues[mod][row][col][gain] = 0;
252                 }
253             }
254         }
255     }
256
257   for(int i = 0 ; i< 1008; i++)
258     {
259       fTmpChannelData[i] = 0;
260     }
261 } // end Reset
262
263 void
264 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
265 {
266   for(int i = 0 ; i< 1008; i++)
267     {
268       fTmpChannelData[i] = 0;
269     }
270 }
271
272
273 void 
274 AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt32_t id)
275 {
276   fEquippmentID = id;
277 }
278
279 int 
280 AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
281 {
282   return  fEquippmentID;
283 }
284
285 void 
286 AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt32_t equippmentID)
287 {
288   int rcuIndex =  (fEquippmentID - 1792)%4;
289   fModuleID = (fEquippmentID  -1792 -rcuIndex)/5;
290
291   if(rcuIndex == 0)
292     {
293       fRcuX = 0; 
294       fRcuZ = 0;
295     }
296
297   if(rcuIndex == 1)
298     {
299       fRcuX = 0; 
300       fRcuZ = 1;
301     }
302  
303   if(rcuIndex == 2)
304     {
305       fRcuX = 1; 
306       fRcuZ = 0;
307     }
308
309
310   if(rcuIndex == 3)
311     {
312       fRcuX = 1; 
313       fRcuZ = 1;
314     }
315
316   fRcuRowOffeset = 32*fRcuX;
317   fRcuColOffeset = 28*fRcuZ;
318
319 }