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