1 /**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2007 *
6 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to perthi@fys.uio.no *
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" // decoder for altro payload
27 #include "AliAltroData.h" // container for altro payload
28 #include "AliAltroBunch.h" // container for altro bunches
31 AliHLTPHOSRawAnalyzerComponentv2::AliHLTPHOSRawAnalyzerComponentv2():AliHLTPHOSRcuProcessor(),
34 fSanityInspectorPtr(0),
45 fMapperPtr = new AliHLTPHOSMapper();
46 fAltroDataPtr = new AliAltroData();
47 fAltroBunchPtr = new AliAltroBunch();
48 fDecoderPtr = new AliAltroDecoder();
49 fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
53 AliHLTPHOSRawAnalyzerComponentv2::~AliHLTPHOSRawAnalyzerComponentv2()
62 AliHLTPHOSRawAnalyzerComponentv2::Deinit()
77 delete fAltroBunchPtr;
85 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
90 AliHLTPHOSRawAnalyzerComponentv2::GetComponentID()
93 return "PhosRawAnalyzerv2";
98 AliHLTPHOSRawAnalyzerComponentv2::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
102 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
105 AliHLTComponentDataType
106 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataType()
109 return AliHLTPHOSDefinitions::fgkChannelDataType;
113 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
116 constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
117 inputMultiplier = 0.5;
121 AliHLTPHOSRawAnalyzerComponentv2::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
122 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
128 const AliHLTComponentBlockData* iter = NULL;
130 // bool droppedRaw = true;
132 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
135 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
137 HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
141 blockSize = DoIt(iter, outputPtr, size, totSize);
147 totSize += blockSize;
148 HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
149 AliHLTComponentBlockData bdChannelData;
150 FillBlockData( bdChannelData );
151 //bdChannelData.fOffset = totSize-blockSize;
152 bdChannelData.fOffset = 0; //CRAP
153 bdChannelData.fSize = blockSize;
154 bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
155 bdChannelData.fSpecification = iter->fSpecification;
156 outputBlocks.push_back(bdChannelData);
166 AliHLTPHOSRawAnalyzerComponentv2::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
172 const int bunchsizecut = 5;
173 Short_t channelCount = 0;
175 AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
177 AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
178 Short_t channelSize = sizeof(AliHLTPHOSChannelDataStruct);
180 totSize += sizeof(AliHLTPHOSChannelDataHeaderStruct);
182 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
183 fDecoderPtr->Decode();
185 while(fDecoderPtr->NextChannel(fAltroDataPtr) == true )
187 if(fAltroDataPtr->GetDataSize() != 0 )
191 while(fAltroDataPtr->NextBunch(fAltroBunchPtr) == true);
193 if(fAltroBunchPtr->GetBunchSize() > bunchsizecut && bunchcount == 0)
195 totSize += channelSize;
198 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
202 nSamples = fAltroBunchPtr->GetBunchSize();
206 crazyness = fSanityInspectorPtr->CheckInsanity(static_cast<const UInt_t*>(fAltroBunchPtr->GetData()), static_cast<const Int_t>(fAltroBunchPtr->GetBunchSize()));
208 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
209 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
211 channelDataPtr->fChannelID = fMapperPtr->GetChannelID(iter->fSpecification, fAltroDataPtr->GetHadd());
212 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
213 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
214 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
222 channelDataHeaderPtr->fNChannels = channelCount;
223 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
224 channelDataHeaderPtr->fInfo = 0;
225 channelDataHeaderPtr->fHasRawData = false;
227 HLTDebug("Number of channels: %d", channelCount);
229 return channelSize*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
233 AliHLTPHOSRawAnalyzerComponentv2::DoInit( int argc, const char** argv )
236 //See base class for documentation
239 fMapperPtr = new AliHLTPHOSMapper();
241 for(int i = 0; i < argc; i++)
243 if(!strcmp("-offset", argv[i]))
245 fOffset = atoi(argv[i+1]);
249 if(fMapperPtr->GetIsInitializedMapping() == false)
251 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());