3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
10 //* for The ALICE HLT Project. *
12 //* Permission to use, copy, modify and distribute this software and its *
13 //* documentation strictly for non-commercial purposes is hereby granted *
14 //* without fee, provided that the above copyright notice appears in all *
15 //* copies and that both the copyright notice and this permission notice *
16 //* appear in the supporting documentation. The authors make no claims *
17 //* about the suitability of this software for any purpose. It is *
18 //* provided "as is" without express or implied warranty. *
19 //**************************************************************************
21 /** @file AliHLTAltroTimebinAverageComponent.cxx
22 @author Kalliopi Kanaki, Oystein Djuvsland, Matthias Richter
30 #include "AliHLTAltroTimebinAverageComponent.h"
31 #include "AliAltroDecoder.h"
32 #include "AliAltroData.h"
33 #include "AliAltroBunch.h"
34 #include "AliHLTAltroEncoder.h"
35 #include "AliRawDataHeader.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTAltroTimebinAverageComponent)
40 AliHLTAltroTimebinAverageComponent::AliHLTAltroTimebinAverageComponent()
46 // see header file for class documentation
48 // refer to README to build package
50 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53 AliHLTAltroTimebinAverageComponent::~AliHLTAltroTimebinAverageComponent()
55 // see header file for class documentation
58 // Public functions to implement AliHLTComponent's interface.
59 // These functions are required for the registration process
61 const char* AliHLTAltroTimebinAverageComponent::GetComponentID()
63 // see header file for class documentation
64 return "AltroTimebinAverager";
67 void AliHLTAltroTimebinAverageComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 // see header file for class documentation
71 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
72 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginPHOS );
75 AliHLTComponentDataType AliHLTAltroTimebinAverageComponent::GetOutputDataType()
77 // see header file for class documentation
78 return kAliHLTDataTypeDDLRaw;
81 int AliHLTAltroTimebinAverageComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
83 // see header file for class documentation
85 tgtList.push_back(kAliHLTDataTypeDDLRaw);
86 return tgtList.size();
89 void AliHLTAltroTimebinAverageComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
91 // see header file for class documentation
96 AliHLTComponent* AliHLTAltroTimebinAverageComponent::Spawn()
98 // see header file for class documentation
99 return new AliHLTAltroTimebinAverageComponent;
102 int AliHLTAltroTimebinAverageComponent::DoInit( int argc, const char** argv )
104 // see header file for class documentation
111 // -- number of timebins
112 if ( !strcmp( argv[i], "ntimebins" ) ) {
113 fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
115 HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
123 if ( !strcmp( argv[i], "start-timebin" ) ) {
124 fStartTimeBin = strtoul( argv[i+1], &cpErr ,0);
126 HLTError("Cannot convert start-timebin specifier '%s'.", argv[i+1]);
134 if ( !strcmp( argv[i], "end-timebin" ) ) {
135 if(strtoul( argv[i+1], &cpErr ,0)<=1024){
136 fEndTimeBin = strtoul( argv[i+1], &cpErr ,0);
139 HLTError("Cannot convert end-timebin specifier '%s'.", argv[i+1]);
146 HLTError("Unknown option '%s'", argv[i]);
154 int AliHLTAltroTimebinAverageComponent::DoDeinit()
156 // see header file for class documentation
160 int AliHLTAltroTimebinAverageComponent::DoEvent( const AliHLTComponentEventData& evtData,
161 const AliHLTComponentBlockData* blocks,
162 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
163 AliHLTUInt32_t& size,
164 vector<AliHLTComponentBlockData>& outputBlocks )
166 // see header file for class documentation
168 AliHLTUInt32_t capacity=size;
170 AliHLTUInt32_t offset=0;
172 const AliHLTComponentBlockData* iter = NULL;
175 AliAltroDecoder* decoder=NULL;
176 AliHLTAltroEncoder* altroEncoder=NULL;
178 for(ndx = 0; ndx < evtData.fBlockCnt; ndx++) {
181 if ( iter->fDataType != kAliHLTDataTypeDDLRaw) {
185 if (decoder) delete decoder;
186 decoder=new AliAltroDecoder;
192 if (altroEncoder) delete altroEncoder;
195 if ((localResult=decoder->SetMemory((UChar_t*)iter->fPtr,iter->fSize))<0) {
196 HLTWarning("can not set up AltroDecoder for data block %s 0x%08x: error %d, skipping data block",
197 DataType2Text(iter->fDataType).c_str(), iter->fSpecification, localResult);
201 if (!decoder->Decode()) {
202 HLTWarning("can not decode data block %s 0x%08x: skipping data block",
203 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
207 UChar_t *RCUTrailer=NULL;
208 Int_t RCUTrailerSize=decoder->GetRCUTrailerSize();
209 if (RCUTrailerSize<=0 || !decoder->GetRCUTrailerData(RCUTrailer) || RCUTrailer==NULL) {
210 HLTWarning("can not find RCU trailer for data block %s 0x%08x: skipping data block",
211 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
215 AliAltroData altrochannel;
216 while (iResult>=0 && decoder->NextChannel(&altrochannel) && iResult>=0) {
217 int hwadd=altrochannel.GetHadd();
219 AliAltroBunch altrobunch;
220 while (iResult>=0 && altrochannel.NextBunch(&altrobunch) && iResult>=0) {
221 int bunchLength=altrobunch.GetBunchSize();
222 int bunchEndTime=altrobunch.GetEndTimeBin();
223 int time=bunchEndTime-bunchLength+1;
224 const UInt_t* bunchData=altrobunch.GetData();
225 for (int bin=bunchLength && iResult>=0; bin>0; ) {
227 if(bunchData[bin]>0){// disregarding 0 data.
229 if(time+bin>=fStartTimeBin && time+bin<=fEndTimeBin){
231 // set up the encoder
232 altroEncoder=new AliHLTAltroEncoder;
237 altroEncoder->SetBuffer(outputPtr+offset,capacity-offset);
238 AliRawDataHeader cdh;
239 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
241 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
244 AliHLTUInt16_t signal=bunchData[bin];
245 if (bin-1>=0) signal+=bunchData[bin-1];
246 altroEncoder->AddSignal((time+bin)/2,signal/2);
248 } // end if between start and end time bin
249 } // end if bunchData[i]>0
251 } //while loop over bunches
253 altroEncoder->SetChannel(hwadd);
255 } // while loop over channels
258 int sizeOfData=altroEncoder->SetLength();
261 HLTError("data encoding failed");
264 if(sizeOfData>(int)capacity){
265 HLTWarning("Buffer too small to add the altrodata: %d of %d byte(s) already used", sizeOfData, size);
269 AliHLTComponentBlockData bd;
272 bd.fSize = sizeOfData;
273 bd.fDataType = iter->fDataType;
274 bd.fSpecification = iter->fSpecification;
275 outputBlocks.push_back( bd );
280 } // while over data blocks
282 if (iResult>=0) size=offset;