]>
Commit | Line | Data |
---|---|---|
a8aea857 | 1 | // -*- Mode: C++ -*- |
2 | // @(#) $Id$ | |
3 | ||
4 | #ifndef ALIHLTFILEPUBLISHER_H | |
5 | #define ALIHLTFILEPUBLISHER_H | |
a7ad9794 | 6 | //* This file is property of and copyright by the ALICE HLT Project * |
7 | //* ALICE Experiment at CERN, All rights reserved. * | |
8 | //* See cxx source for full Copyright notice * | |
a8aea857 | 9 | |
10 | /** @file AliHLTFilePublisher.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief An HLT file publishing (data source) component. | |
14 | @note The class is used in Offline (AliRoot) context | |
15 | */ | |
16 | ||
17 | #include "AliHLTDataSource.h" | |
18 | #include <TList.h> | |
7bcd6cad | 19 | class TFile; |
a8aea857 | 20 | |
21 | /** | |
22 | * @class AliHLTFilePublisher | |
23 | * An HLT data source component which publishes data from one or a sequence | |
24 | * of files.<br> | |
25 | * | |
a7ad9794 | 26 | * <h2>General properties:</h2> |
27 | * | |
a8aea857 | 28 | * Component ID: \b FilePublisher <br> |
a7ad9794 | 29 | * Library: \b libAliHLTUtil.so <br> |
30 | * Input Data Types: none <br> | |
31 | * Output Data Types: according to arguments <br> | |
a8aea857 | 32 | * |
a7ad9794 | 33 | * <h2>Mandatory arguments:</h2> |
1ac82ce6 | 34 | * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting --> |
a8aea857 | 35 | * \li -datafile <i> filename </i> |
36 | * \li -datafilelist <i> file pattern </i> <br> | |
37 | * not yet implemented | |
38 | * \li -datatype <i> datatype dataorigin </i> <br> | |
d397a3b2 | 39 | * data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt> |
a8aea857 | 40 | * \li -dataspec <i> specification </i> <br> |
41 | * data specification treated as decimal number or hex number if | |
42 | * prepended by '0x' | |
d397a3b2 | 43 | * \li -nextevent |
44 | * indicate files published by the next event | |
a8aea857 | 45 | * |
a7ad9794 | 46 | * <h2>Optional arguments:</h2> |
0449b3c8 | 47 | * \li -open_files_at_start |
48 | * Opens all files during component initialisation rather than as needed | |
49 | * during event processing. Note: this feature may result in the system | |
50 | * running out of file handles if a large number of files was specified. | |
a8aea857 | 51 | * |
a7ad9794 | 52 | * <h2>Configuration:</h2> |
53 | * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting --> | |
54 | * Configuration by component arguments. | |
55 | * | |
56 | * <h2>Default CDB entries:</h2> | |
57 | * The component loads no CDB entries. | |
58 | * | |
59 | * <h2>Performance:</h2> | |
60 | * The component does not process any event data. | |
61 | * | |
62 | * <h2>Memory consumption:</h2> | |
63 | * The component does not process any event data. | |
64 | * | |
65 | * <h2>Output size:</h2> | |
66 | * According to the available data. The component is an AliHLTDataSource | |
67 | * and inteded to be used in the AliHLTSystem framework only. The component | |
68 | * implements the standard AliHLTSystem adaptive buffer allocation. | |
69 | * | |
a8aea857 | 70 | * The component needs at least one argument \em -datafile or \em -datafilelist. |
71 | * Both can occur multiple times. The \em -datatype and \em -dataspec | |
72 | * parameters are valid for all files until the next occurrence of | |
d397a3b2 | 73 | * \em -datatype/spec. |
74 | * All files er published within one event, unless the \em -nexevent specifies | |
75 | * where to break into multiple events. | |
a7ad9794 | 76 | * |
77 | * @ingroup alihlt_util_components | |
a8aea857 | 78 | */ |
79 | class AliHLTFilePublisher : public AliHLTDataSource { | |
80 | public: | |
81 | /** standard constructor */ | |
82 | AliHLTFilePublisher(); | |
a8aea857 | 83 | /** destructor */ |
84 | virtual ~AliHLTFilePublisher(); | |
85 | ||
86 | const char* GetComponentID(); | |
87 | AliHLTComponentDataType GetOutputDataType(); | |
8a106878 | 88 | int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList); |
a8aea857 | 89 | void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ); |
90 | AliHLTComponent* Spawn(); | |
91 | ||
92 | /** | |
93 | * Open all files. | |
d397a3b2 | 94 | * Opens all files for all events from the event list @ref fEvents and adds TFile |
0449b3c8 | 95 | * objects to the internal list. It also calculates the maximum event size required. |
96 | * @param keepOpen If this flag is true then the files are kept open, otherwise | |
97 | * this method will close the files afterwards. | |
a8aea857 | 98 | */ |
0449b3c8 | 99 | int OpenFiles(bool keepOpen); |
a8aea857 | 100 | |
992ea13b | 101 | /** Get List of Events, needed in the RootFilePublisher.*/ |
102 | TList* GetEventList() { return &fEvents;} | |
103 | ||
104 | /** Set if root files instead of raw files should be read, | |
105 | * needed in the RootFilePublisher. | |
106 | * @param isRaw kTRUE if raw file, kFALSE for rootfile | |
107 | */ | |
108 | void SetIsRawFile( Bool_t isRaw ) { fIsRaw = isRaw; } | |
109 | ||
a8aea857 | 110 | protected: |
111 | /** | |
112 | * Init method. | |
113 | */ | |
fa5e8413 | 114 | virtual int DoInit( int argc, const char** argv ); |
a8aea857 | 115 | |
116 | /** | |
117 | * Deinit method. | |
118 | */ | |
119 | int DoDeinit(); | |
120 | ||
121 | /** | |
122 | * Data processing method for the component. | |
123 | * @param evtData event data structure | |
124 | * @param trigData trigger data structure | |
125 | * @param outputPtr pointer to target buffer | |
126 | * @param size <i>input</i>: size of target buffer | |
127 | * <i>output</i>:size of produced data | |
128 | * @param outputBlocks list to receive output block descriptors | |
129 | * @return | |
130 | */ | |
131 | int GetEvent( const AliHLTComponentEventData& evtData, | |
132 | AliHLTComponentTriggerData& trigData, | |
133 | AliHLTUInt8_t* outputPtr, | |
134 | AliHLTUInt32_t& size, | |
7bcd6cad | 135 | AliHLTComponentBlockDataList& outputBlocks ); |
a8aea857 | 136 | |
a8abc5d5 | 137 | using AliHLTDataSource::GetEvent; |
138 | ||
a8aea857 | 139 | /** |
140 | * Scan one argument and adjacent parameters. | |
141 | * Can be overloaded by child classes in order to add additional arguments | |
142 | * beyond the standard arguments of the file publisher. The method is called | |
143 | * whenever a non-standard argument is recognized. | |
144 | * @param argc size of the argument array | |
145 | * @param argv agument array for component initialization | |
146 | * @return number of processed members of the argv <br> | |
147 | * -EINVAL unknown argument <br> | |
148 | * -EPROTO parameter for argument missing <br> | |
149 | */ | |
150 | virtual int ScanArgument(int argc, const char** argv); | |
151 | ||
a8aea857 | 152 | /** |
153 | * Get the data type which is set for the current file | |
154 | */ | |
d397a3b2 | 155 | //AliHLTComponentDataType GetCurrentDataType() const; |
a8aea857 | 156 | |
157 | /** | |
158 | * Get the data specification which is set for the current file | |
159 | */ | |
d397a3b2 | 160 | //AliHLTUInt32_t GetCurrentSpecification() const; |
a8aea857 | 161 | |
162 | private: | |
d397a3b2 | 163 | /** prohibit copy constructor */ |
164 | AliHLTFilePublisher(const AliHLTFilePublisher&); | |
165 | /** prohibit assignment operator */ | |
166 | AliHLTFilePublisher& operator=(const AliHLTFilePublisher&); | |
167 | ||
992ea13b | 168 | protected: |
d397a3b2 | 169 | /** |
170 | * File descriptor. | |
171 | */ | |
172 | class FileDesc : public TObject { | |
173 | public: | |
174 | /** constructor not implemented */ | |
175 | FileDesc(); | |
176 | /** constructor to use */ | |
992ea13b | 177 | FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec, Bool_t isRaw=kTRUE); |
d397a3b2 | 178 | /** destructor */ |
179 | ~FileDesc(); | |
180 | ||
181 | /** | |
182 | * Open the file. | |
183 | * @return size of the file, neg. error code if failed | |
184 | */ | |
185 | int OpenFile(); | |
186 | ||
0449b3c8 | 187 | /** |
188 | * Close the file handle. | |
189 | */ | |
190 | void CloseFile(); | |
191 | ||
d397a3b2 | 192 | /** |
193 | * Get name of the file. | |
194 | */ | |
29312178 | 195 | const char* GetName() const {return fName.Data();} |
d397a3b2 | 196 | |
fe050813 | 197 | /** |
198 | * Set data type. | |
199 | */ | |
83fec083 | 200 | int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;} |
fe050813 | 201 | |
202 | /** | |
203 | * Set data specification | |
204 | */ | |
83fec083 | 205 | int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;} |
fe050813 | 206 | |
d397a3b2 | 207 | // implicite type conversions |
208 | operator TFile*() const {return fpInstance;} | |
7bcd6cad | 209 | operator AliHLTComponentDataType() const {return fDataType;} |
210 | operator AliHLTUInt32_t() const {return fSpecification;} | |
d397a3b2 | 211 | |
212 | private: | |
213 | /** prohibited copy constructor */ | |
214 | FileDesc(FileDesc&); | |
215 | /** prohibited copy operator */ | |
216 | FileDesc& operator=(FileDesc&); | |
217 | ||
992ea13b | 218 | /** is raw (kTRUE) or root (kFALSE) file */ |
219 | Bool_t fIsRaw; //! transient | |
d397a3b2 | 220 | /** file name */ |
221 | TString fName; //! transient | |
222 | /** file instance */ | |
223 | TFile* fpInstance; //! transient | |
224 | /** data type */ | |
225 | AliHLTComponentDataType fDataType; //! transient | |
226 | /** data specification */ | |
227 | AliHLTUInt32_t fSpecification; //! transient | |
228 | }; | |
229 | ||
230 | /** | |
231 | * Compound to store all files and meta information for one event. | |
232 | */ | |
233 | class EventFiles : public TObject { | |
234 | public: | |
235 | /** constructor */ | |
236 | EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();} | |
237 | /** destructor */ | |
238 | ~EventFiles() {} | |
239 | ||
240 | /** | |
241 | * Add a file descriptor | |
242 | */ | |
243 | void Add(TObject* pObj) {fFiles.Add(pObj);} | |
244 | ||
245 | operator TList&() {return fFiles;} | |
fa5e8413 | 246 | operator TList*() {return &fFiles;} |
d397a3b2 | 247 | |
248 | private: | |
249 | /** list of file names for the event */ | |
250 | TList fFiles; //! transient | |
251 | /** size of all the files in that event */ | |
252 | Int_t fSize; //! transient | |
253 | }; | |
254 | ||
255 | /** | |
256 | * Insert a file descriptor into the event descriptor. | |
257 | * If the event descriptor is NULL it is created before the file descriptor | |
258 | * is inserted. | |
259 | * @param pCurrEvent reference of the event descriptor pointer | |
260 | * @param pDesc file decriptor | |
261 | * @return neg. error value if failed | |
262 | */ | |
263 | int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc); | |
264 | ||
265 | /** | |
266 | * Insert an event. | |
267 | * The event descriptor is added to the list and the reference is cleared. | |
268 | * @param pEvent event decriptor | |
269 | * @return neg. error value if failed | |
270 | */ | |
271 | int InsertEvent(EventFiles* &pEvent); | |
272 | ||
273 | /** the current event */ | |
274 | TObjLink *fpCurrent; //! transient | |
275 | ||
276 | /** the list of events to be published */ | |
277 | TList fEvents; //! transient | |
278 | ||
a8aea857 | 279 | /** the maximum buffer size i.e. size of the biggest file */ |
992ea13b | 280 | Int_t fMaxSize; //! transient |
0449b3c8 | 281 | |
282 | /** Flag specifying if all the files should be opened during initialisation. */ | |
283 | bool fOpenFilesAtStart; //! transient | |
a8aea857 | 284 | |
8a106878 | 285 | /** output data types */ |
286 | AliHLTComponentDataTypeList fOutputDataTypes; //! transient | |
287 | ||
992ea13b | 288 | /** Is raw file (kTRUE) [default] or root file (kFALSE). */ |
289 | Bool_t fIsRaw; //! transient | |
290 | ||
291 | ClassDef(AliHLTFilePublisher, 3) | |
a8aea857 | 292 | }; |
293 | #endif |