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),
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()
76 delete fAltroBunchPtr;
84 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSRawAnalyzerComponen Deinit");
89 AliHLTPHOSRawAnalyzerComponentv2::GetComponentID()
92 return "PhosRawAnalyzerv2";
97 AliHLTPHOSRawAnalyzerComponentv2::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
101 list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
104 AliHLTComponentDataType
105 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataType()
108 return AliHLTPHOSDefinitions::fgkChannelDataType;
112 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
115 constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
116 inputMultiplier = 0.5;
120 AliHLTPHOSRawAnalyzerComponentv2::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/,
121 AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
124 UInt_t blockSize = 0;
127 const AliHLTComponentBlockData* iter = NULL;
129 bool droppedRaw = true;
131 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
134 if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType )
136 HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
140 blockSize = DoIt(iter, outputPtr, size, totSize);
146 totSize += blockSize;
147 HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
148 AliHLTComponentBlockData bdChannelData;
149 FillBlockData( bdChannelData );
150 //bdChannelData.fOffset = totSize-blockSize;
151 bdChannelData.fOffset = 0; //CRAP
152 bdChannelData.fSize = blockSize;
153 bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
154 bdChannelData.fSpecification = iter->fSpecification;
155 outputBlocks.push_back(bdChannelData);
165 AliHLTPHOSRawAnalyzerComponentv2::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
171 const int bunchsizecut = 5;
172 Short_t channelCount = 0;
174 AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr);
176 AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct));
177 Short_t channelSize = sizeof(AliHLTPHOSChannelDataStruct);
179 totSize += sizeof(AliHLTPHOSChannelDataHeaderStruct);
181 fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
182 fDecoderPtr->Decode();
184 while(fDecoderPtr->NextChannel(fAltroDataPtr) == true )
186 if(fAltroDataPtr->GetDataSize() != 0 )
190 while(fAltroDataPtr->NextBunch(fAltroBunchPtr) == true);
192 if(fAltroBunchPtr->GetBunchSize() > bunchsizecut && bunchcount == 0)
194 totSize += channelSize;
197 HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
201 nSamples = fAltroBunchPtr->GetBunchSize();
205 crazyness = fSanityInspectorPtr->CheckInsanity(static_cast<const UInt_t*>(fAltroBunchPtr->GetData()), static_cast<const Int_t>(fAltroBunchPtr->GetBunchSize()));
207 fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());
208 fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());
210 channelDataPtr->fChannelID = fMapperPtr->GetChannelID(iter->fSpecification, fAltroDataPtr->GetHadd());
211 channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
212 channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
213 channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
221 channelDataHeaderPtr->fNChannels = channelCount;
222 channelDataHeaderPtr->fAlgorithm = fAlgorithm;
223 channelDataHeaderPtr->fInfo = 0;
224 channelDataHeaderPtr->fHasRawData = false;
226 HLTDebug("Number of channels: %d", channelCount);
228 return channelSize*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
232 AliHLTPHOSRawAnalyzerComponentv2::DoInit( int argc, const char** argv )
235 //See base class for documentation
238 fMapperPtr = new AliHLTPHOSMapper();
240 for(int i = 0; i < argc; i++)
242 if(!strcmp("-offset", argv[i]))
244 fOffset = atoi(argv[i+1]);
248 if(fMapperPtr->GetIsInitializedMapping() == false)
250 Logging(kHLTLogFatal, __FILE__ , IntToChar( __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());