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