]>
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 | ||
7bcd6cad | 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 | ||
a8aea857 | 23 | #include "AliHLTDataSource.h" |
24 | #include <TList.h> | |
7bcd6cad | 25 | class TFile; |
a8aea857 | 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> | |
90ebac25 | 33 | * Library: \b libAliHLTUtil. |
a8aea857 | 34 | * |
35 | * Mandatory arguments: <br> | |
1ac82ce6 | 36 | * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting --> |
a8aea857 | 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> | |
d397a3b2 | 41 | * data type ID and origin, e.g. <tt>-datatype 'CLUSTERS' 'TPC ' </tt> |
a8aea857 | 42 | * \li -dataspec <i> specification </i> <br> |
43 | * data specification treated as decimal number or hex number if | |
44 | * prepended by '0x' | |
d397a3b2 | 45 | * \li -nextevent |
46 | * indicate files published by the next event | |
a8aea857 | 47 | * |
48 | * Optional arguments:<br> | |
0449b3c8 | 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. | |
a8aea857 | 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 | |
d397a3b2 | 57 | * \em -datatype/spec. |
58 | * All files er published within one event, unless the \em -nexevent specifies | |
59 | * where to break into multiple events. | |
a8aea857 | 60 | * @ingroup alihlt_component |
61 | */ | |
62 | class AliHLTFilePublisher : public AliHLTDataSource { | |
63 | public: | |
64 | /** standard constructor */ | |
65 | AliHLTFilePublisher(); | |
a8aea857 | 66 | /** destructor */ |
67 | virtual ~AliHLTFilePublisher(); | |
68 | ||
69 | const char* GetComponentID(); | |
70 | AliHLTComponentDataType GetOutputDataType(); | |
8a106878 | 71 | int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList); |
a8aea857 | 72 | void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ); |
73 | AliHLTComponent* Spawn(); | |
74 | ||
75 | /** | |
76 | * Open all files. | |
d397a3b2 | 77 | * Opens all files for all events from the event list @ref fEvents and adds TFile |
0449b3c8 | 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. | |
a8aea857 | 81 | */ |
0449b3c8 | 82 | int OpenFiles(bool keepOpen); |
a8aea857 | 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, | |
7bcd6cad | 109 | AliHLTComponentBlockDataList& outputBlocks ); |
a8aea857 | 110 | |
a8abc5d5 | 111 | using AliHLTDataSource::GetEvent; |
112 | ||
a8aea857 | 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 | */ | |
d397a3b2 | 130 | //AliHLTComponentDataType GetCurrentDataType() const; |
a8aea857 | 131 | |
132 | /** | |
133 | * Get the data specification which is set for the current file | |
134 | */ | |
d397a3b2 | 135 | //AliHLTUInt32_t GetCurrentSpecification() const; |
a8aea857 | 136 | |
137 | private: | |
d397a3b2 | 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 | ||
0449b3c8 | 161 | /** |
162 | * Close the file handle. | |
163 | */ | |
164 | void CloseFile(); | |
165 | ||
d397a3b2 | 166 | /** |
167 | * Get name of the file. | |
168 | */ | |
29312178 | 169 | const char* GetName() const {return fName.Data();} |
d397a3b2 | 170 | |
fe050813 | 171 | /** |
172 | * Set data type. | |
173 | */ | |
83fec083 | 174 | int SetDataType(AliHLTComponentDataType dt) {fDataType=dt; return 0;} |
fe050813 | 175 | |
176 | /** | |
177 | * Set data specification | |
178 | */ | |
83fec083 | 179 | int SetSpecification(AliHLTUInt32_t spec) {fSpecification=spec; return 0;} |
fe050813 | 180 | |
d397a3b2 | 181 | // implicite type conversions |
182 | operator TFile*() const {return fpInstance;} | |
7bcd6cad | 183 | operator AliHLTComponentDataType() const {return fDataType;} |
184 | operator AliHLTUInt32_t() const {return fSpecification;} | |
d397a3b2 | 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 | ||
a8aea857 | 250 | /** the maximum buffer size i.e. size of the biggest file */ |
d397a3b2 | 251 | Int_t fMaxSize; //! transient |
0449b3c8 | 252 | |
253 | /** Flag specifying if all the files should be opened during initialisation. */ | |
254 | bool fOpenFilesAtStart; //! transient | |
a8aea857 | 255 | |
8a106878 | 256 | /** output data types */ |
257 | AliHLTComponentDataTypeList fOutputDataTypes; //! transient | |
258 | ||
259 | ClassDef(AliHLTFilePublisher, 2) | |
a8aea857 | 260 | }; |
261 | #endif |