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