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 // see below for class documentation
18 // refer to README to build package
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
22 #include "AliHLTDataTypes.h"
23 #include "AliRawReader.h" // RAW, base class
28 class AliHLTOUTHandler;
29 class AliHLTPluginBase;
32 * @class AliRawReaderHLT
33 * A specific AliRawReader for detector input replacement by HLTOUT data blocks.
35 * HLT components can produce output data in the detector ddl raw format.
36 * Data blocks of this format can be fed into the normal detector reconstruction
37 * without changes in the actual reconstruction code by means of the
38 * AliRawReaderHLT implementation of the AliRawReader.
40 * @section sec_alirawreaderhlt_concept Conceptual design
41 * The AliRawReader provides an abstract interface to the ddl raw data. All
42 * reconstruction code uses this interface to access the data.
43 * HLT components can send their data in the original ddl raw format. The only
44 * difference of such data blocks is the location since they are shipped as
45 * part of the HLTOUT data stream. The AliRawReaderHLT provides redirection of
48 * The AliRawReaderHLT needs the original AliRawReader in order to get the
49 * data. Furthermore, a string containing the detector specification defines
50 * which data should be read from the HLT stream and which from the original
53 * @note An HLTOUT handler must be available for the HLTOUT data blocks to
54 * be redirected. Please read @ref sec_alirawreaderhlt_module carefully.
56 * @section sec_alirawreaderhlt_usage Selection of the HLTOUT data stream
57 * The input data of a detector can be replaced by the corresponding HLT
58 * data by calling the <tt>AliReconstruction::SetUseHLTData("...")</tt>, e.g.
60 * AliReconstruction rec;
61 * rec.SetUseHLTData("TPC TRD");
63 * will replace the input of TPC and TRD.
65 * The reader can be used directly. In order to avoid library dependencies
66 * downwards, the methed AliRawHLTManager::CreateRawReaderHLT is available
70 * AliRawReader* orgReader=AliRawReader::Create("raw.root");
71 * AliRawReader* rawreader=AliRawHLTManager::CreateRawReaderHLT(orgReader, "ITSSDD");
72 * rawreader->Select("ITSSDD");
74 * while (rawreader->NextEvent()) {
75 * cout << "scanning event " << count++ << endl;
77 * while (rawreader->ReadNextData(pSrc)) {
78 * cout << " equipment: " << rawreader->GetEquipmentId() << endl;
84 * @section sec_alirawreaderhlt_detectorids Detector selection
85 * The constructor gets a detector selection string as parameter and initializes
86 * the redirection according to that. Detector Ids are according to AliDAQ.
87 * Please note the special strings for for ITS and MUON sub-detectors, ITSSPD,
88 * ITSSDD, ITSSSD, and MUONTRK and MUONTRG respectively.
90 * @section sec_alirawreaderhlt_module Module implementation
91 * In order to determine the equipment id for the data block, the HLT module
92 * must implement an HLTOUT handler of class AliHLTOUTHandlerEquId which is of
93 * type @ref AliHLTModuleAgent::AliHLTOUTHandlerType ::kRawReader.
94 * The handler must implement the method
96 * // AliHLTOUTHandlerEquId::ProcessData(AliHLTOUT*)
97 * virtual int ProcessData(AliHLTOUT* pData);
99 * which returns the equipment id and eventually decodes data to be retrieved
100 * by calling AliHLTOUTHandler::GetProcessedData(). If the equipment id of the
101 * DDL has been sent as data specification of the block, the AliHLTOUTHandlerEquId
102 * can be used directly.
104 * Secondly, the AliHLTModuleAgent implementation of the module has to create
105 * the handler for the data blocks. Depending on the data type and specification,
106 * the the following interface methods return handler description and handler.
108 * int AliHLTModuleAgent::GetHandlerDescription(AliHLTComponentDataType dt,
109 * AliHLTUInt32_t spec,
110 * AliHLTOUTHandlerDesc& desc) const;
112 * AliHLTOUTHandler* AliHLTModuleAgent::GetOutputHandler(AliHLTComponentDataType dt,
113 * AliHLTUInt32_t spec);
115 * See section @ref tut_alirawreaderhlt for sample implementation.
117 * @ingroup alihlt_aliroot_reconstruction
119 class AliRawReaderHLT : public AliRawReader {
122 AliRawReaderHLT(AliRawReader* pParentReader, const char* options=NULL);
124 virtual ~AliRawReaderHLT();
126 // interface methods of AliRawReader
127 void Select(Int_t detectorID,
128 Int_t minDDLID = -1, Int_t maxDDLID = -1);
129 // void Select(const char *detectorName,
130 // Int_t minDDLID = -1, Int_t maxDDLID = -1);
132 using AliRawReader::Select;
134 void SelectEquipment(Int_t equipmentType,
135 Int_t minEquipmentId = -1,
136 Int_t maxEquipmentId = -1);
137 void SkipInvalid(Bool_t skip = kTRUE);
138 // void SelectEvents(Int_t type);
140 UInt_t GetType() const;
141 UInt_t GetRunNumber() const;
142 const UInt_t* GetEventId() const;
143 const UInt_t* GetTriggerPattern() const;
144 const UInt_t* GetDetectorPattern() const;
145 const UInt_t* GetAttributes() const;
146 const UInt_t* GetSubEventAttributes() const;
147 UInt_t GetLDCId() const;
148 UInt_t GetGDCId() const;
149 UInt_t GetTimestamp() const;
151 const UInt_t* GetEquipmentAttributes() const;
152 Int_t GetEquipmentElementSize() const;
153 Int_t GetEquipmentHeaderSize() const;
155 Int_t GetEquipmentSize() const;
156 Int_t GetEquipmentType() const;
157 Int_t GetEquipmentId() const;
159 Bool_t ReadNextData(UChar_t*& data);
160 Bool_t ReadNextInt(UInt_t& data);
161 Bool_t ReadNextShort(UShort_t& data);
162 Bool_t ReadNextChar(UChar_t& data);
163 Bool_t ReadNext(UChar_t* data, Int_t size);
168 Bool_t RewindEvents();
173 /** standard constructor prohibited */
175 /** copy constructor prohibited */
176 AliRawReaderHLT(const AliRawReaderHLT&);
177 /** assignment operator prohibited */
178 AliRawReaderHLT& operator=(const AliRawReaderHLT&);
182 * Set the ids for the specified detectors in the detector
183 * list. Currently, no other options are available.
185 int ScanOptions(const char* options);
188 * Read the next data block from the HLT stream
190 Bool_t ReadNextHLTData();
193 * Check if a ddlid is part of the ones which are selected for
196 Bool_t IsHLTInput(int ddlid);
199 * Check if redirection is enabled for at least one detector in the
201 * Set the fbHaveHLTData variable
202 * @return true if data has to be read from the HLT stream.
204 Bool_t EvaluateSelection();
207 * Release the current HLT data.
208 * Releases the current buffer of either the active HLTOUT data
209 * block handler or the HLTOUT instance. The latter implies a
210 * reset of the reader concerning the HLT data blocks.
211 * @param bReleaseHLTOUT release HLTOUT instance if \em true
212 * only current data buffer if \em false
213 * @return neg. error code if failed
215 int ReleaseHLTData(bool bReleaseHLTOUT=true);
218 * Backbone of all Read functions.
219 * Reads the next data into the internal buffer and switches to next
222 * @param data target to receive pointer
223 * @param readHeader kTRUE: switch to next block if no more data
225 Bool_t ReadNextData(UChar_t*& data, Bool_t readHeader);
228 AliRawReader* fpParentReader; //!transient
231 TString fOptions; //!transient
233 /** system options = options w/o detector strings */
234 TString fSystemOptions; //!transient
236 /** current data set, either extracted from the HLT stream or parent raw reader */
237 const AliHLTUInt8_t* fpData; // !transient
239 /** size of the current data set */
240 int fDataSize; // !transient
242 /** current stream offset in the data set */
243 int fOffset; // !transient
245 /** current stream position for the ReadNextData function */
246 int fPosition; // !transient
248 /** equipment id of the current data set, >0 indicates data set from HLT stream */
249 int fEquipmentId; // !transient
251 /** indicates the availibility of data from the HLT stream */
252 bool fbHaveHLTData; // !transient
254 /** list of detectors for which data will be taken from HLT stream */
255 vector<int> fDetectors; // !transient
257 /** instance of the HLTOUT handler */
258 AliHLTOUT* fpHLTOUT; // !transient
260 /** start reading HLTOUT from beginning */
261 bool fbReadFirst; //!transient
263 /** instance of the data handler providing the current data buffer */
264 AliHLTOUTHandler* fpDataHandler; // !transient
266 /** base class for AliRoot HLT plugins */
267 AliHLTPluginBase* fpPluginBase; //!transient
269 ClassDef(AliRawReaderHLT, 5)
272 #define ALIHLTREC_LIBRARY "libHLTrec.so"
273 #define ALIHLTREC_LIBRARY_VERSION 0
274 #define ALIRAWREADERHLT_CREATE_INSTANCE "AliRawReaderHLTCreateInstance"
279 typedef AliRawReader* (*AliRawReaderHLTCreateInstance_t)(AliRawReader* pParentReader, const char* options);
282 * Create an instance of the AliRawReader class
284 AliRawReader* AliRawReaderHLTCreateInstance(AliRawReader* pParentReader, const char* options);