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