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