Coding conventions & doccumentation
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSModuleMergerComponent.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 "AliHLTPHOSModuleMergerComponent.h"
17 #include "AliRawReaderMemory.h"
18 #include "AliCaloRawStream.h"
19 #include <cstdio>
20 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
21
22
23 const AliHLTComponentDataType  AliHLTPHOSModuleMergerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}}; //'zero' terminated array
24 const AliHLTComponentDataType  AliHLTPHOSModuleMergerComponent::fgkOutputDataType=kAliHLTVoidDataType;
25
26 AliHLTPHOSModuleMergerComponent gAliHLTPHOSModuleMergerComponent;
27
28 //_____________________________________________________________________________________________________
29 AliHLTPHOSModuleMergerComponent:: AliHLTPHOSModuleMergerComponent():AliHLTProcessor(),  fPhosEventCount(0),  fEquippmentID(0)
30 {
31
32
33
34
35 //_____________________________________________________________________________________________________
36 AliHLTPHOSModuleMergerComponent::~ AliHLTPHOSModuleMergerComponent()
37 {
38
39 }
40
41
42 //_____________________________________________________________________________________________________
43 AliHLTPHOSModuleMergerComponent::AliHLTPHOSModuleMergerComponent(const  AliHLTPHOSModuleMergerComponent & ) : AliHLTProcessor(),  fPhosEventCount(0),  fEquippmentID(0)
44 {
45
46 }
47
48
49 //_____________________________________________________________________________________________________
50 int 
51 AliHLTPHOSModuleMergerComponent::Deinit()
52 {
53   return 0;
54 }
55
56
57 //_____________________________________________________________________________________________________
58 int 
59 AliHLTPHOSModuleMergerComponent::DoDeinit()
60 {
61   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSModuleMerger DoDeinit");
62   return 0;
63
64 }
65
66
67 //_____________________________________________________________________________________________________
68 const char* 
69 AliHLTPHOSModuleMergerComponent::GetComponentID()
70 {
71   return "ModuleMerger";
72 }
73
74
75 //_____________________________________________________________________________________________________
76 void
77 AliHLTPHOSModuleMergerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
78 {
79   const AliHLTComponentDataType* pType=fgkInputDataTypes;
80   while (pType->fID!=0) 
81     {
82       list.push_back(*pType);
83       pType++;
84     }
85 }
86
87
88 //_____________________________________________________________________________________________________
89 AliHLTComponentDataType 
90 AliHLTPHOSModuleMergerComponent::GetOutputDataType()
91 {
92   return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
93 }
94
95
96 //_____________________________________________________________________________________________________
97 void
98 AliHLTPHOSModuleMergerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
99 {
100   ///
101   constBase = 30;
102   inputMultiplier = 1;
103 }
104
105
106 int  AliHLTPHOSModuleMergerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
107                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
108                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
109 {
110   //Merging of data from 4 RCUS to one module
111   
112   unsigned long ndx;
113   const AliHLTComponentBlockData* iter = NULL;   
114   AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr;
115
116   Reset();
117
118   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
119     {
120       int tmpModuleID = 0;
121       int tmpRcuX = 0;
122       int tmpRcuZ = 0;
123       int tmpCnt =  cellDataPtr->fCnt;
124       iter = blocks+ndx;
125       AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
126       tmpModuleID = cellDataPtr->fModuleID;
127       tmpRcuX     = cellDataPtr->fRcuX ;
128       tmpRcuZ     = cellDataPtr->fRcuZ;
129
130       for(int i= 0; i< tmpCnt; tmpCnt ++)
131         {
132           if(cellDataPtr->fValidData[i].fGain == HIGH_GAIN)
133             {
134               fMaxValues[tmpModuleID][ cellDataPtr->fValidData[i].fZ +  N_ZROWS_RCU*tmpRcuZ][ cellDataPtr->fValidData[i].fX + N_XCOLUMNS_RCU*tmpRcuX][HIGH_GAIN] =  cellDataPtr->fValidData[i].fEnergy;
135             }
136           else if(cellDataPtr->fValidData[i].fGain == LOW_GAIN)
137             {
138               fMaxValues[tmpModuleID][ cellDataPtr->fValidData[i].fZ +  N_ROWS_RCU*tmpRcuZ][ cellDataPtr->fValidData[i].fX +N_COLUMNS_RCU*tmpRcuX][LOW_GAIN] =  cellDataPtr->fValidData[i].fEnergy;
139             }
140         }
141       
142     }
143
144   DumpData(1);
145   fPhosEventCount++; 
146   return 0;
147   
148 }//end DoEvent
149
150
151 //_____________________________________________________________________________________________________
152 int
153 AliHLTPHOSModuleMergerComponent::DoInit( int argc, const char** argv )
154 {
155   //See base classs for documenation
156   Reset();
157
158   if (argc==0 && argv==NULL) {
159     // this is currently just to get rid of the warning "unused parameter"
160   }
161   return 0;
162 }
163
164
165 //_____________________________________________________________________________________________________
166 void
167 AliHLTPHOSModuleMergerComponent::DumpData(int gain)
168 {
169   if(gain < 0 || gain >  N_GAINS)
170     {
171       cout <<"AliHLTPHOSModuleMergerComponent::DumpDat: Error, gain must be between " << 0 << "and" << N_GAINS << endl;
172     }
173   
174   for(int mod = 0; mod < N_MODULES; mod ++)
175     {
176       if(gain == HIGH_GAIN)
177         {
178           cout << endl <<" ***********  MODULE" << mod << "****HIGH_GAIN" <<"************" << endl;
179         }
180       else if(gain == LOW_GAIN)
181         {
182           cout << endl <<" ***********  MODULE" << mod << "****LOW_GAIN" <<"************" << endl;
183         }
184       
185       for(int row = 0; row < N_ROWS_MOD; row ++)
186         {
187           for(int col = 0; col < N_COLUMNS_MOD; col ++)
188             {
189                       if( fMaxValues[mod][row][col][0] != 0)
190                 { 
191                                   cout << fMaxValues[mod][row][col][0] << "\t";
192                 }
193             }
194         } 
195     }
196 }
197
198
199
200 //_____________________________________________________________________________________________________
201 void
202 AliHLTPHOSModuleMergerComponent::Reset()
203 {
204   for(int mod = 0; mod < N_MODULES; mod ++)
205     {
206       for(int row = 0; row <  N_ROWS_MOD; row ++)
207         {
208           for(int col = 0; col < N_COLUMNS_MOD; col ++)
209             {
210               for(int gain = 0; gain < N_GAINS; gain ++ )
211                 { 
212
213                   fMaxValues[mod][row][col][gain] = 0;
214                 }
215             }
216         }
217     }
218
219   for(int i = 0 ; i<  ALTRO_MAX_SAMPLES; i++)
220     {
221       fTmpChannelData[i] = 0;
222     }
223 } // end Reset
224
225
226 //_____________________________________________________________________________________________________
227 void
228 AliHLTPHOSModuleMergerComponent::ResetDataPtr()
229 {
230   for(int i = 0 ; i<  ALTRO_MAX_SAMPLES; i++)
231     {
232       fTmpChannelData[i] = 0;
233     }
234 }
235
236
237 //_____________________________________________________________________________________________________
238 void 
239 AliHLTPHOSModuleMergerComponent::SetEquippmentId(int id)
240 {
241   fEquippmentID = id;
242 }
243
244
245 //_____________________________________________________________________________________________________
246 const int 
247 AliHLTPHOSModuleMergerComponent::GetEquippmentId() const
248 {
249   return  fEquippmentID;
250 }
251
252
253 //_____________________________________________________________________________________________________
254 AliHLTComponent*
255 AliHLTPHOSModuleMergerComponent::Spawn()
256 {
257   return new AliHLTPHOSModuleMergerComponent;
258 }
259
260