Ignore:
Timestamp:
07/22/08 17:49:22 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mfileio
Files:
2 edited

Legend:

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

    r8746 r9034  
    1818!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2005
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    6060#include <TFile.h>           // TFile::GetName
    6161#include <TSystem.h>         // gSystem->ExpandPath
     62#include <TLeafElement.h>
    6263#include <TChainElement.h>
     64#include <TFriendElement.h>
    6365#include <TOrdCollection.h>
    6466
     
    6769#include "MParList.h"
    6870#include "MTaskList.h"
     71#include "MParameters.h"
    6972#include "MStatusDisplay.h"
    7073
    7174#include "MLog.h"
    7275#include "MLogManip.h"
    73 
    7476
    7577ClassImp(MReadTree);
     
    150152}
    151153
     154Bool_t MReadTree::IsOwned(const TChainElement &e) const
     155{
     156    // We cannot be the owner, because it is a basic type like Int, etc.
     157    if (!e.GetBaddressIsPtr())
     158        return kFALSE;
     159
     160    // We cannot be the owener, because there is no class
     161    // we could have created
     162    if (TString(e.GetBaddressClassName()).IsNull())
     163        return kFALSE;
     164
     165    // Let's hope the best that we are the owner
     166    return kTRUE;
     167}
     168
    152169// --------------------------------------------------------------------------
    153170//
     
    165182        TIter Next(fChain->GetStatus());
    166183
     184        // Pointers which we delete must be
     185        //  1) Really pointers
     186        //  2) Have a class name (belong to a loaded class)
    167187        TChainElement *element = NULL;
    168188        while ((element=(TChainElement*)Next()))
    169             if (element->GetBaddress())
    170                 delete (MParContainer**)element->GetBaddress();
     189            if (IsOwned(*element))
     190                delete (void**)element->GetBaddress();
    171191
    172192        //
    173193        // Delete the chain and the veto list
    174194        //
    175 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)
    176         if (fChain->GetFile())
    177             delete fChain->GetFile();
    178 #endif
    179195        delete fChain;
    180196    }
     
    346362    }
    347363
    348 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)
    349     //
    350     // This is a workaround to get rid of crashed if the file doesn't
    351     // exist due to non initialized TFile::fProcessIDs
    352     //
    353     //  (Code taken from TFile::TFile
    354     //
    355     TString newname; // char-array must overcome comming block
    356 
    357     if (strrchr(fname, '?') || strrchr(fname, '*'))
    358     {
    359         *fLog << warn;
    360         *fLog<< "WARNING: Using widcards with older root versions:" << endl;
    361         *fLog << "  You may encounter crashes closing the files..." << endl;
    362     }
    363     else
    364     {
    365         const char *name;
    366 
    367         if ((name = gSystem->ExpandPathName(fname)))
    368         {
    369             newname = name;
    370             delete [] name;
    371         }
    372 
    373         if (newname.IsNull())
    374         {
    375             *fLog << err << dbginf << "Error expanding path " << fname << "." << endl;
    376             return 0;
    377         }
    378 
    379         if (gSystem->AccessPathName(newname, kFileExists))
    380         {
    381             *fLog << err << "ERROR - File '" << fname << "' does not exist." << endl;
    382             return 0;
    383         }
    384 
    385         fname = newname.Data();
    386     }
    387 #endif
     364    TString newname(fname); // char-array must overcome comming block
     365    gSystem->ExpandPathName(newname);
    388366
    389367    //
    390368    // FIXME! A check is missing whether the file already exists or not.
    391369    //
    392     const Int_t numfiles = fChain->Add(fname, entries<0?TChain::kBigNumber:entries);
     370    const Int_t numfiles = fChain->Add(newname, entries<0?TChain::kBigNumber:entries);
     371
     372    //TIter Next(fChain->GetListOfFriends());
     373    //TFriendElement *el = 0;
     374    //while ((el=(TFriendElement*)Next()))
     375    //    static_cast<TChain*>(el->GetTree())->Add(newname, entries<0?TChain::kBigNumber:entries);
    393376
    394377    if (numfiles>0)
     
    399382    }
    400383    else
    401         *fLog << warn << "WARNING: '" << fname << "' not added to " << GetDescriptor() << endl;
     384        *fLog << warn << "WARNING: '" << newname << "' not added to " << GetDescriptor() << endl;
    402385
    403386    return numfiles;
     387}
     388
     389Bool_t MReadTree::AddFriend(TChain &c)
     390{
     391//    if (!fChain)
     392//    {
     393//        *fLog << err << "MReadTree::AddFriend - ERROR: You cannot add a friend, because MReadTree" << endl;
     394//        *fLog <<        "  is supposed to read its tree from memory or its default or its" << endl;
     395//        *fLog <<        "  default constructor was called (no tree name was given)." << endl;
     396//        return 0;
     397//    }
     398
     399    return fChain->AddFriend(&c, "")!=0;
    404400}
    405401
     
    924920    }
    925921
    926     //
    927     // Set the ready to save status of this task (used?), too
    928     //
    929922    MTask::SetReadyToSave(flag);
    930923}
     
    939932//  reading the event. If it returns kAFLSE the event is skipped.
    940933//
    941 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
    942 #include "MRawEvtData.h"
    943 #endif
    944934Int_t MReadTree::Process()
    945935{
    946     //
    947     // This is necessary due to a bug in TChain::LoadTree in root.
    948     // will be fixed in 3.03
    949     //
    950 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)
    951     if (fNumEntry >= GetEntries())
    952         return kFALSE;
    953 #endif
    954 
    955 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
    956     //
    957     // This fixes 99.9% of a memory leak using a root version prior
    958     // to 3.02/??
    959     //
    960     TChainElement *element=NULL;
    961     TIter Next(fChain->GetStatus());
    962     while ((element=(TChainElement*)Next()))
    963     {
    964         MParContainer **c = (MParContainer**)element->GetBaddress();
    965         if (!c) continue;
    966         if ((*c)->InheritsFrom(MRawEvtData::Class()))
    967             static_cast<MRawEvtData*>(*c)->DeletePixels(kFALSE);
    968 
    969     }
    970 #endif
    971 
    972936    if (GetSelector())
    973937    {
     
    1033997    // memory address or a pending address set long before.
    1034998    // So we delete the stuff in PostProcess and not the destructor
    1035     // (which might seg faullt if PreProcess has never been called)
     999    // (which might seg fault if PreProcess has never been called)
    10361000    if (!fChain)
    10371001    {
  • trunk/MagicSoft/Mars/mfileio/MReadTree.h

    r8226 r9034  
    77
    88class MChain;
     9class TChain;
     10class TChainElement;
    911class TBranch;
    1012class TTree;
     
    3840    void SetBranchStatus(TObject *branch, Bool_t status);
    3941    void SetBranchStatus(const char *name, Bool_t status);
     42
     43    Bool_t IsOwned(const TChainElement &e) const;
    4044
    4145    void DisableSubBranches(TBranch *b);
     
    8589    virtual Int_t AddFiles(const MReadTree &read);
    8690    Int_t AddFiles(MDirIter &dir) { return MRead::AddFiles(dir); }
     91    Bool_t AddFriend(TChain &c);
    8792
    8893    Int_t PreProcess(MParList *pList);
Note: See TracChangeset for help on using the changeset viewer.