preparing for new reconstruction sequence, full HLT reconstruction (local + ESD)...
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTEsdManagerImplementation.cxx
CommitLineData
c5123824 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
04df9166 19/// @file AliHLTEsdManagerImplementation.cxx
20/// @author Matthias Richter
21/// @date
22/// @brief Manager for merging and writing of HLT ESDs
23/// This is an implementation of the abstract interface AliHLTEsdManager
c5123824 24
f1207f29 25#include "AliHLTEsdManagerImplementation.h"
c5123824 26#include "AliHLTComponent.h"
27#include "AliESDEvent.h"
28#include "AliHLTMessage.h"
29#include "AliESDEvent.h"
f527516f 30#include "AliESDtrack.h"
2bc81aef 31#include "AliESDFMD.h"
32#include "AliESDVZERO.h"
33#include "AliESDTZERO.h"
34#include "AliESDCaloCells.h"
35#include "AliMultiplicity.h"
36#include "AliESDACORDE.h"
c5123824 37#include "TFile.h"
38#include "TTree.h"
39#include "TClass.h"
40#include "TObject.h"
90c37647 41#include "TList.h"
c5123824 42
5b687e5d 43const float kAliESDVZERODefaultTime = -1024.;
44const float kAliESDVZERODefaultTimeGlitch = 1e-6;
45const float kAliESDZDCDefaultEMEnergy = 0.;
46const float kAliESDZDCDefaultEMEnergyGlitch = 1e-6;
47
c5123824 48/** ROOT macro for the implementation of ROOT specific class methods */
f1207f29 49ClassImp(AliHLTEsdManagerImplementation)
c5123824 50
f1207f29 51AliHLTEsdManagerImplementation::AliHLTEsdManagerImplementation()
c5123824 52 :
794de106 53 fESDs()
54 , fDirectory()
a7100c59 55 , fTreeName()
794de106 56 , fWriteLocal(false)
c5123824 57{
58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
5b687e5d 63
64 CheckClassConditions();
c5123824 65}
66
f1207f29 67AliHLTEsdManagerImplementation::~AliHLTEsdManagerImplementation()
c5123824 68{
69 // see header file for class documentation
62ff1e23 70 for (unsigned int i=0; i<fESDs.size(); i++) {
71 if (fESDs[i]) {
72 delete fESDs[i];
73 }
74 fESDs[i]=NULL;
75 }
c5123824 76}
77
794de106 78int AliHLTEsdManagerImplementation::SetOption(const char* option)
79{
80 // see header file for class documentation
81 int iResult=0;
82 TString strOptions=option;
83 TObjArray* pTokens=strOptions.Tokenize(" ");
84 if (pTokens) {
85 if (pTokens->GetEntriesFast()>0) {
86 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
87 TString data=((TObjString*)pTokens->At(n))->GetString();
88 if (data.IsNull()) continue;
89
90 if (data.CompareTo("-writelocal")==0) {
91 fWriteLocal=true;
92 } else if (data.Contains("-directory=")) {
93 data.ReplaceAll("-directory=", "");
94 SetDirectory(data.Data());
a7100c59 95 } else if (data.Contains("-treename=")) {
96 data.ReplaceAll("-treename=", "");
97 fTreeName=data;
794de106 98 } else {
99 HLTError("unknown argument %s", data.Data());
100 iResult=-EINVAL;
101 break;
102 }
103 }
104 }
105 delete pTokens;
106 }
107 return iResult;
108}
109
f1207f29 110AliHLTEsdManagerImplementation::AliHLTEsdListEntry* AliHLTEsdManagerImplementation::Find(AliHLTComponentDataType dt) const
c5123824 111{
112 // see header file for class documentation
113 AliHLTEsdListEntry* pEntry=NULL;
114 for (unsigned int i=0; i<fESDs.size(); i++) {
62ff1e23 115 if (fESDs[i] && *(fESDs[i])==dt) {
116 pEntry=const_cast<AliHLTEsdListEntry*>(fESDs[i]);
c5123824 117 }
118 }
119 return pEntry;
120}
121
f1207f29 122int AliHLTEsdManagerImplementation::WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
c5123824 123 AliHLTComponentDataType dt, AliESDEvent* tgtesd, int eventno)
124{
125 // see header file for class documentation
4a1f19ed 126 if (pBuffer==NULL || size<4) return -EINVAL;
c5123824 127 int iResult=0;
128 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
129 if (firstWord==size-sizeof(AliHLTUInt32_t)) {
130 HLTDebug("create object from block %s size %d", AliHLTComponent::DataType2Text(dt).c_str(), size);
131 AliHLTMessage msg(const_cast<AliHLTUInt8_t*>(pBuffer), size);
132 TClass* objclass=msg.GetClass();
133 TObject* pObj=msg.ReadObject(objclass);
134 if (pObj && objclass) {
135 HLTDebug("object %p type %s created", pObj, objclass->GetName());
136 AliESDEvent* pESD=dynamic_cast<AliESDEvent*>(pObj);
137 TTree* pTree=NULL;
138 if (!pESD) {
139 pTree=dynamic_cast<TTree*>(pObj);
140 if (pTree) {
141 pESD=new AliESDEvent;
142 pESD->CreateStdContent();
143 if (pTree->GetEntries()>0) {
144 if (pTree->GetEntries()>1) {
145 HLTWarning("only one entry allowed for ESD embedded into tree, data block %s contains tree with %d entires, taking first entry",
146 AliHLTComponent::DataType2Text(dt).c_str(), pTree->GetEntries());
147 }
148 pESD->ReadFromTree(pTree);
149 pTree->GetEvent(0);
150 }
151 } else {
152 HLTWarning("tree of data block %s has no events, skipping data block", AliHLTComponent::DataType2Text(dt).c_str());
153 }
154 }
155 if (pESD) {
156 AliHLTEsdListEntry* entry=Find(dt);
157 if (!entry) {
57584811 158 if ((entry=new AliHLTEsdListEntry(dt))!=NULL) {
159 if (!fDirectory.IsNull()) {
160 entry->SetDirectory(fDirectory);
161 }
a7100c59 162 if (!fTreeName.IsNull()) {
163 entry->SetTreeName(fTreeName);
164 }
57584811 165 fESDs.push_back(entry);
90c37647 166 }
c5123824 167 }
57584811 168 if (entry) {
169 if (tgtesd) {
57584811 170 Merge(tgtesd, pESD);
57584811 171 }
794de106 172
173 // Matthias 2009-06-06: writing of individual ESD files for the different origins was a
174 // first attempt when functionality was missing in the AliRoot framework and remained as
175 // debugging feature. ESD merging is now implemented and data written to the hltEsd, so
176 // the feature is now disabled by default because it causes increasing memory consumption.
177 // Presumably not because of a memory leak but the way the internal TTree is used and kept
178 // in memory.
179 // Writing of local files can be optionally switched on as e.g. by the EsdCollector component.
180 if (fWriteLocal) entry->WriteESD(pESD, eventno);
c5123824 181 } else {
182 HLTError("internal mismatch, can not create list entry");
183 iResult=-ENOMEM;
184 }
185 } else {
186 HLTWarning("data block %s is not of class type AliESDEvent, ignoring ...", AliHLTComponent::DataType2Text(dt).c_str());
187 }
188 if (pTree) {
189 // ESD has been created and must be cleaned up
242e6536 190 pESD->Reset();
c5123824 191 delete pESD;
192 pESD=NULL;
193 }
194 delete pObj;
195 pObj=NULL;
196 } else {
197 }
198 }
199 return iResult;
200}
201
f1207f29 202int AliHLTEsdManagerImplementation::PadESDs(int eventno)
c5123824 203{
204 // see header file for class documentation
90c37647 205 int iResult=0;
206 for (unsigned int i=0; i<fESDs.size(); i++) {
207 if (fESDs[i]) {
208 int res=fESDs[i]->WriteESD(NULL, eventno);
209 if (res<0 && iResult>=0) iResult=res;
210 }
211 }
212 return iResult;
c5123824 213}
214
f1207f29 215void AliHLTEsdManagerImplementation::SetDirectory(const char* directory)
c5123824 216{
217 // see header file for class documentation
90c37647 218 if (!directory) return;
219 fDirectory=directory;
220 for (unsigned int i=0; i<fESDs.size(); i++) {
221 if (fESDs[i]) {
222 fESDs[i]->SetDirectory(directory);
223 }
224 }
225}
226
f1207f29 227TString AliHLTEsdManagerImplementation::GetFileNames(AliHLTComponentDataType dt) const
90c37647 228{
229 TString result;
230 for (unsigned int i=0; i<fESDs.size(); i++) {
231 if (fESDs[i] && *(fESDs[i])==dt) {
232 if (!result.IsNull()) result+=" ";
233 result+=fESDs[i]->GetFileName();
234 }
c5123824 235 }
90c37647 236 return result;
237}
c5123824 238
f1207f29 239TTree* AliHLTEsdManagerImplementation::EmbedIntoTree(AliESDEvent* pESD, const char* name, const char* title)
90c37647 240{
241 // see header file for class documentation
90c37647 242 TTree* pTree=new TTree(name, title);
243 if (pTree) {
244 pESD->WriteToTree(pTree);
245 pTree->Fill();
246 pTree->GetUserInfo()->Add(pESD);
c5123824 247 }
248
90c37647 249 return pTree;
250}
251
f1207f29 252AliHLTEsdManagerImplementation::AliHLTEsdListEntry::AliHLTEsdListEntry(AliHLTComponentDataType dt)
90c37647 253 :
254 fName(),
255 fDirectory(),
83cb7e1d 256 fDt(dt),
257 fpFile(NULL),
258 fpTree(NULL),
f527516f 259 fpEsd(NULL),
a7100c59 260 fPrefix(),
261 fTreeName("esdTree")
90c37647 262{
263 // see header file for class documentation
264}
265
f1207f29 266AliHLTEsdManagerImplementation::AliHLTEsdListEntry::~AliHLTEsdListEntry()
90c37647 267{
268 // see header file for class documentation
242e6536 269 if (fpEsd) delete fpEsd;
270 fpEsd=NULL;
271
272 if (fpTree) delete fpTree;
273 fpTree=NULL;
274
ba93bdb0 275 if (fpFile) {
276 fpFile->Close();
277 delete fpFile;
278 }
242e6536 279 fpFile=NULL;
c5123824 280}
281
f1207f29 282bool AliHLTEsdManagerImplementation::AliHLTEsdListEntry::operator==(AliHLTComponentDataType dt) const
c5123824 283{
284 // see header file for class documentation
285 return fDt==dt;
286}
287
f1207f29 288int AliHLTEsdManagerImplementation::AliHLTEsdListEntry::WriteESD(AliESDEvent* pSrcESD, int eventno)
c5123824 289{
83cb7e1d 290 // see header file for class documentation
291 int iResult=0;
d0d53f68 292
83cb7e1d 293 if (fName.IsNull()) {
294 // this is the first event, create the file name
83cb7e1d 295 fName="";
296 if (!fDirectory.IsNull()) {
297 fName+=fDirectory; fName+="/";
298 }
f527516f 299 fName+="Ali"; fName+=GetPrefix();
83cb7e1d 300 if (fDt!=kAliHLTDataTypeESDObject &&
301 fDt!=kAliHLTDataTypeESDTree) {
302
303 HLTWarning("non-standard ESD type %s", AliHLTComponent::DataType2Text(fDt).c_str());
304 TString id;
305 id.Insert(0, fDt.fID, kAliHLTComponentDataTypefIDsize);
306 id.Remove(TString::kTrailing, ' ');
307 id.ToUpper();
308 fName+="_"; fName+=id; fName+=".root";
309 } else {
310 fName+="ESDs.root";
311 }
312
313 fpFile=new TFile(fName, "RECREATE");
a7100c59 314 fpTree=new TTree(fTreeName, "Tree with HLT ESD objects");
83cb7e1d 315 fpEsd=new AliESDEvent;
4a1f19ed 316 if (fpEsd && fpTree) {
317 fpTree->SetDirectory(0);
83cb7e1d 318 fpEsd->CreateStdContent();
b952ebda 319 *fpEsd=*pSrcESD;
83cb7e1d 320 if (fpTree) {
321 fpEsd->WriteToTree(fpTree);
322 }
323 }
324 }
325
326 if (fpFile && fpTree && fpEsd) {
327 // synchronize and add empty events
328 fpEsd->Reset();
329 int nofCurrentEvents=fpTree->GetEntries();
330 if (nofCurrentEvents<eventno) {
331 iResult=1; // indicate tree to be written
332 HLTDebug("adding %d empty events to file %s", eventno-nofCurrentEvents, fName.Data());
333 for (int i=nofCurrentEvents; i<eventno; i++) {
334 fpTree->Fill();
335 }
336 }
337
338 if (iResult>=0 && pSrcESD) {
b952ebda 339 int nofObjects=fpEsd->GetList()->GetEntries();
83cb7e1d 340 *fpEsd=*pSrcESD;
b952ebda 341 if (nofObjects!=fpEsd->GetList()->GetEntries()) {
342 // The source ESD contains object not present in the target ESD
343 // before. Those objects will not be written to the tree since
344 // the branch layout has been created earlier.
345 // Create new tree with the additional branches, copy the entries
346 // of the current tree into the new tree, and continue.
a7100c59 347 TTree* pNewTree=new TTree(fTreeName, "Tree with HLT ESD objects");
b952ebda 348 pNewTree->SetDirectory(0);
349 AliESDEvent* readESD=new AliESDEvent;
350 readESD->CreateStdContent();
351 readESD->ReadFromTree(fpTree);
352 fpEsd->Reset();
353 fpEsd->WriteToTree(pNewTree);
354 HLTDebug("cloning tree with %d entries", fpTree->GetEntries());
355 for (int event=0; event<fpTree->GetEntries(); event++) {
356 fpTree->GetEntry(event);
357 *fpEsd=*readESD;
358 pNewTree->Fill();
359 fpEsd->Reset();
360 }
361 fpFile->Close();
362 delete fpFile;
363 delete readESD;
364 delete fpTree;
365 fpFile=new TFile(fName, "RECREATE");
366 fpTree=pNewTree;
367 *fpEsd=*pSrcESD;
368 HLTDebug("new ESD with %d objects", fpEsd->GetList()->GetEntries());
369 }
83cb7e1d 370 fpTree->Fill();
371 iResult=1; // indicate tree to be written
372 }
373
374 if (iResult>0) {
375 fpFile->cd();
376 fpTree->GetUserInfo()->Add(fpEsd);
377 fpTree->Write(fpTree->GetName(),TObject::kOverwrite);
378 fpTree->GetUserInfo()->Clear();
379 }
380 }
90c37647 381
4a1f19ed 382 // FIXME: use auto_ptr for the tree and ESD event and add proper
383 // cleanup if something fails
384
90c37647 385 return iResult;
386}
387
f1207f29 388void AliHLTEsdManagerImplementation::AliHLTEsdListEntry::SetDirectory(const char* directory)
90c37647 389{
390 // see header file for class documentation
391 if (!directory) return;
392 if (!fName.IsNull()) {
393 HLTWarning("ESD entry already in writing mode (%s), ignoring directory", fName.Data());
394 return;
395 }
396 fDirectory=directory;
397}
398
f1207f29 399const char* AliHLTEsdManagerImplementation::AliHLTEsdListEntry::GetFileName() const
90c37647 400{
401 // see header file for class documentation
402 return fName.Data();
c5123824 403}
f527516f 404
405const char* AliHLTEsdManagerImplementation::AliHLTEsdListEntry::GetPrefix()
406{
407 // see header file for class documentation
408 if (fPrefix.IsNull()) {
409 fPrefix.Insert(0, fDt.fOrigin, kAliHLTComponentDataTypefOriginSize);
410 fPrefix.Remove(TString::kTrailing, ' ');
411 fPrefix.ToUpper();
412 if (!fPrefix.Contains("HLT")) {
413 fPrefix.Insert(0, "HLT");
414 }
415 }
416 return fPrefix.Data();
417}
418
57584811 419int AliHLTEsdManagerImplementation::Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const
f527516f 420{
421 // see header file for class documentation
422 int iResult=0;
423 if (!pTgt || !pSrc) return -EINVAL;
424
f527516f 425 TIter next(pSrc->GetList());
426 TObject* pSrcObject=NULL;
57584811 427 static int warningCount=0;
f527516f 428 while ((pSrcObject=next())) {
429 if(!pSrcObject->InheritsFrom("TCollection")){
430 // simple objects
2bc81aef 431 // for every type of object we have to find out whether it is empty or not
432 // objects are only copied if non-empty, otherwise valid content would be
433 // overridden by empty objects during the merging
434 bool copy=false;
30d84601 435 TString name=pSrcObject->GetName();
18a9a5ad 436 if(pSrcObject->InheritsFrom("AliHLTTriggerDecision")){
2bc81aef 437 copy=true;
438 } else if (pSrcObject->IsA()==AliESDRun::Class()) {
439 AliESDRun* pESDRun=dynamic_cast<AliESDRun*>(pSrcObject);
440 // zero might be a valid run no in simulation, so we check also whether the CTP trigger classes are set
441 copy=(pESDRun && (pESDRun->GetRunNumber()>0 || !pESDRun->GetActiveTriggerClasses().IsNull()));
442 } else if (pSrcObject->IsA()==AliESDHeader::Class()) {
443 AliESDHeader* pESDHeader=dynamic_cast<AliESDHeader*>(pSrcObject);
444 copy=(pESDHeader && pESDHeader->GetTriggerMask()!=0);
445 } else if (pSrcObject->IsA()==AliESDVertex::Class()) {
446 AliESDVertex* pESDVertex=dynamic_cast<AliESDVertex*>(pSrcObject);
447 copy=(pESDVertex && pESDVertex->GetNContributors()>0);
448 } else if (pSrcObject->IsA()==AliESDTZERO::Class()) {
449 AliESDTZERO* pESDTZero=dynamic_cast<AliESDTZERO*>(pSrcObject);
450 copy=(pESDTZero && (pESDTZero->GetT0zVertex()!=0.0 || pESDTZero->GetT0()!=0.0));
451 } else if (pSrcObject->IsA()==AliESDVZERO::Class()) {
5b687e5d 452 AliESDVZERO* pESDVZERO=dynamic_cast<AliESDVZERO*>(pSrcObject);
453 // object contains data if one of the times exceeds the default value
454 copy=pESDVZERO &&
455 (pESDVZERO->GetV0ATime() > kAliESDVZERODefaultTime+kAliESDVZERODefaultTimeGlitch ||
456 pESDVZERO->GetV0CTime() > kAliESDVZERODefaultTime+kAliESDVZERODefaultTimeGlitch);
2bc81aef 457 } else if (pSrcObject->IsA()==AliESDFMD::Class()) {
458 AliESDFMD* pESDFMD=dynamic_cast<AliESDFMD*>(pSrcObject);
459 copy=(pESDFMD && false); // have to find an easy valid condition
460 } else if (pSrcObject->IsA()==AliESDZDC::Class()) {
461 AliESDZDC* pESDZDC=dynamic_cast<AliESDZDC*>(pSrcObject);
5b687e5d 462 // object contains data if the EM energies are different from the default value
463 copy=pESDZDC &&
464 (TMath::Abs(pESDZDC->GetZDCEMEnergy(0)-kAliESDZDCDefaultEMEnergy) > kAliESDZDCDefaultEMEnergyGlitch ||
465 TMath::Abs(pESDZDC->GetZDCEMEnergy(1)-kAliESDZDCDefaultEMEnergy) > kAliESDZDCDefaultEMEnergyGlitch);
2bc81aef 466 } else if (pSrcObject->IsA()==AliMultiplicity::Class()) {
467 AliMultiplicity* pMultiplicity=dynamic_cast<AliMultiplicity*>(pSrcObject);
468 copy=(pMultiplicity && pMultiplicity->GetNumberOfTracklets()>0);
469 } else if (pSrcObject->IsA()==AliESDCaloTrigger::Class()) {
470 AliESDCaloTrigger* pESDCaloTrigger=dynamic_cast<AliESDCaloTrigger*>(pSrcObject);
471 copy=(pESDCaloTrigger && false); // have to find an easy valid condition
472 } else if (pSrcObject->IsA()==AliESDCaloCells::Class()) {
473 AliESDCaloCells* pESDCaloCells=dynamic_cast<AliESDCaloCells*>(pSrcObject);
474 copy=(pESDCaloCells && false); // have to find an easy valid condition
475 } else if (pSrcObject->IsA()==AliESDACORDE::Class()) {
476 AliESDACORDE* pESDACORDE=dynamic_cast<AliESDACORDE*>(pSrcObject);
477 copy=(pESDACORDE && false); // have to find an easy valid condition
f5ea7ce2 478 } else if (!AliHLTESDEventHelper::IsStdContent(name)) {
479 // this is likely to be ok as long as it is not any object of the std content.
480 copy=true;
2bc81aef 481 } else {
f5ea7ce2 482 HLTError("no merging implemented for object %s, omitting", name.Data());
2bc81aef 483 }
484 if (copy) {
e13512e4 485 //pSrcObject->Print();
30d84601 486 TObject* pTgtObject=pTgt->FindListObject(name);
18a9a5ad 487 if (pTgtObject) {
30d84601 488 pSrcObject->Copy(*pTgtObject);
18a9a5ad 489 } else {
30d84601 490 pTgt->AddObject(pSrcObject->Clone());
18a9a5ad 491 }
18a9a5ad 492 }
f527516f 493 } else if(pSrcObject->InheritsFrom("TClonesArray")){
494 TClonesArray* pTClA=dynamic_cast<TClonesArray*>(pSrcObject);
495 if (pTClA!=NULL && pTClA->GetEntriesFast()>0) {
30d84601 496 TString name=pTClA->GetName();
f527516f 497 TObject* pTgtObject=pTgt->GetList()->FindObject(name);
498 TClonesArray* pTgtArray=NULL;
57584811 499 if (pTgtObject!=NULL && pTgtObject->InheritsFrom("TClonesArray")){
f527516f 500 pTgtArray=dynamic_cast<TClonesArray*>(pTgtObject);
501 if (pTgtArray) {
502 TString classType=pTClA->Class()->GetName();
503 if (classType.CompareTo(pTgtArray->Class()->GetName())==0) {
504 if (pTgtArray->GetEntries()==0) {
57584811 505 pTgtArray->ExpandCreate(pTClA->GetEntries());
506 for(int i=0; i<pTClA->GetEntriesFast(); ++i){
507 (*pTClA)[i]->Copy(*((*pTgtArray)[i]));
508 }
f527516f 509 } else {
57584811 510 if (warningCount++<10) {
511 HLTWarning("TClonesArray \"%s\" in target ESD %p is already filled with %d entries",
512 name.Data(), pTgt, pTgtArray->GetEntries());
513 }
514 iResult=-EBUSY;
f527516f 515 }
516 } else {
57584811 517 if (warningCount++<10) {
518 HLTWarning("TClonesArray \"%s\" exists in target ESD %p, but describes incompatible class type %s instead of %s",
519 name.Data(), pTgt, pTgtArray->GetClass()->GetName(), pTClA->GetClass()->GetName());
520 }
521 iResult=-EBUSY;
f527516f 522 }
523 } else {
57584811 524 if (warningCount++<10) {
525 HLTError("internal error: dynamic cast failed for object %s %p", pTgtObject->GetName(), pTgtObject);
526 }
527 iResult=-EBUSY;
f527516f 528 }
529 } else if (pTgtObject) {
57584811 530 if (warningCount++<10) {
531 HLTWarning("object \"%s\" does already exist in target ESD %p, but is %s rather than TClonesArray"
532 " skipping data",
533 name.Data(), pTgt, pTgtObject->Class()->GetName());
f527516f 534 }
57584811 535 iResult=-EBUSY;
f527516f 536 } else {
57584811 537 if (warningCount++<10) {
538 HLTWarning("object \"%s\" does not exist in target ESD %p, data can not be copied because it will be lost when filling the tree",
539 name.Data(), pTgt);
f527516f 540 }
57584811 541 iResult=-ENOENT;
f527516f 542 }
543 }
544 }
545 }
546 return iResult;
547}
f5ea7ce2 548
549bool AliHLTEsdManagerImplementation::AliHLTESDEventHelper::IsStdContent(const char* key)
550{
551 // check if the key denotes a std object
552 TString needle=key;
553 for (int i=0; i<kESDListN; i++) {
554 if (needle.CompareTo(fgkESDListName[i])==0) return true;
555 }
556 return false;
557}
5b687e5d 558
559int AliHLTEsdManagerImplementation::CheckClassConditions() const
560{
561 // this is a helper method which checks if some thing in the default
562 // object initialization changes during the evolution of the source code
563 // which is necessary for checking the validity of data in the object
564
565 // check AliESDVZERO
566 AliESDVZERO vzerodummy;
567 if (TMath::Abs(vzerodummy.GetV0ATime()-kAliESDVZERODefaultTime) > kAliESDVZERODefaultTimeGlitch ||
568 TMath::Abs(vzerodummy.GetV0CTime()-kAliESDVZERODefaultTime) > kAliESDVZERODefaultTimeGlitch) {
569 HLTWarning("initialization of AliESDVZERO has changed, default time values now %f/%f, "
570 "revision of condition might be needed",
571 vzerodummy.GetV0ATime(), vzerodummy.GetV0CTime());
572 }
573
574 // check AliESDZDC
575 AliESDZDC zdcdummy;
576 if (TMath::Abs(zdcdummy.GetZDCEMEnergy(0)-kAliESDZDCDefaultEMEnergy) > kAliESDZDCDefaultEMEnergyGlitch ||
577 TMath::Abs(zdcdummy.GetZDCEMEnergy(1)-kAliESDZDCDefaultEMEnergy) > kAliESDZDCDefaultEMEnergyGlitch) {
578 HLTWarning("initialization of AliESDZDC has changed, default em energy values now %f/%f, "
579 "revision of condition might be needed",
580 zdcdummy.GetZDCEMEnergy(0), zdcdummy.GetZDCEMEnergy(1));
581 }
582
583 return 0;
584}
0d62191a 585
e820402c 586TObject* AliHLTEsdManagerImplementation::CreateEsdEvent(bool bCreateStdContent) const
0d62191a 587{
588 // create ESDEvent object and optionally initialize standard content
589 AliESDEvent* pESD=new AliESDEvent;
590 if (pESD && bCreateStdContent) pESD->CreateStdContent();
591 return pESD;
592}
593
e820402c 594int AliHLTEsdManagerImplementation::DestroyEsdEvent(TObject* pESDInstance) const
595{
596 // destroy specified ESD object, pointer is invalid afterwords
597 if (!pESDInstance) return -EINVAL;
598 AliESDEvent* pESD=dynamic_cast<AliESDEvent*>(pESDInstance);
599 if (!pESD) return -EINVAL;
600 delete pESD;
601 return 0;
602}
603
604int AliHLTEsdManagerImplementation::AddObject(TObject* pESDInstance, const TObject* pObject, const char* branchname) const
0d62191a 605{
606 // add object to the list of ESD contributors
e820402c 607 if (!pESDInstance || !pObject) return -EINVAL;
608 AliESDEvent* pESD=dynamic_cast<AliESDEvent*>(pESDInstance);
609 if (!pESD) return -EINVAL;
0d62191a 610 TObject* pESDObject=pESD->FindListObject(branchname);
611 if (pESDObject) {
612 // copy the content to the already existing object
613 pObject->Copy(*pESDObject);
614 } else {
615 // add a new object
616 pESD->AddObject(pObject->Clone());
617 }
618 return 0;
619}
620
e820402c 621int AliHLTEsdManagerImplementation::ResetEsdEvent(TObject* pESDInstance) const
0d62191a 622{
623 // reset the specified ESD object
e820402c 624 if (!pESDInstance) return -EINVAL;
625 AliESDEvent* pESD=dynamic_cast<AliESDEvent*>(pESDInstance);
0d62191a 626 if (!pESD) return -EINVAL;
627 pESD->Reset();
628 return 0;
629}