Line data Source code
1 : //-*- Mode: C++ -*-
2 : // $Id$
3 :
4 : #ifndef ALIRAWREADERHLT_H
5 : #define ALIRAWREADERHLT_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 *
9 :
10 : /// @file AliRawReaderHLT.h
11 : /// @author Matthias Richter
12 : /// @date
13 : /// @brief AliRawReader implementation which replaces original input of
14 : /// detectors with the appropriate HLT output.
15 :
16 : #include "AliHLTDataTypes.h"
17 : #include "AliRawReader.h" // RAW, base class
18 : #include "TString.h"
19 : #include <vector>
20 :
21 : class AliHLTOUT;
22 : class AliHLTOUTHandler;
23 : class AliHLTPluginBase;
24 :
25 : /**
26 : * @class AliRawReaderHLT
27 : * A specific AliRawReader for detector input replacement by HLTOUT data blocks.
28 : *
29 : * HLT components can produce output data in the detector ddl raw format.
30 : * Data blocks of this format can be fed into the normal detector reconstruction
31 : * without changes in the actual reconstruction code by means of the
32 : * AliRawReaderHLT implementation of the AliRawReader.
33 : *
34 : * @section sec_alirawreaderhlt_concept Conceptual design
35 : * The AliRawReader provides an abstract interface to the ddl raw data. All
36 : * reconstruction code uses this interface to access the data.
37 : * HLT components can send their data in the original ddl raw format. The only
38 : * difference of such data blocks is the location since they are shipped as
39 : * part of the HLTOUT data stream. The AliRawReaderHLT provides redirection of
40 : * those data blocks.
41 : *
42 : * The AliRawReaderHLT needs the original AliRawReader in order to get the
43 : * data. Furthermore, a string containing the detector specification defines
44 : * which data should be read from the HLT stream and which from the original
45 : * reader.
46 : *
47 : * @note An HLTOUT handler must be available for the HLTOUT data blocks to
48 : * be redirected. Please read @ref sec_alirawreaderhlt_module carefully.
49 : *
50 : * @section sec_alirawreaderhlt_usage Selection of the HLTOUT data stream
51 : * The input data of a detector can be replaced by the corresponding HLT
52 : * data by calling the <tt>AliReconstruction::SetUseHLTData("...")</tt>, e.g.
53 : * <pre>
54 : * AliReconstruction rec;
55 : * rec.SetUseHLTData("TPC TRD");
56 : * </pre>
57 : * will replace the input of TPC and TRD.
58 : *
59 : * The reader can be used directly. In order to avoid library dependencies
60 : * downwards, the methed AliRawHLTManager::CreateRawReaderHLT is available
61 : * in the RAW package.
62 : * <pre>
63 : * {
64 : * AliRawReader* orgReader=AliRawReader::Create("raw.root");
65 : * AliRawReader* rawreader=AliRawHLTManager::CreateRawReaderHLT(orgReader, "ITSSDD");
66 : * rawreader->Select("ITSSDD");
67 : * int count=0;
68 : * while (rawreader->NextEvent()) {
69 : * cout << "scanning event " << count++ << endl;
70 : * UChar_t* pSrc=NULL;
71 : * while (rawreader->ReadNextData(pSrc)) {
72 : * cout << " equipment: " << rawreader->GetEquipmentId() << endl;
73 : * }
74 : * }
75 : * }
76 : * </pre>
77 : *
78 : * @section sec_alirawreaderhlt_detectorids Detector selection
79 : * The constructor gets a detector selection string as parameter and initializes
80 : * the redirection according to that. Detector Ids are according to AliDAQ.
81 : * Please note the special strings for for ITS and MUON sub-detectors, ITSSPD,
82 : * ITSSDD, ITSSSD, and MUONTRK and MUONTRG respectively.
83 : *
84 : * @section sec_alirawreaderhlt_module Module implementation
85 : * In order to determine the equipment id for the data block, the HLT module
86 : * must implement an HLTOUT handler of class AliHLTOUTHandlerEquId which is of
87 : * type @ref AliHLTModuleAgent::AliHLTOUTHandlerType ::kRawReader.
88 : * The handler must implement the method
89 : * <pre>
90 : * // AliHLTOUTHandlerEquId::ProcessData(AliHLTOUT*)
91 : * virtual int ProcessData(AliHLTOUT* pData);
92 : * </pre>
93 : * which returns the equipment id and eventually decodes data to be retrieved
94 : * by calling AliHLTOUTHandler::GetProcessedData(). If the equipment id of the
95 : * DDL has been sent as data specification of the block, the AliHLTOUTHandlerEquId
96 : * can be used directly.
97 : *
98 : * Secondly, the AliHLTModuleAgent implementation of the module has to create
99 : * the handler for the data blocks. Depending on the data type and specification,
100 : * the the following interface methods return handler description and handler.
101 : * <pre>
102 : * int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType dt,
103 : * AliHLTUInt32_t spec,
104 : * AliHLTOUTHandlerDesc& desc) const;
105 : *
106 : * AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType dt,
107 : * AliHLTUInt32_t spec);
108 : * </pre>
109 : * See section @ref tut_alirawreaderhlt for sample implementation.
110 : *
111 : * @ingroup alihlt_aliroot_reconstruction
112 : */
113 : class AliRawReaderHLT : public AliRawReader {
114 : public:
115 : /** constructor */
116 : AliRawReaderHLT(AliRawReader* pParentReader, const char* options=NULL);
117 : /** destructor */
118 : virtual ~AliRawReaderHLT();
119 :
120 : // interface methods of AliRawReader
121 : void Select(Int_t detectorID,
122 : Int_t minDDLID = -1, Int_t maxDDLID = -1);
123 : // void Select(const char *detectorName,
124 : // Int_t minDDLID = -1, Int_t maxDDLID = -1);
125 :
126 : using AliRawReader::Select;
127 :
128 : void SelectEquipment(Int_t equipmentType,
129 : Int_t minEquipmentId = -1,
130 : Int_t maxEquipmentId = -1);
131 : void SkipInvalid(Bool_t skip = kTRUE);
132 : // void SelectEvents(Int_t type);
133 :
134 : UInt_t GetType() const;
135 : UInt_t GetRunNumber() const;
136 : const UInt_t* GetEventId() const;
137 : const UInt_t* GetTriggerPattern() const;
138 : const UInt_t* GetDetectorPattern() const;
139 : const UInt_t* GetAttributes() const;
140 : const UInt_t* GetSubEventAttributes() const;
141 : UInt_t GetLDCId() const;
142 : UInt_t GetGDCId() const;
143 : UInt_t GetTimestamp() const;
144 :
145 : const UInt_t* GetEquipmentAttributes() const;
146 : Int_t GetEquipmentElementSize() const;
147 : Int_t GetEquipmentHeaderSize() const;
148 :
149 : Int_t GetEquipmentSize() const;
150 : Int_t GetEquipmentType() const;
151 : Int_t GetEquipmentId() const;
152 : Bool_t ReadHeader();
153 : Bool_t ReadNextData(UChar_t*& data);
154 : Bool_t ReadNextInt(UInt_t& data);
155 : Bool_t ReadNextShort(UShort_t& data);
156 : Bool_t ReadNextChar(UChar_t& data);
157 : Bool_t ReadNext(UChar_t* data, Int_t size);
158 :
159 : Bool_t Reset();
160 :
161 : Bool_t NextEvent();
162 : Bool_t RewindEvents();
163 :
164 : protected:
165 :
166 : private:
167 : /** standard constructor prohibited */
168 : AliRawReaderHLT();
169 : /** copy constructor prohibited */
170 : AliRawReaderHLT(const AliRawReaderHLT&);
171 : /** assignment operator prohibited */
172 : AliRawReaderHLT& operator=(const AliRawReaderHLT&);
173 :
174 : /**
175 : * Scan the options.
176 : * Set the ids for the specified detectors in the detector
177 : * list. Currently, no other options are available.
178 : */
179 : int ScanOptions(const char* options);
180 :
181 : /**
182 : * Read the next data block from the HLT stream
183 : */
184 : Bool_t ReadNextHLTData();
185 :
186 : /**
187 : * Check if a ddlid is part of the ones which are selected for
188 : * input replacement.
189 : */
190 : Bool_t IsHLTInput(int ddlid);
191 :
192 : /**
193 : * Check if redirection is enabled for at least one detector in the
194 : * selected range.
195 : * Set the fbHaveHLTData variable
196 : * @return true if data has to be read from the HLT stream.
197 : */
198 : Bool_t EvaluateSelection();
199 :
200 : /**
201 : * Release the current HLT data.
202 : * Releases the current buffer of either the active HLTOUT data
203 : * block handler or the HLTOUT instance. The latter implies a
204 : * reset of the reader concerning the HLT data blocks.
205 : * @param bReleaseHLTOUT release HLTOUT instance if \em true
206 : * only current data buffer if \em false
207 : * @return neg. error code if failed
208 : */
209 : int ReleaseHLTData(bool bReleaseHLTOUT=true);
210 :
211 : /**
212 : * Backbone of all Read functions.
213 : * Reads the next data into the internal buffer and switches to next
214 : * block if enabled.
215 : *
216 : * @param data target to receive pointer
217 : * @param readHeader kTRUE: switch to next block if no more data
218 : */
219 : Bool_t ReadNextData(UChar_t*& data, Bool_t readHeader);
220 :
221 : /** the rawreader */
222 : AliRawReader* fpParentReader; //!transient
223 :
224 : /** options */
225 : TString fOptions; //!transient
226 :
227 : /** system options = options w/o detector strings */
228 : TString fSystemOptions; //!transient
229 :
230 : /** current data set, either extracted from the HLT stream or parent raw reader */
231 : const AliHLTUInt8_t* fpData; // !transient
232 :
233 : /** size of the current data set */
234 : int fDataSize; // !transient
235 :
236 : /** current stream offset for reading from input stream */
237 : int fOffset; // !transient
238 :
239 : /** current stream position for block input ReadNextData function */
240 : int fPosition; // !transient
241 :
242 : /** equipment id of the current data set, >0 indicates data set from HLT stream */
243 : int fEquipmentId; // !transient
244 :
245 : /** indicates the availibility of data from the HLT stream */
246 : bool fbHaveHLTData; // !transient
247 :
248 : /** list of detectors for which data will be taken from HLT stream */
249 : vector<int> fDetectors; // !transient
250 :
251 : /** instance of the HLTOUT handler */
252 : AliHLTOUT* fpHLTOUT; // !transient
253 :
254 : /** start reading HLTOUT from beginning */
255 : bool fbReadFirst; //!transient
256 :
257 : /** instance of the data handler providing the current data buffer */
258 : AliHLTOUTHandler* fpDataHandler; // !transient
259 :
260 : /** base class for AliRoot HLT plugins */
261 : AliHLTPluginBase* fpPluginBase; //!transient
262 :
263 6 : ClassDef(AliRawReaderHLT, 0)
264 : };
265 :
266 : #define ALIHLTREC_LIBRARY "libHLTrec.so"
267 : #define ALIHLTREC_LIBRARY_VERSION 0
268 : #define ALIRAWREADERHLT_CREATE_INSTANCE "AliRawReaderHLTCreateInstance"
269 :
270 : #ifdef __cplusplus
271 : extern "C" {
272 : #endif
273 : typedef AliRawReader* (*AliRawReaderHLTCreateInstance_t)(AliRawReader* pParentReader, const char* options);
274 :
275 : /**
276 : * Create an instance of the AliRawReader class
277 : */
278 : AliRawReader* AliRawReaderHLTCreateInstance(AliRawReader* pParentReader, const char* options);
279 : #ifdef __cplusplus
280 : }
281 : #endif
282 : #endif
|