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 AliHLTESDEvent.cxx
20 /// @author Matthias Richter
22 /// @brief A streamlined container class for AliESDEvent.
25 #include "AliHLTESDEvent.h"
26 #include "AliHLTESDtrack.h"
27 #include "AliHLTOnlineESDtrack.h"
28 #include "AliHLTLogging.h"
31 #include "TObjString.h"
32 #include "TObjArray.h"
33 #include "TClonesArray.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTESDEvent)
41 AliHLTESDEvent::AliHLTESDEvent()
45 // see header file for class documentation
47 // refer to README to build package
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53 AliHLTESDEvent::AliHLTESDEvent(const AliHLTESDEvent& src)
58 if (src.fTemplateEsd) {
59 fTemplateEsd=new AliESDEvent;
60 if (fTemplateEsd) *fTemplateEsd=*src.fTemplateEsd;
64 AliHLTESDEvent& AliHLTESDEvent::operator=(const AliHLTESDEvent& src)
66 // assignment operator
67 if (this==&src) return *this;
69 AliESDEvent::operator=(src);
70 if (src.fTemplateEsd) {
71 fTemplateEsd=new AliESDEvent;
72 if (fTemplateEsd) *fTemplateEsd=*src.fTemplateEsd;
78 AliHLTESDEvent::~AliHLTESDEvent()
81 if (fTemplateEsd) delete fTemplateEsd;
85 void AliHLTESDEvent::Print(const char* options) const
87 /// overloaded from TObject, print info
88 AliESDEvent::Print(options);
91 void AliHLTESDEvent::Dump() const
93 /// overloaded from TObject, more crude data dump
97 void AliHLTESDEvent::Clear(Option_t * option)
99 /// overloaded from TObject, clear object
101 AliESDEvent::Clear(option);
104 TObject * AliHLTESDEvent::Clone(const char *newname) const
106 /// overloaded from TObject, clone object
108 return AliESDEvent::Clone(newname);
111 void AliHLTESDEvent::Copy(TObject &object) const
113 /// overloaded from TObject, copy object
115 AliESDEvent::Copy(object);
118 int AliHLTESDEvent::LoadTemplate(const char* /*cdbPath*/)
120 /// load a template from OCDB or create the default template
122 if (fTemplateEsd) delete fTemplateEsd;
127 // default list of skiped ESD objects
138 // "AliMultiplicity,"
141 // "SPDPileupVertices,"
142 // "TrkPileupVertices,"
149 "AliRawDataErrorLogs,"
152 std::auto_ptr<AliESDEvent> ptrEsd(new AliESDEvent);
153 if (!ptrEsd.get()) return -ENOMEM;
155 ptrEsd->CreateStdContent();
157 // remove some of the objects which are not needed
158 if (ptrEsd->GetList() && !skipObjects.IsNull()) {
159 TObjArray* pTokens=skipObjects.Tokenize(",");
163 TObject* pObject=NULL;
164 while ((pObject=next())!=NULL) {
165 id=pObject->GetName();
166 TObject* pObj=ptrEsd->GetList()->FindObject(id);
168 log.LoggingVarargs(kHLTLogInfo, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "removing object %s", id);
169 ptrEsd->GetList()->Remove(pObj);
172 log.LoggingVarargs(kHLTLogWarning, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "failed to remove object '%s' from ESD", id);
175 ptrEsd->GetStdContent();
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);
186 log.LoggingVarargs(kHLTLogWarning, "AliHLTESDEvent", "LoadTemplate" , __FILE__ , __LINE__ , "member 'Tracks' is still in the list, skipping to add customized array");
189 fTemplateEsd = ptrEsd.release();
194 void AliHLTESDEvent::Streamer(TBuffer &R__b)
196 // Stream an object of class AliHLTESDEvent.
199 if (R__b.IsReading()) {
200 R__b.ReadClassBuffer(AliHLTESDEvent::Class(),this);
201 TObject* srcobject=GetList()->FindObject("Tracks");
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);
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;
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());
235 log.LoggingVarargs(kHLTLogInfo, "AliHLTESDEvent", "Streamer" , __FILE__ , __LINE__ , "skipping object %s", esdobject->GetName());
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;
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;
257 esdTracksObject=esdobject;
258 onlineTracksObject=tcltgt;
260 } else if (tcltgt->GetClass()!=AliESDtrack::Class()) {
261 // no handling if not Ali(HLT)ESDtrack
266 // default: just copy the object
267 esdobject->Copy(*tgtobject);
270 // replace with the optimized objects
271 if (esdTracksObject) GetList()->Remove(esdTracksObject);
272 if (onlineTracksObject) GetList()->Add(onlineTracksObject);
274 R__b.WriteClassBuffer(AliHLTESDEvent::Class(),fTemplateEsd);
276 // replace with the original objects
277 if (onlineTracksObject) GetList()->Remove(onlineTracksObject);
278 if (esdTracksObject) GetList()->Add(esdTracksObject);
279 esdTracksObject=NULL; onlineTracksObject=NULL;
281 R__b.WriteClassBuffer(AliHLTESDEvent::Class(),this);
286 void AliHLTESDEvent::Execute(const char *method, const char *params, Int_t *error)
288 // handle custom function calls
289 if (method && strcmp(method, "LoadTemplate")==0) {
290 LoadTemplate(params);
293 AliESDEvent::Execute(method, params, error);