]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRawAnalyzerComponent.cxx
minor changes
[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 #include "AliRawReaderMemory.h"
23 #include "AliCaloRawStream.h"
24 #include <cstdlib>
25 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
26
27 const AliHLTComponentDataType AliHLTPHOSRawAnalyzerComponent::inputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
28 int   AliHLTPHOSRawAnalyzerComponent::fEventCount = 0; 
29
30
31 /**
32  * @class AliHLTPHOSRawAnalyzerComponent
33  * Base class of PHOS HLT online raw analysis component.
34  * The class provides a common interface for the implementation of PHOS 
35  * HLT raw data
36  * processors components. The class is intended for processing of 
37  * arrays of raw data samples to evaluate energy and timing.
38  * The Energy will be given in entities of ADC leves ranging from 0 to
39  * 1023. Timing will be given in entities of samples periods.
40  * Drived clases  must implement the fucntions
41  * - @ref GetComponentID
42  * - @ref Spawn
43  */
44 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTProcessor(), analyzerPtr(0), fEquippmentID(0), fRcuX(0), 
45 fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),  fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
46 {
47
48
49
50 AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
51 {
52   if(fRawMemoryReader != 0)
53     {
54       delete fRawMemoryReader;
55     }
56     if(fPHOSRawStream != 0)
57     {
58       delete fPHOSRawStream;
59     }
60
61 }
62
63
64
65 AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTProcessor(), analyzerPtr(0), 
66 fEquippmentID(0), fRcuX(0), fRcuZ(0),fRcuZOffset(0), fRcuXOffset(0),  fModuleID(0), fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
67 {
68 }
69
70
71 /*
72  *Deinit function called by the HLT framwork at end of run
73  *@return 0 if the denitialzation was sucessfull.
74  */
75 int 
76 AliHLTPHOSRawAnalyzerComponent::Deinit()
77 {
78   cout <<  "Deinit" << endl;
79   return 0;
80 }
81
82
83 /*
84  *Deinit function called by the HLT framwork at end of run
85  *@return 0 if the denitialzation was sucessfull.
86  */
87 int 
88 AliHLTPHOSRawAnalyzerComponent::DoDeinit()
89 {
90   cout << "DoDeinit" << endl;
91   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen DoDeinit");
92
93   if(fRawMemoryReader !=0)
94     {
95       delete fRawMemoryReader;
96     }
97     
98   if(fPHOSRawStream != 0)
99     {
100       delete fPHOSRawStream;
101     }
102   return 0;
103
104 }
105
106 /*
107  *Function called by the HLT framework during initialization
108  *@return the ID of the component
109  */
110 const char* 
111 AliHLTPHOSRawAnalyzerComponent::GetComponentID()
112 {
113   return "AliPhosTestRaw";
114 }
115
116
117 void
118 AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
119 {
120   const AliHLTComponentDataType* pType=inputDataTypes;
121   while (pType->fID!=0) {
122     list.push_back(*pType);
123     pType++;
124   }
125 }
126
127 AliHLTComponentDataType 
128 AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
129 {
130   return AliHLTPHOSDefinitions::gkCellEnergyDataType;
131 }
132
133 void
134 AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
135
136 {
137   constBase = 30;
138   inputMultiplier = 0.1;
139 }
140
141
142 int AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
143                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
144                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
145 {
146   AliHLTUInt8_t tmpMod    = 0;
147   AliHLTUInt8_t tmpZ      = 0;
148   AliHLTUInt8_t tmpX      = 0;
149   AliHLTUInt8_t tmpGain   = 0;
150   Int_t sampleCnt         = 0;
151   Int_t processedChannels = 0;
152   UInt_t offset           = 0; 
153   UInt_t mysize           = 0;
154   UInt_t tSize            = 0;
155   Int_t tmpChannelCnt     = 0;
156   Int_t tmpStartIndex     = 0;
157   AliHLTUInt8_t* outBPtr;
158   outBPtr = outputPtr;
159   const AliHLTComponentBlockData* iter = NULL; 
160   unsigned long ndx;
161
162   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
163     {
164       iter = blocks+ndx;
165       mysize = 0;
166       offset = tSize;
167
168       if ( iter->fDataType != AliHLTPHOSDefinitions::gkDDLPackedRawDataType )
169         {
170           continue;
171         }
172
173       fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
174       analyzerPtr->SetData(fTmpChannelData);
175       fOutPtr =  (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
176       mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
177       fOutPtr->fRcuX = fRcuX;
178       fOutPtr->fRcuZ = fRcuZ;
179       fOutPtr->fModuleID = fModuleID;
180       tmpChannelCnt = 0;
181  
182       while(fPHOSRawStream->Next())
183         {
184           if (fPHOSRawStream->IsNewHWAddress())
185             {
186               if(processedChannels > 0)
187                 {
188                   analyzerPtr->SetData(fTmpChannelData);
189                   analyzerPtr->Evaluate(0, sampleCnt);
190                   //              sampleCnt = 0;
191                   fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
192                   fOutPtr->fValidData[tmpChannelCnt].fZ  = tmpZ;
193                   fOutPtr->fValidData[tmpChannelCnt].fX  = tmpX; 
194                   fOutPtr->fValidData[tmpChannelCnt].fEnergy  = analyzerPtr->GetEnergy();
195                   fOutPtr->fValidData[tmpChannelCnt].fTime    = analyzerPtr->GetTiming();
196                   tmpChannelCnt ++;
197                   ResetDataPtr(tmpStartIndex, sampleCnt);
198                   sampleCnt = 0;
199                 }
200
201               tmpMod  = (AliHLTUInt8_t)fPHOSRawStream->GetModule() ;
202               tmpX  =(AliHLTUInt8_t)fPHOSRawStream->GetRow() - fRcuXOffset;
203               tmpZ  =(AliHLTUInt8_t)fPHOSRawStream->GetColumn() - fRcuZOffset;
204               tmpGain =  fPHOSRawStream->IsLowGain(); 
205               processedChannels ++;
206             }
207
208           
209           if(sampleCnt == 0)
210             {
211               tmpStartIndex = fPHOSRawStream->GetTime();
212             }
213           
214           fTmpChannelData[fPHOSRawStream->GetTime()] =  fPHOSRawStream->GetSignal();
215           sampleCnt ++;
216
217         }
218    
219       tmpChannelCnt ++;
220       analyzerPtr->SetData(fTmpChannelData);
221       analyzerPtr->Evaluate(0, sampleCnt);
222       //                  sampleCnt = 0;
223       fOutPtr->fValidData[tmpChannelCnt].fGain = tmpGain;
224       fOutPtr->fValidData[tmpChannelCnt].fZ  = tmpZ;
225       fOutPtr->fValidData[tmpChannelCnt].fX  = tmpX; 
226       fOutPtr->fValidData[tmpChannelCnt].fEnergy  = analyzerPtr->GetEnergy();
227       fOutPtr->fValidData[tmpChannelCnt].fTime    = analyzerPtr->GetTiming();
228       //      tmpChannelCnt ++;
229    
230       ResetDataPtr(tmpStartIndex, sampleCnt);
231       sampleCnt = 0;
232
233
234
235       fOutPtr->fCnt =  tmpChannelCnt;
236       AliHLTComponentBlockData bd;
237       FillBlockData( bd );
238       bd.fOffset = offset;
239       bd.fSize = mysize;
240       bd.fDataType = AliHLTPHOSDefinitions::gkCellEnergyDataType;
241       bd.fSpecification = 0xFFFFFFFF;
242       outputBlocks.push_back( bd );
243       tSize += mysize;
244       outBPtr += mysize;
245       
246       if( tSize > size )
247         {
248           Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
249                    "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
250                    , tSize, size );
251           return EMSGSIZE;
252         }
253     }
254
255   fEventCount++; 
256   size = tSize;
257   return 0;
258 }//end DoEvent
259
260
261 int
262 AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
263 {
264   int equippmentID = atoi(argv[6]);
265   Reset();
266   fRawMemoryReader = new AliRawReaderMemory();
267   fPHOSRawStream = new  AliCaloRawStream(fRawMemoryReader,"PHOS");
268   fPHOSRawStream->SetOldRCUFormat(kFALSE);
269   fRawMemoryReader->SetEquipmentID(equippmentID); 
270   SetEquippmentID(equippmentID);
271   SetCoordinates(equippmentID);
272   if (argc==0 && argv==NULL) {
273     // this is currently just to get rid of the warning "unused parameter"
274   }
275   return 0;
276 }
277
278
279 void
280 AliHLTPHOSRawAnalyzerComponent::DumpData(int gain)
281 {
282   for(int mod = 0; mod < N_MODULES; mod ++)
283     {
284       printf("\n ***********  MODULE %d ************\n", mod);
285       for(int row = 0; row <  N_ROWS_MOD; row ++)
286         {
287           for(int col = 0; col <  N_COLUMNS_MOD; col ++)
288             {
289               if( fMaxValues[mod][row][col][0] != 0)
290                 { 
291                   cout << fMaxValues[mod][row][col][gain] << "\t";
292                 }
293             }
294         } 
295     }
296 }
297
298
299 void
300 AliHLTPHOSRawAnalyzerComponent::DumpData()
301 {
302   DumpData(0);
303 }
304
305 void
306 AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data)
307 {
308       cout << endl;
309       
310       for(int i=0; i<  ALTRO_MAX_SAMPLES; i++)
311         {
312           if (data[i] != 0)
313             {
314               cout <<i <<"\t";
315             }
316         }
317       cout << endl;
318       
319       for(int i=0; i<  ALTRO_MAX_SAMPLES; i++)
320         {
321           if (data[i] != 0)
322             {
323               cout <<data[i] <<"\t";
324             }
325         }
326       
327       cout << endl;
328 }
329
330
331 void
332 AliHLTPHOSRawAnalyzerComponent::Reset()
333 {
334   for(int mod = 0; mod < N_MODULES; mod ++)
335     {
336       for(int row = 0; row < N_ROWS_MOD; row ++)
337         {
338           for(int col = 0; col < N_COLUMNS_MOD; col ++)
339             {
340               for(int gain = 0; gain < N_GAINS; gain ++ )
341                 {
342                   fMaxValues[mod][row][col][gain] = 0;
343                 }
344             }
345         }
346     }
347
348   ResetDataPtr();
349
350 } // end Reset
351
352
353 void
354 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr()
355 {
356   for(int i = 0 ; i< ALTRO_MAX_SAMPLES; i++)
357     {
358       fTmpChannelData[i] = 0;
359     }
360 }
361
362 void
363 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int sampleCnt)
364 {
365   for(int i = 0 ; i< sampleCnt; i++)
366     {
367       fTmpChannelData[i] = 0;
368     }
369 }
370
371 void
372 AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
373 {
374   for(int i = startindex ; i< sampleCnt; i++)
375     {
376       fTmpChannelData[i] = 0;
377     }
378 }
379
380 void 
381 AliHLTPHOSRawAnalyzerComponent::SetEquippmentID(AliHLTUInt16_t id)
382 {
383   fEquippmentID = id;
384 }
385
386
387 AliHLTUInt16_t
388 AliHLTPHOSRawAnalyzerComponent::GetEquippmentID()
389 {
390   return  fEquippmentID;
391 }
392
393
394 void 
395 AliHLTPHOSRawAnalyzerComponent::SetCoordinates(AliHLTUInt16_t equippmentID)
396 {
397   int rcuIndex =  (fEquippmentID - 1792)%N_RCUS_PER_MODULE;
398   fModuleID = (fEquippmentID  -1792 -rcuIndex)/N_RCUS_PER_MODULE;
399   
400   if(rcuIndex == 0)
401     {
402       fRcuX = 0; 
403       fRcuZ = 0;
404     }
405
406   if(rcuIndex == 1)
407     {
408       fRcuX = 0; 
409       fRcuZ = 1;
410     }
411  
412   if(rcuIndex == 2)
413     {
414       fRcuX = 1; 
415       fRcuZ = 0;
416     }
417
418   if(rcuIndex == 3)
419     {
420       fRcuX = 1; 
421       fRcuZ = 1;
422     }
423
424
425
426   fRcuZOffset =  N_ZROWS_RCU*fRcuZ;
427   fRcuXOffset =  N_XCOLUMNS_RCU*fRcuX;
428
429   cout <<"********InitInfo************"<< endl;
430   cout <<"AliHLTPHOSRawAnalyzerComponent::SetCoordinate"<< endl;
431   cout <<"Equpippment ID =\t"<< fEquippmentID <<endl;
432   cout <<"Module ID =\t"<<  (int)fModuleID<<endl;
433   cout <<"RCUX =\t\t" << (int)fRcuX << endl;
434   cout <<"RCUZ =\t\t" << (int)fRcuZ << endl;
435   cout <<"RcuZOffset = \t" <<  (int)fRcuZOffset << endl;
436   cout <<"RcuXOffset = \t" <<  (int)fRcuXOffset << endl << endl;
437 }