Possiblity to run the simulation starting from an external root file containing geome...
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponent.cxx
CommitLineData
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
2b7cf4fb 19
20/// @class AliHLTPHOSRawAnalyzerComponent
21/// Base class of PHOS HLT online raw analysis component.
22/// The class provides a common interface for the implementation of PHOS
23/// HLT raw data
24/// processors components. The class is intended for processing of
25/// arrays of raw data samples to evaluate energy and timing.
26/// The Energy will be given in entities of ADC leves ranging from 0 to
27/// 1023. Timing will be given in entities of samples periods.
28/// Drived clases must implement the fucntions
29/// - @ref GetComponentID
30/// - @ref Spawn
31
2b7cf4fb 32#include "AliHLTPHOSRawAnalyzer.h"
cbab66dd 33#include "AliHLTPHOSRawAnalyzerComponent.h"
9dfd64cf 34#include "AliRawReaderMemory.h"
0a211711 35#include "AliCaloRawStream.h"
bde48b84 36#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
2b7cf4fb 37#include "AliHLTPHOSRcuChannelDataStruct.h"
e086ee30 38#include "AliHLTDDLDecoder.h"
39#include "AliHLTAltroData.h"
cbab66dd 40
e086ee30 41#include "AliHLTPHOSMapper.h"
ee7849e6 42
d2a0b488 43using namespace std;
4df5dd10 44
2b7cf4fb 45
d504c864 46//_________________________________________________________________________________________________
d2a0b488 47AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent():AliHLTPHOSProcessor(), fAnalyzerPtr(0),
48fSendChannelData(kFALSE),fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 49{
e086ee30 50 fMapperPtr = new AliHLTPHOSMapper();
d504c864 51}
2b7cf4fb 52
d504c864 53//_________________________________________________________________________________________________
cbab66dd 54AliHLTPHOSRawAnalyzerComponent::~AliHLTPHOSRawAnalyzerComponent()
55{
0a211711 56 if(fRawMemoryReader != 0)
57 {
58 delete fRawMemoryReader;
59 }
60 if(fPHOSRawStream != 0)
61 {
62 delete fPHOSRawStream;
63 }
cbab66dd 64}
65
d504c864 66//_________________________________________________________________________________________________
d2a0b488 67AliHLTPHOSRawAnalyzerComponent::AliHLTPHOSRawAnalyzerComponent(const AliHLTPHOSRawAnalyzerComponent & ) : AliHLTPHOSProcessor(), fAnalyzerPtr(0),
68fSendChannelData(kFALSE),fPHOSRawStream(0), fRawMemoryReader(0), fOutPtr(0)
cbab66dd 69{
cbab66dd 70
cbab66dd 71}
72
d504c864 73//_________________________________________________________________________________________________
cbab66dd 74int
d2a0b488 75AliHLTPHOSRawAnalyzerComponent::Deinit()
cbab66dd 76{
d2a0b488 77 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
9dfd64cf 78
0a211711 79 if(fRawMemoryReader !=0)
80 {
81 delete fRawMemoryReader;
82 }
83
84 if(fPHOSRawStream != 0)
85 {
86 delete fPHOSRawStream;
87 }
cbab66dd 88 return 0;
cbab66dd 89
d2a0b488 90 return 0;
cbab66dd 91}
92
d504c864 93//_________________________________________________________________________________________________
9dfd64cf 94const char*
95AliHLTPHOSRawAnalyzerComponent::GetComponentID()
96{
97 return "AliPhosTestRaw";
98}
ee7849e6 99
1c1b3412 100
d504c864 101//_________________________________________________________________________________________________
cbab66dd 102void
ee7849e6 103AliHLTPHOSRawAnalyzerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
cbab66dd 104{
146c463a 105 const AliHLTComponentDataType* pType=fgkInputDataTypes;
ee7849e6 106 while (pType->fID!=0) {
107 list.push_back(*pType);
108 pType++;
109 }
cbab66dd 110}
111
d504c864 112//_________________________________________________________________________________________________
cbab66dd 113AliHLTComponentDataType
114AliHLTPHOSRawAnalyzerComponent::GetOutputDataType()
115{
d504c864 116 return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
cbab66dd 117}
118
d504c864 119
120//_________________________________________________________________________________________________
cbab66dd 121void
9dfd64cf 122AliHLTPHOSRawAnalyzerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
123
cbab66dd 124{
ef408bb3 125 constBase = 30;
2b7cf4fb 126 inputMultiplier = 1;
cbab66dd 127}
128
d504c864 129//_________________________________________________________________________________________________
130int
131AliHLTPHOSRawAnalyzerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
cbab66dd 132{
bde48b84 133 Int_t sampleCnt = 0;
2947a32c 134 Int_t processedChannels = 0;
bde48b84 135 UInt_t offset = 0;
136 UInt_t mysize = 0;
137 UInt_t tSize = 0;
2bcb5a06 138 Int_t tmpChannelCnt = 0;
432edd34 139 Int_t tmpStartIndex = 0;
53740333 140 AliHLTUInt8_t* outBPtr;
2b7cf4fb 141 unsigned long first;
142 unsigned long last;
53740333 143 outBPtr = outputPtr;
0a211711 144 const AliHLTComponentBlockData* iter = NULL;
145 unsigned long ndx;
cf434398 146
0a211711 147 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
148 {
0a211711 149 iter = blocks+ndx;
53740333 150 mysize = 0;
151 offset = tSize;
152
d504c864 153 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
0a211711 154 {
e086ee30 155 cout <<"WARNING: notAliHLTPHOSDefinitions::fgkDDLPackedRawDataTyp " << endl;
156 // continue;
0a211711 157 }
ef408bb3 158
e086ee30 159 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
e086ee30 160 fDecoderPtr->Decode();
e086ee30 161 fOutPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)outBPtr;
162
6e709a0d 163 // int tmpCnt = 0;
164
e086ee30 165 while( fDecoderPtr->NextChannel(fAltroDataPtr) == true )
166 {
e086ee30 167
168 fAnalyzerPtr->SetData(fAltroDataPtr->fData);
6e709a0d 169 fAnalyzerPtr->Evaluate(0, fAltroDataPtr->fDataSize -2);
e086ee30 170
171 fOutPtr->fValidData[tmpChannelCnt].fGain = fMapperPtr->ALTRO_MAP[fAltroDataPtr->fHadd].gain;
172 fOutPtr->fValidData[tmpChannelCnt].fZ = fMapperPtr->ALTRO_MAP[fAltroDataPtr->fHadd].row;
173 fOutPtr->fValidData[tmpChannelCnt].fX = fMapperPtr->ALTRO_MAP[fAltroDataPtr->fHadd].col;
174 fOutPtr->fValidData[tmpChannelCnt].fEnergy = (float)fAnalyzerPtr->GetEnergy();
175 fOutPtr->fValidData[tmpChannelCnt].fTime = (float)fAnalyzerPtr->GetTiming();
176 tmpChannelCnt ++;
6e709a0d 177 // tmpCnt ++;
e086ee30 178 }
e086ee30 179
180 mysize += sizeof(AliHLTPHOSRcuCellEnergyDataStruct);
6e709a0d 181
e086ee30 182 fOutPtr->fCnt = tmpChannelCnt;
183 AliHLTComponentBlockData bd;
184 FillBlockData( bd );
185 bd.fOffset = offset;
186 bd.fSize = mysize;
187
188 bd.fDataType = AliHLTPHOSDefinitions::fgkCellEnergyDataType;
189 bd.fSpecification = 0xFFFFFFFF;
190 outputBlocks.push_back( bd );
191
192 tSize += mysize;
193 outBPtr += mysize;
194
195 if( tSize > size )
196 {
6e709a0d 197 cout <<"kHLTLogFatal, HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent Too much dataData written over allowed buffer. Amount written:"
e086ee30 198 << tSize << " allowed" << size << endl;
199 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRawAnalyzerComponent::DoEvent", "Too much data",
200 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
201 , tSize, size );
202 return EMSGSIZE;
203 }
e086ee30 204 }
e086ee30 205
d2a0b488 206 fPhosEventCount++;
2b7cf4fb 207
208 if(fPrintInfo == kTRUE)
209 {
d2a0b488 210 if(fPhosEventCount%fPrintInfoFrequncy == 0)
2b7cf4fb 211 {
d2a0b488 212 cout <<"Analyzing event " << fPhosEventCount << "for Equippment " << fkEquippmentID << endl;
2b7cf4fb 213 }
214 }
53740333 215 size = tSize;
e086ee30 216
2947a32c 217 return 0;
218}//end DoEvent
e086ee30 219
0a211711 220
221
d504c864 222//_________________________________________________________________________________________________
0a211711 223int
224AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv )
225{
e086ee30 226
227cout <<"AliHLTPHOSRawAnalyzerComponent::DoInit( int argc, const char** argv ) "<< endl;
228
229 fAltroDataPtr = new AliHLTAltroData();
230 fDecoderPtr = new AliHLTDDLDecoder();
2b7cf4fb 231 fSendChannelData = kFALSE;
232 fPrintInfo = kFALSE;
2947a32c 233 Reset();
0a211711 234 fRawMemoryReader = new AliRawReaderMemory();
235 fPHOSRawStream = new AliCaloRawStream(fRawMemoryReader,"PHOS");
e086ee30 236
237 // fPHOSRawStream->SetOldRCUFormat(kFALSE);
238
239 fPHOSRawStream->SetOldRCUFormat(kTRUE);
240
2b7cf4fb 241 int iResult=0;
242 TString argument="";
d2a0b488 243 iResult = ScanArguments(argc, argv);
2b7cf4fb 244
245
d2a0b488 246 if(fIsSetEquippmentID == kFALSE)
2b7cf4fb 247 {
e56d0892 248 cout << "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>" << endl;
2b7cf4fb 249 Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
250 "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID <number>");
e086ee30 251 iResult = -3;
2b7cf4fb 252 }
d2a0b488 253 else
254 {
255 fRawMemoryReader->SetEquipmentID(fkEquippmentID);
256 }
2b7cf4fb 257
d2a0b488 258 return iResult;
e086ee30 259
260
261return 0;
262
0a211711 263}
9dfd64cf 264
e086ee30 265/*
d504c864 266//_________________________________________________________________________________________________
2ca5f55f 267void
268AliHLTPHOSRawAnalyzerComponent::DumpData(int gain) const
0a211711 269{
432edd34 270 for(int mod = 0; mod < N_MODULES; mod ++)
2947a32c 271 {
272 printf("\n *********** MODULE %d ************\n", mod);
432edd34 273 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 274 {
432edd34 275 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 276 {
277 if( fMaxValues[mod][row][col][0] != 0)
278 {
432edd34 279 cout << fMaxValues[mod][row][col][gain] << "\t";
2947a32c 280 }
281 }
282 }
283 }
284}
e086ee30 285*/
9dfd64cf 286
432edd34 287
d504c864 288//_________________________________________________________________________________________________
6e709a0d 289
290/*
2ca5f55f 291void
292AliHLTPHOSRawAnalyzerComponent::DumpChannelData(Double_t *data) const
68d9caee 293{
d2a0b488 294 cout << endl;
295 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
296 {
297 if (data[i] != 0)
68d9caee 298 {
d2a0b488 299 cout <<i <<"\t";
68d9caee 300 }
d2a0b488 301 }
302 cout << endl;
303
304 for(int i=0; i< ALTRO_MAX_SAMPLES; i++)
305 {
306 if (data[i] != 0)
68d9caee 307 {
d2a0b488 308 cout <<data[i] <<"\t";
68d9caee 309 }
d2a0b488 310 }
311
312 cout << endl;
68d9caee 313}
6e709a0d 314*/
315
68d9caee 316
d504c864 317//_________________________________________________________________________________________________
2947a32c 318void
319AliHLTPHOSRawAnalyzerComponent::Reset()
320{
432edd34 321 for(int mod = 0; mod < N_MODULES; mod ++)
9dfd64cf 322 {
432edd34 323 for(int row = 0; row < N_ROWS_MOD; row ++)
2947a32c 324 {
432edd34 325 for(int col = 0; col < N_COLUMNS_MOD; col ++)
2947a32c 326 {
432edd34 327 for(int gain = 0; gain < N_GAINS; gain ++ )
2947a32c 328 {
329 fMaxValues[mod][row][col][gain] = 0;
330 }
331 }
332 }
333 }
9dfd64cf 334
2b7cf4fb 335 ResetDataPtr(0, ALTRO_MAX_SAMPLES);
432edd34 336
337} // end Reset
338
e086ee30 339
340
6e709a0d 341
d504c864 342//_________________________________________________________________________________________________
2947a32c 343void
432edd34 344AliHLTPHOSRawAnalyzerComponent::ResetDataPtr(int startindex, int sampleCnt)
2947a32c 345{
432edd34 346 for(int i = startindex ; i< sampleCnt; i++)
2947a32c 347 {
348 fTmpChannelData[i] = 0;
349 }
cbab66dd 350}
ef408bb3 351