Ignore:
Timestamp:
05/15/12 14:47:27 (12 years ago)
Author:
Jens Buss
Message:
possibility to define if output file will be updated or recreated
File:
1 edited

Legend:

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

    r13660 r13737  
    66using namespace std;
    77
     8/*
     9  POSSIBLE IMPROVEMENT:
     10
     11  creat files on the heap and handover pointers
     12
     13  */
     14
     15
     16
     17
    818void
    919CreateRootFile(
    1020        TString         loc_fname,
     21        bool            overwrite,
    1122        int             verbosityLevel
    1223        )
    1324{
    14     TFile output_rootfile(loc_fname,"UPDATE");
     25    TFile* output_rootfile;
    1526
    16     if (output_rootfile.IsZombie())
     27    if(!overwrite)
     28    {
     29        output_rootfile = new TFile(loc_fname);
     30        if (output_rootfile->IsZombie())
     31        {
     32            cout << "file does not exist...creating file" << endl;
     33            delete output_rootfile;
     34            output_rootfile = new TFile(loc_fname,"NEW");
     35        }
     36        else
     37        {
     38            cout << "file does exist and will be updated" << endl;
     39            output_rootfile->OpenFile(loc_fname,"UPDATE");
     40        }
     41    }
     42    else if(overwrite)
     43    {
     44        cout << "overwriting file" << endl;
     45        output_rootfile = new TFile(loc_fname,"RECREATE");
     46    }
     47
     48    if (output_rootfile->IsZombie())
    1749    {
    1850        cout << "Error opening file" << endl;
     
    2153    else {
    2254        if (verbosityLevel > 1) cout << "creating root-file...successfull" << endl;
    23         output_rootfile.pwd();
    24         output_rootfile.Close();
     55        output_rootfile->pwd();
     56        output_rootfile->Close();
     57        delete output_rootfile;
    2558    }
    2659}
Note: See TracChangeset for help on using the changeset viewer.