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 "AliHLTEsdManager.h"
29 #include "AliHLTComponent.h" // DataType2Text
30 #include "AliHLTMisc.h"
32 #include "TObjString.h"
33 #include "TObjArray.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTOUTHandlerEsdBranch)
40 AliHLTOUTHandlerEsdBranch::AliHLTOUTHandlerEsdBranch(const char* branchname)
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 AliHLTOUTHandlerEsdBranch::~AliHLTOUTHandlerEsdBranch()
57 // see header file for class documentation
58 if (fESD) fManager->DestroyEsdEvent(fESD);
60 if (fpData) delete fpData;
62 if (fManager) AliHLTEsdManager::Delete(fManager);
66 int AliHLTOUTHandlerEsdBranch::ProcessData(AliHLTOUT* pData)
68 // see header file for class documentation
69 if (!pData) return -EINVAL;
72 if (CheckStatus(kHandlerError)) {
73 HLTWarning("kEsd handler for ESD branch '%s' in error state, skipping processing of associated HLTOUT blocks", fBranch.Data());
78 fManager=AliHLTMisc::LoadInstance((AliHLTEsdManager*)NULL, "AliHLTEsdManagerImplementation", "libHLTrec.so");
82 AliHLTComponentDataType dt=kAliHLTVoidDataType;
83 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
84 if (pData->SelectFirstDataBlock()>=0) {
85 pData->GetDataBlockDescription(dt, spec);
86 ALIHLTERRORGUARD(1, "failed to create AliHLTEsdManagerImplementation object, skipping handling of HLTOUT data %s 0x%80x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
92 // create the ESD container, but without std content
93 fESD = fManager->CreateEsdEvent();
95 if (!fpData) fpData=new TArrayC;
97 fManager->ResetEsdEvent(fESD);
98 iResult=ExtractAndAddObjects(pData);
101 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
103 if (!pMsg->CompBuffer()) {
104 fSize=pMsg->Length();
105 fpData->Set(fSize, pMsg->Buffer());
107 fSize=pMsg->CompLength();
108 fpData->Set(fSize, pMsg->CompBuffer());
113 HLTError("streaming of object failed");
119 int AliHLTOUTHandlerEsdBranch::ExtractAndAddObjects(AliHLTOUT* pData)
122 // Extract streamed object from the HLTOUT and add to ESD
123 // The default method works only for single blocks in the HLTOUT,
124 // A specific child class is required if multiple blocks should be
127 if (!fESD || !fManager) return -ENOSYS;
129 iResult=pData->SelectFirstDataBlock();
130 if (iResult<0) return iResult;
132 TObject* pObject=pData->GetDataObject();
134 TString bname=fBranch;
135 if (bname.IsNull()) {
136 bname=pObject->GetName();
137 if (bname.CompareTo(pObject->ClassName())==0) {
138 ALIHLTERRORGUARD(5, "no branch name specified for unnamed object %s, not added to ESD", bname.Data());
142 if (!bname.IsNull()) {
143 iResult=fManager->AddObject(fESD, pObject, bname.Data());
147 pData->ReleaseDataObject(pObject);
150 AliHLTComponentDataType dt=kAliHLTVoidDataType;
151 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
152 pData->GetDataBlockDescription(dt, spec);
153 HLTError("Can not get TObject from HLTOUT buffer for block %s 0x%x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
157 if (pData->SelectNextDataBlock()>=0) {
158 ALIHLTERRORGUARD(5, "the default function can only handle one single data block/object");
164 int AliHLTOUTHandlerEsdBranch::GetProcessedData(const AliHLTUInt8_t* &pData)
166 // see header file for class documentation
172 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
176 int AliHLTOUTHandlerEsdBranch::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
178 // see header file for class documentation
180 if (!fpData || size != fSize ||
181 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
182 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);