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