Line data Source code
1 : // $Id$
2 :
3 : //**************************************************************************
4 : //* This file is property of and copyright by the *
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"
28 : #include "AliHLTEsdManager.h"
29 : #include "AliHLTComponent.h" // DataType2Text
30 : #include "AliHLTMisc.h"
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 */
38 126 : ClassImp(AliHLTOUTHandlerEsdBranch)
39 :
40 : AliHLTOUTHandlerEsdBranch::AliHLTOUTHandlerEsdBranch(const char* branchname)
41 0 : : AliHLTOUTHandler()
42 0 : , fBranch(branchname)
43 0 : , fESD(NULL)
44 0 : , fpData(NULL)
45 0 : , fSize(0)
46 0 : , fManager(NULL)
47 0 : {
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.
56 0 : }
57 :
58 : AliHLTOUTHandlerEsdBranch::~AliHLTOUTHandlerEsdBranch()
59 0 : {
60 : // destructor
61 0 : if (fESD) fManager->DestroyEsdEvent(fESD);
62 0 : fESD=NULL;
63 0 : if (fpData) delete fpData;
64 0 : fpData=NULL;
65 0 : if (fManager) AliHLTEsdManager::Delete(fManager);
66 0 : fManager=NULL;
67 0 : }
68 :
69 : int AliHLTOUTHandlerEsdBranch::ProcessData(AliHLTOUT* pData)
70 : {
71 : // data processing function
72 0 : if (!pData) return -EINVAL;
73 : int iResult=0;
74 :
75 0 : if (CheckStatus(kHandlerError)) {
76 0 : HLTWarning("kEsd handler for ESD branch '%s' in error state, skipping processing of associated HLTOUT blocks", fBranch.Data());
77 0 : return -EPERM;
78 : }
79 :
80 0 : if (!fManager) {
81 0 : fManager=AliHLTMisc::LoadInstance((AliHLTEsdManager*)NULL, "AliHLTEsdManagerImplementation", "libHLTrec.so");
82 0 : }
83 :
84 0 : if (!fManager) {
85 0 : AliHLTComponentDataType dt=kAliHLTVoidDataType;
86 0 : AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
87 0 : if (pData->SelectFirstDataBlock()>=0) {
88 0 : pData->GetDataBlockDescription(dt, spec);
89 0 : ALIHLTERRORGUARD(1, "failed to create AliHLTEsdManagerImplementation object, skipping handling of HLTOUT data %s 0x%80x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
90 0 : }
91 : return -ENOSYS;
92 0 : }
93 :
94 0 : if (!fESD) {
95 : // create the ESD container, but without std content
96 0 : fESD = fManager->CreateEsdEvent();
97 0 : }
98 0 : if (!fpData) fpData=new TArrayC;
99 0 : if (fESD && fpData) {
100 0 : fManager->ResetEsdEvent(fESD);
101 0 : iResult=ExtractAndAddObjects(pData);
102 0 : }
103 :
104 0 : AliHLTMessage* pMsg=AliHLTMessage::Stream(fESD);
105 0 : if (pMsg) {
106 0 : if (!pMsg->CompBuffer()) {
107 0 : fSize=pMsg->Length();
108 0 : fpData->Set(fSize, pMsg->Buffer());
109 0 : } else {
110 0 : fSize=pMsg->CompLength();
111 0 : fpData->Set(fSize, pMsg->CompBuffer());
112 : }
113 0 : delete pMsg;
114 : pMsg=NULL;
115 0 : } else {
116 0 : HLTError("streaming of object failed");
117 : }
118 :
119 : return iResult;
120 0 : }
121 :
122 : int 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 :
130 0 : if (!fESD || !fManager) return -ENOSYS;
131 : int iResult=0;
132 0 : iResult=pData->SelectFirstDataBlock();
133 0 : if (iResult<0) return iResult;
134 :
135 0 : TObject* pObject=pData->GetDataObject();
136 0 : if (pObject) {
137 0 : TString bname=fBranch;
138 0 : if (bname.IsNull()) {
139 0 : bname=pObject->GetName();
140 0 : if (bname.CompareTo(pObject->ClassName())==0) {
141 0 : ALIHLTERRORGUARD(5, "no branch name specified for unnamed object %s, not added to ESD", bname.Data());
142 0 : bname="";
143 : }
144 : }
145 0 : if (!bname.IsNull()) {
146 0 : iResult=fManager->AddObject(fESD, pObject, bname.Data());
147 0 : } else {
148 : iResult=-EBADF;
149 : }
150 0 : pData->ReleaseDataObject(pObject);
151 : pObject=NULL;
152 0 : } else {
153 0 : AliHLTComponentDataType dt=kAliHLTVoidDataType;
154 0 : AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
155 0 : pData->GetDataBlockDescription(dt, spec);
156 0 : HLTError("Can not get TObject from HLTOUT buffer for block %s 0x%x", AliHLTComponent::DataType2Text(dt).c_str(), spec);
157 : iResult=-ENODATA;
158 0 : }
159 :
160 0 : if (pData->SelectNextDataBlock()>=0) {
161 0 : ALIHLTERRORGUARD(5, "the default function can only handle one single data block/object");
162 0 : }
163 :
164 : return iResult;
165 0 : }
166 :
167 : int AliHLTOUTHandlerEsdBranch::GetProcessedData(const AliHLTUInt8_t* &pData)
168 : {
169 : // get processed data
170 0 : if (!fpData) {
171 0 : pData=NULL;
172 0 : return 0;
173 : }
174 :
175 0 : pData=reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray());
176 0 : return fSize;
177 0 : }
178 :
179 : int AliHLTOUTHandlerEsdBranch::ReleaseProcessedData(const AliHLTUInt8_t* pData, int size)
180 : {
181 : // release pointer instance
182 : int iResult=0;
183 0 : if (!fpData || size != fSize ||
184 0 : const_cast<AliHLTUInt8_t*>(pData) != reinterpret_cast<AliHLTUInt8_t*>(fpData->GetArray())) {
185 0 : HLTError("attempt to release to wrong data buffer %p size %d, expected %p size %d", pData, size, fpData?fpData->GetArray():NULL, fSize);
186 : }
187 0 : fSize=0;
188 0 : return iResult;
189 : }
|