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
27 #include "AliHLTAltroTimebinAverageComponent.h"
28 #include "AliHLTErrorGuard.h"
29 #include "AliAltroRawStreamV3.h"
30 #include "AliHLTAltroEncoder.h"
31 #include "AliRawReaderMemory.h"
32 #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 std::auto_ptr<AliRawReaderMemory> pRawReader(new AliRawReaderMemory);
176 if (pRawReader.get()) return -ENOMEM;
178 for(ndx = 0; ndx < evtData.fBlockCnt; ndx++) {
181 if ( iter->fDataType != kAliHLTDataTypeDDLRaw) {
185 static AliHLTErrorGuard required("AliHLTAltroTimebinAverageComponent", "DoEvent", "component commission required after major changes, need to extract equipment id from data specification");
186 (++required).Throw(1);
190 if (!pRawReader->AddBuffer((UChar_t*)iter->fPtr,iter->fSize, 768)) {
191 ALIHLTERRORGUARD(1, "can not set up AltroDecoder for data block %s 0x%08x,"
192 " skipping data block and suppressing further messages",
193 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
197 std::auto_ptr<AliAltroRawStreamV3> altroRawStream(new AliAltroRawStreamV3(pRawReader.get()));
198 std::auto_ptr<AliHLTAltroEncoder> altroEncoder(new AliHLTAltroEncoder);
200 if (!altroRawStream.get() || !altroEncoder.get()) {
205 altroRawStream->Reset();
206 if (!altroRawStream->NextDDL()) {
207 ALIHLTERRORGUARD(1, "internal error, can not read data from AliRawReaderMemory");
211 UChar_t *RCUTrailer=NULL;
212 Int_t RCUTrailerSize=altroRawStream->GetRCUTrailerSize();
213 if (RCUTrailerSize<=0 || !altroRawStream->GetRCUTrailerData(RCUTrailer) || RCUTrailer==NULL) {
214 ALIHLTERRORGUARD(1, "can not find RCU trailer for data block %s 0x%08x: skipping data block",
215 DataType2Text(iter->fDataType).c_str(), iter->fSpecification);
219 altroEncoder->SetBuffer(outputPtr+offset,capacity-offset);
220 AliRawDataHeader cdh;
221 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
223 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
225 while (iResult>=0 && altroRawStream->NextChannel()) {
226 int hwadd=altroRawStream->GetHWAddress();
228 while (iResult>=0 && altroRawStream->NextBunch()) {
229 int bunchLength=altroRawStream->GetBunchLength();
230 int time=altroRawStream->GetStartTimeBin();
231 const UShort_t* bunchData=altroRawStream->GetSignals();
232 for (int bin=bunchLength && iResult>=0; bin>0; ) {
234 if(bunchData[bin]>0){// disregarding 0 data.
236 if(time+bin>=fStartTimeBin && time+bin<=fEndTimeBin){
237 AliHLTUInt16_t signal=bunchData[bin];
238 if (bin-1>=0) signal+=bunchData[bin-1];
239 altroEncoder->AddSignal((time+bin)/2,signal/2);
241 } // end if between start and end time bin
242 } // end if bunchData[i]>0
244 } //while loop over bunches
245 if (true/*condition deprecated but keep formatting*/) {
246 altroEncoder->SetChannel(hwadd);
248 } // while loop over channels
250 if (true/*condition deprecated but keep formatting*/) {
251 int sizeOfData=altroEncoder->SetLength();
254 HLTError("data encoding failed");
257 if(sizeOfData>(int)capacity){
258 HLTWarning("Buffer too small to add the altrodata: %d of %d byte(s) already used", sizeOfData, size);
262 AliHLTComponentBlockData bd;
265 bd.fSize = sizeOfData;
266 bd.fDataType = iter->fDataType;
267 bd.fSpecification = iter->fSpecification;
268 outputBlocks.push_back( bd );
273 } // while over data blocks
275 if (iResult>=0) size=offset;