]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTRawReaderPublisherComponent.cxx
AOD replication (Roberta Arnaldi, AM)
[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;
587c9cf9 225
226 // process data events only
227 if (!IsDataEvent()) return 0;
228
a1dbf058 229 unsigned int offset=0;
10ca703e 230 assert(outputPtr!=NULL || size==0);
6666bfe5 231 AliRawReader* pRawReader=GetRawReader();
232 if (pRawReader) {
0a51d3cf 233 pRawReader->Reset();
234 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
4eb069ae 235 if (fVerbose) {
236 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
237 } else {
238 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
239 }
bee77626 240 list<int> processedIds;
6666bfe5 241 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
0a51d3cf 242 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
6daf06e2 243 if (pHeader==NULL) {
244 HLTError("can not get data header from RawReader, skipping data block ...");
245 continue;
246 }
a1dbf058 247 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
6666bfe5 248 int id=pRawReader->GetEquipmentId();
10ca703e 249 AliInfo(Form("got header for id %d, size %d", id, readSize));
0a51d3cf 250 if (fMinEquId>id || fMaxEquId<id) {
6666bfe5 251 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
252 continue;
253 }
bee77626 254 processedIds.push_back(id);
d4968bff 255 if (readSize+offset<=size) {
bee77626 256 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
257 if (readSize>sizeof(AliRawDataHeader)) {
258 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
0a51d3cf 259 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
6666bfe5 260 iResult=-ENODATA;
261 break;
262 }
6666bfe5 263 }
6666bfe5 264 AliHLTComponentBlockData bd;
265 FillBlockData( bd );
266 bd.fOffset = offset;
267 bd.fSize = readSize;
268 bd.fDataType = fDataType;
0a51d3cf 269 if (fSpecification == kAliHLTVoidDataSpec) {
270 GetSpecificationFromEquipmentId(id, bd.fSpecification);
271 } else {
272 bd.fSpecification=fSpecification;
273 }
6666bfe5 274 outputBlocks.push_back( bd );
bee77626 275 } else {
276 // we keep the loop going in order to collect the full size
277 fMaxSize=offset+readSize;
278 iResult=-ENOSPC;
6666bfe5 279 }
280 offset+=readSize;
281 }
4eb069ae 282 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
bee77626 283 // add further empty data blocks
284 AliRawDataHeader header;
285 header.fSize=sizeof(AliRawDataHeader);
286 processedIds.sort();
287 list<int>::iterator curr=processedIds.begin();
288 for (int id=fMinEquId; id<=fMaxEquId; id++) {
289 if (curr!=processedIds.end() && *curr<=id) {
290 curr++;
291 } else {
292 if (sizeof(AliRawDataHeader)<=size-offset) {
293 HLTInfo("add empty data block for equipment id %d", id);
294 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
295 AliHLTComponentBlockData bd;
296 FillBlockData( bd );
297 bd.fOffset = offset;
298 bd.fSize = sizeof(AliRawDataHeader);
299 bd.fDataType = fDataType;
300 if (fSpecification == kAliHLTVoidDataSpec) {
301 GetSpecificationFromEquipmentId(id, bd.fSpecification);
302 } else {
303 bd.fSpecification=fSpecification;
304 }
305 outputBlocks.push_back( bd );
306 } else {
307 // we keep the loop going in order to collect the full size
308 fMaxSize=offset+sizeof(AliRawDataHeader);
309 iResult=-ENOSPC;
310 }
311 offset+=sizeof(AliRawDataHeader);
312 }
313 }
314 }
315 if (offset<=size) {
316 size=offset;
317 } else {
318 size=0;
319 outputBlocks.clear();
320 }
6666bfe5 321 } else {
322 AliErrorStream() << "RawReader uninitialized" << endl;
323 iResult=-EFAULT;
324 }
325 return iResult;
326}
327
0a51d3cf 328int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
f3506ea2 329 // see header file for class documentation
0a51d3cf 330 return specification=id;
6666bfe5 331}