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