]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUTHandlerEsdBranch.cxx
Why the h*ll do we make a remote commit when pulling?
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHandlerEsdBranch.cxx
CommitLineData
bbad69c8 1// $Id$
2
3//**************************************************************************
2dfe97e6 4//* This file is property of and copyright by the *
bbad69c8 5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
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//**************************************************************************
18
19/// @file AliHLTOUTHandlerEsdBranch.cxx
20/// @author Matthias Richter
21/// @date 01.07.2010
22/// @brief HLTOUT handler of type kEsd to merge objects into the hltEsd.
23
24#include "AliHLTOUTHandlerEsdBranch.h"
25#include "AliHLTOUT.h"
26#include "AliHLTMessage.h"
27#include "AliHLTErrorGuard.h"
1bd2ee2f 28#include "AliHLTEsdManager.h"
29#include "AliHLTComponent.h" // DataType2Text
30#include "AliHLTMisc.h"
bbad69c8 31#include "TString.h"
32#include "TObjString.h"
33#include "TObjArray.h"
34#include "TArrayC.h"
35#include <cassert>
36
37/** ROOT macro for the implementation of ROOT specific class methods */
38ClassImp(AliHLTOUTHandlerEsdBranch)
39
40AliHLTOUTHandlerEsdBranch::AliHLTOUTHandlerEsdBranch(const char* branchname)
41 : AliHLTOUTHandler()
42 , fBranch(branchname)
43 , fESD(NULL)
44 , fpData(NULL)
45 , fSize(0)
1bd2ee2f 46 , fManager(NULL)
bbad69c8 47{
2dfe97e6 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.
52 //
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.
bbad69c8 56}
57
58AliHLTOUTHandlerEsdBranch::~AliHLTOUTHandlerEsdBranch()
59{
2dfe97e6 60 // destructor
1bd2ee2f 61 if (fESD) fManager->DestroyEsdEvent(fESD);
62 fESD=NULL;
63 if (fpData) delete fpData;
64 fpData=NULL;
65 if (fManager) AliHLTEsdManager::Delete(fManager);
66 fManager=NULL;
bbad69c8 67}
68
69int AliHLTOUTHandlerEsdBranch::ProcessData(AliHLTOUT* pData)
70{
2dfe97e6 71 // data processing function
bbad69c8 72 if (!pData) return -EINVAL;
73 int iResult=0;
74
75 if (CheckStatus(kHandlerError)) {
76 HLTWarning("kEsd handler for ESD branch '%s' in error state, skipping processing of associated HLTOUT blocks", fBranch.Data());
77 return -EPERM;
78 }
79
1bd2ee2f 80 if (!fManager) {
81 fManager=AliHLTMisc::LoadInstance((AliHLTEsdManager*)NULL, "AliHLTEsdManagerImplementation", "libHLTrec.so");
82 }
83
84 if (!fManager) {
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);
90 }
91 return -ENOSYS;
92 }
93
bbad69c8 94 if (!fESD) {
95 // create the ESD container, but without std content
1bd2ee2f 96 fESD = fManager->CreateEsdEvent();
bbad69c8 97 }
98 if (!fpData) fpData=new TArrayC;
99 if (fESD && fpData) {
1bd2ee2f 100 fManager->ResetEsdEvent(fESD);
bbad69c8 101 iResult=ExtractAndAddObjects(pData);
102 }
103
104 AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
105 if (pMsg) {
106 if (!pMsg->CompBuffer()) {
107 fSize=pMsg->Length();
108 fpData->Set(fSize, pMsg->Buffer());
109 } else {
110 fSize=pMsg->CompLength();
111 fpData->Set(fSize, pMsg->CompBuffer());
112 }
113 delete pMsg;
114 pMsg=NULL;
115 } else {
116 HLTError("streaming of object failed");
117 }
118
119 return iResult;
120}
121
122int AliHLTOUTHandlerEsdBranch::ExtractAndAddObjects(AliHLTOUT* pData)
123{
124 // Default method
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
128 // treated.
129
1bd2ee2f 130 if (!fESD || !fManager) return -ENOSYS;
bbad69c8 131 int iResult=0;
132 iResult=pData->SelectFirstDataBlock();
133 if (iResult<0) return iResult;
134
135 TObject* pObject=pData->GetDataObject();
136 if (pObject) {
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());
142 bname="";
143 }
144 }
145 if (!bname.IsNull()) {
1bd2ee2f 146 iResult=fManager->AddObject(fESD, pObject, bname.Data());
bbad69c8 147 } else {
148 iResult=-EBADF;
149 }
150 pData->ReleaseDataObject(pObject);
151 pObject=NULL;
152 } else {
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);
157 iResult=-ENODATA;
158 }
159
160 if (pData->SelectNextDataBlock()>=0) {
161 ALIHLTERRORGUARD(5, "the default function can only handle one single data block/object");
162 }
163
164 return iResult;
165}
166
bbad69c8 167int AliHLTOUTHandlerEsdBranch::GetProcessedData(const AliHLTUInt8_t* &pData)
168{
2dfe97e6 169 // get processed data
bbad69c8 170 if (!fpData) {
171 pData=NULL;
172 return 0;
173 }
174
175 pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
176 return fSize;
177}
178
179int AliHLTOUTHandlerEsdBranch::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
180{
2dfe97e6 181 // release pointer instance
bbad69c8 182 int iResult=0;
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);
186 }
187 fSize=0;
188 return iResult;
189}