]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
Coding convention & removal of some obsolete code
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the Experimental Nuclear     *
3  * Physics Group, Dep. of Physics                                         *
4  * University of Oslo, Norway, 2007                                       *
5  *                                                                        * 
6  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
7  * Contributors are mentioned in the code where appropriate.              *
8  * Please report bugs to perthi@fys.uio.no                                * 
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 #include "AliHLTPHOSRawAnalyzerComponent.h"
20 #include <iostream>
21 #include "stdio.h"
22
23 #include "AliRawReaderMemory.h"
24 #include "AliCaloRawStream.h"
25 #include <cstdlib>
26 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
27 //#include "AliHLTPHOSDataHeaderStruct.h"
28
29
30 const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
31 int   AliHLTPHOSRawAnalyzerComponent::fEventCount = 0; 
32
33 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(), fEquippmentID(0), fRcuX(0), 
34 fRcuZ(0),fRcuRowOffeset(0), fRcuColOffeset(0),  fModuleID(0), fPHOSRawStream(), fRawMemoryReader(0), fOutPtr(0)
35 {
36
37
38
39 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
40 {
41   if(fRawMemoryReader != 0)
42     {
43       delete fRawMemoryReader;
44     }
45     if(fPHOSRawStream != 0)
46     {
47       delete fPHOSRawStream;
48     }
49
50 }
51
52
53
54 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(), 
55 fEquippmentID(0), fRcuX(0), fRcuZ(0),fRcuRowOffeset(0), fRcuColOffeset(0),  fModuleID(0), fPHOSRawStream(), fRawMemoryReader(0), fOutPtr(0)
56 {
57 }
58
59
60 int 
61 AliHLTPHOSRawAnalyzerComponent::Deinit()
62 {
63   return 0;
64 }
65
66 int 
67 AliHLTPHOSRawAnalyzerComponent::DoDeinit()
68 {
69   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
70
71   if(fRawMemoryReader !=0)
72     {
73       delete fRawMemoryReader;
74     }
75     
76   if(fPHOSRawStream != 0)
77     {
78       delete fPHOSRawStream;
79     }
80   return 0;
81
82 }
83
84 const char* 
85 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
86 {
87   return "AliPhosTestRaw";
88 }
89
90 void
91 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
92 {
93   const AliHLTComponentDataType* pType=inputDataTypes;
94   while (pType->fID!=0) {
95     list.push_back(*pType);
96     pType++;
97   }
98 }
99
100 AliHLTComponentDataType 
101 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
102 {
103   return AliHLTPHOSDefinitions::gkCellEnergyDataType;
104 }
105
106 void
107 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
108
109 {
110   constBase = 30;
111   inputMultiplier = 0.1;
112 }
113
114
115 int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
116                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
117                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
118 {
119   Int_t tmpMod            = 0;
120   Int_t tmpRow            = 0;
121   Int_t tmpCol            = 0;
122   Int_t tmpGain           = 0;
123   Int_t sampleCnt         = 0;
124   Int_t processedChannels = 0;
125   UInt_t offset           = 0; 
126   UInt_t mysize           = 0;
127   UInt_t tSize            = 0;
128   Int_t tmpChannelCnt     = 0;
129   AliHLTUInt8_t* outBPtr;
130   outBPtr = outputPtr;
131   const AliHLTComponentBlockData* iter = NULL; 
132   unsigned long ndx;
133
134   if((fEventCount % 100) == 0)
135     {
136       cout << "analyzing event: " << fEventCount << endl;
137     }
138
139   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
140     {
141       iter = blocks+ndx;
142       mysize = 0;
143       offset = tSize;
144
145       if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
146         {
147           cout << "Warning: data type = is nOT gkDDLPackedRawDataType " << endl;
148           continue;
149         }
150
151       fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
152       analyzerPtr->SetData(fTmpChannelData);
153       fOutPtr =  (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
154       mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
155       fOutPtr->fRcuX = fRcuX;
156       fOutPtr->fRcuZ = fRcuZ;
157       fOutPtr->fModuleID = fModuleID;
158       tmpChannelCnt = 0;
159  
160       if(fEventCount%100 ==0)
161         {
162           cout <<"Analyzing event: " << fEventCount << endl; 
163         }
164  
165       while(fPHOSRawStream->Next())
166         {
167           if (fPHOSRawStream->IsNewHWAddress())
168             {
169               if(processedChannels > 0)
170                 {
171                   analyzerPtr->SetData(fTmpChannelData);
172                   analyzerPtr->Evaluate(0, sampleCnt);
173                   fOutPtr->fCellEnergies[tmpRow][tmpCol][tmpGain] =  analyzerPtr->GetEnergy();
174                   sampleCnt = 0;
175                   fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
176                   fOutPtr->fValidData[tmpChannelCnt].fRow  = tmpRow;
177                   fOutPtr->fValidData[tmpChannelCnt].fCol  = tmpCol; 
178                   tmpChannelCnt ++;
179                   ResetDataPtr();
180                   sampleCnt = 0;
181
182                 }
183
184               tmpMod  =  fPHOSRawStream->GetModule() ;
185               tmpRow  =  fPHOSRawStream->GetRow() - fRcuRowOffeset;
186               tmpCol  =  fPHOSRawStream->GetColumn() - fRcuColOffeset;
187               tmpGain =  fPHOSRawStream->IsLowGain(); 
188               processedChannels ++;
189             }
190           fTmpChannelData[fPHOSRawStream->GetTime()] =  fPHOSRawStream->GetSignal();
191           sampleCnt ++;
192
193         }
194    
195       fOutPtr->fCnt =  tmpChannelCnt;
196       AliHLTComponentBlockData bd;
197       FillBlockData( bd );
198       bd.fOffset = offset;
199       bd.fSize = mysize;
200       bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
201       bd.fSpecification = 0xFFFFFFFF;
202       outputBlocks.push_back( bd );
203       tSize += mysize;
204       outBPtr += mysize;
205       
206       if( tSize > size )
207         {
208           Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
209                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
210                    , tSize, size );
211           return EMSGSIZE;
212         }
213     }
214
215   fEventCount++; 
216   size = tSize;
217   return 0;
218 }//end DoEvent
219
220
221
222 int
223 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
224 {
225   int equippmentID = atoi(argv[6]);
226   Reset();
227   fRawMemoryReader = new AliRawReaderMemory();
228   fPHOSRawStream = new  AliCaloRawStream(fRawMemoryReader,"PHOS");
229   fRawMemoryReader->SetEquipmentID(equippmentID); 
230   SetEquippmentID(equippmentID);
231   SetCoordinates(equippmentID);
232   if (argc==0 && argv==NULL) {
233     // this is currently just to get rid of the warning "unused parameter"
234   }
235   return 0;
236 }
237
238 void
239 AliHLTPHOSRawAnalyzerComponent::DumpData()
240 {
241   for(int mod = 0; mod <5; mod ++)
242     {
243       printf("\n ***********  MODULE %d ************\n", mod);
244       for(int row = 0; row < 64; row ++)
245         {
246           for(int col = 0; col < 56; col ++)
247             {
248               if( fMaxValues[mod][row][col][0] != 0)
249                 { 
250                   cout << fMaxValues[mod][row][col][0] << "\t";
251                 }
252             }
253         } 
254     }
255 }
256
257 void
258 AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data)
259 {
260       cout << endl;
261       
262       for(int i=0; i< 1008; i++)
263         {
264           if (data[i] != 0)
265             {
266               cout <<i <<"\t";
267             }
268         }
269       cout << endl;
270       
271       for(int i=0; i< 1008; i++)
272         {
273           if (data[i] != 0)
274             {
275               cout <<data[i] <<"\t";
276             }
277         }
278       
279       cout << endl;
280 }
281
282
283
284 void
285 AliHLTPHOSRawAnalyzerComponent::Reset()
286 {
287   for(int mod = 0; mod <5; mod ++)
288     {
289       for(int row = 0; row < 64; row ++)
290         {
291           for(int col = 0; col < 56; col ++)
292             {
293               for(int gain = 0; gain <2; gain ++ )
294                 {
295                   fMaxValues[mod][row][col][gain] = 0;
296                 }
297             }
298         }
299     }
300
301   for(int i = 0 ; i< 1008; i++)
302     {
303       fTmpChannelData[i] = 0;
304     }
305 } // end Reset
306
307 void
308 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
309 {
310   for(int i = 0 ; i< 1008; i++)
311     {
312       fTmpChannelData[i] = 0;
313     }
314 }
315
316
317 void 
318 AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt32_t id)
319 {
320   fEquippmentID = id;
321 }
322
323 int 
324 AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
325 {
326   return  fEquippmentID;
327 }
328
329 void 
330 AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt32_t equippmentID)
331 {
332   int rcuIndex =  (fEquippmentID - 1792)%4;
333   fModuleID = (fEquippmentID  -1792 -rcuIndex)/5;
334
335   if(rcuIndex == 0)
336     {
337       fRcuX = 0; 
338       fRcuZ = 0;
339     }
340
341   if(rcuIndex == 1)
342     {
343       fRcuX = 0; 
344       fRcuZ = 1;
345     }
346  
347   if(rcuIndex == 2)
348     {
349       fRcuX = 1; 
350       fRcuZ = 0;
351     }
352
353
354   if(rcuIndex == 3)
355     {
356       fRcuX = 1; 
357       fRcuZ = 1;
358     }
359
360   fRcuRowOffeset = 32*fRcuX;
361   fRcuColOffeset = 28*fRcuZ;
362
363 }