]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTESDEvent.cxx
removing the HLT autoconf build system, however keep on using that for the
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTESDEvent.cxx
CommitLineData
3e6a7541 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
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 AliHLTESDEvent.cxx
20/// @author Matthias Richter
21/// @date 2010-10-29
22/// @brief A streamlined container class for AliESDEvent.
23/// @note
24
25#include "AliHLTESDEvent.h"
26#include "AliHLTESDtrack.h"
27#include "AliHLTOnlineESDtrack.h"
28#include "AliHLTLogging.h"
29#include "TList.h"
30#include "TString.h"
31#include "TObjString.h"
32#include "TObjArray.h"
33#include "TClonesArray.h"
34#include "TClass.h"
35#include <cerrno>
36#include <memory>
37
38/** ROOT macro for the implementation of ROOT specific class methods */
39ClassImp(AliHLTESDEvent)
40
41AliHLTESDEvent::AliHLTESDEvent()
42 : AliESDEvent()
43 , fTemplateEsd(NULL)
44{
45 // see header file for class documentation
46 // or
47 // refer to README to build package
48 // or
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50
51}
52
53AliHLTESDEvent::AliHLTESDEvent(const AliHLTESDEvent& src)
54 : AliESDEvent(src)
55 , fTemplateEsd(NULL)
56{
57 // copy contructor
58 if (src.fTemplateEsd) {
59 fTemplateEsd=new AliESDEvent;
60 if (fTemplateEsd) *fTemplateEsd=*src.fTemplateEsd;
61 }
62}
63
64AliHLTESDEvent& AliHLTESDEvent::operator=(const AliHLTESDEvent& src)
65{
66 // assignment operator
67 if (this==&src) return *this;
68
69 AliESDEvent::operator=(src);
70 if (src.fTemplateEsd) {
71 fTemplateEsd=new AliESDEvent;
72 if (fTemplateEsd) *fTemplateEsd=*src.fTemplateEsd;
73 }
74
75 return *this;
76}
77
78AliHLTESDEvent::~AliHLTESDEvent()
79{
80 // destructor
81 if (fTemplateEsd) delete fTemplateEsd;
82 fTemplateEsd=NULL;
83}
84
85void AliHLTESDEvent::Print(const char* options) const
86{
87 /// overloaded from TObject, print info
88 AliESDEvent::Print(options);
89}
90
91void AliHLTESDEvent::Dump() const
92{
93 /// overloaded from TObject, more crude data dump
94 AliESDEvent::Dump();
95}
96
97void AliHLTESDEvent::Clear(Option_t * option)
98{
99 /// overloaded from TObject, clear object
100
101 AliESDEvent::Clear(option);
102}
103
104TObject * AliHLTESDEvent::Clone(const char *newname) const
105{
106 /// overloaded from TObject, clone object
107
108 return AliESDEvent::Clone(newname);
109}
110
111void AliHLTESDEvent::Copy(TObject &object) const
112{
113 /// overloaded from TObject, copy object
114
115 AliESDEvent::Copy(object);
116}
117
118int AliHLTESDEvent::LoadTemplate(const char* /*cdbPath*/)
119{
120 /// load a template from OCDB or create the default template
121
122 if (fTemplateEsd) delete fTemplateEsd;
123 fTemplateEsd=NULL;
124
125 AliHLTLogging log;
126
127 // default list of skiped ESD objects
128 TString skipObjects=
129 // "AliESDRun,"
130 // "AliESDHeader,"
131 // "AliESDZDC,"
132 "AliESDFMD,"
133 // "AliESDVZERO,"
134 // "AliESDTZERO,"
135 // "TPCVertex,"
136 // "SPDVertex,"
137 // "PrimaryVertex,"
138 // "AliMultiplicity,"
139 // "PHOSTrigger,"
140 // "EMCALTrigger,"
141 // "SPDPileupVertices,"
142 // "TrkPileupVertices,"
143 "Tracks,"
144 "MuonTracks,"
145 "PmdTracks,"
146 "TrdTracks,"
147 "Cascades,"
148 "Kinks,"
149 "AliRawDataErrorLogs,"
150 "AliESDACORDE";
151
152 std::auto_ptr<AliESDEvent> ptrEsd(new AliESDEvent);
153 if (!ptrEsd.get()) return -ENOMEM;
154
155 ptrEsd->CreateStdContent();
156
157 // remove some of the objects which are not needed
158 if (ptrEsd->GetList() && !skipObjects.IsNull()) {
159 TObjArray* pTokens=skipObjects.Tokenize(",");
160 if (pTokens) {
161 const char* id=NULL;
162 TIter next(pTokens);
163 TObject* pObject=NULL;
164 while ((pObject=next())!=NULL) {
165 id=pObject->GetName();
166 TObject* pObj=ptrEsd->GetList()->FindObject(id);
167 if (pObj) {
168 log.LoggingVarargs(kHLTLogInfo, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "removing object %s", id);
169 ptrEsd->GetList()->Remove(pObj);
170 delete pObj;
171 } else {
172 log.LoggingVarargs(kHLTLogWarning, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "failed to remove object '%s' from ESD", id);
173 }
174 }
175 ptrEsd->GetStdContent();
176 delete pTokens;
177 }
178 }
179
180 // add the new objects
181 if (ptrEsd->GetList()->FindObject("Tracks")==NULL) {
182 TClonesArray* pTracks=new TClonesArray("AliHLTOnlineESDtrack",0);
183 pTracks->SetName("Tracks");
184 ptrEsd->AddObject(pTracks);
185 } else {
186 log.LoggingVarargs(kHLTLogWarning, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "member 'Tracks' is still in the list, skipping to add customized array");
187 }
188
189 fTemplateEsd = ptrEsd.release();
190
191 return 0;
192}
193
194void AliHLTESDEvent::Streamer(TBuffer &R__b)
195{
196 // Stream an object of class AliHLTESDEvent.
197
198 AliHLTLogging log;
199 if (R__b.IsReading()) {
200 R__b.ReadClassBuffer(AliHLTESDEvent::Class(),this);
201 TObject* srcobject=GetList()->FindObject("Tracks");
202 if (srcobject) {
203 TClonesArray* tclsrc=dynamic_cast<TClonesArray*>(srcobject);
204 if (tclsrc && tclsrc->GetClass() && tclsrc->GetClass()==AliHLTOnlineESDtrack::Class()) {
205 GetList()->Remove(tclsrc);
206 TClonesArray* tcltgt=new TClonesArray("AliHLTESDtrack",0);
207 if (tcltgt) {
208 tcltgt->SetName("Tracks");
209 tcltgt->ExpandCreate(tclsrc->GetEntriesFast());
210 for (int i=0; i<tclsrc->GetEntriesFast(); i++) {
211 AliHLTOnlineESDtrack* pHLTTrack=dynamic_cast<AliHLTOnlineESDtrack*>(tclsrc->At(i));
212 if (pHLTTrack==NULL || (*tcltgt)[i]==NULL) continue;
213 AliHLTESDtrack* pESDTrack=dynamic_cast<AliHLTESDtrack*>((*tcltgt)[i]);
214 if (pESDTrack==NULL) continue;
215 *pESDTrack=*pHLTTrack;
216 }
217 AddObject(tcltgt);
218 tclsrc->Clear("C");
219 delete tclsrc;
220 tclsrc=NULL;
221 srcobject=NULL;
222 }
223 }
224 }
225 } else {
226 if (fTemplateEsd) {
227 TObject* esdTracksObject=NULL;
228 TObject* onlineTracksObject=NULL;
229 fTemplateEsd->Reset();
230 TIter nextobject(this->GetList());
231 TObject* esdobject=NULL;
232 while ((esdobject=nextobject())) {
233 TObject* tgtobject=fTemplateEsd->GetList()->FindObject(esdobject->GetName());
234 if (!tgtobject) {
235 log.LoggingVarargs(kHLTLogInfo, "AliHLTESDEvent", "Streamer" , __FILE__ , __LINE__ , "skipping object %s", esdobject->GetName());
236 continue;
237 }
238
239 if (strcmp(tgtobject->GetName(), "Tracks")==0 && tgtobject->IsA()==TClonesArray::Class()) {
240 // special handling of Tracks array, replace Tracks array with own array
241 TClonesArray* tclsrc=dynamic_cast<TClonesArray*>(esdobject);
242 TClonesArray* tcltgt=dynamic_cast<TClonesArray*>(tgtobject);
243 if (!tclsrc || !tcltgt) continue;
244 tcltgt->Clear("C");
245
246 if (tcltgt->GetClass()==AliHLTOnlineESDtrack::Class()) {
247 tcltgt->ExpandCreate(tclsrc->GetEntriesFast());
248 for (int i=0; i<tclsrc->GetEntriesFast(); i++) {
249 if (!tclsrc->At(i)) continue;
250 AliESDtrack* pESDTrack=dynamic_cast<AliESDtrack*>(tclsrc->At(i));
251 TObject* tgtobj=(*tcltgt)[i];
252 if (pESDTrack==NULL || tgtobj==NULL) continue;
253 AliHLTOnlineESDtrack* pHLTTrack=dynamic_cast<AliHLTOnlineESDtrack*>(tgtobj);
254 if (!pHLTTrack) continue;
255 *pHLTTrack=*pESDTrack;
256 }
257 esdTracksObject=esdobject;
258 onlineTracksObject=tcltgt;
259 continue;
260 } else if (tcltgt->GetClass()!=AliESDtrack::Class()) {
261 // no handling if not Ali(HLT)ESDtrack
262 continue;
263 }
264 }
265
266 // default: just copy the object
267 esdobject->Copy(*tgtobject);
268 }
269
270 // replace with the optimized objects
271 if (esdTracksObject) GetList()->Remove(esdTracksObject);
272 if (onlineTracksObject) GetList()->Add(onlineTracksObject);
273
274 R__b.WriteClassBuffer(AliHLTESDEvent::Class(),fTemplateEsd);
275
276 // replace with the original objects
277 if (onlineTracksObject) GetList()->Remove(onlineTracksObject);
278 if (esdTracksObject) GetList()->Add(esdTracksObject);
279 esdTracksObject=NULL; onlineTracksObject=NULL;
280 } else {
281 R__b.WriteClassBuffer(AliHLTESDEvent::Class(),this);
282 }
283 }
284}
285
286void AliHLTESDEvent::Execute(const char *method, const char *params, Int_t *error)
287{
288 // handle custom function calls
289 if (method && strcmp(method, "LoadTemplate")==0) {
290 LoadTemplate(params);
291 return;
292 }
293 AliESDEvent::Execute(method, params, error);
294}