]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTFilePublisher.h
tracking at slice borders improved
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTFilePublisher.h
CommitLineData
a8aea857 1// -*- Mode: C++ -*-
a9c4e244 2// $Id$
a8aea857 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
a9c4e244 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//
a8aea857 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>
a9c4e244 36 * \li -datafilelist <i> configfile </i> <br>
37 * read arguments from a configfile
a8aea857 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'
43 *
a7ad9794 44 * <h2>Optional arguments:</h2>
0449b3c8 45 * \li -open_files_at_start
46 * Opens all files during component initialisation rather than as needed
47 * during event processing. Note: this feature may result in the system
48 * running out of file handles if a large number of files was specified.
a9c4e244 49 * \li -nextevent
50 * indicate files published by the next event
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
992ea13b 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
a8aea857 110 protected:
111 /**
112 * Init method.
113 */
fa5e8413 114 virtual int DoInit( int argc, const char** argv );
a8aea857 115
a9c4e244 116 /// inherited from AliHLTComponent: argument scan
117 int ScanConfigurationArgument(int argc, const char** argv);
118
a8aea857 119 /**
120 * Deinit method.
121 */
122 int DoDeinit();
123
124 /**
125 * Data processing method for the component.
9bb806cd 126 * @param [in] evtData event data structure
127 * @param [in] trigData trigger data structure
128 * @param [in] outputPtr pointer to target buffer
129 * @param [in,out] size <i>input</i>: size of target buffer
a8aea857 130 * <i>output</i>:size of produced data
9bb806cd 131 * @param [in] outputBlocks list to receive output block descriptors
a8aea857 132 * @return
133 */
134 int GetEvent( const AliHLTComponentEventData& evtData,
135 AliHLTComponentTriggerData& trigData,
136 AliHLTUInt8_t* outputPtr,
137 AliHLTUInt32_t& size,
7bcd6cad 138 AliHLTComponentBlockDataList& outputBlocks );
a8aea857 139
a8abc5d5 140 using AliHLTDataSource::GetEvent;
141
a8aea857 142 /**
143 * Scan one argument and adjacent parameters.
144 * Can be overloaded by child classes in order to add additional arguments
145 * beyond the standard arguments of the file publisher. The method is called
146 * whenever a non-standard argument is recognized.
147 * @param argc size of the argument array
148 * @param argv agument array for component initialization
149 * @return number of processed members of the argv <br>
150 * -EINVAL unknown argument <br>
151 * -EPROTO parameter for argument missing <br>
152 */
153 virtual int ScanArgument(int argc, const char** argv);
154
a8aea857 155 /**
156 * Get the data type which is set for the current file
157 */
d397a3b2 158 //AliHLTComponentDataType GetCurrentDataType() const;
a8aea857 159
160 /**
161 * Get the data specification which is set for the current file
162 */
d397a3b2 163 //AliHLTUInt32_t GetCurrentSpecification() const;
a8aea857 164
165 private:
d397a3b2 166 /** prohibit copy constructor */
167 AliHLTFilePublisher(const AliHLTFilePublisher&);
168 /** prohibit assignment operator */
169 AliHLTFilePublisher& operator=(const AliHLTFilePublisher&);
170
992ea13b 171 protected:
d397a3b2 172 /**
173 * File descriptor.
174 */
175 class FileDesc : public TObject {
176 public:
177 /** constructor not implemented */
178 FileDesc();
179 /** constructor to use */
992ea13b 180 FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec, Bool_t isRaw=kTRUE);
d397a3b2 181 /** destructor */
182 ~FileDesc();
183
184 /**
185 * Open the file.
186 * @return size of the file, neg. error code if failed
187 */
188 int OpenFile();
189
0449b3c8 190 /**
191 * Close the file handle.
192 */
193 void CloseFile();
194
d397a3b2 195 /**
196 * Get name of the file.
197 */
29312178 198 const char* GetName() const {return fName.Data();}
d397a3b2 199
fe050813 200 /**
201 * Set data type.
202 */
83fec083 203 int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;}
fe050813 204
205 /**
206 * Set data specification
207 */
83fec083 208 int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;}
fe050813 209
d397a3b2 210 // implicite type conversions
211 operator TFile*() const {return fpInstance;}
7bcd6cad 212 operator AliHLTComponentDataType() const {return fDataType;}
213 operator AliHLTUInt32_t() const {return fSpecification;}
d397a3b2 214
215 private:
216 /** prohibited copy constructor */
217 FileDesc(FileDesc&);
218 /** prohibited copy operator */
219 FileDesc& operator=(FileDesc&);
220
992ea13b 221 /** is raw (kTRUE) or root (kFALSE) file */
222 Bool_t fIsRaw; //! transient
d397a3b2 223 /** file name */
224 TString fName; //! transient
225 /** file instance */
226 TFile* fpInstance; //! transient
227 /** data type */
228 AliHLTComponentDataType fDataType; //! transient
229 /** data specification */
230 AliHLTUInt32_t fSpecification; //! transient
231 };
232
233 /**
234 * Compound to store all files and meta information for one event.
235 */
236 class EventFiles : public TObject {
237 public:
238 /** constructor */
239 EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();}
240 /** destructor */
241 ~EventFiles() {}
242
243 /**
244 * Add a file descriptor
245 */
246 void Add(TObject* pObj) {fFiles.Add(pObj);}
247
248 operator TList&() {return fFiles;}
fa5e8413 249 operator TList*() {return &fFiles;}
d397a3b2 250
251 private:
252 /** list of file names for the event */
253 TList fFiles; //! transient
254 /** size of all the files in that event */
255 Int_t fSize; //! transient
256 };
257
258 /**
259 * Insert a file descriptor into the event descriptor.
260 * If the event descriptor is NULL it is created before the file descriptor
261 * is inserted.
262 * @param pCurrEvent reference of the event descriptor pointer
263 * @param pDesc file decriptor
264 * @return neg. error value if failed
265 */
266 int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc);
267
268 /**
269 * Insert an event.
270 * The event descriptor is added to the list and the reference is cleared.
271 * @param pEvent event decriptor
272 * @return neg. error value if failed
273 */
274 int InsertEvent(EventFiles* &pEvent);
275
276 /** the current event */
277 TObjLink *fpCurrent; //! transient
278
279 /** the list of events to be published */
280 TList fEvents; //! transient
281
a8aea857 282 /** the maximum buffer size i.e. size of the biggest file */
992ea13b 283 Int_t fMaxSize; //! transient
0449b3c8 284
285 /** Flag specifying if all the files should be opened during initialisation. */
286 bool fOpenFilesAtStart; //! transient
a8aea857 287
8a106878 288 /** output data types */
289 AliHLTComponentDataTypeList fOutputDataTypes; //! transient
290
992ea13b 291 /** Is raw file (kTRUE) [default] or root file (kFALSE). */
292 Bool_t fIsRaw; //! transient
293
a9c4e244 294 ClassDef(AliHLTFilePublisher, 0)
a8aea857 295};
296#endif