3 #ifndef ALIHLTFILEWRITER_H
4 #define ALIHLTFILEWRITER_H
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
7 //* See cxx source for full Copyright notice *
9 /** @file AliHLTFileWriter.h
10 @author Matthias Richter
12 @brief An HLT file dump (data sink) component.
15 #include "AliHLTDataSink.h"
19 * @class AliHLTFileWriter
20 * An HLT data sink component which writes data to file(s).
22 * <h2>General properties:</h2>
24 * Component ID: \b FileWriter <br>
25 * Library: \b libAliHLTUtil.so <br>
26 * Input Data Types: ::kAliHLTAllDataTypes <br>
27 * Output Data Types: none <br>
29 * \b Note: ::kAliHLTAllDataTypes contains both ::kAliHLTAnyDataType and
30 * ::kAliHLTVoidDataType
32 * <h2>Mandatory arguments:</h2>
33 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
35 * <h2>Optional arguments:</h2>
36 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
37 * \li -datafile <i> filename </i> <br>
39 * \li -directory <i> directory </i> <br>
41 * \li -subdir[=pattern] <br>
42 * create sub dir for each event, the format pattern can contain printf
43 * specifiers to print the event no into the dir name, default is
44 * 'event%03d' (-subdir w/o additional pattern)
45 * \b note: the idfmt string is reset since the subdir contains the id
46 * \li -idfmt[=pattern] <br>
47 * format specifier for the event id in the file name, <br>
48 * default: on, default pattern: '_0x%08x'
49 * \li -specfmt[=pattern] <br>
50 * format specifier for the data specification in the file name <br>
51 * default: off, default pattern: '_0x%08x'
52 * \li -blocknofmt[=pattern] <br>
53 * format specifier for the block no in the file name <br>
54 * default: on, default pattern: '_0x%02x'
56 * don't use the event number but an event counter beginning from 0
57 * \li -concatenate-blocks <br>
58 * concatenate all blocks of one event into one file, this skips
59 * the block no, and the block data type in the file name
60 * \li -concatenate-events <br>
61 * concatenate all events into one file, this skips the event no,
62 * the block no, and the block data type in the file name. Currently,
63 * this implies the -concatenate-blocks option.
64 * \li -write-all-events <br>
65 * by default, the file writer ignores all steering events like the
66 * the SOR/EOR events, with this option, all events will be considered
68 * \li -write-all-blocks <br>
69 * by default, the file writer ignores all blocks of origin {PRIV}
70 * (::kAliHLTDataOriginPrivate), with this option, all blocks will
71 * be written. For SOR/EOR events, a short string will be added in
74 * combines both -write-all-events and -write-all-blocks
76 * <h2>Configuration:</h2>
77 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
78 * Configuration by component arguments.
80 * <h2>Default CDB entries:</h2>
81 * The component loads no CDB entries.
83 * <h2>Performance:</h2>
84 * The component does not process any event data.
86 * <h2>Memory consumption:</h2>
87 * The component does not process any event data.
89 * <h2>Output size:</h2>
90 * No data published (AliHLTDataSink).
93 * By default, file name is built from the basename, the event number, the
94 * block number and the data type in the format:
98 * If the basename was not given, \em 'event' ist used instead. A file
99 * extension after the last dot is separated from the basename and appended
102 * The naming rule can be changed by the -xxfmt options, which can contain
103 * printf format specifiers in order to print the corresponding variable. E.g.
105 * -specfmt append specification
106 * -subdir=test_%d store in sub folders
107 * -blocknofmt=_0x%x format block no in hex
108 * -idfmt=_%04d print id in 4-digits decimal number
109 * -idfmt= print no id
112 * The class can be used as a base class for file writers. Additional
113 * argument scan can be implemented in @ref ScanArgument which is called
114 * for each unknown argument.
116 * @ingroup alihlt_util_components
118 class AliHLTFileWriter : public AliHLTDataSink {
120 /** standard constructor */
123 virtual ~AliHLTFileWriter();
125 virtual const char* GetComponentID();
126 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
127 virtual AliHLTComponent* Spawn();
133 int DoInit( int argc, const char** argv );
142 * The DoInit function is not available for child classes. InitWriter is the
143 * corresponding function for classes derived from AliHLTFileWriter.
145 virtual int InitWriter();
149 * The DoDeinit function is not available for child classes. CloseWriter is the
150 * corresponding function for classes derived from AliHLTFileWriter.
152 virtual int CloseWriter();
155 * Data processing method for the component.
156 * The function can be overloaded by other file writer components.
157 * @param evtData event data structure
158 * @param trigData trigger data structure
160 virtual int DumpEvent( const AliHLTComponentEventData& evtData,
161 AliHLTComponentTriggerData& trigData );
163 using AliHLTDataSink::DumpEvent;
166 * Scan one argument and adjacent parameters.
167 * Can be overloaded by child classes in order to add additional arguments
168 * beyond the standard arguments of the file publisher. The method is called
169 * whenever a non-standard argument is recognized. Make sure to return
170 * <tt> -EPROTO </tt> if the argument is not recognized be the child.
171 * @param argc size of the argument array
172 * @param argv agument array for component initialization
173 * @return number of processed members of the argv <br>
174 * -EINVAL unknown argument <br>
175 * -EPROTO parameter for argument missing <br>
177 virtual int ScanArgument(int argc, const char** argv);
180 * Build file name from eventID data type and the specified directory and basename.
181 * @param eventID [in] the ID of the event
182 * @param blockID [in] the ID of the current block
183 * no block string appended if -1
184 * @param dataType [in] the data type of the data block
185 * no type string appanded if @ref kAliHLTVoidDataType
186 * @param specification data specification of the block
187 * @param filename [out] string to receive the file name
189 int BuildFileName(const AliHLTEventID_t eventID, const int blockID,
190 const AliHLTComponentDataType& dataType,
191 const AliHLTUInt32_t specification,
196 * @return current mode flags
198 int SetMode(Short_t mode);
202 * @return current mode flags
204 int ClearMode(Short_t mode);
208 * @return 1 if flag is set, 0 if not
210 int CheckMode(Short_t mode) const;
213 * Get the currently set file extension.
215 TString GetExtension() {return fExtension;}
218 * Set the file extension.
220 void SetExtension(const char* extension) {fExtension=extension!=NULL?extension:"";}
223 * Get the target directory
225 TString GetDirectory() {return fDirectory;}
228 * Working modes of the writer
233 * flag to indicate whether to write each incoming block to separate files
234 * or all blocks of one event to one file. set = concatenate (one file).
236 kConcatenateBlocks = 0x1,
239 * flag to indicate whether to concatenate incoming blocks of the same type
240 * for all events to one file. If also @ref kConcatenateBlocks is set,
241 * or all blocks of all events are written to the same file.
243 kConcatenateEvents = 0x2,
245 /** event enumeration flag */
248 /** write all events including steering events */
249 kWriteAllEvents = 0x8,
251 /** write all blocks including private ones */
252 kWriteAllBlocks = 0x10
256 /** copy constructor prohibited */
257 AliHLTFileWriter(const AliHLTFileWriter&);
258 /** assignment operator prohibited */
259 AliHLTFileWriter& operator=(const AliHLTFileWriter&);
261 /** the basename of the output file */
262 TString fBaseName; // see above
263 /** the extension of the output file */
264 TString fExtension; // see above
265 /** target directory */
266 TString fDirectory; // see above
267 /** base name of the event sub directories */
268 TString fSubDirFormat; // see above
269 /** event id format string (when added to file name) */
270 TString fIdFormat; // see above
271 /** specification format string (when added to file name) */
272 TString fSpecFormat; // see above
273 /** format string for block no (when added to file name) */
274 TString fBlcknoFormat; // see above
276 /** enumeration format string */
277 TString fCurrentFileName; // see above
280 /** mode specifier, see @ref TWriterMode */
281 Short_t fMode; // see above
283 ClassDef(AliHLTFileWriter, 2)