]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/RCU/AliHLTAltroTimebinAverageComponent.cxx
Updates
[u/mrichter/AliRoot.git] / HLT / RCU / AliHLTAltroTimebinAverageComponent.cxx
CommitLineData
881c4032 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
8//* Oystein Djuvsland
9//* Matthias Richter *
10//* for The ALICE HLT Project. *
11//* *
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//**************************************************************************
20
21/** @file AliHLTAltroTimebinAverageComponent.cxx
22 @author Kalliopi Kanaki, Oystein Djuvsland, Matthias Richter
23 @date 26.08.2008
24 @brief
25*/
26
881c4032 27#include "AliHLTAltroTimebinAverageComponent.h"
ff4a65b9 28#include "AliHLTErrorGuard.h"
29#include "AliAltroRawStreamV3.h"
881c4032 30#include "AliHLTAltroEncoder.h"
ff4a65b9 31#include "AliRawReaderMemory.h"
881c4032 32#include "AliRawDataHeader.h"
ff4a65b9 33#include <memory>
881c4032 34
a7f38894 35using namespace std;
36
881c4032 37/** ROOT macro for the implementation of ROOT specific class methods */
38ClassImp(AliHLTAltroTimebinAverageComponent)
39
40AliHLTAltroTimebinAverageComponent::AliHLTAltroTimebinAverageComponent()
41 :
42 fStartTimeBin(0),
43 fEndTimeBin(1024),
44 fNTimeBins(1024)
45{
46 // see header file for class documentation
47 // or
48 // refer to README to build package
49 // or
50 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
51}
52
53AliHLTAltroTimebinAverageComponent::~AliHLTAltroTimebinAverageComponent()
54{
55 // see header file for class documentation
56}
57
58// Public functions to implement AliHLTComponent's interface.
59// These functions are required for the registration process
60
61const char* AliHLTAltroTimebinAverageComponent::GetComponentID()
62{
63 // see header file for class documentation
64 return "AltroTimebinAverager";
65}
66
67void AliHLTAltroTimebinAverageComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68{
69 // see header file for class documentation
70 list.clear();
71 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
72 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginPHOS );
73}
74
75AliHLTComponentDataType AliHLTAltroTimebinAverageComponent::GetOutputDataType()
76{
77 // see header file for class documentation
78 return kAliHLTDataTypeDDLRaw;
79}
80
81int AliHLTAltroTimebinAverageComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
82{
83 // see header file for class documentation
84 tgtList.clear();
85 tgtList.push_back(kAliHLTDataTypeDDLRaw);
86 return tgtList.size();
87}
88
89void AliHLTAltroTimebinAverageComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
90{
91 // see header file for class documentation
92 constBase=0;
93 inputMultiplier=1.0;
94}
95
96AliHLTComponent* AliHLTAltroTimebinAverageComponent::Spawn()
97{
98 // see header file for class documentation
99 return new AliHLTAltroTimebinAverageComponent;
100}
101
102int AliHLTAltroTimebinAverageComponent::DoInit( int argc, const char** argv )
103{
104 // see header file for class documentation
105
106 Int_t i = 0;
107 Char_t* cpErr;
108
109 while ( i < argc ) {
110
111 // -- number of timebins
112 if ( !strcmp( argv[i], "ntimebins" ) ) {
113 fNTimeBins = strtoul( argv[i+1], &cpErr ,0);
114 if ( *cpErr ) {
115 HLTError("Cannot convert ntimebins specifier '%s'.", argv[i+1]);
116 return EINVAL;
117 }
118 i+=2;
119 continue;
120 }
121
122 // -- first timebin
123 if ( !strcmp( argv[i], "start-timebin" ) ) {
124 fStartTimeBin = strtoul( argv[i+1], &cpErr ,0);
125 if ( *cpErr ) {
126 HLTError("Cannot convert start-timebin specifier '%s'.", argv[i+1]);
127 return EINVAL;
128 }
129 i+=2;
130 continue;
131 }
132
133 // -- last timebin
134 if ( !strcmp( argv[i], "end-timebin" ) ) {
135 if(strtoul( argv[i+1], &cpErr ,0)<=1024){
136 fEndTimeBin = strtoul( argv[i+1], &cpErr ,0);
137 }
138 if ( *cpErr ) {
139 HLTError("Cannot convert end-timebin specifier '%s'.", argv[i+1]);
140 return EINVAL;
141 }
142 i+=2;
143 continue;
144 }
145
146 HLTError("Unknown option '%s'", argv[i]);
147 return -EINVAL;
148
149 }
150
151 return 0;
152}
153
154int AliHLTAltroTimebinAverageComponent::DoDeinit()
155{
156 // see header file for class documentation
157 return 0;
158}
159
160int AliHLTAltroTimebinAverageComponent::DoEvent( const AliHLTComponentEventData& evtData,
161 const AliHLTComponentBlockData* blocks,
162 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
163 AliHLTUInt32_t& size,
164 vector<AliHLTComponentBlockData>& outputBlocks )
165{
166 // see header file for class documentation
167 int iResult=0;
168 AliHLTUInt32_t capacity=size;
169 size=0;
170 AliHLTUInt32_t offset=0;
171
172 const AliHLTComponentBlockData* iter = NULL;
173 unsigned long ndx;
174
ff4a65b9 175 std::auto_ptr<AliRawReaderMemory> pRawReader(new AliRawReaderMemory);
176 if (pRawReader.get()) return -ENOMEM;
881c4032 177
178 for(ndx = 0; ndx < evtData.fBlockCnt; ndx++) {
179 iter = blocks+ndx;
180
181 if ( iter->fDataType != kAliHLTDataTypeDDLRaw) {
182 continue;
183 }
881c4032 184
ff4a65b9 185 static AliHLTErrorGuard required("AliHLTAltroTimebinAverageComponent", "DoEvent", "component commission required after major changes, need to extract equipment id from data specification");
186 (++required).Throw(1);
881c4032 187
ff4a65b9 188 pRawReader->Reset();
189 // FIXME: set ddl no
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);
881c4032 194 continue;
195 }
ff4a65b9 196
197 std::auto_ptr<AliAltroRawStreamV3> altroRawStream(new AliAltroRawStreamV3(pRawReader.get()));
198 std::auto_ptr<AliHLTAltroEncoder> altroEncoder(new AliHLTAltroEncoder);
199
200 if (!altroRawStream.get() || !altroEncoder.get()) {
201 iResult=-ENOMEM;
202 break;
203 }
204
205 altroRawStream->Reset();
206 if (!altroRawStream->NextDDL()) {
207 ALIHLTERRORGUARD(1, "internal error, can not read data from AliRawReaderMemory");
881c4032 208 continue;
209 }
210
211 UChar_t *RCUTrailer=NULL;
ff4a65b9 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);
881c4032 216 continue;
217 }
ff4a65b9 218
219 altroEncoder->SetBuffer(outputPtr+offset,capacity-offset);
220 AliRawDataHeader cdh;
221 altroEncoder->SetCDH((AliHLTUInt8_t*)iter->fPtr,sizeof(AliRawDataHeader));
222
223 altroEncoder->SetRCUTrailer(RCUTrailer, RCUTrailerSize);
224
225 while (iResult>=0 && altroRawStream->NextChannel()) {
226 int hwadd=altroRawStream->GetHWAddress();
227
228 while (iResult>=0 && altroRawStream->NextBunch()) {
229 int bunchLength=altroRawStream->GetBunchLength();
230 int time=altroRawStream->GetStartTimeBin();
231 const UShort_t* bunchData=altroRawStream->GetSignals();
881c4032 232 for (int bin=bunchLength && iResult>=0; bin>0; ) {
233 bin--;
234 if(bunchData[bin]>0){// disregarding 0 data.
235
236 if(time+bin>=fStartTimeBin && time+bin<=fEndTimeBin){
881c4032 237 AliHLTUInt16_t signal=bunchData[bin];
238 if (bin-1>=0) signal+=bunchData[bin-1];
239 altroEncoder->AddSignal((time+bin)/2,signal/2);
240 bin--;
241 } // end if between start and end time bin
242 } // end if bunchData[i]>0
243 } // for loop
244 } //while loop over bunches
ff4a65b9 245 if (true/*condition deprecated but keep formatting*/) {
881c4032 246 altroEncoder->SetChannel(hwadd);
247 }
248 } // while loop over channels
249
ff4a65b9 250 if (true/*condition deprecated but keep formatting*/) {
881c4032 251 int sizeOfData=altroEncoder->SetLength();
252
253 if (sizeOfData<0) {
254 HLTError("data encoding failed");
255 return sizeOfData;
256 }
257 if(sizeOfData>(int)capacity){
258 HLTWarning("Buffer too small to add the altrodata: %d of %d byte(s) already used", sizeOfData, size);
259 return -ENOSPC;
260 }
261
262 AliHLTComponentBlockData bd;
263 FillBlockData( bd );
264 bd.fOffset = offset;
265 bd.fSize = sizeOfData;
266 bd.fDataType = iter->fDataType;
267 bd.fSpecification = iter->fSpecification;
268 outputBlocks.push_back( bd );
269
270 offset+=bd.fSize;
271 }
272
273 } // while over data blocks
274
275 if (iResult>=0) size=offset;
276 return iResult;
277}
278