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 *
10 /// @file AliRawReaderHLT.h
11 /// @author Matthias Richter
13 /// @brief AliRawReader implementation which replaces original input of
14 /// detectors with the appropriate HLT output.
16 #include "AliHLTDataTypes.h"
17 #include "AliRawReader.h" // RAW, base class
22 class AliHLTOUTHandler;
23 class AliHLTPluginBase;
26 * @class AliRawReaderHLT
27 * A specific AliRawReader for detector input replacement by HLTOUT data blocks.
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.
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
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
47 * @note An HLTOUT handler must be available for the HLTOUT data blocks to
48 * be redirected. Please read @ref sec_alirawreaderhlt_module carefully.
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.
54 * AliReconstruction rec;
55 * rec.SetUseHLTData("TPC TRD");
57 * will replace the input of TPC and TRD.
59 * The reader can be used directly. In order to avoid library dependencies
60 * downwards, the methed AliRawHLTManager::CreateRawReaderHLT is available
64 * AliRawReader* orgReader=AliRawReader::Create("raw.root");
65 * AliRawReader* rawreader=AliRawHLTManager::CreateRawReaderHLT(orgReader, "ITSSDD");
66 * rawreader->Select("ITSSDD");
68 * while (rawreader->NextEvent()) {
69 * cout << "scanning event " << count++ << endl;
71 * while (rawreader->ReadNextData(pSrc)) {
72 * cout << " equipment: " << rawreader->GetEquipmentId() << endl;
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.
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
90 * // AliHLTOUTHandlerEquId::ProcessData(AliHLTOUT*)
91 * virtual int ProcessData(AliHLTOUT* pData);
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.
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.
102 * int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType dt,
103 * AliHLTUInt32_t spec,
104 * AliHLTOUTHandlerDesc& desc) const;
106 * AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType dt,
107 * AliHLTUInt32_t spec);
109 * See section @ref tut_alirawreaderhlt for sample implementation.
111 * @ingroup alihlt_aliroot_reconstruction
113 class AliRawReaderHLT : public AliRawReader {
116 AliRawReaderHLT(AliRawReader* pParentReader, const char* options=NULL);
118 virtual ~AliRawReaderHLT();
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);
126 using AliRawReader::Select;
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);
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;
145 const UInt_t* GetEquipmentAttributes() const;
146 Int_t GetEquipmentElementSize() const;
147 Int_t GetEquipmentHeaderSize() const;
149 Int_t GetEquipmentSize() const;
150 Int_t GetEquipmentType() const;
151 Int_t GetEquipmentId() const;
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);
162 Bool_t RewindEvents();
167 /** standard constructor prohibited */
169 /** copy constructor prohibited */
170 AliRawReaderHLT(const AliRawReaderHLT&);
171 /** assignment operator prohibited */
172 AliRawReaderHLT& operator=(const AliRawReaderHLT&);
176 * Set the ids for the specified detectors in the detector
177 * list. Currently, no other options are available.
179 int ScanOptions(const char* options);
182 * Read the next data block from the HLT stream
184 Bool_t ReadNextHLTData();
187 * Check if a ddlid is part of the ones which are selected for
190 Bool_t IsHLTInput(int ddlid);
193 * Check if redirection is enabled for at least one detector in the
195 * Set the fbHaveHLTData variable
196 * @return true if data has to be read from the HLT stream.
198 Bool_t EvaluateSelection();
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
209 int ReleaseHLTData(bool bReleaseHLTOUT=true);
212 * Backbone of all Read functions.
213 * Reads the next data into the internal buffer and switches to next
216 * @param data target to receive pointer
217 * @param readHeader kTRUE: switch to next block if no more data
219 Bool_t ReadNextData(UChar_t*& data, Bool_t readHeader);
222 AliRawReader* fpParentReader; //!transient
225 TString fOptions; //!transient
227 /** system options = options w/o detector strings */
228 TString fSystemOptions; //!transient
230 /** current data set, either extracted from the HLT stream or parent raw reader */
231 const AliHLTUInt8_t* fpData; // !transient
233 /** size of the current data set */
234 int fDataSize; // !transient
236 /** current stream offset for reading from input stream */
237 int fOffset; // !transient
239 /** current stream position for block input ReadNextData function */
240 int fPosition; // !transient
242 /** equipment id of the current data set, >0 indicates data set from HLT stream */
243 int fEquipmentId; // !transient
245 /** indicates the availibility of data from the HLT stream */
246 bool fbHaveHLTData; // !transient
248 /** list of detectors for which data will be taken from HLT stream */
249 vector<int> fDetectors; // !transient
251 /** instance of the HLTOUT handler */
252 AliHLTOUT* fpHLTOUT; // !transient
254 /** start reading HLTOUT from beginning */
255 bool fbReadFirst; //!transient
257 /** instance of the data handler providing the current data buffer */
258 AliHLTOUTHandler* fpDataHandler; // !transient
260 /** base class for AliRoot HLT plugins */
261 AliHLTPluginBase* fpPluginBase; //!transient
263 ClassDef(AliRawReaderHLT, 0)
266 #define ALIHLTREC_LIBRARY "libHLTrec.so"
267 #define ALIHLTREC_LIBRARY_VERSION 0
268 #define ALIRAWREADERHLT_CREATE_INSTANCE "AliRawReaderHLTCreateInstance"
273 typedef AliRawReader* (*AliRawReaderHLTCreateInstance_t)(AliRawReader* pParentReader, const char* options);
276 * Create an instance of the AliRawReader class
278 AliRawReader* AliRawReaderHLTCreateInstance(AliRawReader* pParentReader, const char* options);