@@ -226,15 +226,15 @@ Bool_t FairFileSource::Init()
226226 for (auto fileName : fInputChainList ) {
227227 // Temporarily open the input file to extract information which
228228 // is needed to bring the friend trees in the correct order
229- TFile* inputFile = TFile::Open (fileName);
230- if (inputFile->IsZombie ()) {
229+ std::unique_ptr< TFile> inputFile{ TFile::Open (fileName)} ;
230+ if ((!inputFile) || inputFile->IsZombie ()) {
231231 LOG (fatal) << " Error opening the file " << fileName.Data ()
232232 << " which should be added to the input chain or as friend chain" ;
233233 }
234234
235235 if (fCheckFileLayout ) {
236236 // Check if the branchlist is the same as for the first input file.
237- Bool_t isOk = CompareBranchList (inputFile, chainName);
237+ Bool_t isOk = CompareBranchList (inputFile. get () , chainName);
238238 if (!isOk) {
239239 LOG (fatal) << " Branch structure of the input file " << fRootFile ->GetName ()
240240 << " and the file to be added " << fileName.Data () << " are different." ;
@@ -246,9 +246,6 @@ Bool_t FairFileSource::Init()
246246 // GetRunIdInfo(inputFile->GetName(), chainName);
247247 // Add the file to the input chain
248248 fInChain ->Add (fileName);
249-
250- // Close the temporarly file
251- inputFile->Close ();
252249 }
253250 }
254251 fNoOfEntries = fInChain ->GetEntries ();
@@ -349,25 +346,23 @@ void FairFileSource::AddFriendsToChain()
349346 // then already existing friend chain. If this type of friend tree
350347 // does not exist already create a new friend chain and add the file.
351348 Bool_t inputLevelFound = kFALSE ;
352- TFile* inputFile;
353349 for (auto level : fInputLevel ) {
354350 inputLevel = level;
355351
356- inputFile = TFile::Open (fileName);
357- if (inputFile->IsZombie ()) {
352+ std::unique_ptr<TFile> inputFile{ TFile::Open (fileName)} ;
353+ if ((!inputFile) || inputFile->IsZombie ()) {
358354 LOG (fatal) << " Error opening the file " << level.Data ()
359355 << " which should be added to the input chain or as friend chain" ;
360356 }
361357
362358 // Check if the branchlist is already stored in the map. If it is
363359 // already stored add the file to the chain.
364- Bool_t isOk = CompareBranchList (inputFile, inputLevel);
360+ Bool_t isOk = CompareBranchList (inputFile. get () , inputLevel);
365361 if (isOk) {
366362 inputLevelFound = kTRUE ;
367363 inputFile->Close ();
368364 continue ;
369365 }
370- inputFile->Close ();
371366 }
372367 if (!inputLevelFound) {
373368 inputLevel = Form (" FriendTree_%i" , friendType);
@@ -500,7 +495,7 @@ void FairFileSource::CheckFriendChains()
500495void FairFileSource::CreateNewFriendChain (TString inputFile, TString inputLevel)
501496{
502497 TDirectory::TContext restorecwd{};
503- TFile* f = TFile::Open (inputFile);
498+ std::unique_ptr< TFile> f{ TFile::Open (inputFile)} ;
504499
505500 TString folderName1 = FairRootManager::GetFolderName ();
506501 TString folderName = Form (" /%s" , folderName1.Data ());
@@ -538,8 +533,6 @@ void FairFileSource::CreateNewFriendChain(TString inputFile, TString inputLevel)
538533
539534 TChain* chain = new TChain (inputLevel, folderName);
540535 fFriendTypeList [inputLevel] = chain;
541-
542- f->Close ();
543536}
544537
545538Bool_t FairFileSource::ActivateObject (TObject** obj, const char * BrName)
0 commit comments