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