3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Per Thomas Hille, Oystein Djuvsland *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 #include "AliHLTPHOSRawAnalyzer.h"
19 #include "AliHLTPHOSRawAnalyzerComponentv2.h"
20 #include "AliHLTPHOSChannelDataHeaderStruct.h"
21 #include "AliHLTPHOSChannelDataStruct.h"
22 #include "AliHLTPHOSMapper.h"
23 #include "AliHLTPHOSSanityInspector.h"
24 #include "AliAltroDecoder.h"
25 #include "AliAltroData.h"
26 #include "AliAltroBunch.h"
29 AliHLTPHOSRawAnalyzerComponentv2::AliHLTPHOSRawAnalyzerComponentv2():
30 AliHLTPHOSRcuProcessor(),
33 fSanityInspectorPtr(0),
44 fMapperPtr = new AliHLTPHOSMapper();
45 fAltroDataPtr = new AliAltroData();
46 fAltroBunchPtr = new AliAltroBunch();
47 fDecoderPtr = new AliAltroDecoder();
48 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
52 AliHLTPHOSRawAnalyzerComponentv2::~AliHLTPHOSRawAnalyzerComponentv2()
61 AliHLTPHOSRawAnalyzerComponentv2::Deinit()
81 delete fAltroBunchPtr;
93 AliHLTPHOSRawAnalyzerComponentv2::GetComponentID()
96 return "PhosRawAnalyzerv2";
101 AliHLTPHOSRawAnalyzerComponentv2::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
105 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
108 AliHLTComponentDataType
109 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataType()
112 return AliHLTPHOSDefinitions::fgkChannelDataType;
116 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
119 constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
120 inputMultiplier = 0.5;
124 AliHLTPHOSRawAnalyzerComponentv2::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
125 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
131 const AliHLTComponentBlockData* iter = NULL;
134 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
137 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
139 HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
143 blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
144 if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
149 totSize += blockSize; //Keeping track of the used size
150 // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
152 //Filling the block data
153 AliHLTComponentBlockData bdChannelData;
154 FillBlockData( bdChannelData );
155 bdChannelData.fOffset = 0; //FIXME
156 bdChannelData.fSize = blockSize;
157 bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
158 bdChannelData.fSpecification = iter->fSpecification;
159 outputBlocks.push_back(bdChannelData);
161 outputPtr += blockSize; //Updating position of the output buffer
165 size = totSize; //telling the framework how much buffer space we have used.
171 AliHLTPHOSRawAnalyzerComponentv2::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
177 Short_t channelCount = 0;
179 // Firs we want to write a header to the output
180 AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
182 // Then comes the channel data
183 AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
185 //Adding to the total size of data written
186 totSize += sizeof(AliHLTPHOSChannelDataHeaderStruct);
189 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
190 fDecoderPtr->Decode();
193 while(fDecoderPtr->NextChannel(fAltroDataPtr) == true )
195 if(fAltroDataPtr->GetDataSize() != 0 )
197 //Want to get the "first in time" "bunch"
198 while(fAltroDataPtr->NextBunch(fAltroBunchPtr) == true) {}
200 //Skip strangely short bunches
201 if(fAltroBunchPtr->GetBunchSize() > fBunchSizeCut)
203 totSize += sizeof(AliHLTPHOSChannelDataStruct);
206 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
210 nSamples = fAltroBunchPtr->GetBunchSize();
212 //crazyness = fSanityInspectorPtr->CheckInsanity(static_cast<const UInt_t*>(fAltroBunchPtr->GetData()), static_cast<const Int_t>(fAltroBunchPtr->GetBunchSize()));
214 //Evalute signal amplitude and timing
215 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
216 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
218 //Checking for sane timing...
219 if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition)
221 // Writing to the output buffer
222 channelDataPtr->fChannelID = fMapperPtr->GetChannelID(iter->fSpecification, fAltroDataPtr->GetHadd());
223 //channelDataPtr->fChannelID = fMapperPtr->GetChannelID(1, fAltroDataPtr->GetHadd());
224 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
225 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
226 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
228 channelDataPtr++; // Updating position of the free output.
235 channelDataHeaderPtr->fNChannels = channelCount;
236 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
237 channelDataHeaderPtr->fInfo = 0;
238 channelDataHeaderPtr->fHasRawData = false;
240 HLTDebug("Number of channels: %d", channelCount);
242 //returning the size used
243 return sizeof(AliHLTPHOSChannelDataStruct)*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
247 AliHLTPHOSRawAnalyzerComponentv2::DoInit( int argc, const char** argv )
250 //See base class for documentation
253 fMapperPtr = new AliHLTPHOSMapper();
255 for(int i = 0; i < argc; i++)
257 if(!strcmp("-offset", argv[i]))
259 fOffset = atoi(argv[i+1]);
261 if(!strcmp("-bunchsizecut", argv[i]))
263 fBunchSizeCut = atoi(argv[i+1]);
265 if(!strcmp("-minpeakposition", argv[i]))
267 fMinPeakPosition = atoi(argv[i+1]);
269 if(!strcmp("-maxpeakposition", argv[i]))
271 fMaxPeakPosition = atoi(argv[i+1]);
275 if(fMapperPtr->GetIsInitializedMapping() == false)
277 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initialise mapping from file %s, aborting", fMapperPtr->GetFilePath());