4 /**************************************************************************
5 * This file is property of and copyright by the ALICE HLT Project *
6 * All rights reserved. *
8 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
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 **************************************************************************/
19 #include "AliHLTPHOSRawAnalyzer.h"
20 #include "AliHLTPHOSRawAnalyzerComponentv2.h"
21 #include "AliHLTPHOSChannelDataHeaderStruct.h"
22 #include "AliHLTPHOSChannelDataStruct.h"
23 #include "AliHLTPHOSMapper.h"
24 #include "AliHLTPHOSSanityInspector.h"
25 #include "AliHLTPHOSBaseline.h"
26 #include "AliAltroDecoder.h"
27 #include "AliAltroData.h"
28 #include "AliAltroBunch.h"
31 AliHLTPHOSRawAnalyzerComponentv2::AliHLTPHOSRawAnalyzerComponentv2():
32 AliHLTPHOSRcuProcessor(),
35 fSanityInspectorPtr(0),
46 fMapperPtr = new AliHLTPHOSMapper();
47 fAltroDataPtr = new AliAltroData();
48 fAltroBunchPtr = new AliAltroBunch();
49 fDecoderPtr = new AliAltroDecoder();
50 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
54 AliHLTPHOSRawAnalyzerComponentv2::~AliHLTPHOSRawAnalyzerComponentv2()
63 AliHLTPHOSRawAnalyzerComponentv2::Deinit()
83 delete fAltroBunchPtr;
95 AliHLTPHOSRawAnalyzerComponentv2::GetComponentID()
98 return "PhosRawAnalyzerv2";
103 AliHLTPHOSRawAnalyzerComponentv2::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
107 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
110 AliHLTComponentDataType
111 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataType()
114 return AliHLTPHOSDefinitions::fgkChannelDataType;
118 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
121 constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
122 inputMultiplier = 0.5;
126 AliHLTPHOSRawAnalyzerComponentv2::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
127 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
133 const AliHLTComponentBlockData* iter = NULL;
136 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
139 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
141 HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
145 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
146 if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
151 totSize += blockSize; //Keeping track of the used size
152 // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
154 AliHLTComponentBlockData bdChannelData;
155 FillBlockData( bdChannelData );
156 bdChannelData.fOffset = 0; //CRAP
157 bdChannelData.fSize = blockSize;
158 bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
159 bdChannelData.fSpecification = iter->fSpecification;
160 outputBlocks.push_back(bdChannelData);
162 outputPtr += blockSize; //Updating position of the output buffer
166 size = totSize; //telling the framework how much buffer space we have used.
172 AliHLTPHOSRawAnalyzerComponentv2::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
178 Short_t channelCount = 0;
180 // Firs we want to write a header to the output
181 AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
183 // Then comes the channel data
184 AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
186 Short_t channelSize = sizeof(AliHLTPHOSChannelDataStruct);
188 totSize += sizeof(AliHLTPHOSChannelDataHeaderStruct);
190 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
191 fDecoderPtr->Decode();
193 while(fDecoderPtr->NextChannel(fAltroDataPtr) == true )
195 if(fAltroDataPtr->GetDataSize() != 0 )
198 while(fAltroDataPtr->NextBunch(fAltroBunchPtr) == true) {}
200 if(fAltroBunchPtr->GetBunchSize() > fBunchSizeCut)
202 totSize += channelSize;
205 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
209 nSamples = fAltroBunchPtr->GetBunchSize();
211 //crazyness = fSanityInspectorPtr->CheckInsanity(static_cast<const UInt_t*>(fAltroBunchPtr->GetData()), static_cast<const Int_t>(fAltroBunchPtr->GetBunchSize()));
213 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
214 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
216 if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition && fAltroBunchPtr->GetBunchSize() > fBunchSizeCut)
218 // Writing to the output buffer
219 channelDataPtr->fChannelID = fMapperPtr->GetChannelID(iter->fSpecification, fAltroDataPtr->GetHadd());
220 //channelDataPtr->fChannelID = fMapperPtr->GetChannelID(1, fAltroDataPtr->GetHadd());
221 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
222 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
223 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
225 channelDataPtr++; // Updating position of the free output.
231 channelDataHeaderPtr->fNChannels = channelCount;
232 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
233 channelDataHeaderPtr->fInfo = 0;
234 channelDataHeaderPtr->fHasRawData = false;
236 HLTDebug("Number of channels: %d", channelCount);
238 return channelSize*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
242 AliHLTPHOSRawAnalyzerComponentv2::DoInit( int argc, const char** argv )
245 //See base class for documentation
248 fMapperPtr = new AliHLTPHOSMapper();
250 for(int i = 0; i < argc; i++)
252 if(!strcmp("-offset", argv[i]))
254 fOffset = atoi(argv[i+1]);
256 if(!strcmp("-bunchsizecut", argv[i]))
258 fBunchSizeCut = atoi(argv[i+1]);
260 if(!strcmp("-minpeakposition", argv[i]))
262 fMinPeakPosition = atoi(argv[i+1]);
264 if(!strcmp("-maxpeakposition", argv[i]))
266 fMaxPeakPosition = atoi(argv[i+1]);
270 if(fMapperPtr->GetIsInitializedMapping() == false)
272 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());