Changeset 6373 for trunk


Ignore:
Timestamp:
02/11/05 10:36:02 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r6367 r6373  
    2222                                                 -*-*- END OF LINE -*-*-
    2323
     24 2005/02/11 Thomas Bretz
     25
     26  * mfileio/MWriteRootFile.[h,cc]:
     27    - added the possibility to write to an already existing file.
     28      This doesn't affect the old behaviour, but using this new feature
     29      might still have problems.
     30
     31  * mfileio/MReadReports.cc:
     32    - fixed column-level in PrintStatistics
     33
     34
     35
    2436 2005/02/10 Abelardo Moralejo
    2537
     
    2941   * macros/starmc2.C
    3042     - Added comment about value of cleaning levels
     43
    3144
    3245
     
    5265     - make sure that all variables are set correctly independent on
    5366       the order of their initialization by the user
     67
    5468
    5569
  • trunk/MagicSoft/Mars/mfileio/MReadReports.cc

    r5143 r6373  
    425425{
    426426    MRead::PrintStatistics(lvl, title, time);
    427     fTrees->PrintStatistics(lvl, title, GetCpuTime());
    428 }
     427    fTrees->PrintStatistics(lvl+1, title, GetCpuTime());
     428}
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r6348 r6373  
    9797    //
    9898    //fTrees.SetOwner();
     99
     100    gROOT->GetListOfCleanups()->Add(this); // To remove fDisplay
     101    SetBit(kMustCleanup);
    99102}
    100103
     
    188191    // Open the rootfile
    189192    //
    190     fOut = new TFile(str, opt, ftitle, comp);
     193    TObject *find = gROOT->FindObject(str);
     194    if (find && find->InheritsFrom(TFile::Class()))
     195    {
     196        fOut = (TFile*)find;
     197        fOut->SetBit(kMustCleanup);
     198        SetBit(kIsNotOwner);
     199
     200        *fLog << inf << "File '" << fname << "' already open... using." << endl;
     201        *fLog << "Make sure that you do NOT write to trees which are" << endl;
     202        *fLog << "scheduled already by a different MWriteRootFile..." << endl;
     203    }
     204    else
     205        fOut = new TFile(str, opt, ftitle, comp);
    191206}
    192207
     
    203218    Print();
    204219
    205     if (fOut)
     220    if (fOut && !TestBit(kIsNotOwner))
    206221    {
    207222        //
     
    216231        //
    217232        delete fOut;
    218         fOut = 0;
    219     }
    220 
    221     //
    222     // Remark:
    223     // - Trees are automatically deleted by the the file
    224     //   (unless file.SetDirectory(0) was called)
    225     // - Branches are automatically deleted by the tree destructor
    226     //
    227 
    228     *fLog << inf << "Output File closed and object deleted." << endl;
     233
     234        //
     235        // Remark:
     236        // - Trees are automatically deleted by the the file
     237        //   (unless file.SetDirectory(0) was called)
     238        // - Branches are automatically deleted by the tree destructor
     239        //
     240        *fLog << inf << "Output File closed and object deleted." << endl;
     241    }
     242
     243    fOut = 0;
    229244}
    230245
     
    244259void MWriteRootFile::Print(Option_t *) const
    245260{
     261    if (!fOut)
     262        return;
     263
    246264    *fLog << all << underline << "File: " << GetFileName() << endl;
    247265
     
    267285        name += branch->GetName();
    268286
    269         *fLog << " " << name.Strip(TString::kTrailing, '.') << ": \t" << (ULong_t)branch->GetEntries() << " entries." << endl;
     287        *fLog << " + " << name.Strip(TString::kTrailing, '.') << ": \t" << (ULong_t)branch->GetEntries() << " entries." << endl;
    270288    }
    271289
     
    274292    while ((t=(TTree*)NextTree()))
    275293        if (t->TestBit(kIsNewTree))
    276             *fLog << " " << t->GetName() << ": \t" << (ULong_t)t->GetEntries() << " entries." << endl;
     294            *fLog << " + " << t->GetName() << ": \t" << (ULong_t)t->GetEntries() << " entries." << endl;
     295
     296    TIter NextKey(fOut->GetListOfKeys());
     297    while ((obj=NextKey()))
     298    {
     299        if (!obj->InheritsFrom(TTree::Class()))
     300            continue;
     301
     302        if (fTrees.FindObject(obj) && obj->TestBit(kIsNewTree))
     303            continue;
     304
     305        *fLog << " - " << obj->GetName() << ": \t" << (ULong_t)((TTree*)t)->GetEntries() << " entries." << endl;
     306    }
    277307    *fLog << endl;
     308
    278309}
    279310
     
    662693Bool_t MWriteRootFile::ChangeFile(const char *fname)
    663694{
     695    if (!fOut)
     696    {
     697        TObject *find = gROOT->FindObject(fname);
     698        if (find && find->InheritsFrom(TFile::Class()))
     699        {
     700            fOut = (TFile*)find;
     701            SetBit(kIsNotOwner);
     702            return kTRUE;
     703        }
     704
     705        *fLog << err << "MWriteRootFile::ChangeFile: Expecting file '" << fname;
     706        *fLog << "' in gROOT->FindObject... not found." << endl;
     707        return kFALSE;
     708    }
     709
    664710    //
    665711    // The following code is more or less a copy of TTree::ChangeFile
     
    879925}
    880926
     927void MWriteRootFile::RecursiveRemove(TObject *obj)
     928{
     929    if (obj==fOut && TestBit(kIsNotOwner))
     930    {
     931        ResetBit(kIsNotOwner);
     932        fOut=0;
     933    }
     934}
     935
    881936// --------------------------------------------------------------------------
    882937//
     
    925980    }
    926981}
     982
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h

    r4826 r6373  
    8282
    8383    enum {
    84         kFillTree  = BIT(14),
     84        kIsNotOwner = BIT(14), // MWriteRootFile is not owner of fOut
     85        kFillTree   = BIT(14),
    8586        // Be carefull these bits are already in use!
    8687        // TBranch::kAutoDelete = BIT(15)
    8788        // TBranchElement::kDeleteObject = BIT(16)
    88         kIsNewTree = BIT(17)
     89        kIsNewTree  = BIT(17)
    8990    };
    9091
     
    130131    Bool_t cd(const char *path=0);
    131132
     133    void RecursiveRemove(TObject *obj);
     134
    132135    ClassDef(MWriteRootFile, 1) // Task to write data into a root file
    133136};
Note: See TracChangeset for help on using the changeset viewer.