]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTFilePublisher.h
attaching file writer to the StreamerInfo component
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFilePublisher.h
1 // -*- Mode: C++ -*-
2 // @(#) $Id$
3
4 #ifndef ALIHLTFILEPUBLISHER_H
5 #define ALIHLTFILEPUBLISHER_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               *
9
10 /** @file   AliHLTFilePublisher.h
11     @author Matthias Richter
12     @date   
13     @brief  An HLT file publishing (data source) component.
14     @note   The class is used in Offline (AliRoot) context
15 */
16
17 #include "AliHLTDataSource.h"
18 #include <TList.h>
19 class TFile;
20
21 /**
22  * @class AliHLTFilePublisher
23  * An HLT data source component which publishes data from one or a sequence
24  * of files.<br>
25  *
26  * <h2>General properties:</h2>
27  *
28  * Component ID: \b FilePublisher <br>
29  * Library: \b libAliHLTUtil.so     <br>
30  * Input Data Types: none <br>
31  * Output Data Types: according to arguments <br>
32  *
33  * <h2>Mandatory arguments:</h2>
34  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
35  * \li -datafile     <i> filename      </i>
36  * \li -datafilelist <i> file pattern  </i> <br>
37  *      not yet implemented
38  * \li -datatype     <i> datatype   dataorigin </i> <br>
39  *      data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt>
40  * \li -dataspec     <i> specification </i> <br>
41  *      data specification treated as decimal number or hex number if
42  *      prepended by '0x'
43  * \li -nextevent
44  *      indicate files published by the next event
45  *
46  * <h2>Optional arguments:</h2>
47  * \li -open_files_at_start
48  *      Opens all files during component initialisation rather than as needed
49  *      during event processing. Note: this feature may result in the system
50  *      running out of file handles if a large number of files was specified.
51  *
52  * <h2>Configuration:</h2>
53  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
54  * Configuration by component arguments.
55  *
56  * <h2>Default CDB entries:</h2>
57  * The component loads no CDB entries.
58  *
59  * <h2>Performance:</h2>
60  * The component does not process any event data.
61  *
62  * <h2>Memory consumption:</h2>
63  * The component does not process any event data.
64  *
65  * <h2>Output size:</h2>
66  * According to the available data. The component is an AliHLTDataSource
67  * and inteded to be used in the AliHLTSystem framework only. The component
68  * implements the standard AliHLTSystem adaptive buffer allocation. 
69  *
70  * The component needs at least one argument \em -datafile or \em -datafilelist.
71  * Both can occur multiple times. The \em -datatype and \em -dataspec
72  * parameters are valid for all files until the next occurrence of
73  * \em -datatype/spec.
74  * All files er published within one event, unless the \em -nexevent specifies
75  * where to break into multiple events.
76  *
77  * @ingroup alihlt_util_components
78  */
79 class AliHLTFilePublisher : public AliHLTDataSource  {
80  public:
81   /** standard constructor */
82   AliHLTFilePublisher();
83   /** destructor */
84   virtual ~AliHLTFilePublisher();
85
86   const char* GetComponentID();
87   AliHLTComponentDataType GetOutputDataType();
88   int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
89   void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
90   AliHLTComponent* Spawn();
91
92   /**
93    * Open all files.
94    * Opens all files for all events from the event list @ref fEvents and adds TFile
95    * objects to the internal list. It also calculates the maximum event size required.
96    * @param keepOpen  If this flag is true then the files are kept open, otherwise
97    *                  this method will close the files afterwards.
98    */
99   int OpenFiles(bool keepOpen);
100
101   /** Get List of Events, needed in the RootFilePublisher.*/
102   TList* GetEventList() { return &fEvents;} 
103   
104   /** Set if root files instead of raw files should be read,
105    *  needed in the RootFilePublisher.
106    *  @param isRaw  kTRUE if raw file, kFALSE for rootfile
107    */
108   void SetIsRawFile( Bool_t isRaw ) { fIsRaw = isRaw; }
109
110  protected:
111   /**
112    * Init method.
113    */
114   virtual int DoInit( int argc, const char** argv );
115
116   /**
117    * Deinit method.
118    */
119   int DoDeinit();
120
121   /**
122    * Data processing method for the component.
123    * @param evtData       event data structure
124    * @param trigData      trigger data structure
125    * @param outputPtr     pointer to target buffer
126    * @param size          <i>input</i>: size of target buffer
127    *                      <i>output</i>:size of produced data
128    * @param outputBlocks  list to receive output block descriptors
129    * @return
130    */
131   int GetEvent( const AliHLTComponentEventData& evtData,
132                         AliHLTComponentTriggerData& trigData,
133                         AliHLTUInt8_t* outputPtr, 
134                         AliHLTUInt32_t& size,
135                         AliHLTComponentBlockDataList& outputBlocks );
136
137   using AliHLTDataSource::GetEvent;
138
139   /**
140    * Scan one argument and adjacent parameters.
141    * Can be overloaded by child classes in order to add additional arguments
142    * beyond the standard arguments of the file publisher. The method is called
143    * whenever a non-standard argument is recognized.
144    * @param argc           size of the argument array
145    * @param argv           agument array for component initialization
146    * @return number of processed members of the argv <br>
147    *         -EINVAL unknown argument <br>
148    *         -EPROTO parameter for argument missing <br>
149    */
150   virtual int ScanArgument(int argc, const char** argv);
151
152   /**
153    * Get the data type which is set for the current file
154    */
155   //AliHLTComponentDataType GetCurrentDataType() const;
156
157   /**
158    * Get the data specification which is set for the current file
159    */
160   //AliHLTUInt32_t          GetCurrentSpecification() const;
161   
162  private:
163   /** prohibit copy constructor */
164   AliHLTFilePublisher(const AliHLTFilePublisher&);
165   /** prohibit assignment operator */
166   AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
167
168  protected:
169   /**
170    * File descriptor.
171    */
172   class FileDesc : public TObject {
173   public:
174     /** constructor not implemented */
175     FileDesc();
176     /** constructor to use */
177     FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec, Bool_t isRaw=kTRUE);
178     /** destructor */
179     ~FileDesc();
180
181     /**
182      * Open the file.
183      * @return size of the file, neg. error code if failed
184      */
185     int OpenFile();
186
187     /**
188      * Close the file handle.
189      */
190     void CloseFile();
191
192     /**
193      * Get name of the file.
194      */
195     const char* GetName() const {return fName.Data();}
196
197     /**
198      * Set data type.
199      */
200     int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;}
201
202     /**
203      * Set data specification
204      */
205     int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;}
206
207     // implicite type conversions
208     operator TFile*() const   {return fpInstance;}
209     operator AliHLTComponentDataType() const {return fDataType;}
210     operator AliHLTUInt32_t() const {return fSpecification;}
211
212   private:
213     /** prohibited copy constructor */
214     FileDesc(FileDesc&);
215     /** prohibited copy operator */
216     FileDesc& operator=(FileDesc&);
217
218     /** is raw (kTRUE) or root (kFALSE) file */
219     Bool_t fIsRaw;                                                 //! transient     
220     /** file name */
221     TString                 fName;                                 //! transient
222     /** file instance */
223     TFile*                  fpInstance;                            //! transient
224     /** data type */
225     AliHLTComponentDataType fDataType;                             //! transient
226     /** data specification */
227     AliHLTUInt32_t          fSpecification;                        //! transient
228   };
229
230   /**
231    * Compound to store all files and meta information for one event.
232    */
233   class EventFiles : public TObject {
234   public:
235     /** constructor */
236     EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();}
237     /** destructor */
238     ~EventFiles() {}
239
240     /**
241      * Add a file descriptor
242      */
243     void Add(TObject* pObj) {fFiles.Add(pObj);}
244
245     operator TList&() {return fFiles;}
246     operator TList*() {return &fFiles;}
247
248   private:
249     /** list of file names for the event */
250     TList fFiles;                                                  //! transient
251     /** size of all the files in that event */
252     Int_t fSize;                                                   //! transient
253   };
254
255   /**
256    * Insert a file descriptor into the event descriptor.
257    * If the event descriptor is NULL it is created before the file descriptor
258    * is inserted.
259    * @param pCurrEvent   reference of the event descriptor pointer
260    * @param pDesc        file decriptor
261    * @return neg. error value if failed
262    */
263   int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc);
264
265   /**
266    * Insert an event.
267    * The event descriptor is added to the list and the reference is cleared.
268    * @param pEvent        event decriptor
269    * @return neg. error value if failed
270    */
271   int InsertEvent(EventFiles* &pEvent);
272
273   /** the current event */
274   TObjLink *fpCurrent;                                             //! transient
275
276   /** the list of events to be published */
277   TList fEvents;                                                   //! transient
278
279   /** the maximum buffer size i.e. size of the biggest file */
280   Int_t fMaxSize;                                                  //! transient
281   
282   /** Flag specifying if all the files should be opened during initialisation.  */
283   bool fOpenFilesAtStart;                                          //! transient
284
285   /** output data types  */
286   AliHLTComponentDataTypeList fOutputDataTypes;                    //! transient
287
288   /** Is raw file (kTRUE) [default] or root file (kFALSE). */
289   Bool_t fIsRaw;                                                   //! transient     
290
291   ClassDef(AliHLTFilePublisher, 3)
292 };
293 #endif