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