Line data Source code
1 : // $Id: AliHLTESDMCEventPublisherComponent.cxx 25452 2008-04-25 21:46:04Z richterm $
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: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
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 AliHLTESDMCEventPublisherComponent.cxx
20 : @author Jochen Thaeder
21 : @date
22 : @brief Component for publishing ESD and MC events.
23 : @note The class is used in Offline (AliRoot) context
24 : */
25 :
26 : #include "AliHLTESDMCEventPublisherComponent.h"
27 : #include "AliHLTErrorGuard.h"
28 :
29 : #include "TList.h"
30 : #include "TTree.h"
31 : #include "TKey.h"
32 : #include "TFile.h"
33 :
34 : /** ROOT macro for the implementation of ROOT specific class methods */
35 8 : ClassImp(AliHLTESDMCEventPublisherComponent)
36 :
37 : /*
38 : * ---------------------------------------------------------------------------------
39 : * Constructor / Destructor
40 : * ---------------------------------------------------------------------------------
41 : */
42 :
43 : // #################################################################################
44 : AliHLTESDMCEventPublisherComponent::AliHLTESDMCEventPublisherComponent()
45 : :
46 3 : AliHLTFilePublisher(),
47 3 : fpCurrentFolder(NULL),
48 3 : fpCurrentFileList(NULL),
49 3 : fCurrentEvent(0),
50 3 : fNEventsInFolder(0),
51 3 : fFolderList(),
52 3 : fSpecification(0),
53 3 : fPublishESD(kFALSE),
54 3 : fPublishHLTESD(kFALSE),
55 3 : fPublishMC(kFALSE),
56 3 : fFastMC(kFALSE),
57 3 : fpTreeESD(NULL),
58 3 : fpTreeHLTESD(NULL),
59 3 : fpTreeE(NULL),
60 3 : fpTreeK(NULL),
61 3 : fpTreeTR(NULL),
62 3 : fpESD(NULL),
63 3 : fpHLTESD(NULL),
64 3 : fpESDClone(NULL),
65 3 : fpMC(NULL),
66 3 : fpHLTMC(NULL),
67 3 : fOutputSize(0),
68 3 : fApplyParticleCuts(kFALSE),
69 18 : fSkippedEsdObjects() {
70 : // see header file for class documentation
71 : // or
72 : // refer to README to build package
73 : // or
74 : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
75 :
76 : // Set file to ROOT-File
77 3 : SetIsRawFile( kFALSE );
78 :
79 3 : fFolderList.SetOwner();
80 6 : }
81 :
82 : // #################################################################################
83 18 : AliHLTESDMCEventPublisherComponent::~AliHLTESDMCEventPublisherComponent() {
84 : // see header file for class documentation
85 :
86 : // file list and file name list are owner of their objects and
87 : // delete all the objects
88 9 : }
89 :
90 : /*
91 : * ---------------------------------------------------------------------------------
92 : * Public functions to implement AliHLTComponent's interface.
93 : * These functions are required for the registration process
94 : * ---------------------------------------------------------------------------------
95 : */
96 :
97 : // #################################################################################
98 : const char* AliHLTESDMCEventPublisherComponent::GetComponentID() {
99 : // see header file for class documentation
100 648 : return "ESDMCEventPublisher";
101 : }
102 :
103 : // #################################################################################
104 : AliHLTComponent* AliHLTESDMCEventPublisherComponent::Spawn() {
105 : // see header file for class documentation
106 0 : return new AliHLTESDMCEventPublisherComponent;
107 0 : }
108 :
109 : void AliHLTESDMCEventPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
110 : // see header file for class documentation
111 0 : constBase=fOutputSize;
112 0 : inputMultiplier=0.0;
113 0 : }
114 :
115 : /*
116 : * ---------------------------------------------------------------------------------
117 : * Protected functions to implement AliHLTComponent's interface.
118 : * These functions provide initialization as well as the actual processing
119 : * capabilities of the component.
120 : * ---------------------------------------------------------------------------------
121 : */
122 :
123 : // #################################################################################
124 : Int_t AliHLTESDMCEventPublisherComponent::DoInit(int argc, const char** argv) {
125 : // see header file for class documentation
126 :
127 : Int_t iResult = 0;
128 : Int_t bMissingParam=0;
129 :
130 0 : TString argument="";
131 :
132 0 : fSpecification = kAliHLTVoidDataSpec;
133 :
134 : // -- Loop over all arguments
135 0 : for ( Int_t iter = 0; iter<argc && iResult>=0; iter++) {
136 0 : argument=argv[iter];
137 0 : if (argument.IsNull()) continue;
138 :
139 : // -- Check for which type to publish
140 : // Can be one, all or some of : ESD, HLTESD and MC
141 0 : if ( !argument.CompareTo("-entrytype") ) {
142 0 : if ((bMissingParam=(++iter>=argc))) break;
143 :
144 0 : TString parameter(argv[iter]);
145 0 : parameter.Remove(TString::kLeading, ' ');
146 :
147 0 : if ( !parameter.CompareTo("ESD") )
148 0 : fPublishESD = kTRUE;
149 0 : else if ( !parameter.CompareTo("HLTESD") )
150 0 : fPublishHLTESD = kTRUE;
151 0 : else if ( !parameter.CompareTo("MC") )
152 0 : fPublishMC = kTRUE;
153 0 : else if ( !parameter.CompareTo("MCFAST") ) {
154 0 : fPublishMC = kTRUE;
155 0 : fFastMC = kTRUE;
156 0 : }
157 : else {
158 0 : HLTError("Wrong parameter %s for argument %s.", parameter.Data(), argument.Data());
159 : iResult=-EINVAL;
160 : }
161 0 : }
162 :
163 : // -- Data path to reconstructed data
164 0 : else if ( ! argument.CompareTo("-datapath") ) {
165 0 : if ((bMissingParam=(++iter>=argc))) break;
166 :
167 0 : TString parameter(argv[iter]);
168 0 : parameter.Remove(TString::kLeading, ' ');
169 :
170 0 : fFolderList.Add( new TObjString(parameter) );
171 0 : }
172 :
173 : // -- Data Specification
174 : // -- see header file !!!
175 0 : else if ( ! argument.CompareTo("-dataspec") ) {
176 0 : if ((bMissingParam=(++iter>=argc))) break;
177 :
178 0 : TString parameter(argv[iter]);
179 0 : parameter.Remove(TString::kLeading, ' ');
180 :
181 0 : if ( parameter.IsDigit() )
182 0 : fSpecification = (AliHLTUInt32_t) parameter.Atoi();
183 0 : else if ( parameter.BeginsWith("0x") && parameter.Replace(0,2,"",0).IsHex() )
184 0 : sscanf(parameter.Data(),"%x", &fSpecification);
185 : else {
186 0 : HLTError("Wrong parameter for argument %s, number expected", argument.Data());
187 : iResult=-EINVAL;
188 : }
189 0 : }
190 : // -- applyParticleCuts
191 0 : else if ( !argument.CompareTo("-applyParticleCuts") ) {
192 0 : fApplyParticleCuts = kTRUE;
193 0 : }
194 :
195 0 : else if ( !argument.CompareTo("-skip-esd-object") ) {
196 0 : if ((bMissingParam=(++iter>=argc))) break;
197 0 : if (!fSkippedEsdObjects.IsNull()) fSkippedEsdObjects+=" ";
198 0 : fSkippedEsdObjects+=argv[iter];
199 : }
200 :
201 : // -- Argument not known
202 : else {
203 0 : HLTError("Unknown argument %s.", argument.Data());
204 : iResult = -EINVAL;
205 : }
206 :
207 : } // for ( Int iter = 0; iter<argc && iResult>=0; iter++) {
208 :
209 : // -- Check if parameter is missing
210 0 : if ( bMissingParam ) {
211 0 : HLTError("Missing parameter for argument %s.", argument.Data());
212 : iResult=-EINVAL;
213 0 : }
214 :
215 : // -- Check if at least on entrytype was specified
216 0 : if ( fPublishESD||fPublishHLTESD||fPublishMC )
217 0 : AddDataTypesToOutputlist();
218 : else {
219 0 : HLTError("At least one -entrytype argument needs to be specified.");
220 : iResult=-EINVAL;
221 : }
222 :
223 : // -- Check if at least one datapath was specified
224 0 : if ( !fFolderList.GetEntries() ) {
225 0 : HLTError("At least one -datapath argument needs to be specified.");
226 : iResult=-EINVAL;
227 0 : }
228 :
229 : // -- Add files according to entry type to event
230 0 : if ( iResult >= 0 ) {
231 0 : iResult = InsertFiles();
232 0 : }
233 :
234 : // -- Calculate event size
235 0 : if ( fPublishESD )
236 0 : fMaxSize += sizeof(AliESDEvent);
237 0 : if ( fPublishHLTESD )
238 0 : fMaxSize += sizeof(AliESDEvent);
239 0 : if ( fPublishMC )
240 0 : fMaxSize += sizeof(AliMCEvent) + 20000;
241 :
242 0 : if ( fEvents.GetSize() == 0) {
243 0 : HLTError("No Files have been added.");
244 : iResult=-EINVAL;
245 0 : }
246 :
247 0 : if ( iResult < 0 ) {
248 0 : fEvents.Clear();
249 : }
250 :
251 0 : if (!fSkippedEsdObjects.IsNull()) {
252 0 : fpESDClone=new AliESDEvent;
253 0 : }
254 :
255 : return iResult;
256 0 : }
257 :
258 : // #################################################################################
259 : Int_t AliHLTESDMCEventPublisherComponent::DoDeinit() {
260 : // see header file for class documentation
261 :
262 : Int_t iResult = 0;
263 :
264 0 : if ( fpESD )
265 0 : delete fpESD;
266 0 : fpESD = NULL;
267 :
268 0 : if ( fpHLTESD )
269 0 : delete fpHLTESD;
270 0 : fpHLTESD = NULL;
271 :
272 0 : if ( fpESDClone )
273 0 : delete fpESDClone;
274 0 : fpESDClone = NULL;
275 :
276 0 : if ( fpMC )
277 0 : delete fpMC;
278 0 : fpMC = NULL;
279 :
280 0 : if ( fpHLTMC )
281 0 : delete fpHLTMC;
282 0 : fpHLTMC = NULL;
283 :
284 :
285 0 : CloseCurrentFileList();
286 :
287 0 : AliHLTFilePublisher::DoDeinit();
288 :
289 0 : return iResult;
290 : }
291 :
292 : // #################################################################################
293 : void AliHLTESDMCEventPublisherComponent::AddDataTypesToOutputlist() {
294 : // see header file for class documentation
295 :
296 : // add all different data types to the list
297 0 : if ( fPublishESD )
298 0 : fOutputDataTypes.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginOffline);
299 0 : else if ( fPublishHLTESD )
300 0 : fOutputDataTypes.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT);
301 0 : else if( fPublishMC )
302 0 : fOutputDataTypes.push_back(kAliHLTDataTypeMCObject);
303 0 : }
304 :
305 : // #################################################################################
306 : Int_t AliHLTESDMCEventPublisherComponent::InsertFiles(){
307 : // see header file for class documentation
308 :
309 : Int_t iResult=0;
310 :
311 0 : EventFiles* pCurrentFolder = NULL;
312 :
313 : TObjString *objPath = 0;
314 0 : TIter next(&fFolderList);
315 :
316 : // Loop over all folders
317 0 : while ( ( objPath = (TObjString*) next() ) && iResult>=0 ) {
318 :
319 0 : TString pathAliESDs = objPath->GetString();
320 0 : pathAliESDs.Append("/AliESDs.root");
321 :
322 0 : TString pathKinematics = objPath->GetString();
323 0 : pathKinematics.Append("/Kinematics.root");
324 :
325 0 : TString pathgalice = objPath->GetString();
326 0 : pathgalice.Append("/galice.root");
327 :
328 0 : TString pathTrackRefs = objPath->GetString();
329 0 : pathTrackRefs.Append("/TrackRefs.root");
330 :
331 :
332 : // Add ESD file for this folder
333 0 : if ( fPublishESD || fPublishHLTESD ) {
334 0 : FileDesc* pDesc=new FileDesc( pathAliESDs.Data(), kAliHLTDataTypeESDObject, kAliHLTVoidDataSpec, kFALSE);
335 0 : if ( pDesc )
336 0 : iResult = InsertFile( pCurrentFolder, pDesc );
337 : else
338 : iResult = -ENOMEM;
339 0 : }
340 :
341 : // Add MC files for this folder
342 0 : if ( fPublishMC ) {
343 0 : FileDesc* pDescKinematics=new FileDesc( pathKinematics.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE);
344 0 : if ( pDescKinematics )
345 0 : iResult = InsertFile( pCurrentFolder, pDescKinematics );
346 : else
347 : iResult = -ENOMEM;
348 :
349 0 : FileDesc* pDescgalice=new FileDesc( pathgalice.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE);
350 0 : if ( pDescgalice )
351 0 : iResult = InsertFile( pCurrentFolder, pDescgalice );
352 : else
353 : iResult = -ENOMEM;
354 :
355 0 : if ( ! fFastMC ) {
356 0 : FileDesc* pDescTrackRefs=new FileDesc( pathTrackRefs.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE);
357 0 : if ( pDescTrackRefs )
358 0 : iResult = InsertFile( pCurrentFolder, pDescTrackRefs );
359 : else
360 : iResult = -ENOMEM;
361 0 : }
362 0 : }
363 :
364 : // -- Add all files belonging to one eventfolder
365 0 : InsertEvent( pCurrentFolder );
366 :
367 0 : } // while ( ( path = (TObjString*)next() ) ) {
368 :
369 : return iResult;
370 0 : }
371 :
372 : // #################################################################################
373 : Int_t AliHLTESDMCEventPublisherComponent::GetEvent( const AliHLTComponentEventData& /*evtData*/,
374 : AliHLTComponentTriggerData& /*trigData*/,
375 : AliHLTUInt8_t* /*outputPtr*/,
376 : AliHLTUInt32_t& size,
377 : vector<AliHLTComponentBlockData>& /*outputBlocks*/ ) {
378 : // see header file for class documentation
379 :
380 0 : if ( !IsDataEvent() ) return 0;
381 :
382 : Int_t iResult=0;
383 0 : size=0;
384 :
385 : // -- Initialize folder list and
386 : // re-initialize after reaching the end in the event before
387 : //
388 0 : if ( !fpCurrentFolder ) {
389 0 : fpCurrentFolder = GetEventList()->FirstLink();
390 :
391 : // -- Set file list of this folder and open the files
392 0 : if ( fpCurrentFolder ) {
393 0 : iResult = OpenCurrentFileList();
394 0 : }
395 : else {
396 0 : HLTError("Folder link can not be retrieved from folder list.");
397 : iResult=-ENOENT;
398 : }
399 : }
400 :
401 : // -- if file list was properly created
402 0 : if ( iResult >= 0 && fpCurrentFileList ) {
403 :
404 : // -- Publish ESDs
405 0 : if ( fPublishESD && fpTreeESD ) {
406 0 : fpTreeESD->GetEntry(fCurrentEvent);
407 0 : AliESDEvent* pESDpublish=fpESD;
408 0 : if (fpESDClone && CopyESDObjects(fpESDClone, fpESD, fSkippedEsdObjects.Data())>=0) {
409 0 : pESDpublish=fpESDClone;
410 0 : }
411 0 : if ((iResult=PushBack( pESDpublish, kAliHLTDataTypeESDObject|kAliHLTDataOriginOffline , fSpecification ))==-ENOSPC) {
412 0 : fOutputSize+=GetLastObjectSize();
413 0 : }
414 0 : }
415 :
416 : // -- Publish HLTESDs
417 0 : if ( fPublishHLTESD && fpTreeHLTESD ) {
418 0 : fpTreeHLTESD->GetEntry(fCurrentEvent);
419 0 : AliESDEvent* pESDpublish=fpHLTESD;
420 0 : if (fpESDClone && CopyESDObjects(fpESDClone, fpHLTESD, fSkippedEsdObjects.Data())>=0) {
421 0 : pESDpublish=fpESDClone;
422 0 : }
423 0 : if ((iResult=PushBack(pESDpublish, kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT , fSpecification ))==-ENOSPC) {
424 0 : fOutputSize+=GetLastObjectSize();
425 0 : }
426 0 : }
427 :
428 : // -- Publish MC
429 0 : if ( fPublishMC ) {
430 :
431 0 : TObjLink *flnk = fpCurrentFileList->FirstLink();
432 :
433 : // -- Loop over files in the current list
434 0 : while (flnk && iResult>=0) {
435 :
436 0 : FileDesc* pFileDesc = dynamic_cast<FileDesc*>( flnk->GetObject() );
437 0 : if (!pFileDesc) {
438 0 : ALIHLTERRORGUARD(1, "internal mismatch, object is not of type FileDesc");
439 0 : break;
440 : }
441 0 : TFile* pFile = *pFileDesc;
442 0 : if ( !pFile ) {
443 0 : HLTError("No pointer to file");
444 : iResult=-EFAULT;
445 0 : continue;
446 : }
447 :
448 0 : TString filename = pFile->GetName();
449 0 : filename.Remove(0,filename.Last('/')+1);
450 :
451 0 : TString foldername( Form("Event%d", fCurrentEvent) );
452 :
453 : // -- Open Kinematics
454 0 : if ( !filename.CompareTo("Kinematics.root") ){
455 :
456 0 : if ( fNEventsInFolder != (UInt_t)(pFile->GetListOfKeys()->GetEntries()) ) {
457 0 : HLTError("Not all files contain the same number of events : %u and %d",
458 : fNEventsInFolder, pFile->GetListOfKeys()->GetEntries() );
459 : iResult=-EFAULT;
460 0 : }
461 :
462 : // -- Get Tree K
463 : else {
464 0 : TDirectoryFile *dirK = dynamic_cast<TDirectoryFile*> (pFile->Get(foldername));
465 0 : if ( dirK )
466 0 : fpTreeK = dynamic_cast<TTree*> (dirK->Get("TreeK"));
467 : else {
468 0 : HLTError("Directory %s could not be found.", foldername.Data() );
469 : iResult=-EFAULT;
470 : }
471 : }
472 : } // if ( !filename.CompareTo("Kinematics.root") ){
473 :
474 : // -- Open TrackReferences
475 0 : else if ( !fFastMC && !filename.CompareTo("TrackRefs.root") ) {
476 :
477 0 : if ( fNEventsInFolder != (UInt_t)(pFile->GetListOfKeys()->GetEntries()) ) {
478 0 : HLTError("Not all files contain the same number of events : %u and %d",
479 : fNEventsInFolder, pFile->GetListOfKeys()->GetEntries() );
480 : iResult=-EFAULT;
481 0 : }
482 :
483 : // -- Get Tree TR
484 : else {
485 0 : TDirectoryFile *dirTR = dynamic_cast<TDirectoryFile*> (pFile->Get(foldername));
486 0 : if ( dirTR )
487 0 : fpTreeTR = dynamic_cast<TTree*> (dirTR->Get("TreeTR"));
488 : else {
489 0 : HLTError("Directory %s could not be found.", foldername.Data() );
490 : iResult=-EFAULT;
491 : }
492 : }
493 : } // else if ( !filename.CompareTo("TrackRefs.root") ){
494 :
495 0 : flnk = flnk->Next();
496 :
497 0 : } // while (flnk && iResult>=0) {
498 :
499 0 : if ( fpMC ) delete fpMC;
500 0 : fpMC = new AliMCEvent();
501 :
502 0 : if ( fpTreeE && fpTreeK && fpTreeTR ) {
503 0 : fpMC->ConnectTreeE(fpTreeE);
504 0 : fpTreeE->GetEntry(fCurrentEvent);
505 :
506 0 : fpMC->ConnectTreeK(fpTreeK);
507 0 : fpMC->ConnectTreeTR(fpTreeTR);
508 0 : }
509 0 : else if( fpTreeE && fpTreeK && fFastMC ) {
510 0 : fpMC->ConnectTreeE(fpTreeE);
511 0 : fpTreeE->GetEntry(fCurrentEvent);
512 :
513 0 : fpMC->ConnectTreeK(fpTreeK);
514 0 : }
515 : else {
516 0 : HLTError("Not all trees needed for MC Event have been created.");
517 : iResult=-EFAULT;
518 : }
519 :
520 : // -- Fill AliHLTMCEvent
521 0 : if ( iResult>=0 && fpMC ) {
522 0 : if ((iResult=PushBack( fpMC, kAliHLTDataTypeMCObject|kAliHLTDataOriginOffline , fSpecification ))==-ENOSPC) {
523 0 : fOutputSize+=GetLastObjectSize();
524 0 : }
525 :
526 0 : fpHLTMC = new AliHLTMCEvent( fApplyParticleCuts );
527 :
528 0 : if ( iResult>=0 && !(iResult=fpHLTMC->FillMCEvent(fpMC)) )
529 0 : if ((iResult=PushBack( fpHLTMC, kAliHLTDataTypeMCObject|kAliHLTDataOriginHLT , fSpecification ))==-ENOSPC) {
530 0 : fOutputSize+=GetLastObjectSize();
531 0 : }
532 : }
533 :
534 0 : } // if ( fPublishMC ) {
535 :
536 : // -- Next Event in Folder,
537 : // if last event was already reached:
538 : // -> Reser and close files
539 0 : if (iResult>=0 && ++fCurrentEvent >= fNEventsInFolder )
540 0 : iResult = CloseCurrentFileList();
541 :
542 : } // if ( iResult >= 0 && fCurrentFileList ) {
543 :
544 : // -- Next Folder
545 : // (fpCurrentEvent will be NULL*pFileDesc if end of events in file is reached)
546 0 : if ( iResult >= 0 && fpCurrentFolder && !fCurrentEvent ) {
547 0 : fpCurrentFolder=fpCurrentFolder->Next();
548 :
549 : // -- if next Folder present : Set current file list of next folder
550 : // else : end of folder list reached, reset fpCurrentFileList
551 0 : if ( fpCurrentFolder )
552 0 : iResult = OpenCurrentFileList();
553 :
554 : }
555 :
556 : return iResult;
557 0 : }
558 :
559 : // #################################################################################
560 : Int_t AliHLTESDMCEventPublisherComponent::OpenCurrentFileList() {
561 : // see header file for class documentation
562 :
563 : Int_t iResult = 0;
564 : Int_t nEntries = -1;
565 :
566 : // -- Get Current Folder
567 0 : EventFiles* pCurrentFolderDesc = dynamic_cast<EventFiles*>( fpCurrentFolder->GetObject() );
568 :
569 : // -- Get List of files in current folder
570 0 : if ( pCurrentFolderDesc )
571 0 : fpCurrentFileList = *pCurrentFolderDesc; // type conversion operator defined
572 : else {
573 0 : HLTError("Folder descriptor can not be retrieved from folder list link");
574 : iResult=-EFAULT;
575 : }
576 :
577 0 : if ( fpCurrentFileList && iResult >= 0 ) {
578 :
579 0 : TObjLink *flnk = fpCurrentFileList->FirstLink();
580 :
581 : // -- Loop over all files in folder
582 : // ----------------------------------
583 0 : while ( flnk && iResult>=0 ) {
584 0 : FileDesc* pFileDesc = dynamic_cast<FileDesc*>( flnk->GetObject() );
585 0 : if (!pFileDesc) {
586 0 : ALIHLTERRORGUARD(1, "internal mismatch, object is not of type FileDesc");
587 0 : break;
588 : }
589 0 : TFile* pFile = *pFileDesc;
590 :
591 : // If file is not opened yet, open it ... which it should not
592 0 : if (pFile != NULL ) {
593 0 : HLTError("File already open, this should not happen.");
594 : iResult=-EFAULT;
595 0 : continue;
596 : }
597 :
598 0 : pFileDesc->OpenFile();
599 0 : if ( (pFile = *pFileDesc ) == NULL ) {
600 0 : HLTError("Opening file failed." );
601 : iResult=-EFAULT;
602 0 : continue;
603 : }
604 :
605 : // -- Open trees
606 : // ---------------
607 0 : TString filename = pFile->GetName();
608 0 : filename.Remove(0,filename.Last('/')+1);
609 :
610 : // -- Open ESD tree
611 0 : if ( !filename.CompareTo("AliESDs.root") && fPublishESD ) {
612 0 : fpTreeESD = dynamic_cast<TTree*>(pFile->Get("esdTree") );
613 :
614 0 : if ( fpTreeESD ) {
615 0 : if ( nEntries == -1 )
616 0 : nEntries = (Int_t)(fpTreeESD->GetEntriesFast());
617 0 : else if ( nEntries != (Int_t)(fpTreeESD->GetEntriesFast()) ) {
618 0 : HLTError("Not all files contain the same number of events : %d and %ld",
619 : nEntries, fpTreeESD->GetEntriesFast());
620 : iResult=-EFAULT;
621 0 : }
622 :
623 : // Setup AliESDEvent
624 0 : if ( fpESD ) delete fpESD;
625 0 : fpESD = new AliESDEvent();
626 0 : fpESD->ReadFromTree(fpTreeESD);
627 :
628 : } // if ( fpTreeESD ) {
629 : else {
630 0 : HLTError("Getting ESD tree failed for file %s.", pFile->GetName() );
631 : iResult=-EFAULT;
632 : }
633 : } // if ( !filename.CompareTo("AliESDs.root") && fPublishESD ){
634 :
635 :
636 : // -- Open HLTESD tree
637 0 : if ( !filename.CompareTo("AliESDs.root") && fPublishHLTESD ) {
638 0 : fpTreeHLTESD = dynamic_cast<TTree*>(pFile->Get("HLTesdTree") );
639 :
640 0 : if ( fpTreeHLTESD ) {
641 0 : if ( nEntries == -1 )
642 0 : nEntries = (Int_t)(fpTreeHLTESD->GetEntriesFast());
643 0 : else if ( nEntries != (Int_t)(fpTreeHLTESD->GetEntriesFast()) ) {
644 0 : HLTError("Not all files contain the same number of events : %d and %ld",
645 : nEntries, fpTreeHLTESD->GetEntriesFast());
646 : iResult=-EFAULT;
647 0 : }
648 :
649 : // Setup AliESDEvent
650 0 : if ( fpHLTESD ) delete fpHLTESD;
651 0 : fpHLTESD = new AliESDEvent();
652 0 : fpHLTESD->ReadFromTree(fpTreeHLTESD);
653 :
654 : } // if ( fpTreeHLTESD ) {
655 : else {
656 0 : HLTError("Getting HLTESD tree failed for file %s.", pFile->GetName() );
657 : iResult=-EFAULT;
658 : }
659 :
660 : } // if ( !filename.CompareTo("AliESDs.root") && fPublishHLTESD ){
661 :
662 : // -- Open galice tree : TreeE
663 0 : else if ( !filename.CompareTo("galice.root") && fPublishMC ) {
664 0 : fpTreeE = dynamic_cast<TTree*>(pFile->Get("TE") );
665 :
666 0 : if ( fpTreeE ) {
667 0 : if ( nEntries == -1 )
668 0 : nEntries = (Int_t)(fpTreeE->GetEntriesFast());
669 0 : else if ( nEntries != (Int_t)(fpTreeE->GetEntriesFast()) ) {
670 0 : HLTError("Not all files contain the same number of events : %d and %ld",
671 : nEntries, fpTreeE->GetEntriesFast());
672 : iResult=-EFAULT;
673 0 : }
674 : } // if ( fpTreeE ) {
675 : else {
676 0 : HLTError("Getting TreeE failed for file %s.", pFile->GetName() );
677 : iResult=-EFAULT;
678 : }
679 : } // if ( !filename.CompareTo("galice.root") && fPublishMC ){
680 :
681 0 : flnk = flnk->Next();
682 :
683 0 : } // while ( flnk && iResult>=0 ) {
684 :
685 0 : } // if ( fpCurrentFileList && iResult >= 0 ) {
686 : else {
687 0 : HLTError("Current file list could not get created.");
688 : iResult=-EFAULT;
689 : }
690 :
691 0 : if ( iResult >= 0 )
692 0 : fNEventsInFolder = (UInt_t)(nEntries);
693 :
694 0 : return iResult;
695 0 : }
696 :
697 : // #################################################################################
698 : Int_t AliHLTESDMCEventPublisherComponent::CloseCurrentFileList() {
699 : // see header file for class documentation
700 :
701 : Int_t iResult = 0;
702 :
703 : // -- Reset
704 0 : fCurrentEvent = 0;
705 0 : fNEventsInFolder = 0;
706 :
707 : // if not set, no files are open ...
708 0 : if ( fpCurrentFileList ) {
709 :
710 0 : TObjLink *flnk = fpCurrentFileList->FirstLink();
711 :
712 : // -- Loop over all files in folder
713 0 : while ( flnk && iResult>=0 ) {
714 0 : FileDesc* pFileDesc = dynamic_cast<FileDesc*>( flnk->GetObject() );
715 0 : if (!pFileDesc) {
716 0 : ALIHLTERRORGUARD(1, "internal mismatch, object is not of type FileDesc");
717 0 : break;
718 : }
719 :
720 0 : TFile* pFile = *pFileDesc;
721 :
722 : // If is opened, close it
723 0 : if ( pFile != NULL ) {
724 0 : pFileDesc->CloseFile();
725 0 : }
726 :
727 0 : if ( (pFile = *pFileDesc ) != NULL ) {
728 0 : HLTError("Closing file %s failed.", pFile->GetName() );
729 : iResult=-EFAULT;
730 0 : }
731 :
732 0 : flnk = flnk->Next();
733 :
734 0 : } // while ( flnk && iResult>=0 ) {
735 :
736 0 : fpCurrentFileList = NULL;
737 :
738 0 : } // if ( fpCurrentFileList && iResult >= 0 ) {
739 :
740 0 : return iResult;
741 0 : }
742 :
743 : // #################################################################################
744 : Int_t AliHLTESDMCEventPublisherComponent::CopyESDObjects(AliESDEvent* pTgt,
745 : const AliESDEvent* pSrc,
746 : const char* skippedObjects) const {
747 : // clone an ESD by copying all objects but skip the specified ones
748 :
749 : Int_t iResult = 0;
750 0 : if (!pSrc || !pTgt) return -EINVAL;
751 :
752 : // copy the full ESD
753 0 : pTgt->Reset();
754 0 : *pTgt=*pSrc;
755 :
756 : // filter according to the list of objects to be skipped
757 0 : if (pTgt->GetList() && skippedObjects!=NULL) {
758 0 : TString skipObjects=skippedObjects;
759 0 : TObjArray* pTokens=skipObjects.Tokenize(" ");
760 0 : if (pTokens) {
761 : const char* id=NULL;
762 0 : TIter next(pTokens);
763 : TObject* pObject=NULL;
764 0 : while ((pObject=next())!=NULL) {
765 0 : id=pObject->GetName();
766 0 : TObject* pObj=pTgt->GetList()->FindObject(id);
767 0 : if (pObj) {
768 : HLTDebug("removing object %s", id);
769 0 : pTgt->GetList()->Remove(pObj);
770 0 : delete pObj;
771 : } else {
772 0 : HLTWarning("failed to remove object '%s' from ESD", id);
773 : }
774 : }
775 0 : pTgt->GetStdContent();
776 0 : delete pTokens;
777 0 : }
778 0 : }
779 :
780 0 : return iResult;
781 0 : }
|