enhanced functionality (sub dirs, file name format specifiers)
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFileWriter.h
CommitLineData
e74abd18 1// @(#) $Id$
2
3#ifndef ALIHLTFILEWRITER_H
4#define ALIHLTFILEWRITER_H
79c114b5 5/* This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
e74abd18 7 * See cxx source for full Copyright notice */
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>
17//#include <TList.h>
e74abd18 18
19/**
20 * @class AliHLTFileWriter
21 * An HLT data sink component which writes data to file(s).
22 *
23 * Component ID: \b FileWriter <br>
24 * Library: \b libHLTBase (in order to use the component from the external
25 * interface, it might be necessary to specify a dummy library with the
26 * \em -componentlibrary argument).
27 *
28 * Mandatory arguments: <br>
29 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
30 *
31 * Optional arguments: <br>
32 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
33 * \li -datafile <i> filename </i> <br>
34 * file name base
35 * \li -directory <i> directory </i> <br>
36 * target directory
5ab95e9a 37 * \li -subdir[=pattern] <br>
38 * create sub dir for each event, the format patern can contain printf
39 * specifiers to print the evntn no into the dir name, default is
40 * 'event%03d' (-subdir w/o additional pattern)
41 * \li -idfmt[=pattern] <br>
42 * format specifier for the event id in the file name, <br>
43 * default: on, default pattern: '_0x%08x'
44 * \li -specfmt[=pattern] <br>
45 * format specifier for the data specification in the file name <br>
46 * default: off, default pattern: '_0x%08x'
47 * \li -blocknofmt[=pattern] <br>
48 * format specifier for the block no in the file name <br>
49 * default: on, default pattern: '_0x%02x'
e74abd18 50 * \li -enumerate <br>
51 * don't use the event number but an event counter beginning from 0
52 * \li -concatenate-blocks <br>
53 * concatenate all blocks of one event into one file, this skips
54 * the block no, and the block data type in the file name
55 * \li -concatenate-events <br>
56 * concatenate all events into one file, this skips the event no,
57 * the block no, and the block data type in the file name. Currently,
58 * this implies the -concatenate-blocks option.
59 *
5ab95e9a 60 * By default, file name is built from the basename, the event number, the
61 * block number and the data type in the format:
e74abd18 62 * <pre>
5ab95e9a 63 * basename_eventno_dt
e74abd18 64 * </pre>
65 * If the basename was not given, \em 'event' ist used instead. A file
66 * extension after the last dot is separated from the basename and appended
67 * to the final name.
68 *
5ab95e9a 69 * The naming rule can be changed by the -xxfmt options, which can contain
70 * printf format specifiers in order to print the corresponding variable. E.g.
71 * <pre>
72 * -specfmt append specification
73 * -subdir=test_%d store in sub folders
74 * -blcknofmt=_0x%x format block no in hex
75 * -idfmt=_%04d print id in 4-digits decimal number
76 * </pre>
77 *
e74abd18 78 * The class can be used as a base class for file writers. Additional
79 * argument scan can be implemented in @ref ScanArgument which is called
80 * for each unknown argument.
81 * @ingroup alihlt_component
82 */
83class AliHLTFileWriter : public AliHLTDataSink {
84 public:
85 /** standard constructor */
86 AliHLTFileWriter();
e74abd18 87 /** destructor */
88 virtual ~AliHLTFileWriter();
89
90 virtual const char* GetComponentID();
91 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
92 virtual AliHLTComponent* Spawn();
93
94 protected:
95 /**
96 * Init method.
97 */
98 int DoInit( int argc, const char** argv );
99
100 /**
101 * Deinit method.
102 */
103 int DoDeinit();
104
105 /**
106 * Init the writer.
107 * The DoInit function is not available for child classes. InitWriter is the
108 * corresponding function for classes derived from AliHLTFileWriter.
109 */
110 virtual int InitWriter();
111
112 /**
79c114b5 113 * Close the writer.
e74abd18 114 * The DoDeinit function is not available for child classes. CloseWriter is the
115 * corresponding function for classes derived from AliHLTFileWriter.
116 */
117 virtual int CloseWriter();
118
119 /**
120 * Data processing method for the component.
121 * The function can be overloaded by other file writer components.
122 * @param evtData event data structure
123 * @param blocks input data block descriptors
124 * @param trigData trigger data structure
125 */
126 virtual int DumpEvent( const AliHLTComponentEventData& evtData,
127 const AliHLTComponentBlockData* blocks,
128 AliHLTComponentTriggerData& trigData );
129
130 /**
131 * Scan one argument and adjacent parameters.
132 * Can be overloaded by child classes in order to add additional arguments
133 * beyond the standard arguments of the file publisher. The method is called
134 * whenever a non-standard argument is recognized. Make sure to return
135 * <tt> -EPROTO </tt> if the argument is not recognized be the child.
136 * @param argc size of the argument array
137 * @param argv agument array for component initialization
138 * @return number of processed members of the argv <br>
139 * -EINVAL unknown argument <br>
140 * -EPROTO parameter for argument missing <br>
141 */
142 virtual int ScanArgument(int argc, const char** argv);
143
144 /**
145 * Build file name from eventID data type and the specified directory and basename.
146 * @param eventID [in] the ID of the event
147 * @param blockID [in] the ID of the current block
148 * no block string appended if -1
149 * @param dataType [in] the data type of the data block
150 * no type string appanded if @ref kAliHLTVoidDataType
151 * @param filename [out] string to receive the file name
152 */
5ab95e9a 153 int BuildFileName(const AliHLTEventID_t eventID, const int blockID,
154 const AliHLTComponentDataType& dataType,
155 const AliHLTUInt32_t specification,
156 TString& filename);
e74abd18 157
158 /**
159 * Set a mode flag.
160 * @return current mode flags
161 */
162 int SetMode(Short_t mode);
163
164 /**
165 * Clear a mode flag.
166 * @return current mode flags
167 */
168 int ClearMode(Short_t mode);
169
170 /**
171 * Check a mode flag.
172 * @return 1 if flag is set, 0 if not
173 */
5df0cbb9 174 int CheckMode(Short_t mode) const;
e74abd18 175
176 /**
177 * Working modes of the writer
178 * @internal
179 */
180 enum TWriterMode {
181 /**
182 * flag to indicate whether to write each incoming block to separate files
183 * or all blocks of one event to one file. set = concatenate (one file).
184 */
185 kConcatenateBlocks = 0x1,
186
187 /**
188 * flag to indicate whether to concatenate incoming blocks of the same type
189 * for all events to one file. If also @ref kConcatenateBlocks is set,
190 * or all blocks of all events are written to the same file.
191 */
192 kConcatenateEvents = 0x2,
193
194 /** event enumeration flag */
195 kEnumerate = 0x4
5ab95e9a 196
e74abd18 197 };
198
199 private:
5ab95e9a 200 /** copy constructor prohibited */
201 AliHLTFileWriter(const AliHLTFileWriter&);
202 /** assignment operator prohibited */
203 AliHLTFileWriter& operator=(const AliHLTFileWriter&);
204
e74abd18 205 /** the basename of the output file */
206 TString fBaseName; // see above
207 /** the extension of the output file */
208 TString fExtension; // see above
209 /** target directory */
210 TString fDirectory; // see above
5ab95e9a 211 /** base name of the event sub directories */
212 TString fSubDirFormat; // see above
213 /** event id format string (when added to file name) */
214 TString fIdFormat; // see above
215 /** specification format string (when added to file name) */
216 TString fSpecFormat; // see above
217 /** format string for block no (when added to file name) */
218 TString fBlcknoFormat; // see above
e74abd18 219 /** enumeration format string */
220 TString fCurrentFileName; // see above
221
222 /** mode specifier, see @ref TWriterMode */
223 Short_t fMode; // see above
224
5ab95e9a 225 ClassDef(AliHLTFileWriter, 2)
e74abd18 226};
227#endif