]>
Commit | Line | Data |
---|---|---|
2d7ff710 | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | * for The ALICE Off-line Project. * | |
8 | * * | |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
14 | * about the suitability of this software for any purpose. It is * | |
15 | * provided "as is" without express or implied warranty. * | |
16 | **************************************************************************/ | |
17 | ||
18 | /** @file AliHLTFilePublisher.cxx | |
19 | @author Matthias Richter | |
20 | @date | |
21 | @brief HLT file publisher component implementation. */ | |
22 | ||
23 | #if __GNUC__>= 3 | |
24 | using namespace std; | |
25 | #endif | |
26 | ||
27 | #include "AliHLTFilePublisher.h" | |
28 | #include <TObjString.h> | |
29 | #include <TMath.h> | |
30 | #include <TFile.h> | |
31 | ||
32 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
33 | ClassImp(AliHLTFilePublisher) | |
34 | ||
35 | AliHLTFilePublisher::AliHLTFilePublisher() | |
36 | : | |
37 | fFileNames(), | |
38 | fFiles(), | |
39 | fpCurrent(NULL), | |
40 | fDataType(kAliHLTVoidDataType), | |
41 | fSpecification(~(AliHLTUInt32_t)0), | |
42 | fMaxSize(0) | |
43 | { | |
70ed7d01 | 44 | // see header file for class documentation |
45 | // or | |
46 | // refer to README to build package | |
47 | // or | |
48 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
49 | ||
2d7ff710 | 50 | // make the lists owners of their objects in order to automatically |
51 | // de-allocate the objects | |
52 | fFileNames.SetOwner(); | |
53 | fFiles.SetOwner(); | |
54 | } | |
55 | ||
56 | AliHLTFilePublisher::AliHLTFilePublisher(const AliHLTFilePublisher&) | |
57 | : | |
58 | fFileNames(), | |
59 | fFiles(), | |
60 | fpCurrent(NULL), | |
61 | fDataType(kAliHLTVoidDataType), | |
62 | fSpecification(0), | |
63 | fMaxSize(0) | |
64 | { | |
70ed7d01 | 65 | // see header file for class documentation |
2d7ff710 | 66 | HLTFatal("copy constructor untested"); |
67 | } | |
68 | ||
69 | AliHLTFilePublisher& AliHLTFilePublisher::operator=(const AliHLTFilePublisher&) | |
70 | { | |
70ed7d01 | 71 | // see header file for class documentation |
2d7ff710 | 72 | HLTFatal("assignment operator untested"); |
73 | return *this; | |
74 | } | |
75 | ||
76 | AliHLTFilePublisher::~AliHLTFilePublisher() | |
77 | { | |
70ed7d01 | 78 | // see header file for class documentation |
79 | ||
2d7ff710 | 80 | // file list and file name list are owner of their objects and |
81 | // delete all the objects | |
82 | } | |
83 | ||
84 | const char* AliHLTFilePublisher::GetComponentID() | |
85 | { | |
70ed7d01 | 86 | // see header file for class documentation |
2d7ff710 | 87 | return "FilePublisher"; |
88 | } | |
89 | ||
2d7ff710 | 90 | AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType() |
91 | { | |
70ed7d01 | 92 | // see header file for class documentation |
8b250b0e | 93 | AliHLTComponentDataType dt = |
94 | {sizeof(AliHLTComponentDataType), | |
95 | kAliHLTVoidDataTypeID, | |
96 | kAliHLTVoidDataOrigin}; | |
97 | return dt; | |
2d7ff710 | 98 | } |
99 | ||
100 | void AliHLTFilePublisher::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
101 | { | |
70ed7d01 | 102 | // see header file for class documentation |
2d7ff710 | 103 | constBase=fMaxSize; |
104 | inputMultiplier=1.0; | |
105 | } | |
106 | ||
107 | AliHLTComponent* AliHLTFilePublisher::Spawn() | |
108 | { | |
70ed7d01 | 109 | // see header file for class documentation |
2d7ff710 | 110 | return new AliHLTFilePublisher; |
111 | } | |
112 | ||
113 | int AliHLTFilePublisher::DoInit( int argc, const char** argv ) | |
114 | { | |
70ed7d01 | 115 | // see header file for class documentation |
116 | ||
9ce4bf4a | 117 | //HLTDebug("%d %s", argc, argv[0]); |
2d7ff710 | 118 | int iResult=0; |
119 | TString argument=""; | |
120 | int bMissingParam=0; | |
9ce4bf4a | 121 | for (int i=0; i<argc && iResult>=0; i++) { |
2d7ff710 | 122 | argument=argv[i]; |
3cde846d | 123 | if (argument.IsNull()) continue; |
2d7ff710 | 124 | |
125 | // -datafile | |
126 | if (argument.CompareTo("-datafile")==0) { | |
127 | if ((bMissingParam=(++i>=argc))) break; | |
128 | TObjString* parameter=new TObjString(argv[i]); | |
129 | if (parameter) { | |
130 | fFileNames.Add(parameter); | |
131 | } else { | |
132 | iResult=-ENOMEM; | |
133 | } | |
134 | ||
135 | // -datafilelist | |
136 | } else if (argument.CompareTo("-datafilelist")==0) { | |
137 | if ((bMissingParam=(++i>=argc))) break; | |
138 | HLTWarning("-datafilelist option not yet implemented"); | |
139 | ||
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]))); | |
3cde846d | 144 | if ((bMissingParam=(++i>=argc))) break; |
145 | memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i]))); | |
2d7ff710 | 146 | |
147 | // -dataspec | |
148 | } else if (argument.CompareTo("-dataspec")==0) { | |
149 | if ((bMissingParam=(++i>=argc))) break; | |
150 | TString parameter(argv[i]); | |
3cde846d | 151 | parameter.Remove(TString::kLeading, ' '); // remove all blanks |
2d7ff710 | 152 | if (parameter.IsDigit()) { |
153 | fSpecification=(AliHLTUInt32_t)parameter.Atoi(); | |
3cde846d | 154 | } else if (parameter.BeginsWith("0x") && |
155 | parameter.Replace(0,2,"",0).IsHex()) { | |
156 | sscanf(parameter.Data(),"%x", &fSpecification); | |
2d7ff710 | 157 | } else { |
158 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
159 | iResult=-EINVAL; | |
160 | } | |
2d7ff710 | 161 | } else { |
9ce4bf4a | 162 | if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) { |
163 | HLTError("unknown argument %s", argument.Data()); | |
164 | break; | |
165 | } else if (iResult==-EPROTO) { | |
166 | bMissingParam=1; | |
167 | break; | |
168 | } else if (iResult>=0) { | |
169 | i+=iResult; | |
170 | iResult=0; | |
171 | } | |
2d7ff710 | 172 | } |
173 | } | |
174 | if (bMissingParam) { | |
175 | HLTError("missing parameter for argument %s", argument.Data()); | |
176 | iResult=-EINVAL; | |
177 | } | |
178 | if (fFileNames.GetSize()==0) { | |
179 | HLTError("the publisher needs at least one file argument"); | |
180 | iResult=-EINVAL; | |
181 | } | |
182 | if (iResult>=0) iResult=OpenFiles(); | |
183 | if (iResult<0) { | |
184 | fFileNames.Clear(); | |
185 | } | |
186 | return iResult; | |
187 | } | |
188 | ||
9ce4bf4a | 189 | int AliHLTFilePublisher::ScanArgument(int argc, const char** argv) |
190 | { | |
70ed7d01 | 191 | // see header file for class documentation |
192 | ||
9ce4bf4a | 193 | // there are no other arguments than the standard ones |
194 | return -EINVAL; | |
195 | } | |
196 | ||
2d7ff710 | 197 | int AliHLTFilePublisher::OpenFiles() |
198 | { | |
70ed7d01 | 199 | // see header file for class documentation |
2d7ff710 | 200 | int iResult=0; |
201 | TObjLink *lnk=fFileNames.FirstLink(); | |
202 | while (lnk && iResult>=0) { | |
203 | TObjString* pFileName=(TObjString*)lnk->GetObject(); | |
204 | if (pFileName) { | |
205 | TString fullFN= pFileName->GetString() + "?filetype=raw"; | |
206 | TFile* pFile = new TFile(fullFN); | |
207 | if (pFile) { | |
208 | if (pFile->IsZombie()==0) { | |
209 | fFiles.Add(pFile); | |
210 | if (pFile->GetSize()>fMaxSize) fMaxSize=pFile->GetSize(); | |
211 | } else { | |
212 | HLTError("can not open file %s", (pFileName->GetString()).Data()); | |
213 | fFiles.Clear(); | |
214 | iResult=-ENOENT; | |
215 | } | |
216 | } | |
217 | } | |
218 | lnk = lnk->Next(); | |
219 | } | |
220 | ||
221 | return iResult; | |
222 | } | |
223 | ||
224 | int AliHLTFilePublisher::DoDeinit() | |
225 | { | |
70ed7d01 | 226 | // see header file for class documentation |
2d7ff710 | 227 | int iResult=0; |
228 | fFileNames.Clear(); | |
229 | fFiles.Clear(); | |
230 | return iResult; | |
231 | } | |
232 | ||
233 | int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData, | |
234 | AliHLTComponentTriggerData& trigData, | |
235 | AliHLTUInt8_t* outputPtr, | |
236 | AliHLTUInt32_t& size, | |
237 | vector<AliHLTComponentBlockData>& outputBlocks ) | |
238 | { | |
239 | int iResult=0; | |
9ce4bf4a | 240 | TObjLink *lnk=NULL; |
2d7ff710 | 241 | if (fpCurrent) lnk=fpCurrent->Next(); |
242 | if (lnk==NULL) lnk=fFiles.FirstLink(); | |
243 | fpCurrent=lnk; | |
244 | if (lnk) { | |
245 | TFile* pFile=(TFile*)lnk->GetObject(); | |
246 | if (pFile) { | |
247 | int iCopy=pFile->GetSize(); | |
9ce4bf4a | 248 | pFile->Seek(0); |
249 | if (iCopy>(int)size) { | |
2d7ff710 | 250 | iCopy=size; |
251 | HLTWarning("buffer to small, data of file %s truncated", pFile->GetName()); | |
252 | } | |
253 | if (pFile->ReadBuffer((char*)outputPtr, iCopy)!=0) { | |
254 | // ReadBuffer returns 1 in case of failure and 0 in case of success | |
255 | iResult=-EIO; | |
256 | } else { | |
257 | AliHLTComponentBlockData bd; | |
258 | FillBlockData(bd); | |
259 | bd.fPtr=outputPtr; | |
260 | bd.fOffset=0; | |
261 | bd.fSize=iCopy; | |
262 | bd.fDataType=fDataType; | |
263 | bd.fSpecification=fSpecification; | |
264 | outputBlocks.push_back(bd); | |
265 | size=iCopy; | |
266 | } | |
267 | } else { | |
9ce4bf4a | 268 | HLTError("no file available"); |
2d7ff710 | 269 | iResult=-EFAULT; |
270 | } | |
271 | } else { | |
272 | iResult=-ENOENT; | |
273 | } | |
274 | return iResult; | |
275 | } |