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