Coding conventions
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFileWriter.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTFILEWRITER_H
4 #define ALIHLTFILEWRITER_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /** @file   AliHLTFileWriter.h
9     @author Matthias Richter
10     @date   
11     @brief  An HLT file dump (data sink) component.
12 */
13
14 #include "AliHLTDataSink.h"
15 #include <TString.h>
16 //#include <TList.h>
17
18 /**
19  * @class AliHLTFileWriter
20  * An HLT data sink component which writes data to file(s).
21  *
22  * Component ID: \b FileWriter <br>
23  * Library: \b libHLTBase (in order to use the component from the external
24  * interface, it might be necessary to specify a dummy library with the
25  * \em -componentlibrary argument).
26  *
27  * Mandatory arguments: <br>
28  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
29  *
30  * Optional arguments: <br>
31  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
32  * \li -datafile     <i> filename   </i> <br>
33  *      file name base
34  * \li -directory    <i> directory  </i> <br>
35  *      target directory
36  * \li -enumerate <br>
37  *      don't use the event number but an event counter beginning from 0
38  * \li -concatenate-blocks <br>
39  *      concatenate all blocks of one event into one file, this skips
40  *      the block no, and the block data type in the file name
41  * \li -concatenate-events <br>
42  *      concatenate all events into one file, this skips the event no,
43  *      the block no, and the block data type in the file name. Currently,
44  *      this implies the -concatenate-blocks option.
45  *
46  * The file name is built from the basename, the event number, the block
47  * number and the data type in the format:
48  * <pre>
49  * basename_eventno_blockno_dt
50  * </pre>
51  * If the basename was not given, \em 'event' ist used instead. A file
52  * extension after the last dot is separated from the basename and appended
53  * to the final name.
54  *
55  * The class can be used as a base class for file writers. Additional
56  * argument scan can be implemented in @ref ScanArgument which is called
57  * for each unknown argument.
58  * @ingroup alihlt_component
59  */
60 class AliHLTFileWriter : public AliHLTDataSink  {
61  public:
62   /** standard constructor */
63   AliHLTFileWriter();
64   /** not a valid copy constructor, defined according to effective C++ style */
65   AliHLTFileWriter(const AliHLTFileWriter&);
66   /** not a valid assignment op, but defined according to effective C++ style */
67   AliHLTFileWriter& operator=(const AliHLTFileWriter&);
68   /** destructor */
69   virtual ~AliHLTFileWriter();
70
71   virtual const char* GetComponentID();
72   virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
73   virtual AliHLTComponent* Spawn();
74
75  protected:
76   /**
77    * Init method.
78    */
79   int DoInit( int argc, const char** argv );
80
81   /**
82    * Deinit method.
83    */
84   int DoDeinit();
85
86   /**
87    * Init the writer.
88    * The DoInit function is not available for child classes. InitWriter is the
89    * corresponding function for classes derived from AliHLTFileWriter.
90    */
91   virtual int InitWriter();
92
93   /**
94    * Init the writer.
95    * The DoDeinit function is not available for child classes. CloseWriter is the
96    * corresponding function for classes derived from AliHLTFileWriter.
97    */
98   virtual int CloseWriter();
99
100   /**
101    * Data processing method for the component.
102    * The function can be overloaded by other file writer components.
103    * @param evtData       event data structure
104    * @param blocks        input data block descriptors
105    * @param trigData      trigger data structure
106    */
107   virtual int DumpEvent( const AliHLTComponentEventData& evtData,
108                          const AliHLTComponentBlockData* blocks, 
109                          AliHLTComponentTriggerData& trigData );
110
111   /**
112    * Scan one argument and adjacent parameters.
113    * Can be overloaded by child classes in order to add additional arguments
114    * beyond the standard arguments of the file publisher. The method is called
115    * whenever a non-standard argument is recognized. Make sure to return 
116    * <tt> -EPROTO </tt> if the argument is not recognized be the child.
117    * @param argc           size of the argument array
118    * @param argv           agument array for component initialization
119    * @return number of processed members of the argv <br>
120    *         -EINVAL unknown argument <br>
121    *         -EPROTO parameter for argument missing <br>
122    */
123   virtual int ScanArgument(int argc, const char** argv);
124
125   /**
126    * Build file name from eventID data type and the specified directory and basename.
127    * @param eventID [in]   the ID of the event
128    * @param blockID [in]   the ID of the current block
129    *                       no block string appended if -1
130    * @param dataType [in]  the data type of the data block
131    *                       no type string appanded if @ref kAliHLTVoidDataType
132    * @param filename [out] string to receive the file name
133    */
134   int BuildFileName(const AliHLTEventID_t eventID, const int blockID, const AliHLTComponentDataType& dataType, TString& filename);
135
136   /**
137    * Set a mode flag.
138    * @return current mode flags
139    */
140   int SetMode(Short_t mode);
141     
142   /**
143    * Clear a mode flag.
144    * @return current mode flags
145    */
146   int ClearMode(Short_t mode);
147
148   /**
149    * Check a mode flag.
150    * @return 1 if flag is set, 0 if not
151    */
152   int CheckMode(Short_t mode) const;
153
154   /**
155    * Working modes of the writer
156    * @internal
157    */
158   enum TWriterMode {
159     /**
160      * flag to indicate whether to write each incoming block to separate files
161      * or all blocks of one event to one file. set = concatenate (one file).
162      */
163     kConcatenateBlocks = 0x1,
164
165     /**
166      * flag to indicate whether to concatenate incoming blocks of the same type
167      * for all events to one file. If also @ref kConcatenateBlocks is set,
168      * or all blocks of all events are written to the same file.
169      */
170     kConcatenateEvents = 0x2,
171
172     /** event enumeration flag */
173     kEnumerate = 0x4
174   };
175
176  private:
177   /** the basename of the output file */
178   TString    fBaseName;                                            // see above
179   /** the extension of the output file */
180   TString    fExtension;                                           // see above
181   /** target directory */
182   TString    fDirectory;                                           // see above
183   /** enumeration format string */
184   TString    fCurrentFileName;                                     // see above
185
186   /** mode specifier, see @ref TWriterMode */
187   Short_t    fMode;                                                // see above
188
189   ClassDef(AliHLTFileWriter, 1)
190 };
191 #endif