]>
Commit | Line | Data |
---|---|---|
a8aea857 | 1 | // -*- Mode: C++ -*- |
2 | // @(#) $Id$ | |
3 | ||
4 | #ifndef ALIHLTFILEPUBLISHER_H | |
5 | #define ALIHLTFILEPUBLISHER_H | |
b6800be0 | 6 | /* This file is property of and copyright by the ALICE HLT Project * |
7 | * ALICE Experiment at CERN, All rights reserved. * | |
a8aea857 | 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" | |
d397a3b2 | 18 | #include <TFile.h> |
a8aea857 | 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> | |
90ebac25 | 27 | * Library: \b libAliHLTUtil. |
a8aea857 | 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> | |
d397a3b2 | 35 | * data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt> |
a8aea857 | 36 | * \li -dataspec <i> specification </i> <br> |
37 | * data specification treated as decimal number or hex number if | |
38 | * prepended by '0x' | |
d397a3b2 | 39 | * \li -nextevent |
40 | * indicate files published by the next event | |
a8aea857 | 41 | * |
42 | * Optional arguments:<br> | |
0449b3c8 | 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. | |
a8aea857 | 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 | |
d397a3b2 | 51 | * \em -datatype/spec. |
52 | * All files er published within one event, unless the \em -nexevent specifies | |
53 | * where to break into multiple events. | |
a8aea857 | 54 | * @ingroup alihlt_component |
55 | */ | |
56 | class AliHLTFilePublisher : public AliHLTDataSource { | |
57 | public: | |
58 | /** standard constructor */ | |
59 | AliHLTFilePublisher(); | |
a8aea857 | 60 | /** destructor */ |
61 | virtual ~AliHLTFilePublisher(); | |
62 | ||
63 | const char* GetComponentID(); | |
64 | AliHLTComponentDataType GetOutputDataType(); | |
65 | void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ); | |
66 | AliHLTComponent* Spawn(); | |
67 | ||
68 | /** | |
69 | * Open all files. | |
d397a3b2 | 70 | * Opens all files for all events from the event list @ref fEvents and adds TFile |
0449b3c8 | 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. | |
a8aea857 | 74 | */ |
0449b3c8 | 75 | int OpenFiles(bool keepOpen); |
a8aea857 | 76 | |
77 | protected: | |
78 | /** | |
79 | * Init method. | |
80 | */ | |
81 | int DoInit( int argc, const char** argv ); | |
82 | ||
83 | /** | |
84 | * Deinit method. | |
85 | */ | |
86 | int DoDeinit(); | |
87 | ||
88 | /** | |
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 | |
96 | * @return | |
97 | */ | |
98 | int GetEvent( const AliHLTComponentEventData& evtData, | |
99 | AliHLTComponentTriggerData& trigData, | |
100 | AliHLTUInt8_t* outputPtr, | |
101 | AliHLTUInt32_t& size, | |
102 | vector<AliHLTComponentBlockData>& outputBlocks ); | |
103 | ||
104 | /** | |
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> | |
114 | */ | |
115 | virtual int ScanArgument(int argc, const char** argv); | |
116 | ||
117 | protected: | |
118 | /** | |
119 | * Get the data type which is set for the current file | |
120 | */ | |
d397a3b2 | 121 | //AliHLTComponentDataType GetCurrentDataType() const; |
a8aea857 | 122 | |
123 | /** | |
124 | * Get the data specification which is set for the current file | |
125 | */ | |
d397a3b2 | 126 | //AliHLTUInt32_t GetCurrentSpecification() const; |
a8aea857 | 127 | |
128 | private: | |
d397a3b2 | 129 | /** prohibit copy constructor */ |
130 | AliHLTFilePublisher(const AliHLTFilePublisher&); | |
131 | /** prohibit assignment operator */ | |
132 | AliHLTFilePublisher& operator=(const AliHLTFilePublisher&); | |
133 | ||
134 | /** | |
135 | * File descriptor. | |
136 | */ | |
137 | class FileDesc : public TObject { | |
138 | public: | |
139 | /** constructor not implemented */ | |
140 | FileDesc(); | |
141 | /** constructor to use */ | |
142 | FileDesc(const char* name, AliHLTComponentDataType dt, AliHLTUInt32_t spec); | |
143 | /** destructor */ | |
144 | ~FileDesc(); | |
145 | ||
146 | /** | |
147 | * Open the file. | |
148 | * @return size of the file, neg. error code if failed | |
149 | */ | |
150 | int OpenFile(); | |
151 | ||
0449b3c8 | 152 | /** |
153 | * Close the file handle. | |
154 | */ | |
155 | void CloseFile(); | |
156 | ||
d397a3b2 | 157 | /** |
158 | * Get name of the file. | |
159 | */ | |
29312178 | 160 | const char* GetName() const {return fName.Data();} |
d397a3b2 | 161 | |
fe050813 | 162 | /** |
163 | * Set data type. | |
164 | */ | |
83fec083 | 165 | int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;} |
fe050813 | 166 | |
167 | /** | |
168 | * Set data specification | |
169 | */ | |
83fec083 | 170 | int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;} |
fe050813 | 171 | |
d397a3b2 | 172 | // implicite type conversions |
173 | operator TFile*() const {return fpInstance;} | |
174 | operator AliHLTComponentDataType() {return fDataType;} | |
175 | operator AliHLTUInt32_t() {return fSpecification;} | |
176 | ||
177 | private: | |
178 | /** prohibited copy constructor */ | |
179 | FileDesc(FileDesc&); | |
180 | /** prohibited copy operator */ | |
181 | FileDesc& operator=(FileDesc&); | |
182 | ||
183 | /** file name */ | |
184 | TString fName; //! transient | |
185 | /** file instance */ | |
186 | TFile* fpInstance; //! transient | |
187 | /** data type */ | |
188 | AliHLTComponentDataType fDataType; //! transient | |
189 | /** data specification */ | |
190 | AliHLTUInt32_t fSpecification; //! transient | |
191 | }; | |
192 | ||
193 | /** | |
194 | * Compound to store all files and meta information for one event. | |
195 | */ | |
196 | class EventFiles : public TObject { | |
197 | public: | |
198 | /** constructor */ | |
199 | EventFiles() : fFiles(), fSize(0) {fFiles.SetOwner();} | |
200 | /** destructor */ | |
201 | ~EventFiles() {} | |
202 | ||
203 | /** | |
204 | * Add a file descriptor | |
205 | */ | |
206 | void Add(TObject* pObj) {fFiles.Add(pObj);} | |
207 | ||
208 | operator TList&() {return fFiles;} | |
209 | ||
210 | private: | |
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 | |
215 | }; | |
216 | ||
217 | /** | |
218 | * Insert a file descriptor into the event descriptor. | |
219 | * If the event descriptor is NULL it is created before the file descriptor | |
220 | * is inserted. | |
221 | * @param pCurrEvent reference of the event descriptor pointer | |
222 | * @param pDesc file decriptor | |
223 | * @return neg. error value if failed | |
224 | */ | |
225 | int InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc); | |
226 | ||
227 | /** | |
228 | * Insert an event. | |
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 | |
232 | */ | |
233 | int InsertEvent(EventFiles* &pEvent); | |
234 | ||
235 | /** the current event */ | |
236 | TObjLink *fpCurrent; //! transient | |
237 | ||
238 | /** the list of events to be published */ | |
239 | TList fEvents; //! transient | |
240 | ||
a8aea857 | 241 | /** the maximum buffer size i.e. size of the biggest file */ |
d397a3b2 | 242 | Int_t fMaxSize; //! transient |
0449b3c8 | 243 | |
244 | /** Flag specifying if all the files should be opened during initialisation. */ | |
245 | bool fOpenFilesAtStart; //! transient | |
a8aea857 | 246 | |
d397a3b2 | 247 | ClassDef(AliHLTFilePublisher, 1) |
a8aea857 | 248 | }; |
249 | #endif |