Changeset 9034 for trunk/MagicSoft/Mars/mfileio
- Timestamp:
- 07/22/08 17:49:22 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mfileio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfileio/MReadTree.cc
r8746 r9034 18 18 ! Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 520 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 60 60 #include <TFile.h> // TFile::GetName 61 61 #include <TSystem.h> // gSystem->ExpandPath 62 #include <TLeafElement.h> 62 63 #include <TChainElement.h> 64 #include <TFriendElement.h> 63 65 #include <TOrdCollection.h> 64 66 … … 67 69 #include "MParList.h" 68 70 #include "MTaskList.h" 71 #include "MParameters.h" 69 72 #include "MStatusDisplay.h" 70 73 71 74 #include "MLog.h" 72 75 #include "MLogManip.h" 73 74 76 75 77 ClassImp(MReadTree); … … 150 152 } 151 153 154 Bool_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 152 169 // -------------------------------------------------------------------------- 153 170 // … … 165 182 TIter Next(fChain->GetStatus()); 166 183 184 // Pointers which we delete must be 185 // 1) Really pointers 186 // 2) Have a class name (belong to a loaded class) 167 187 TChainElement *element = NULL; 168 188 while ((element=(TChainElement*)Next())) 169 if ( element->GetBaddress())170 delete ( MParContainer**)element->GetBaddress();189 if (IsOwned(*element)) 190 delete (void**)element->GetBaddress(); 171 191 172 192 // 173 193 // Delete the chain and the veto list 174 194 // 175 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,00)176 if (fChain->GetFile())177 delete fChain->GetFile();178 #endif179 195 delete fChain; 180 196 } … … 346 362 } 347 363 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); 388 366 389 367 // 390 368 // FIXME! A check is missing whether the file already exists or not. 391 369 // 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); 393 376 394 377 if (numfiles>0) … … 399 382 } 400 383 else 401 *fLog << warn << "WARNING: '" << fname << "' not added to " << GetDescriptor() << endl;384 *fLog << warn << "WARNING: '" << newname << "' not added to " << GetDescriptor() << endl; 402 385 403 386 return numfiles; 387 } 388 389 Bool_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; 404 400 } 405 401 … … 924 920 } 925 921 926 //927 // Set the ready to save status of this task (used?), too928 //929 922 MTask::SetReadyToSave(flag); 930 923 } … … 939 932 // reading the event. If it returns kAFLSE the event is skipped. 940 933 // 941 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)942 #include "MRawEvtData.h"943 #endif944 934 Int_t MReadTree::Process() 945 935 { 946 //947 // This is necessary due to a bug in TChain::LoadTree in root.948 // will be fixed in 3.03949 //950 #if ROOT_VERSION_CODE < ROOT_VERSION(3,03,01)951 if (fNumEntry >= GetEntries())952 return kFALSE;953 #endif954 955 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)956 //957 // This fixes 99.9% of a memory leak using a root version prior958 // 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 #endif971 972 936 if (GetSelector()) 973 937 { … … 1033 997 // memory address or a pending address set long before. 1034 998 // So we delete the stuff in PostProcess and not the destructor 1035 // (which might seg faul lt if PreProcess has never been called)999 // (which might seg fault if PreProcess has never been called) 1036 1000 if (!fChain) 1037 1001 { -
trunk/MagicSoft/Mars/mfileio/MReadTree.h
r8226 r9034 7 7 8 8 class MChain; 9 class TChain; 10 class TChainElement; 9 11 class TBranch; 10 12 class TTree; … … 38 40 void SetBranchStatus(TObject *branch, Bool_t status); 39 41 void SetBranchStatus(const char *name, Bool_t status); 42 43 Bool_t IsOwned(const TChainElement &e) const; 40 44 41 45 void DisableSubBranches(TBranch *b); … … 85 89 virtual Int_t AddFiles(const MReadTree &read); 86 90 Int_t AddFiles(MDirIter &dir) { return MRead::AddFiles(dir); } 91 Bool_t AddFriend(TChain &c); 87 92 88 93 Int_t PreProcess(MParList *pList);
Note:
See TracChangeset
for help on using the changeset viewer.