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 "AliHLTErrorGuard.h"
32 #include "AliAltroRawStreamV3.h"
33 #include "AliHLTAltroEncoder.h"
34 #include "AliRawReaderMemory.h"
35 #include "AliRawDataHeader.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTAltroTimebinAverageComponent)
41 AliHLTAltroTimebinAverageComponent::AliHLTAltroTimebinAverageComponent()
47 // see header file for class documentation
49 // refer to README to build package
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 AliHLTAltroTimebinAverageComponent::~AliHLTAltroTimebinAverageComponent()
56 // see header file for class documentation
59 // Public functions to implement AliHLTComponent's interface.
60 // These functions are required for the registration process
62 const char* AliHLTAltroTimebinAverageComponent::GetComponentID()
64 // see header file for class documentation
65 return "AltroTimebinAverager";
68 void AliHLTAltroTimebinAverageComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
70 // see header file for class documentation
72 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
73 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginPHOS );
76 AliHLTComponentDataType AliHLTAltroTimebinAverageComponent::GetOutputDataType()
78 // see header file for class documentation
79 return kAliHLTDataTypeDDLRaw;
82 int AliHLTAltroTimebinAverageComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
84 // see header file for class documentation
86 tgtList.push_back(kAliHLTDataTypeDDLRaw);
87 return tgtList.size();
90 void AliHLTAltroTimebinAverageComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
92 // see header file for class documentation
97 AliHLTComponent* AliHLTAltroTimebinAverageComponent::Spawn()
99 // see header file for class documentation
100 return new AliHLTAltroTimebinAverageComponent;
103 int AliHLTAltroTimebinAverageComponent::DoInit( int argc, const char** argv )
105 // see header file for class documentation
112 // -- number of timebins
113 if ( !strcmp( argv[i], "ntimebins" ) ) {
114 fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
116 HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
124 if ( !strcmp( argv[i], "start-timebin" ) ) {
125 fStartTimeBin = strtoul( argv[i+1], &cpErr ,0);
127 HLTError("Cannot convert start-timebin specifier '%s'.", argv[i+1]);
135 if ( !strcmp( argv[i], "end-timebin" ) ) {
136 if(strtoul( argv[i+1], &cpErr ,0)<=1024){
137 fEndTimeBin = strtoul( argv[i+1], &cpErr ,0);
140 HLTError("Cannot convert end-timebin specifier '%s'.", argv[i+1]);
147 HLTError("Unknown option '%s'", argv[i]);
155 int AliHLTAltroTimebinAverageComponent::DoDeinit()
157 // see header file for class documentation
161 int AliHLTAltroTimebinAverageComponent::DoEvent( const AliHLTComponentEventData& evtData,
162 const AliHLTComponentBlockData* blocks,
163 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
164 AliHLTUInt32_t& size,
165 vector<AliHLTComponentBlockData>& outputBlocks )
167 // see header file for class documentation
169 AliHLTUInt32_t capacity=size;
171 AliHLTUInt32_t offset=0;
173 const AliHLTComponentBlockData* iter = NULL;
176 std::auto_ptr<AliRawReaderMemory> pRawReader(new AliRawReaderMemory);
177 if (pRawReader.get()) return -ENOMEM;
179 for(ndx = 0; ndx < evtData.fBlockCnt; ndx++) {
182 if ( iter->fDataType != kAliHLTDataTypeDDLRaw) {
186 static AliHLTErrorGuard required("AliHLTAltroTimebinAverageComponent", "DoEvent", "component commission required after major changes, need to extract equipment id from data specification");
187 (++required).Throw(1);
191 if (!pRawReader->AddBuffer((UChar_t*)iter->fPtr,iter->fSize, 768)) {
192 ALIHLTERRORGUARD(1, "can not set up AltroDecoder for data block %s 0x%08x,"
193 " skipping data block and suppressing further messages",
194 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
198 std::auto_ptr<AliAltroRawStreamV3> altroRawStream(new AliAltroRawStreamV3(pRawReader.get()));
199 std::auto_ptr<AliHLTAltroEncoder> altroEncoder(new AliHLTAltroEncoder);
201 if (!altroRawStream.get() || !altroEncoder.get()) {
206 altroRawStream->Reset();
207 if (!altroRawStream->NextDDL()) {
208 ALIHLTERRORGUARD(1, "internal error, can not read data from AliRawReaderMemory");
212 UChar_t *RCUTrailer=NULL;
213 Int_t RCUTrailerSize=altroRawStream->GetRCUTrailerSize();
214 if (RCUTrailerSize<=0 || !altroRawStream->GetRCUTrailerData(RCUTrailer) || RCUTrailer==NULL) {
215 ALIHLTERRORGUARD(1, "can not find RCU trailer for data block %s 0x%08x: skipping data block",
216 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
220 altroEncoder->SetBuffer(outputPtr+offset,capacity-offset);
221 AliRawDataHeader cdh;
222 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
224 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
226 while (iResult>=0 && altroRawStream->NextChannel()) {
227 int hwadd=altroRawStream->GetHWAddress();
229 while (iResult>=0 && altroRawStream->NextBunch()) {
230 int bunchLength=altroRawStream->GetBunchLength();
231 int time=altroRawStream->GetStartTimeBin();
232 const UShort_t* bunchData=altroRawStream->GetSignals();
233 for (int bin=bunchLength && iResult>=0; bin>0; ) {
235 if(bunchData[bin]>0){// disregarding 0 data.
237 if(time+bin>=fStartTimeBin && time+bin<=fEndTimeBin){
238 AliHLTUInt16_t signal=bunchData[bin];
239 if (bin-1>=0) signal+=bunchData[bin-1];
240 altroEncoder->AddSignal((time+bin)/2,signal/2);
242 } // end if between start and end time bin
243 } // end if bunchData[i]>0
245 } //while loop over bunches
246 if (true/*condition deprecated but keep formatting*/) {
247 altroEncoder->SetChannel(hwadd);
249 } // while loop over channels
251 if (true/*condition deprecated but keep formatting*/) {
252 int sizeOfData=altroEncoder->SetLength();
255 HLTError("data encoding failed");
258 if(sizeOfData>(int)capacity){
259 HLTWarning("Buffer too small to add the altrodata: %d of %d byte(s) already used", sizeOfData, size);
263 AliHLTComponentBlockData bd;
266 bd.fSize = sizeOfData;
267 bd.fDataType = iter->fDataType;
268 bd.fSpecification = iter->fSpecification;
269 outputBlocks.push_back( bd );
274 } // while over data blocks
276 if (iResult>=0) size=offset;