]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTFilePublisher.h
correct handling of multiple output data types
[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 <TFile.h>
19 #include <TList.h>
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  * Component ID: \b FilePublisher <br>
27  * Library: \b libAliHLTUtil.
28  *
29  * Mandatory arguments: <br>
30  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
31  * \li -datafile     <i> filename      </i>
32  * \li -datafilelist <i> file pattern  </i> <br>
33  *      not yet implemented
34  * \li -datatype     <i> datatype   dataorigin </i> <br>
35  *      data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt>
36  * \li -dataspec     <i> specification </i> <br>
37  *      data specification treated as decimal number or hex number if
38  *      prepended by '0x'
39  * \li -nextevent
40  *      indicate files published by the next event
41  *
42  * Optional arguments:<br>
43  * \li -open_files_at_start
44  *      Opens all files during component initialisation rather than as needed
45  *      during event processing. Note: this feature may result in the system
46  *      running out of file handles if a large number of files was specified.
47  *
48  * The component needs at least one argument \em -datafile or \em -datafilelist.
49  * Both can occur multiple times. The \em -datatype and \em -dataspec
50  * parameters are valid for all files until the next occurrence of
51  * \em -datatype/spec.
52  * All files er published within one event, unless the \em -nexevent specifies
53  * where to break into multiple events.
54  * @ingroup alihlt_component
55  */
56 class AliHLTFilePublisher : public AliHLTDataSource  {
57  public:
58   /** standard constructor */
59   AliHLTFilePublisher();
60   /** destructor */
61   virtual ~AliHLTFilePublisher();
62
63   const char* GetComponentID();
64   AliHLTComponentDataType GetOutputDataType();
65   int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
66   void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
67   AliHLTComponent* Spawn();
68
69   /**
70    * Open all files.
71    * Opens all files for all events from the event list @ref fEvents and adds TFile
72    * objects to the internal list. It also calculates the maximum event size required.
73    * @param keepOpen  If this flag is true then the files are kept open, otherwise
74    *                  this method will close the files afterwards.
75    */
76   int OpenFiles(bool keepOpen);
77
78  protected:
79   /**
80    * Init method.
81    */
82   int DoInit( int argc, const char** argv );
83
84   /**
85    * Deinit method.
86    */
87   int DoDeinit();
88
89   /**
90    * Data processing method for the component.
91    * @param evtData       event data structure
92    * @param trigData      trigger data structure
93    * @param outputPtr     pointer to target buffer
94    * @param size          <i>input</i>: size of target buffer
95    *                      <i>output</i>:size of produced data
96    * @param outputBlocks  list to receive output block descriptors
97    * @return
98    */
99   int GetEvent( const AliHLTComponentEventData& evtData,
100                         AliHLTComponentTriggerData& trigData,
101                         AliHLTUInt8_t* outputPtr, 
102                         AliHLTUInt32_t& size,
103                         vector<AliHLTComponentBlockData>& outputBlocks );
104
105   /**
106    * Scan one argument and adjacent parameters.
107    * Can be overloaded by child classes in order to add additional arguments
108    * beyond the standard arguments of the file publisher. The method is called
109    * whenever a non-standard argument is recognized.
110    * @param argc           size of the argument array
111    * @param argv           agument array for component initialization
112    * @return number of processed members of the argv <br>
113    *         -EINVAL unknown argument <br>
114    *         -EPROTO parameter for argument missing <br>
115    */
116   virtual int ScanArgument(int argc, const char** argv);
117
118  protected:
119   /**
120    * Get the data type which is set for the current file
121    */
122   //AliHLTComponentDataType GetCurrentDataType() const;
123
124   /**
125    * Get the data specification which is set for the current file
126    */
127   //AliHLTUInt32_t          GetCurrentSpecification() const;
128   
129  private:
130   /** prohibit copy constructor */
131   AliHLTFilePublisher(const AliHLTFilePublisher&);
132   /** prohibit assignment operator */
133   AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
134
135   /**
136    * File descriptor.
137    */
138   class FileDesc : public TObject {
139   public:
140     /** constructor not implemented */
141     FileDesc();
142     /** constructor to use */
143     FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec);
144     /** destructor */
145     ~FileDesc();
146
147     /**
148      * Open the file.
149      * @return size of the file, neg. error code if failed
150      */
151     int OpenFile();
152
153     /**
154      * Close the file handle.
155      */
156     void CloseFile();
157
158     /**
159      * Get name of the file.
160      */
161     const char* GetName() const {return fName.Data();}
162
163     /**
164      * Set data type.
165      */
166     int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;}
167
168     /**
169      * Set data specification
170      */
171     int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;}
172
173     // implicite type conversions
174     operator TFile*() const   {return fpInstance;}
175     operator AliHLTComponentDataType() {return fDataType;}
176     operator AliHLTUInt32_t() {return fSpecification;}
177
178   private:
179     /** prohibited copy constructor */
180     FileDesc(FileDesc&);
181     /** prohibited copy operator */
182     FileDesc& operator=(FileDesc&);
183
184     /** file name */
185     TString                 fName;                                 //! transient
186     /** file instance */
187     TFile*                  fpInstance;                            //! transient
188     /** data type */
189     AliHLTComponentDataType fDataType;                             //! transient
190     /** data specification */
191     AliHLTUInt32_t          fSpecification;                        //! transient
192   };
193
194   /**
195    * Compound to store all files and meta information for one event.
196    */
197   class EventFiles : public TObject {
198   public:
199     /** constructor */
200     EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();}
201     /** destructor */
202     ~EventFiles() {}
203
204     /**
205      * Add a file descriptor
206      */
207     void Add(TObject* pObj) {fFiles.Add(pObj);}
208
209     operator TList&() {return fFiles;}
210
211   private:
212     /** list of file names for the event */
213     TList fFiles;                                                  //! transient
214     /** size of all the files in that event */
215     Int_t fSize;                                                   //! transient
216   };
217
218   /**
219    * Insert a file descriptor into the event descriptor.
220    * If the event descriptor is NULL it is created before the file descriptor
221    * is inserted.
222    * @param pCurrEvent   reference of the event descriptor pointer
223    * @param pDesc        file decriptor
224    * @return neg. error value if failed
225    */
226   int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc);
227
228   /**
229    * Insert an event.
230    * The event descriptor is added to the list and the reference is cleared.
231    * @param pEvent        event decriptor
232    * @return neg. error value if failed
233    */
234   int InsertEvent(EventFiles* &pEvent);
235
236   /** the current event */
237   TObjLink *fpCurrent;                                             //! transient
238
239   /** the list of events to be published */
240   TList fEvents;                                                   //! transient
241
242   /** the maximum buffer size i.e. size of the biggest file */
243   Int_t                   fMaxSize;                                //! transient
244   
245   /** Flag specifying if all the files should be opened during initialisation.  */
246   bool fOpenFilesAtStart;                                          //! transient
247
248   /** output data types  */
249   AliHLTComponentDataTypeList fOutputDataTypes;                    //! transient
250
251   ClassDef(AliHLTFilePublisher, 2)
252 };
253 #endif