Ignore:
Timestamp:
05/09/12 14:08:42 (12 years ago)
Author:
Jens Buss
Message:
added delete for file-object
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/rootmacros/PulseTemplates/rootfilehandler.C

    r13611 r13617  
    2727
    2828
    29 TFile*
     29void
    3030OpenRootFile(
    31         const char * loc_fname,
    32         int verbosityLevel
     31        TFile*          output_rootfile,
     32        const char *    loc_fname,
     33        int             verbosityLevel
    3334        )
    3435{
    35     TFile* tf = new TFile(loc_fname,"UPDATE");
    36     if (tf->IsZombie())
     36    output_rootfile = new TFile(loc_fname,"UPDATE");
     37    if (output_rootfile->IsZombie())
    3738    {
    3839        cout << "Error opening file" << endl;
    3940        exit(-1);
    4041    }
    41     else {
    42         if (verbosityLevel > 1) cout << "...opening root-file:"
    43                                      << loc_fname
    44                                      << " successfull" << endl;
     42    else
     43    {
     44        if (verbosityLevel > 1)
     45        {
     46            cout << "...opening root-file:"
     47                 << loc_fname
     48                 << " successfull" << endl;
     49        }
    4550    }
    46     return tf;
     51    return;
    4752}
    4853//end of OpenRootFile
     
    5257void
    5358CloseRootFile(
    54         TFile* tf
     59        TFile* output_rootfile
    5560        )
    5661{
    57     if (tf->IsZombie())
     62    if (output_rootfile->IsZombie())
    5863    {
    5964    cout << "Error closing file" << endl;
    6065    exit(-1);
    6166    } else {
    62     tf->Close();
     67    output_rootfile->Close();
     68    delete output_rootfile;
    6369    }
    6470}
     
    8187                                 << subdirectory << endl ;
    8288
    83     TFile* tf = OpenRootFile(loc_fname, verbosityLevel);
     89    TFile* output_rootfile = NULL;
     90    OpenRootFile(output_rootfile, loc_fname, verbosityLevel);
    8491    if ( !( subdirectory.CompareTo("root") ) ) //if subdirectory = root
    8592    {
    86         tf->cd();
     93        output_rootfile->cd();
    8794    }
    8895    else
    8996    {
    90         tf->cd();
    91         tf->mkdir(subdirectory,subdirectory);
    92         tf->cd(subdirectory);
     97        output_rootfile->cd();
     98        output_rootfile->mkdir(subdirectory,subdirectory);
     99        output_rootfile->cd(subdirectory);
    93100    }
    94101    histList->Write(); // write the major histograms into the top level directory
    95102    if (verbosityLevel > 3) tf->ls();
    96     CloseRootFile( tf ); // close the file
     103    CloseRootFile( output_rootfile ); // close the file
    97104    if (verbosityLevel > 2) cout << "...done" << endl;
    98105}
Note: See TracChangeset for help on using the changeset viewer.