Ignore:
Timestamp:
02/03/09 13:28:09 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r9230 r9292  
    106106// --------------------------------------------------------------------------
    107107//
    108 // Try to get the file from gROOT->GetListOfFiles.
     108// Try to get the file from gROOT->GetListOfFiles. (In case the file name
     109// is /dev/null we look for a file with name /dev/null and the given title)
    109110// If it is found fOut is set to it and returned.
    110111// Otherwise a new file is opened and returned.
     
    112113TFile *MWriteRootFile::OpenFile(const char *name, Option_t *option, const char *title, Int_t comp)
    113114{
    114     TFile *file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(name));
    115 
    116     // If the file was not found with its name try its expanded name
     115    TFile *file = 0;
     116
     117    if (TString(name)=="/dev/null")
     118    {
     119        TIter Next(gROOT->GetListOfFiles());
     120        TObject *obj = 0;
     121        while ((obj=Next()))
     122            if (TString(obj->GetName())=="/dev/null" && TString(obj->GetTitle())==title)
     123            {
     124                *fLog << inf3 << "Found file '/dev/null' <Title=" << title << ">" << endl;
     125                file = dynamic_cast<TFile*>(obj);
     126                break;
     127            }
     128    }
     129    else
     130    {
     131        file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(name));
     132
     133        // If the file was not found with its name try its expanded name
     134        if (!file)
     135        {
     136            TString fqp(name);
     137            gSystem->ExpandPathName(fqp);
     138            file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(fqp));
     139        }
     140    }
     141
    117142    if (!file)
    118     {
    119         TString fqp(name);
    120         gSystem->ExpandPathName(fqp);
    121         file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(fqp));
    122     }
    123 
    124     if (!file || TString(name)=="/dev/null")
    125143    {
    126144        file = new TFile(name, option, title, comp);
     
    130148            return NULL;
    131149        }
     150
     151        *fLog << inf3 << "New file '" << name << "' <Title=" << title << "> created." << endl;
    132152
    133153        file->SetOption(option); // IMPORTANT!
     
    143163    *fLog << inf;
    144164    *fLog << "File '" << name << "' already open... using." << endl;
     165    *fLog << inf3;
    145166    *fLog << "Make sure that you do NOT write to trees which are" << endl;
    146167    *fLog << "scheduled already by a different MWriteRootFile..." << endl;
     
    170191// ftitle:      File title stored in the file (see TFile)
    171192// name, title: Name and title of this object
     193//
     194// Until the first file is opened a dummy file with name /dev/null is
     195// opened to allow creation of trees and branches in the file.
     196// To distinguish between different /dev/null-files the given title is used.
    172197//
    173198MWriteRootFile::MWriteRootFile(const Int_t comp,
Note: See TracChangeset for help on using the changeset viewer.