3 //**************************************************************************
4 //* This file is property of and copyright by the *
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 // The handler extracts objects from HLTOUT data blocks or converts
49 // data to objects to be added to hltEsd branches. The default implementation
50 // covers the first case right away, the class can be used directly for single
51 // objects streamed to the HLTOUT.
53 // The handler produces a partial ESD containing the data objects. The framework
54 // merges all the different partial ESDs in the AliHLTEsdManager, respectively the
55 // specific implementation AliHLTEsdManagerImplementation.
58 AliHLTOUTHandlerEsdBranch::~AliHLTOUTHandlerEsdBranch()
61 if (fESD) fManager->DestroyEsdEvent(fESD);
63 if (fpData) delete fpData;
65 if (fManager) AliHLTEsdManager::Delete(fManager);
69 int AliHLTOUTHandlerEsdBranch::ProcessData(AliHLTOUT* pData)
71 // data processing function
72 if (!pData) return -EINVAL;
75 if (CheckStatus(kHandlerError)) {
76 HLTWarning("kEsd handler for ESD branch '%s' in error state, skipping processing of associated HLTOUT blocks", fBranch.Data());
81 fManager=AliHLTMisc::LoadInstance((AliHLTEsdManager*)NULL, "AliHLTEsdManagerImplementation", "libHLTrec.so");
85 AliHLTComponentDataType dt=kAliHLTVoidDataType;
86 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
87 if (pData->SelectFirstDataBlock()>=0) {
88 pData->GetDataBlockDescription(dt, spec);
89 ALIHLTERRORGUARD(1, "failed to create AliHLTEsdManagerImplementation object, skipping handling of HLTOUT data %s 0x%80x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
95 // create the ESD container, but without std content
96 fESD = fManager->CreateEsdEvent();
98 if (!fpData) fpData=new TArrayC;
100 fManager->ResetEsdEvent(fESD);
101 iResult=ExtractAndAddObjects(pData);
104 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
106 if (!pMsg->CompBuffer()) {
107 fSize=pMsg->Length();
108 fpData->Set(fSize, pMsg->Buffer());
110 fSize=pMsg->CompLength();
111 fpData->Set(fSize, pMsg->CompBuffer());
116 HLTError("streaming of object failed");
122 int AliHLTOUTHandlerEsdBranch::ExtractAndAddObjects(AliHLTOUT* pData)
125 // Extract streamed object from the HLTOUT and add to ESD
126 // The default method works only for single blocks in the HLTOUT,
127 // A specific child class is required if multiple blocks should be
130 if (!fESD || !fManager) return -ENOSYS;
132 iResult=pData->SelectFirstDataBlock();
133 if (iResult<0) return iResult;
135 TObject* pObject=pData->GetDataObject();
137 TString bname=fBranch;
138 if (bname.IsNull()) {
139 bname=pObject->GetName();
140 if (bname.CompareTo(pObject->ClassName())==0) {
141 ALIHLTERRORGUARD(5, "no branch name specified for unnamed object %s, not added to ESD", bname.Data());
145 if (!bname.IsNull()) {
146 iResult=fManager->AddObject(fESD, pObject, bname.Data());
150 pData->ReleaseDataObject(pObject);
153 AliHLTComponentDataType dt=kAliHLTVoidDataType;
154 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
155 pData->GetDataBlockDescription(dt, spec);
156 HLTError("Can not get TObject from HLTOUT buffer for block %s 0x%x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
160 if (pData->SelectNextDataBlock()>=0) {
161 ALIHLTERRORGUARD(5, "the default function can only handle one single data block/object");
167 int AliHLTOUTHandlerEsdBranch::GetProcessedData(const AliHLTUInt8_t* &pData)
169 // get processed data
175 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
179 int AliHLTOUTHandlerEsdBranch::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
181 // release pointer instance
183 if (!fpData || size != fSize ||
184 const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
185 HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);