code documentation; minor enhancement of BlockFilter
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFilePublisher.h
CommitLineData
a8aea857 1// -*- Mode: C++ -*-
2// @(#) $Id$
3
4#ifndef ALIHLTFILEPUBLISHER_H
5#define ALIHLTFILEPUBLISHER_H
a7ad9794 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 *
a8aea857 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>
7bcd6cad 19class TFile;
a8aea857 20
21/**
22 * @class AliHLTFilePublisher
23 * An HLT data source component which publishes data from one or a sequence
24 * of files.<br>
25 *
a7ad9794 26 * <h2>General properties:</h2>
27 *
a8aea857 28 * Component ID: \b FilePublisher <br>
a7ad9794 29 * Library: \b libAliHLTUtil.so <br>
30 * Input Data Types: none <br>
31 * Output Data Types: according to arguments <br>
a8aea857 32 *
a7ad9794 33 * <h2>Mandatory arguments:</h2>
1ac82ce6 34 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
a8aea857 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>
d397a3b2 39 * data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt>
a8aea857 40 * \li -dataspec <i> specification </i> <br>
41 * data specification treated as decimal number or hex number if
42 * prepended by '0x'
d397a3b2 43 * \li -nextevent
44 * indicate files published by the next event
a8aea857 45 *
a7ad9794 46 * <h2>Optional arguments:</h2>
0449b3c8 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.
a8aea857 51 *
a7ad9794 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 *
a8aea857 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
d397a3b2 73 * \em -datatype/spec.
74 * All files er published within one event, unless the \em -nexevent specifies
75 * where to break into multiple events.
a7ad9794 76 *
77 * @ingroup alihlt_util_components
a8aea857 78 */
79class AliHLTFilePublisher : public AliHLTDataSource {
80 public:
81 /** standard constructor */
82 AliHLTFilePublisher();
a8aea857 83 /** destructor */
84 virtual ~AliHLTFilePublisher();
85
86 const char* GetComponentID();
87 AliHLTComponentDataType GetOutputDataType();
8a106878 88 int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
a8aea857 89 void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
90 AliHLTComponent* Spawn();
91
92 /**
93 * Open all files.
d397a3b2 94 * Opens all files for all events from the event list @ref fEvents and adds TFile
0449b3c8 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.
a8aea857 98 */
0449b3c8 99 int OpenFiles(bool keepOpen);
a8aea857 100
101 protected:
102 /**
103 * Init method.
104 */
105 int DoInit( int argc, const char** argv );
106
107 /**
108 * Deinit method.
109 */
110 int DoDeinit();
111
112 /**
113 * Data processing method for the component.
114 * @param evtData event data structure
115 * @param trigData trigger data structure
116 * @param outputPtr pointer to target buffer
117 * @param size <i>input</i>: size of target buffer
118 * <i>output</i>:size of produced data
119 * @param outputBlocks list to receive output block descriptors
120 * @return
121 */
122 int GetEvent( const AliHLTComponentEventData& evtData,
123 AliHLTComponentTriggerData& trigData,
124 AliHLTUInt8_t* outputPtr,
125 AliHLTUInt32_t& size,
7bcd6cad 126 AliHLTComponentBlockDataList& outputBlocks );
a8aea857 127
a8abc5d5 128 using AliHLTDataSource::GetEvent;
129
a8aea857 130 /**
131 * Scan one argument and adjacent parameters.
132 * Can be overloaded by child classes in order to add additional arguments
133 * beyond the standard arguments of the file publisher. The method is called
134 * whenever a non-standard argument is recognized.
135 * @param argc size of the argument array
136 * @param argv agument array for component initialization
137 * @return number of processed members of the argv <br>
138 * -EINVAL unknown argument <br>
139 * -EPROTO parameter for argument missing <br>
140 */
141 virtual int ScanArgument(int argc, const char** argv);
142
143 protected:
144 /**
145 * Get the data type which is set for the current file
146 */
d397a3b2 147 //AliHLTComponentDataType GetCurrentDataType() const;
a8aea857 148
149 /**
150 * Get the data specification which is set for the current file
151 */
d397a3b2 152 //AliHLTUInt32_t GetCurrentSpecification() const;
a8aea857 153
154 private:
d397a3b2 155 /** prohibit copy constructor */
156 AliHLTFilePublisher(const AliHLTFilePublisher&);
157 /** prohibit assignment operator */
158 AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
159
160 /**
161 * File descriptor.
162 */
163 class FileDesc : public TObject {
164 public:
165 /** constructor not implemented */
166 FileDesc();
167 /** constructor to use */
168 FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec);
169 /** destructor */
170 ~FileDesc();
171
172 /**
173 * Open the file.
174 * @return size of the file, neg. error code if failed
175 */
176 int OpenFile();
177
178 /**
0449b3c8 179 * Close the file handle.
180 */
181 void CloseFile();
182
183 /**
d397a3b2 184 * Get name of the file.
185 */
29312178 186 const char* GetName() const {return fName.Data();}
d397a3b2 187
fe050813 188 /**
189 * Set data type.
190 */
83fec083 191 int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;}
fe050813 192
193 /**
194 * Set data specification
195 */
83fec083 196 int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;}
fe050813 197
d397a3b2 198 // implicite type conversions
199 operator TFile*() const {return fpInstance;}
7bcd6cad 200 operator AliHLTComponentDataType() const {return fDataType;}
201 operator AliHLTUInt32_t() const {return fSpecification;}
d397a3b2 202
203 private:
204 /** prohibited copy constructor */
205 FileDesc(FileDesc&);
206 /** prohibited copy operator */
207 FileDesc& operator=(FileDesc&);
208
209 /** file name */
210 TString fName; //! transient
211 /** file instance */
212 TFile* fpInstance; //! transient
213 /** data type */
214 AliHLTComponentDataType fDataType; //! transient
215 /** data specification */
216 AliHLTUInt32_t fSpecification; //! transient
217 };
218
219 /**
220 * Compound to store all files and meta information for one event.
221 */
222 class EventFiles : public TObject {
223 public:
224 /** constructor */
225 EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();}
226 /** destructor */
227 ~EventFiles() {}
228
229 /**
230 * Add a file descriptor
231 */
232 void Add(TObject* pObj) {fFiles.Add(pObj);}
233
234 operator TList&() {return fFiles;}
235
236 private:
237 /** list of file names for the event */
238 TList fFiles; //! transient
239 /** size of all the files in that event */
240 Int_t fSize; //! transient
241 };
242
243 /**
244 * Insert a file descriptor into the event descriptor.
245 * If the event descriptor is NULL it is created before the file descriptor
246 * is inserted.
247 * @param pCurrEvent reference of the event descriptor pointer
248 * @param pDesc file decriptor
249 * @return neg. error value if failed
250 */
251 int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc);
252
253 /**
254 * Insert an event.
255 * The event descriptor is added to the list and the reference is cleared.
256 * @param pEvent event decriptor
257 * @return neg. error value if failed
258 */
259 int InsertEvent(EventFiles* &pEvent);
260
261 /** the current event */
262 TObjLink *fpCurrent; //! transient
263
264 /** the list of events to be published */
265 TList fEvents; //! transient
266
a8aea857 267 /** the maximum buffer size i.e. size of the biggest file */
d397a3b2 268 Int_t fMaxSize; //! transient
0449b3c8 269
270 /** Flag specifying if all the files should be opened during initialisation. */
271 bool fOpenFilesAtStart; //! transient
a8aea857 272
8a106878 273 /** output data types */
274 AliHLTComponentDataTypeList fOutputDataTypes; //! transient
275
276 ClassDef(AliHLTFilePublisher, 2)
a8aea857 277};
278#endif