3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTOUTRawReader.cxx
20 @author Matthias Richter
22 @brief HLTOUT data wrapper for AliRawReader. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30 #include "AliHLTOUTRawReader.h"
31 #include "AliHLTHOMERLibManager.h"
32 #include "AliRawReader.h"
33 #include "AliHLTHOMERReader.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTOUTRawReader)
38 AliHLTOUTRawReader::AliHLTOUTRawReader(AliRawReader* pRawreader)
40 AliHLTOUTHomerBuffer(NULL, 0),
41 fpRawreader(pRawreader),
44 // see header file for class documentation
46 // refer to README to build package
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
51 const int AliHLTOUTRawReader::fgkIdShift=16;
53 AliHLTOUTRawReader::~AliHLTOUTRawReader()
55 // see header file for class documentation
57 if (fpCurrent) fpManager->DeleteReader(fpCurrent);
62 int AliHLTOUTRawReader::GenerateIndex()
64 // see header file for class documentation
65 // step through all HLT ddls, create HOMER readers and
68 if (fpRawreader && fpManager) {
70 // there was a bug in AliDAQ returning the wrong equipment id
71 // for the HLT links. It has been fixed in the trunk on Feb 5th 2008
72 // and from v4-10-Release (Rev-02). For the moment we select directly
73 // to support older AliRoot versions
74 //fpRawreader->Select("HLT");
75 fpRawreader->SelectEquipment(0,7680, 7689);
77 while (fpRawreader->ReadNextData(pSrc) && pSrc!=NULL && iResult>=0) {
78 AliHLTUInt32_t id=(fpRawreader->GetEquipmentId());
79 unsigned int size=fpRawreader->GetDataSize();
81 AliHLTHOMERReader* pReader=OpenReader(pSrc, size);
83 // we use the equipment id to identify the different homer blocks
86 iResult=ScanReader(pReader, id);
87 fpManager->DeleteReader(pReader);
96 int AliHLTOUTRawReader::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
99 // see header file for class documentation
104 Int_t id = Int_t(index>>fgkIdShift);
105 AliHLTUInt32_t blockNo=index&((0x1<<fgkIdShift)-1);
107 // block from the same ddl requested?
108 if (fpCurrent && fpRawreader->GetEquipmentId()!=id) {
109 fpManager->DeleteReader(fpCurrent);
113 // open ddl for equipment id and create HOMER reader
115 fpRawreader->Reset();
116 fpRawreader->SelectEquipment(-1, id, id);
118 if (fpRawreader->ReadNextData(pSrc) && pSrc!=NULL) {
119 int srcSize=fpRawreader->GetDataSize();
120 fpCurrent=OpenReader(pSrc, srcSize);
121 if (fpCurrent && fpCurrent->ReadNextEvent()!=0) {
131 AliHLTMonitoringReader* pReader=fpCurrent;
132 if ((pBuffer=static_cast<const AliHLTUInt8_t*>(pReader->GetBlockData(blockNo)))!=NULL) {
133 size=pReader->GetBlockDataLength(blockNo);
144 AliHLTHOMERReader* AliHLTOUTRawReader::OpenReader(UChar_t* pSrc, unsigned int size)
146 // see header file for class documentation
147 unsigned int offset=sizeof(AliHLTOUTEventHeader);
148 const AliRawDataHeader* pCDH=fpRawreader->GetDataHeader();
149 AliHLTUInt32_t id=(fpRawreader->GetEquipmentId());
150 AliHLTUInt32_t statusFlags=pCDH->GetStatus();
151 AliHLTOUTEventHeader* pHLTHeader=reinterpret_cast<AliHLTOUTEventHeader*>(pSrc);
153 // consistency check for the block size
154 if (pHLTHeader->fLength!=size) {
155 HLTWarning("can not treat HLT data block %d: size missmatch, header %d, but buffer is %d", id, pHLTHeader->fLength, size);
159 // determine the offset of the homer block
160 // the HLT header is mandatory, HLT decision and HLT
161 // payload are optional. HLT decision is always before HLT
162 // payload if existent.
163 if (statusFlags&(0x1<<kCDHFlagsHLTDecision)) {
164 // the block contains HLT decision data, this is just
166 AliHLTUInt32_t* pDecisionLen=reinterpret_cast<AliHLTUInt32_t*>(pSrc+offset);
167 if ((*pDecisionLen)*sizeof(AliHLTUInt32_t)+offset<size) {
168 // the first 32bit word specifies the number of 32bit words in the
169 // decision block -> +1 for this length word
170 offset+=((*pDecisionLen)+1)*sizeof(AliHLTUInt32_t);
172 HLTWarning("size missmatch: HLT decision block bigger than total block length, skipping ...");
177 // check if there is payload
178 if (!(statusFlags&(0x1<<kCDHFlagsHLTPayload))) return NULL;
180 // continue if there is no data left in the buffer
182 HLTWarning("no HLT payload available, but bit is set, skipping ...");
186 // check for the HOME descriptor type id
187 AliHLTUInt64_t* pHomerDesc=reinterpret_cast<AliHLTUInt64_t*>(pSrc+offset);
188 if (*(pHomerDesc+kID_64b_Offset) != HOMER_BLOCK_DESCRIPTOR_TYPEID &&
189 ByteSwap64(*(pHomerDesc+kID_64b_Offset)) != HOMER_BLOCK_DESCRIPTOR_TYPEID) {
190 HLTWarning("format error: can not find HOMER block descriptor typid, skipping this data block");
194 return fpManager->OpenReaderBuffer(pSrc+offset, size-offset);