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