added new helper components to libAliHLTUtil (EsdCollector and AliHLTOUTPublisher...
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFileWriter.h
CommitLineData
e74abd18 1// @(#) $Id$
2
3#ifndef ALIHLTFILEWRITER_H
4#define ALIHLTFILEWRITER_H
6daf06e2 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 *
e74abd18 8
9/** @file AliHLTFileWriter.h
10 @author Matthias Richter
11 @date
12 @brief An HLT file dump (data sink) component.
13*/
14
15#include "AliHLTDataSink.h"
5df0cbb9 16#include <TString.h>
e74abd18 17
18/**
19 * @class AliHLTFileWriter
20 * An HLT data sink component which writes data to file(s).
21 *
6daf06e2 22 * <h2>General properties:</h2>
e74abd18 23 *
6daf06e2 24 * Component ID: \b FileWriter <br>
25 * Library: \b libAliHLTUtil.so <br>
26 * Input Data Types: @ref kAliHLTAllDataTypes <br>
27 * Output Data Types: none <br>
28 *
29 * kAliHLTAllDataTypes contains both kAliHLTAnyDataType and kAliHLTVoidDataType
30 *
31 * <h2>Mandatory arguments:</h2>
1ac82ce6 32 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
e74abd18 33 *
6daf06e2 34 * <h2>Optional arguments:</h2>
1ac82ce6 35 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
e74abd18 36 * \li -datafile <i> filename </i> <br>
37 * file name base
38 * \li -directory <i> directory </i> <br>
39 * target directory
5ab95e9a 40 * \li -subdir[=pattern] <br>
6daf06e2 41 * create sub dir for each event, the format pattern can contain printf
42 * specifiers to print the event no into the dir name, default is
5ab95e9a 43 * 'event%03d' (-subdir w/o additional pattern)
6daf06e2 44 * \b note: the idfmt string is reset since the subdir contains the id
5ab95e9a 45 * \li -idfmt[=pattern] <br>
46 * format specifier for the event id in the file name, <br>
47 * default: on, default pattern: '_0x%08x'
48 * \li -specfmt[=pattern] <br>
49 * format specifier for the data specification in the file name <br>
50 * default: off, default pattern: '_0x%08x'
51 * \li -blocknofmt[=pattern] <br>
52 * format specifier for the block no in the file name <br>
53 * default: on, default pattern: '_0x%02x'
e74abd18 54 * \li -enumerate <br>
55 * don't use the event number but an event counter beginning from 0
56 * \li -concatenate-blocks <br>
57 * concatenate all blocks of one event into one file, this skips
58 * the block no, and the block data type in the file name
59 * \li -concatenate-events <br>
60 * concatenate all events into one file, this skips the event no,
61 * the block no, and the block data type in the file name. Currently,
62 * this implies the -concatenate-blocks option.
63 *
6daf06e2 64 * <h2>Configuration:</h2>
65 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
66 * no configuration
67 *
68 * <h2>Default CDB entries:</h2>
69 * The component loads no CDB entries.
70 *
71 * <h2>Performance:</h2>
72 * The component does not any event data processing.
73 *
74 * <h2>Memory consumption:</h2>
75 * The component does not any event data processing.
76 *
77 * <h2>Output size:</h2>
78 * The component has no output data.
79 *
80 *
5ab95e9a 81 * By default, file name is built from the basename, the event number, the
82 * block number and the data type in the format:
e74abd18 83 * <pre>
5ab95e9a 84 * basename_eventno_dt
e74abd18 85 * </pre>
86 * If the basename was not given, \em 'event' ist used instead. A file
87 * extension after the last dot is separated from the basename and appended
88 * to the final name.
89 *
5ab95e9a 90 * The naming rule can be changed by the -xxfmt options, which can contain
91 * printf format specifiers in order to print the corresponding variable. E.g.
92 * <pre>
93 * -specfmt append specification
94 * -subdir=test_%d store in sub folders
6daf06e2 95 * -blocknofmt=_0x%x format block no in hex
5ab95e9a 96 * -idfmt=_%04d print id in 4-digits decimal number
6daf06e2 97 * -idfmt= print no id
5ab95e9a 98 * </pre>
99 *
e74abd18 100 * The class can be used as a base class for file writers. Additional
101 * argument scan can be implemented in @ref ScanArgument which is called
102 * for each unknown argument.
103 * @ingroup alihlt_component
104 */
105class AliHLTFileWriter : public AliHLTDataSink {
106 public:
107 /** standard constructor */
108 AliHLTFileWriter();
e74abd18 109 /** destructor */
110 virtual ~AliHLTFileWriter();
111
112 virtual const char* GetComponentID();
113 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
114 virtual AliHLTComponent* Spawn();
115
116 protected:
117 /**
118 * Init method.
119 */
120 int DoInit( int argc, const char** argv );
121
122 /**
123 * Deinit method.
124 */
125 int DoDeinit();
126
127 /**
128 * Init the writer.
129 * The DoInit function is not available for child classes. InitWriter is the
130 * corresponding function for classes derived from AliHLTFileWriter.
131 */
132 virtual int InitWriter();
133
134 /**
79c114b5 135 * Close the writer.
e74abd18 136 * The DoDeinit function is not available for child classes. CloseWriter is the
137 * corresponding function for classes derived from AliHLTFileWriter.
138 */
139 virtual int CloseWriter();
140
141 /**
142 * Data processing method for the component.
143 * The function can be overloaded by other file writer components.
144 * @param evtData event data structure
e74abd18 145 * @param trigData trigger data structure
146 */
147 virtual int DumpEvent( const AliHLTComponentEventData& evtData,
e74abd18 148 AliHLTComponentTriggerData& trigData );
149
a8abc5d5 150 using AliHLTDataSink::DumpEvent;
151
e74abd18 152 /**
153 * Scan one argument and adjacent parameters.
154 * Can be overloaded by child classes in order to add additional arguments
155 * beyond the standard arguments of the file publisher. The method is called
156 * whenever a non-standard argument is recognized. Make sure to return
157 * <tt> -EPROTO </tt> if the argument is not recognized be the child.
158 * @param argc size of the argument array
159 * @param argv agument array for component initialization
160 * @return number of processed members of the argv <br>
161 * -EINVAL unknown argument <br>
162 * -EPROTO parameter for argument missing <br>
163 */
164 virtual int ScanArgument(int argc, const char** argv);
165
166 /**
167 * Build file name from eventID data type and the specified directory and basename.
168 * @param eventID [in] the ID of the event
169 * @param blockID [in] the ID of the current block
170 * no block string appended if -1
171 * @param dataType [in] the data type of the data block
172 * no type string appanded if @ref kAliHLTVoidDataType
62fd2539 173 * @param specification data specification of the block
e74abd18 174 * @param filename [out] string to receive the file name
175 */
5ab95e9a 176 int BuildFileName(const AliHLTEventID_t eventID, const int blockID,
177 const AliHLTComponentDataType& dataType,
178 const AliHLTUInt32_t specification,
179 TString& filename);
e74abd18 180
181 /**
182 * Set a mode flag.
183 * @return current mode flags
184 */
185 int SetMode(Short_t mode);
186
187 /**
188 * Clear a mode flag.
189 * @return current mode flags
190 */
191 int ClearMode(Short_t mode);
192
193 /**
194 * Check a mode flag.
195 * @return 1 if flag is set, 0 if not
196 */
5df0cbb9 197 int CheckMode(Short_t mode) const;
e74abd18 198
626bfcc1 199 /**
200 * Get the currently set file extension.
201 */
202 TString GetExtension() {return fExtension;}
203
204 /**
205 * Set the file extension.
206 */
207 void SetExtension(const char* extension) {fExtension=extension!=NULL?extension:"";}
208
c1292031 209 /**
210 * Get the target directory
211 */
212 TString GetDirectory() {return fDirectory;}
213
e74abd18 214 /**
215 * Working modes of the writer
216 * @internal
217 */
218 enum TWriterMode {
219 /**
220 * flag to indicate whether to write each incoming block to separate files
221 * or all blocks of one event to one file. set = concatenate (one file).
222 */
223 kConcatenateBlocks = 0x1,
224
225 /**
226 * flag to indicate whether to concatenate incoming blocks of the same type
227 * for all events to one file. If also @ref kConcatenateBlocks is set,
228 * or all blocks of all events are written to the same file.
229 */
230 kConcatenateEvents = 0x2,
231
232 /** event enumeration flag */
233 kEnumerate = 0x4
5ab95e9a 234
e74abd18 235 };
236
237 private:
5ab95e9a 238 /** copy constructor prohibited */
239 AliHLTFileWriter(const AliHLTFileWriter&);
240 /** assignment operator prohibited */
241 AliHLTFileWriter& operator=(const AliHLTFileWriter&);
242
e74abd18 243 /** the basename of the output file */
244 TString fBaseName; // see above
245 /** the extension of the output file */
246 TString fExtension; // see above
247 /** target directory */
248 TString fDirectory; // see above
5ab95e9a 249 /** base name of the event sub directories */
250 TString fSubDirFormat; // see above
251 /** event id format string (when added to file name) */
252 TString fIdFormat; // see above
253 /** specification format string (when added to file name) */
254 TString fSpecFormat; // see above
255 /** format string for block no (when added to file name) */
256 TString fBlcknoFormat; // see above
e1440dab 257 protected:
e74abd18 258 /** enumeration format string */
259 TString fCurrentFileName; // see above
e1440dab 260 private:
e74abd18 261
262 /** mode specifier, see @ref TWriterMode */
263 Short_t fMode; // see above
264
5ab95e9a 265 ClassDef(AliHLTFileWriter, 2)
e74abd18 266};
267#endif