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