]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
Removed the AliHLTPHOSValidCellDataStruct.h from Makefile.am
[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 "AliHLTPHOSRcuCellEnergyDataStruct.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 sampleCnt         = 0;
118   Int_t processedChannels = 0;
119   UInt_t offset           = 0; 
120   UInt_t mysize           = 0;
121   UInt_t tSize            = 0;
122
123   //  AliHLTPHOSRcuCellEnergyDataStruct
124   AliHLTPHOSRcuCellEnergyDataStruct* outPtr; 
125   AliHLTUInt8_t* outBPtr;
126   outBPtr = outputPtr;
127   const AliHLTComponentBlockData* iter = NULL; 
128   unsigned long ndx;
129
130   Reset();
131
132   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
133     {
134       iter = blocks+ndx;
135       mysize = 0;
136       offset = tSize;
137
138
139       if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
140         {
141           cout << "Warning: data type = is nOT gkDDLPackedRawDataType " << endl;
142           continue;
143         }
144
145       fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
146       analyzerPtr->SetData(fTmpChannelData);
147       outPtr =  (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
148       mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
149       outPtr->fRcuX = fRcuX;
150       outPtr->fRcuZ = fRcuZ;
151       outPtr->fModuleID = fModuleID;
152       outPtr->fCnt = 0;
153
154       while(fPHOSRawStream->Next())
155         {
156           if (fPHOSRawStream->IsNewHWAddress())
157             {
158               if(processedChannels > 0)
159                 {
160                   analyzerPtr->SetData(fTmpChannelData);
161                   //              cout << "sampleCnt = " << sampleCnt << endl;
162                   analyzerPtr->Evaluate(0, sampleCnt);
163                   fMaxValues[tmpMod][tmpRow][tmpCol][tmpGain] = analyzerPtr->GetEnergy();
164
165                   //      outPtr->fValidData[fCnt] = ;
166                   outPtr->fCnt ++;
167                   //fCnt;
168                   outPtr->fCellEnergies[tmpRow - fRcuRowOffeset][tmpCol - fRcuColOffeset][tmpGain] =  fMaxValues[tmpMod][tmpRow][tmpCol][tmpGain];
169                   sampleCnt = 0;
170                   ResetDataPtr(); 
171
172                 }
173
174               tmpMod  =  fPHOSRawStream->GetModule();
175               tmpRow  =  fPHOSRawStream->GetRow();
176               tmpCol  =  fPHOSRawStream->GetColumn();
177               tmpGain =  fPHOSRawStream->IsLowGain(); 
178               
179               processedChannels ++;
180             }
181           fTmpChannelData[fPHOSRawStream->GetTime()] =  fPHOSRawStream->GetSignal();
182           sampleCnt ++;
183         }
184       
185  
186       AliHLTComponentBlockData bd;
187       FillBlockData( bd );
188       bd.fOffset = offset;
189       bd.fSize = mysize;
190       bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
191       bd.fSpecification = 0xFFFFFFFF;
192       outputBlocks.push_back( bd );
193       tSize += mysize;
194       outBPtr += mysize;
195       
196       if( tSize > size )
197         {
198           Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
199                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
200                    , tSize, size );
201           return EMSGSIZE;
202         }
203       
204     }
205
206   fEventCount++; 
207   size = tSize;
208   return 0;
209 }//end DoEvent
210
211
212
213 int
214 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
215 {
216   int equippmentID = atoi(argv[6]);
217   Reset();
218   fRawMemoryReader = new AliRawReaderMemory();
219   fPHOSRawStream = new  AliCaloRawStream(fRawMemoryReader,"PHOS");
220   fRawMemoryReader->SetEquipmentID(equippmentID); 
221   SetEquippmentID(equippmentID);
222   SetCoordinates(equippmentID);
223   if (argc==0 && argv==NULL) {
224     // this is currently just to get rid of the warning "unused parameter"
225   }
226   return 0;
227 }
228
229 void
230 AliHLTPHOSRawAnalyzerComponent::DumpData()
231 {
232   for(int mod = 0; mod <5; mod ++)
233     {
234       printf("\n ***********  MODULE %d ************\n", mod);
235       for(int row = 0; row < 64; row ++)
236         {
237           for(int col = 0; col < 56; col ++)
238             {
239               if( fMaxValues[mod][row][col][0] != 0)
240                 { 
241                   cout << fMaxValues[mod][row][col][0] << "\t";
242                 }
243             }
244         } 
245     }
246 }
247
248
249 void
250 AliHLTPHOSRawAnalyzerComponent::Reset()
251 {
252   for(int mod = 0; mod <5; mod ++)
253     {
254       for(int row = 0; row < 64; row ++)
255         {
256           for(int col = 0; col < 56; col ++)
257             {
258               for(int gain = 0; gain <2; gain ++ )
259                 {
260                   fMaxValues[mod][row][col][gain] = 0;
261                 }
262             }
263         }
264     }
265
266   for(int i = 0 ; i< 1008; i++)
267     {
268       fTmpChannelData[i] = 0;
269     }
270 } // end Reset
271
272 void
273 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
274 {
275   for(int i = 0 ; i< 1008; i++)
276     {
277       fTmpChannelData[i] = 0;
278     }
279 }
280
281
282 void 
283 AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt32_t id)
284 {
285   fEquippmentID = id;
286 }
287
288 int 
289 AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
290 {
291   return  fEquippmentID;
292 }
293
294 void 
295 AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt32_t equippmentID)
296 {
297   int rcuIndex =  (fEquippmentID - 1792)%4;
298   fModuleID = (fEquippmentID  -1792 -rcuIndex)/5;
299
300   if(rcuIndex == 0)
301     {
302       fRcuX = 0; 
303       fRcuZ = 0;
304     }
305
306   if(rcuIndex == 1)
307     {
308       fRcuX = 0; 
309       fRcuZ = 1;
310     }
311  
312   if(rcuIndex == 2)
313     {
314       fRcuX = 1; 
315       fRcuZ = 0;
316     }
317
318
319   if(rcuIndex == 3)
320     {
321       fRcuX = 1; 
322       fRcuZ = 1;
323     }
324
325   fRcuRowOffeset = 32*fRcuX;
326   fRcuColOffeset = 28*fRcuZ;
327
328 }