4 #ifndef ALIHLTFILEWRITER_H
5 #define ALIHLTFILEWRITER_H
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 *
10 /** @file AliHLTFileWriter.h
11 @author Matthias Richter
13 @brief An HLT file dump (data sink) component.
16 #include "AliHLTDataSink.h"
19 class AliHLTBlockDataCollection;
22 * @class AliHLTFileWriter
23 * An HLT data sink component which writes data to file(s).
25 * <h2>General properties:</h2>
27 * Component ID: \b FileWriter <br>
28 * Library: \b libAliHLTUtil.so <br>
29 * Input Data Types: ::kAliHLTAllDataTypes <br>
30 * Output Data Types: none <br>
32 * \b Note: ::kAliHLTAllDataTypes contains both ::kAliHLTAnyDataType and
33 * ::kAliHLTVoidDataType
35 * <h2>Mandatory arguments:</h2>
36 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
38 * <h2>Optional arguments:</h2>
39 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
40 * \li -datafile <i> filename </i> <br>
42 * \li -directory <i> directory </i> <br>
44 * \li -subdir[=pattern] <br>
45 * create sub dir for each event, the format pattern can contain printf
46 * specifiers to print the event no into the dir name, default is
47 * 'event%%03lu' (-subdir w/o additional pattern). The format specifyer
48 * %%lu is automatically added if missing in the pattern. Please note the
49 * \b long int type of the event id <br>
50 * \b note: the idfmt string is reset since the subdir contains the id
51 * \li -idfmt[=pattern] <br>
52 * format specifier for the event id in the file name, <br>
53 * default: on, default pattern: '_0x%%08x'
54 * \li -specfmt[=pattern] <br>
55 * format specifier for the data specification in the file name <br>
56 * default: off, default pattern: '_0x%%08x'
57 * \li -blocknofmt[=pattern] <br>
58 * format specifier for the block no in the file name <br>
59 * default: on, default pattern: '_0x%%02x'
60 * \li -skip-datatype <br>
61 * do not consider data type when building the file name.
63 * don't use the event number but an event counter beginning from 0
64 * \li -concatenate-blocks <br>
65 * concatenate all blocks of one event into one file, this skips
66 * the block no, and the block data type in the file name
67 * \li -concatenate-events <br>
68 * concatenate all events into one file, this skips the event no,
69 * the block no, and the block data type in the file name. Currently,
70 * this implies the -concatenate-blocks option.
71 * \li -publisher-conf <i>filename</i> <br>
72 * write configuration file for FilePublisher component (AliHLTFilePublisher) <br>
73 * one line per file: -datatype id origin -datafile filename <br>
74 * events separated by -nextevent
75 * \li -write-all-events <br>
76 * by default, the file writer ignores all steering events like the
77 * the SOR/EOR events, with this option, all events will be considered
79 * \li -write-all-blocks <br>
80 * by default, the file writer ignores all blocks of origin {PRIV}
81 * (::kAliHLTDataOriginPrivate), with this option, all blocks will
82 * be written. For SOR/EOR events, a short string will be added in
85 * combines both -write-all-events and -write-all-blocks
86 * \li -burst-buffer <size> <br>
87 * size of burst buffer, blocks are written to buffer until it is filled
88 * and written in one burst (though to different files according to conf)<br>
89 * \b Note: burst write is currently only supported for mode
90 * -concatenate-events AND -concatenate-blocks (both enabled).
91 * \li -datatype <i> id origin </i> <br>
92 * data block selection by AliHLTBlockDataCollection
93 * \li -origin <i> origin </i> <br>
94 * data block selection by AliHLTBlockDataCollection
95 * \li -typeid <i> id </i> <br>
96 * data block selection by AliHLTBlockDataCollection
97 * \li -dataspec <i> specification </i> <br>
98 * data block selection by AliHLTBlockDataCollection
100 * <h2>Configuration:</h2>
101 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
102 * Configuration by component arguments.
104 * <h2>Default CDB entries:</h2>
105 * The component loads no CDB entries.
107 * <h2>Performance:</h2>
108 * The component does not process any event data.
110 * <h2>Memory consumption:</h2>
111 * The component does not process any event data.
113 * <h2>Output size:</h2>
114 * No data published (AliHLTDataSink).
117 * By default, file name is built from the basename, the event number, the
118 * block number and the data type in the format:
120 * basename_eventno_dt
122 * If the basename was not given, \em 'event' ist used instead. A file
123 * extension after the last dot is separated from the basename and appended
126 * The naming rule can be changed by the -xxfmt options, which can contain
127 * printf format specifiers in order to print the corresponding variable. E.g.
129 * -specfmt append specification
130 * -subdir=test store in sub folders
131 * -blocknofmt=_0x%%x format block no in hex
132 * -idfmt=_%%04d print id in 4-digits decimal number
133 * -idfmt= print no id
136 * The class can be used as a base class for file writers. Additional
137 * argument scan can be implemented in @ref ScanArgument which is called
138 * for each unknown argument.
140 * @ingroup alihlt_util_components
142 class AliHLTFileWriter : public AliHLTDataSink {
144 /** standard constructor */
147 virtual ~AliHLTFileWriter();
149 virtual const char* GetComponentID();
150 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
151 virtual AliHLTComponent* Spawn();
157 int DoInit( int argc, const char** argv );
166 * The DoInit function is not available for child classes. InitWriter is the
167 * corresponding function for classes derived from AliHLTFileWriter.
169 virtual int InitWriter();
173 * The DoDeinit function is not available for child classes. CloseWriter is the
174 * corresponding function for classes derived from AliHLTFileWriter.
176 virtual int CloseWriter();
179 * Data processing method for the component.
180 * The function can be overloaded by other file writer components.
181 * @param evtData event data structure
182 * @param trigData trigger data structure
184 virtual int DumpEvent( const AliHLTComponentEventData& evtData,
185 AliHLTComponentTriggerData& trigData );
187 using AliHLTDataSink::DumpEvent;
190 * Scan one argument and adjacent parameters.
191 * Can be overloaded by child classes in order to add additional arguments
192 * beyond the standard arguments of the file publisher. The method is called
193 * whenever a non-standard argument is recognized. Make sure to return
194 * <tt> -EPROTO </tt> if the argument is not recognized be the child.
195 * @param argc size of the argument array
196 * @param argv agument array for component initialization
197 * @return number of processed members of the argv <br>
198 * -EINVAL unknown argument <br>
199 * -EPROTO parameter for argument missing <br>
201 virtual int ScanArgument(int argc, const char** argv);
204 * Build file name from eventID data type and the specified directory and basename.
205 * @param [in] eventID the ID of the event
206 * @param [in] blockID the ID of the current block
207 * no block string appended if -1
208 * @param [in] dataType the data type of the data block
209 * no type string appanded if @ref kAliHLTVoidDataType
210 * @param [in] specification data specification of the block
211 * @param [out] filename string to receive the file name
213 int BuildFileName(const AliHLTEventID_t eventID, const int blockID,
214 const AliHLTComponentDataType& dataType,
215 const AliHLTUInt32_t specification,
220 * @return current mode flags
222 int SetMode(Short_t mode);
226 * @return current mode flags
228 int ClearMode(Short_t mode);
232 * @return 1 if flag is set, 0 if not
234 int CheckMode(Short_t mode) const;
237 * Get the currently set file extension.
239 TString GetExtension() {return fExtension;}
242 * Set the file extension.
244 void SetExtension(const char* extension) {fExtension=extension!=NULL?extension:"";}
247 * Get the target directory
249 TString GetDirectory() {return fDirectory;}
252 * Working modes of the writer
257 * flag to indicate whether to write each incoming block to separate files
258 * or all blocks of one event to one file. set = concatenate (one file).
260 kConcatenateBlocks = 0x1,
263 * flag to indicate whether to concatenate incoming blocks of the same type
264 * for all events to one file. If also @ref kConcatenateBlocks is set,
265 * or all blocks of all events are written to the same file.
267 kConcatenateEvents = 0x2,
269 /** event enumeration flag */
272 /** write all events including steering events */
273 kWriteAllEvents = 0x8,
275 /** write all blocks including private ones */
276 kWriteAllBlocks = 0x10,
278 /** skip the data type information when creating the file name */
282 /** argument scan concerning block descriptor selections */
283 AliHLTBlockDataCollection* fpBlockDataCollection; //!transient
286 /** copy constructor prohibited */
287 AliHLTFileWriter(const AliHLTFileWriter&);
288 /** assignment operator prohibited */
289 AliHLTFileWriter& operator=(const AliHLTFileWriter&);
292 * Set defaults for all internal properties
297 * Schedule block for writing.
298 * The block is written immediately unless burst mode is activated.
299 * In burst mode, the block is buffered in the burst buffer until it is filled.
300 * Content of the burst buffer is then written in one burst.
302 * In the first implementation, burst write is only foreseen for the base
305 int ScheduleBlock(int blockno, const AliHLTEventID_t& eventID,
306 const AliHLTComponentBlockData* pDesc);
309 * Flush burst buffer.
315 * Build file name from the block attributes and compare with the
316 * lat file name in order to correctly append data or not.
318 int WriteBlock(int blockno, const AliHLTEventID_t& eventID,
319 const AliHLTComponentBlockData* pDesc);
321 /** the basename of the output file */
322 TString fBaseName; // see above
323 /** the extension of the output file */
324 TString fExtension; // see above
325 /** target directory */
326 TString fDirectory; // see above
327 /** base name of the event sub directories */
328 TString fSubDirFormat; // see above
329 /** event id format string (when added to file name) */
330 TString fIdFormat; // see above
331 /** specification format string (when added to file name) */
332 TString fSpecFormat; // see above
333 /** format string for block no (when added to file name) */
334 TString fBlcknoFormat; // see above
336 /** enumeration format string */
337 TString fCurrentFileName; // see above
340 /** mode specifier, see @ref TWriterMode */
341 Short_t fMode; // see above
343 /** burst buffer for postponed data write */
344 AliHLTUInt8_t* fpBurstBuffer; //!transient
346 /** size of burst buffer */
347 AliHLTUInt32_t fBurstBufferSize; //!transient
349 /** block descriptor list for postponed burst write*/
350 AliHLTComponentBlockDataList fBurstBlocks; //!transient
352 /** event ids for the burst blocks */
353 vector<AliHLTEventID_t> fBurstBlockEvents; //!transient
355 /// configuration file of FilePublisher component
356 TString fPublisherConfName; // see above
357 /// current event for FilePublisher configuration
358 int fPublisherConfEvent; // see above
360 ClassDef(AliHLTFileWriter, 0)