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 AliHLTOUTHandlerEsdBranch.cxx
20 /// @author Matthias Richter
22 /// @brief HLTOUT handler of type kEsd to merge objects into the hltEsd.
24 #include "AliHLTOUTHandlerEsdBranch.h"
25 #include "AliHLTOUT.h"
26 #include "AliHLTMessage.h"
27 #include "AliHLTErrorGuard.h"
28 #include "AliESDEvent.h"
30 #include "TObjString.h"
31 #include "TObjArray.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTOUTHandlerEsdBranch)
38 AliHLTOUTHandlerEsdBranch::AliHLTOUTHandlerEsdBranch(const char* branchname)
45 // see header file for class documentation
47 // refer to README to build package
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 AliHLTOUTHandlerEsdBranch::~AliHLTOUTHandlerEsdBranch()
54 // see header file for class documentation
57 int AliHLTOUTHandlerEsdBranch::ProcessData(AliHLTOUT* pData)
59 // see header file for class documentation
60 if (!pData) return -EINVAL;
63 if (CheckStatus(kHandlerError)) {
64 HLTWarning("kEsd handler for ESD branch '%s' in error state, skipping processing of associated HLTOUT blocks", fBranch.Data());
69 // create the ESD container, but without std content
70 fESD = new AliESDEvent;
72 if (!fpData) fpData=new TArrayC;
75 iResult=ExtractAndAddObjects(pData);
78 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
80 if (!pMsg->CompBuffer()) {
82 fpData->Set(fSize, pMsg->Buffer());
84 fSize=pMsg->CompLength();
85 fpData->Set(fSize, pMsg->CompBuffer());
90 HLTError("streaming of object failed");
96 int AliHLTOUTHandlerEsdBranch::ExtractAndAddObjects(AliHLTOUT* pData)
99 // Extract streamed object from the HLTOUT and add to ESD
100 // The default method works only for single blocks in the HLTOUT,
101 // A specific child class is required if multiple blocks should be
105 iResult=pData->SelectFirstDataBlock();
106 if (iResult<0) return iResult;
108 TObject* pObject=pData->GetDataObject();
110 TString bname=fBranch;
111 if (bname.IsNull()) {
112 bname=pObject->GetName();
113 if (bname.CompareTo(pObject->ClassName())==0) {
114 ALIHLTERRORGUARD(5, "no branch name specified for unnamed object %s, not added to ESD", bname.Data());
118 if (!bname.IsNull()) {
119 iResult=Add(pObject, bname.Data());
123 pData->ReleaseDataObject(pObject);
126 AliHLTComponentDataType dt=kAliHLTVoidDataType;
127 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
128 pData->GetDataBlockDescription(dt, spec);
129 HLTError("Can not get TObject from HLTOUT buffer for block %s 0x%x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
133 if (pData->SelectNextDataBlock()>=0) {
134 ALIHLTERRORGUARD(5, "the default function can only handle one single data block/object");
140 int AliHLTOUTHandlerEsdBranch::Add(TObject* object, const char* branchname)
142 // add object to the specified branch in the internal ESD
143 if (fESD && object) {
144 TObject* pESDObject=fESD->FindListObject(branchname);
146 // copy the content to the already existing object
147 object->Copy(*pESDObject);
150 fESD->AddObject(object->Clone());
156 int AliHLTOUTHandlerEsdBranch::GetProcessedData(const AliHLTUInt8_t* &pData)
158 // see header file for class documentation
164 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
168 int AliHLTOUTHandlerEsdBranch::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
170 // see header file for class documentation
172 if (!fpData || size != fSize ||
173 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
174 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);