]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTRawReaderPublisherComponent.cxx
a few fixes for rare bugs/malfunctions
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTRawReaderPublisherComponent.cxx
CommitLineData
6666bfe5 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: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTRawReaderPublisherComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief A general tree publisher component for the AliRawReader.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include "AliHLTRawReaderPublisherComponent.h"
32#include "AliRawReader.h"
e39ae6fb 33#include "AliDAQ.h"
6666bfe5 34#include "AliLog.h"
35#include <cerrno>
36#include <cassert>
bee77626 37#include <list>
6666bfe5 38
6666bfe5 39/** ROOT macro for the implementation of ROOT specific class methods */
40ClassImp(AliHLTRawReaderPublisherComponent)
41
42AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
43 :
0a51d3cf 44 fMaxSize(5000000),
6666bfe5 45 fDetector(),
46 fMinEquId(-1),
47 fMaxEquId(-1),
48 fVerbose(kFALSE),
0a51d3cf 49 fDataType(kAliHLTVoidDataType),
4eb069ae 50 fSpecification(kAliHLTVoidDataSpec),
51 fSkipEmpty(kFALSE)
6666bfe5 52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
61{
62 // see header file for class documentation
63}
64
65const char* AliHLTRawReaderPublisherComponent::GetComponentID()
66{
67 // see header file for class documentation
68 return "AliRawReaderPublisher";
69}
70
71AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
72{
f3506ea2 73 // see header file for class documentation
6666bfe5 74 return fDataType;
75}
76
77void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
78{
f3506ea2 79 // see header file for class documentation
6666bfe5 80 constBase=fMaxSize;
81 inputMultiplier=1;
82}
83
84AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
85{
86 // see header file for class documentation
87 return new AliHLTRawReaderPublisherComponent;
88}
89
90int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
91{
92 // see header file for class documentation
93 int iResult=0;
94
95 // scan arguments
96 TString argument="";
97 int bMissingParam=0;
98 for (int i=0; i<argc && iResult>=0; i++) {
99 argument=argv[i];
100 if (argument.IsNull()) continue;
101
102 // -detector
103 if (argument.CompareTo("-detector")==0) {
104 if ((bMissingParam=(++i>=argc))) break;
105 fDetector=argv[i];
106
107 // -equipmentid, -minid
108 } else if (argument.CompareTo("-equipmentid")==0 ||
109 argument.CompareTo("-minid")==0) {
110 if ((bMissingParam=(++i>=argc))) break;
111 TString parameter(argv[i]);
112 parameter.Remove(TString::kLeading, ' '); // remove all blanks
113 if (parameter.IsDigit()) {
114 fMinEquId=(AliHLTUInt32_t)parameter.Atoi();
115 } else {
116 HLTError("wrong parameter for argument %s, number expected", argument.Data());
117 iResult=-EINVAL;
118 }
119
120 // -maxid
121 } else if (argument.CompareTo("-maxid")==0) {
122 if ((bMissingParam=(++i>=argc))) break;
123 TString parameter(argv[i]);
124 parameter.Remove(TString::kLeading, ' '); // remove all blanks
125 if (parameter.IsDigit()) {
126 fMaxEquId=(AliHLTUInt32_t)parameter.Atoi();
127 } else {
128 HLTError("wrong parameter for argument %s, number expected", argument.Data());
129 iResult=-EINVAL;
130 }
131
132 // -verbose
133 } else if (argument.CompareTo("-verbose")==0) {
134 fVerbose=kTRUE;
135
4eb069ae 136 // -skipempty
137 } else if (argument.CompareTo("-skipempty")==0) {
138 fSkipEmpty=kTRUE;
139
6666bfe5 140 // -datatype
141 } else if (argument.CompareTo("-datatype")==0) {
142 if ((bMissingParam=(++i>=argc))) break;
143 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
144 if ((bMissingParam=(++i>=argc))) break;
145 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
146
147 // -dataspec
148 } else if (argument.CompareTo("-dataspec")==0) {
149 if ((bMissingParam=(++i>=argc))) break;
150 TString parameter(argv[i]);
151 parameter.Remove(TString::kLeading, ' '); // remove all blanks
152 if (parameter.IsDigit()) {
153 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
154 } else if (parameter.BeginsWith("0x") &&
155 parameter.Replace(0,2,"",0).IsHex()) {
156 sscanf(parameter.Data(),"%x", &fSpecification);
157 } else {
158 HLTError("wrong parameter for argument %s, number expected", argument.Data());
159 iResult=-EINVAL;
160 }
161 } else {
162 HLTError("unknown argument %s", argument.Data());
163 iResult=-EINVAL;
164 }
165 }
166 if (bMissingParam) {
167 HLTError("missing parameter for argument %s", argument.Data());
168 iResult=-EINVAL;
169 }
170
171 if (iResult<0) return iResult;
172
e39ae6fb 173 if (!fDetector.IsNull()) {
174 int ddloffset=-1;
175 int ddlcount=-1;
176 if ((ddloffset=AliDAQ::DdlIDOffset(fDetector))<0 ||
177 (ddlcount=AliDAQ::NumberOfDdls(fDetector))<0) {
178 return -EINVAL;
179 }
180 if (fMinEquId<0) fMinEquId=ddloffset;
181 else fMinEquId+=ddloffset;
182
183 if (fMaxEquId<0 || fMaxEquId>ddlcount) fMaxEquId=ddloffset+ddlcount;
184 else fMaxEquId+=ddloffset;
185 }
186
6666bfe5 187 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
188
189 if (fMinEquId<0) {
e39ae6fb 190 AliErrorStream() << "equipment id required, use \'-equipmentid\' or \'-detector\' option" << endl;
6666bfe5 191 return -EINVAL;
192 }
193
194 AliHLTUInt32_t dummy;
195 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
196 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
197 //return -EINVAL;
198 }
199
200 AliRawReader* pRawReader=GetRawReader();
201 if ((pRawReader=GetRawReader())!=NULL) {
6666bfe5 202 } else {
203 AliErrorStream() << "RawReader instance needed" << endl;
204 return -EINVAL;
205 }
206
207 return iResult;
208}
209
210int AliHLTRawReaderPublisherComponent::DoDeinit()
211{
212 // see header file for class documentation
213 int iResult=0;
214 return iResult;
215}
216
d76bc02a 217int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
218 AliHLTComponentTriggerData& /*trigData*/,
6666bfe5 219 AliHLTUInt8_t* outputPtr,
220 AliHLTUInt32_t& size,
221 vector<AliHLTComponentBlockData>& outputBlocks)
222{
223 // see header file for class documentation
224 int iResult=0;
53f79557 225 AliHLTUInt32_t capacity=size;
226 size=0;
587c9cf9 227
228 // process data events only
229 if (!IsDataEvent()) return 0;
230
a1dbf058 231 unsigned int offset=0;
10ca703e 232 assert(outputPtr!=NULL || size==0);
6666bfe5 233 AliRawReader* pRawReader=GetRawReader();
234 if (pRawReader) {
0a51d3cf 235 pRawReader->Reset();
236 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
4eb069ae 237 if (fVerbose) {
238 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
239 } else {
240 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
241 }
bee77626 242 list<int> processedIds;
6666bfe5 243 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
0a51d3cf 244 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
6daf06e2 245 if (pHeader==NULL) {
246 HLTError("can not get data header from RawReader, skipping data block ...");
247 continue;
248 }
a1dbf058 249 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
6666bfe5 250 int id=pRawReader->GetEquipmentId();
10ca703e 251 AliInfo(Form("got header for id %d, size %d", id, readSize));
0a51d3cf 252 if (fMinEquId>id || fMaxEquId<id) {
6666bfe5 253 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
254 continue;
255 }
bee77626 256 processedIds.push_back(id);
53f79557 257 if (readSize+offset<=capacity) {
bee77626 258 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
259 if (readSize>sizeof(AliRawDataHeader)) {
260 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
0a51d3cf 261 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
6666bfe5 262 iResult=-ENODATA;
263 break;
264 }
6666bfe5 265 }
6666bfe5 266 AliHLTComponentBlockData bd;
267 FillBlockData( bd );
268 bd.fOffset = offset;
269 bd.fSize = readSize;
270 bd.fDataType = fDataType;
0a51d3cf 271 if (fSpecification == kAliHLTVoidDataSpec) {
272 GetSpecificationFromEquipmentId(id, bd.fSpecification);
273 } else {
274 bd.fSpecification=fSpecification;
275 }
6666bfe5 276 outputBlocks.push_back( bd );
bee77626 277 } else {
278 // we keep the loop going in order to collect the full size
279 fMaxSize=offset+readSize;
280 iResult=-ENOSPC;
6666bfe5 281 }
282 offset+=readSize;
283 }
4eb069ae 284 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
bee77626 285 // add further empty data blocks
286 AliRawDataHeader header;
287 header.fSize=sizeof(AliRawDataHeader);
288 processedIds.sort();
289 list<int>::iterator curr=processedIds.begin();
290 for (int id=fMinEquId; id<=fMaxEquId; id++) {
291 if (curr!=processedIds.end() && *curr<=id) {
292 curr++;
293 } else {
53f79557 294 if (sizeof(AliRawDataHeader)<=capacity-offset) {
bee77626 295 HLTInfo("add empty data block for equipment id %d", id);
296 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
297 AliHLTComponentBlockData bd;
298 FillBlockData( bd );
299 bd.fOffset = offset;
300 bd.fSize = sizeof(AliRawDataHeader);
301 bd.fDataType = fDataType;
302 if (fSpecification == kAliHLTVoidDataSpec) {
303 GetSpecificationFromEquipmentId(id, bd.fSpecification);
304 } else {
305 bd.fSpecification=fSpecification;
306 }
307 outputBlocks.push_back( bd );
308 } else {
309 // we keep the loop going in order to collect the full size
310 fMaxSize=offset+sizeof(AliRawDataHeader);
311 iResult=-ENOSPC;
312 }
313 offset+=sizeof(AliRawDataHeader);
314 }
315 }
316 }
53f79557 317 if (offset<=capacity) {
bee77626 318 size=offset;
319 } else {
bee77626 320 outputBlocks.clear();
321 }
6666bfe5 322 } else {
323 AliErrorStream() << "RawReader uninitialized" << endl;
324 iResult=-EFAULT;
325 }
326 return iResult;
327}
328
0a51d3cf 329int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
f3506ea2 330 // see header file for class documentation
0a51d3cf 331 return specification=id;
6666bfe5 332}