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