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