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 */
10 /** @file AliHLTFilePublisher.h
11 @author Matthias Richter
13 @brief An HLT file publishing (data source) component.
14 @note The class is used in Offline (AliRoot) context
17 #include "AliHLTDataSource.h"
22 * @class AliHLTFilePublisher
23 * An HLT data source component which publishes data from one or a sequence
26 * Component ID: \b FilePublisher <br>
27 * Library: \b libAliHLTUtil.
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>
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
40 * indicate files published by the next event
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.
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
52 * All files er published within one event, unless the \em -nexevent specifies
53 * where to break into multiple events.
54 * @ingroup alihlt_component
56 class AliHLTFilePublisher : public AliHLTDataSource {
58 /** standard constructor */
59 AliHLTFilePublisher();
61 virtual ~AliHLTFilePublisher();
63 const char* GetComponentID();
64 AliHLTComponentDataType GetOutputDataType();
65 void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
66 AliHLTComponent* Spawn();
70 * Opens all files for all events from the event list @ref fEvents and adds TFile
71 * objects to the internal list. It also calculates the maximum event size required.
72 * @param keepOpen If this flag is true then the files are kept open, otherwise
73 * this method will close the files afterwards.
75 int OpenFiles(bool keepOpen);
81 int DoInit( int argc, const char** argv );
89 * Data processing method for the component.
90 * @param evtData event data structure
91 * @param trigData trigger data structure
92 * @param outputPtr pointer to target buffer
93 * @param size <i>input</i>: size of target buffer
94 * <i>output</i>:size of produced data
95 * @param outputBlocks list to receive output block descriptors
98 int GetEvent( const AliHLTComponentEventData& evtData,
99 AliHLTComponentTriggerData& trigData,
100 AliHLTUInt8_t* outputPtr,
101 AliHLTUInt32_t& size,
102 vector<AliHLTComponentBlockData>& outputBlocks );
105 * Scan one argument and adjacent parameters.
106 * Can be overloaded by child classes in order to add additional arguments
107 * beyond the standard arguments of the file publisher. The method is called
108 * whenever a non-standard argument is recognized.
109 * @param argc size of the argument array
110 * @param argv agument array for component initialization
111 * @return number of processed members of the argv <br>
112 * -EINVAL unknown argument <br>
113 * -EPROTO parameter for argument missing <br>
115 virtual int ScanArgument(int argc, const char** argv);
119 * Get the data type which is set for the current file
121 //AliHLTComponentDataType GetCurrentDataType() const;
124 * Get the data specification which is set for the current file
126 //AliHLTUInt32_t GetCurrentSpecification() const;
129 /** prohibit copy constructor */
130 AliHLTFilePublisher(const AliHLTFilePublisher&);
131 /** prohibit assignment operator */
132 AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
137 class FileDesc : public TObject {
139 /** constructor not implemented */
141 /** constructor to use */
142 FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec);
148 * @return size of the file, neg. error code if failed
153 * Close the file handle.
158 * Get name of the file.
160 const char* GetName() const {return fName.Data();}
165 int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;}
168 * Set data specification
170 int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;}
172 // implicite type conversions
173 operator TFile*() const {return fpInstance;}
174 operator AliHLTComponentDataType() {return fDataType;}
175 operator AliHLTUInt32_t() {return fSpecification;}
178 /** prohibited copy constructor */
180 /** prohibited copy operator */
181 FileDesc& operator=(FileDesc&);
184 TString fName; //! transient
186 TFile* fpInstance; //! transient
188 AliHLTComponentDataType fDataType; //! transient
189 /** data specification */
190 AliHLTUInt32_t fSpecification; //! transient
194 * Compound to store all files and meta information for one event.
196 class EventFiles : public TObject {
199 EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();}
204 * Add a file descriptor
206 void Add(TObject* pObj) {fFiles.Add(pObj);}
208 operator TList&() {return fFiles;}
211 /** list of file names for the event */
212 TList fFiles; //! transient
213 /** size of all the files in that event */
214 Int_t fSize; //! transient
218 * Insert a file descriptor into the event descriptor.
219 * If the event descriptor is NULL it is created before the file descriptor
221 * @param pCurrEvent reference of the event descriptor pointer
222 * @param pDesc file decriptor
223 * @return neg. error value if failed
225 int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc);
229 * The event descriptor is added to the list and the reference is cleared.
230 * @param pEvent event decriptor
231 * @return neg. error value if failed
233 int InsertEvent(EventFiles* &pEvent);
235 /** the current event */
236 TObjLink *fpCurrent; //! transient
238 /** the list of events to be published */
239 TList fEvents; //! transient
241 /** the maximum buffer size i.e. size of the biggest file */
242 Int_t fMaxSize; //! transient
244 /** Flag specifying if all the files should be opened during initialisation. */
245 bool fOpenFilesAtStart; //! transient
247 ClassDef(AliHLTFilePublisher, 1)