Changeset 6499
- Timestamp:
- 02/15/05 18:38:11 (20 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/manalysis/MMatrixLoop.cc
r5807 r6499 64 64 // 65 65 // Return name of MHMatrix, <n/a> if not available 66 // The name of the matrix must nor contain a '/' 66 67 // 67 TString MMatrixLoop::GetF ileName() const68 TString MMatrixLoop::GetFullFileName() const 68 69 { 69 70 return fMatrix ? fMatrix->GetName() : "<n/a>"; -
trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h
r5803 r6499 20 20 // MRead 21 21 UInt_t GetEntries(); 22 TString GetF ileName() const;22 TString GetFullFileName() const; 23 23 Bool_t Rewind() { fNumRow=0; return kTRUE; } 24 24 -
trunk/MagicSoft/Mars/mbase/MInputStreamID.h
r1014 r6499 24 24 MInputStreamID(const char *name=NULL, const char *title=NULL); 25 25 26 Bool_t HasStreamId() const { return fStreamId.CompareTo("all", TString::kIgnoreCase)!=0; } 27 26 28 const TString &GetStreamId() const { return fStreamId; } 27 29 void SetStreamId(const char *t) { fStreamId = t; } -
trunk/MagicSoft/Mars/mfileio/MRead.cc
r5160 r6499 52 52 *fLog << err << "ERROR - Rewind() not implemented for " << GetDescriptor() << endl; 53 53 return kFALSE; 54 } 55 56 // -------------------------------------------------------------------------- 57 // 58 // Return the name of the file we are actually reading from. 59 // 60 TString MRead::GetFileName() const 61 { 62 TString name(GetFullFileName()); 63 if (name.IsNull()) 64 return "<n/a>"; 65 name.Remove(0, name.Last('/')+1); 66 return name; 54 67 } 55 68 -
trunk/MagicSoft/Mars/mfileio/MRead.h
r5160 r6499 18 18 19 19 virtual UInt_t GetEntries() = 0; 20 virtual TString GetFileName() const = 0; 20 virtual TString GetFileName() const; 21 virtual TString GetFullFileName() const = 0; 21 22 virtual Bool_t Rewind(); 22 23 -
trunk/MagicSoft/Mars/mfileio/MReadReports.cc
r6373 r6499 134 134 // If no master is available "<MReadReports>" is returned. 135 135 // 136 TString MReadReports::GetF ileName() const136 TString MReadReports::GetFullFileName() const 137 137 { 138 138 if (!TestBit(kHasMaster)) -
trunk/MagicSoft/Mars/mfileio/MReadReports.h
r5143 r6499 30 30 31 31 UInt_t GetEntries(); 32 TString GetF ileName() const;32 TString GetFullFileName() const; 33 33 34 34 Int_t PreProcess(MParList *plist); -
trunk/MagicSoft/Mars/mfileio/MReadRflFile.h
r4898 r6499 53 53 Bool_t Rewind() { fNumFile=0; return kTRUE; } 54 54 UInt_t GetEntries() { return fEntries; } 55 TString GetF ileName() const { return fFileName; }55 TString GetFullFileName() const { return fFileName; } 56 56 57 57 Bool_t SearchFor(Int_t runno, Int_t eventno); -
trunk/MagicSoft/Mars/mfileio/MReadTree.cc
r6085 r6499 1120 1120 // Return the name of the file we are actually reading from. 1121 1121 // 1122 TString MReadTree::GetF ileName() const1122 TString MReadTree::GetFullFileName() const 1123 1123 { 1124 1124 const TFile *file = fChain ? fChain->GetFile() : fTree->GetCurrentFile(); 1125 1125 1126 1126 if (!file) 1127 return TString("<unknown>"); 1128 1129 TString name(file->GetName()); 1130 name.Remove(0, name.Last('/')+1); 1131 return name; 1127 return "<unknown>"; 1128 1129 return file->GetName(); 1132 1130 } 1133 1131 -
trunk/MagicSoft/Mars/mfileio/MReadTree.h
r5692 r6499 70 70 UInt_t GetEntries(); 71 71 72 TString GetFileName() const; 72 //TString GetFileName() const; 73 TString GetFullFileName() const; 73 74 Int_t GetFileIndex() const; 74 75 … … 92 93 93 94 #endif 95 -
trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
r6459 r6499 43 43 // constructor or specify 'memory' as option in the constructor. 44 44 // 45 // Afterwards the tree can be found using gROOT->FindObject("treename") 45 // Afterwards the tree can be found using 46 // gROOT->GetListOfFiles()->FindObject("treename") 46 47 // 47 48 // Currently(!) the tree is not deleted at all! Please make sure to … … 90 91 // 91 92 fBranches.SetOwner(); 93 fCopies.SetOwner(); 92 94 93 95 // … … 100 102 gROOT->GetListOfCleanups()->Add(this); // To remove fDisplay 101 103 SetBit(kMustCleanup); 104 } 105 106 // -------------------------------------------------------------------------- 107 // 108 // Try to get the file from gROOT->GetListOfFiles. 109 // If it is found fOut is set to it and returned. 110 // Otherwise a new file is opened and returned. 111 // 112 TFile *MWriteRootFile::OpenFile(const char *name, Option_t *option, const char *title, Int_t comp) 113 { 114 TFile *file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(name)); 115 if (!file) 116 { 117 file = new TFile(name, option, title, comp); 118 file->SetOption(option); // IMPORTANT! 119 ResetBit(kIsNotOwner); 120 return file; 121 } 122 123 fOut = file; 124 fOut->SetBit(kMustCleanup); 125 SetBit(kIsNotOwner); 126 127 *fLog << inf; 128 *fLog << "File '" << name << "' already open... using." << endl; 129 *fLog << "Make sure that you do NOT write to trees which are" << endl; 130 *fLog << "scheduled already by a different MWriteRootFile..." << endl; 131 return fOut; 102 132 } 103 133 … … 139 169 // a valid file. (Stupid workaround - but does a good job) 140 170 // 141 fOut = new TFile("/dev/null", option, ftitle, comp); 142 fOut->SetOption(option); // IMPORTANT! 171 fOut = OpenFile("/dev/null", option, ftitle, comp); 143 172 } 144 173 … … 192 221 // Open the rootfile 193 222 // 194 TObject *find = gROOT->FindObject(str); 195 if (find && find->InheritsFrom(TFile::Class())) 196 { 197 fOut = (TFile*)find; 198 fOut->SetBit(kMustCleanup); 199 SetBit(kIsNotOwner); 200 201 *fLog << inf << "File '" << fname << "' already open... using." << endl; 202 *fLog << "Make sure that you do NOT write to trees which are" << endl; 203 *fLog << "scheduled already by a different MWriteRootFile..." << endl; 204 } 205 else 206 fOut = new TFile(str, opt, ftitle, comp); 223 fOut = OpenFile(str, opt, ftitle, comp); 207 224 } 208 225 … … 217 234 // Print some statistics to the looging out. 218 235 // 219 Print();220 221 236 if (fOut && !TestBit(kIsNotOwner)) 222 237 { 238 Print(); 239 223 240 // 224 241 // If the file is still open (no error) write the keys. This is necessary … … 267 284 if (fTrees.GetEntries()==0) 268 285 { 269 *fLog << " No contents." << endl;286 *fLog << " No contents." << endl; 270 287 return; 271 288 } … … 295 312 *fLog << " + " << t->GetName() << ": \t" << (ULong_t)t->GetEntries() << " entries." << endl; 296 313 297 TIter NextKey(fOut->GetList OfKeys());314 TIter NextKey(fOut->GetList()); 298 315 while ((obj=NextKey())) 299 316 { … … 304 321 continue; 305 322 306 *fLog << " - " << obj->GetName() << ": \t" << (ULong_t)((TTree*) t)->GetEntries() << " entries." << endl;323 *fLog << " - " << obj->GetName() << ": \t" << (ULong_t)((TTree*)obj)->GetEntries() << " entries." << endl; 307 324 } 308 325 *fLog << endl; 309 310 326 } 311 327 … … 357 373 // is the name of the tree. 358 374 // 359 void MWriteRootFile::AddContainer(MParContainer *cont, const char *tname, 360 Bool_t must) 375 void MWriteRootFile::AddContainer(MParContainer *cont, const char *tname, Bool_t must) 361 376 { 362 377 if (!fOut && !tname) … … 380 395 MRootFileBranch *entry = new MRootFileBranch(cont, tname, must); 381 396 fBranches.AddLast(entry); 397 } 398 399 // -------------------------------------------------------------------------- 400 // 401 // If you want to copy a full tree (or some branches of some trees) 402 // completely from one file to another one you can use this 403 // 404 void MWriteRootFile::AddCopySource(const char *tname, const char *bname) 405 { 406 fCopies.Add(new TNamed(tname, bname?bname:"*")); 407 fCopies.Sort(); 382 408 } 383 409 … … 497 523 tree->SetBit(kIsNewTree); 498 524 525 *fLog << inf << "Tree " << tname << " created in " << gDirectory->GetName() << endl; 526 499 527 gDirectory = save; 500 501 *fLog << inf << "Tree " << tname << " created." << endl;502 528 } 503 529 … … 666 692 // If we are writing into memory we don't split into seperate files 667 693 // 668 if (!fOut )694 if (!fOut || TestBit(kIsNotOwner)) 669 695 return kTRUE; 670 696 … … 694 720 Bool_t MWriteRootFile::ChangeFile(const char *fname) 695 721 { 696 if (!fOut) 697 { 698 TObject *find = gROOT->FindObject(fname); 699 if (find && find->InheritsFrom(TFile::Class())) 700 { 701 fOut = (TFile*)find; 702 SetBit(kIsNotOwner); 703 return kTRUE; 704 } 705 706 *fLog << err << "MWriteRootFile::ChangeFile: Expecting file '" << fname; 707 *fLog << "' in gROOT->FindObject... not found." << endl; 708 return kFALSE; 709 } 710 711 // 712 // The following code is more or less a copy of TTree::ChangeFile 713 // 714 const Int_t compr = fOut->GetCompressionLevel(); 715 const TString title = fOut->GetTitle(); 716 const TString opt = fOut->GetOption(); 717 718 *fLog << inf << "MWriteRootFile - Open new file " << fname << " (Title=" << title << ", Option=" << opt << ", Compression=" << compr << ")" << endl; 722 const Int_t compr = fOut ? fOut->GetCompressionLevel() : 0; 723 const TString title = fOut ? fOut->GetTitle() : ""; 724 const TString opt = fOut ? fOut->GetOption() : ""; 719 725 720 726 // Open new file with old setup 721 TFile *newfile = TFile::Open(fname, opt, title, compr); 727 TFile *newfile = OpenFile(fname, opt, title, compr); 728 if (newfile && newfile==fOut) 729 { 730 *fLog << inf << "Found open file " << fname << "... using." << endl; 731 return kTRUE; 732 } 733 722 734 if (!newfile) 723 735 { 724 736 *fLog << err << "ERROR - Cannot open new file " << fname << endl; 725 return kFALSE; 726 } 737 return kFALSE; 738 } 739 740 *fLog << inf << "Open new file " << fname << " (Title=" << title << ", Option=" << opt << ", Compression=" << compr << ")" << endl; 727 741 728 742 // Print statistics of old file … … 743 757 744 758 // If this is not a tree do nothing. 745 if (!obj->InheritsFrom( "TTree"))759 if (!obj->InheritsFrom(TTree::Class())) 746 760 continue; 747 761 … … 784 798 // If you need more difficult rules please send me an eMail... 785 799 // 786 TString MWriteRootFile::GetNewFileName( const char *inname) const800 TString MWriteRootFile::GetNewFileName(TString &inname) const 787 801 { 788 802 // Remove the path from the filename … … 847 861 path.Append("/"); 848 862 863 inname.Prepend(path); 864 849 865 // Create full qualified pathname 850 866 path += fname; … … 854 870 // -------------------------------------------------------------------------- 855 871 // 872 // Writes a copy of the TTree t to the currently open file using 873 // TTree::CloneTree() 874 // 875 void MWriteRootFile::CopyTree(TTree &t) 876 { 877 *fLog << "Copy of tree " << t.GetName() << " in progress..." << flush; 878 879 TTree *clone=t.CloneTree(); 880 clone->Write(); 881 delete clone; 882 883 *fLog << "done." << endl; 884 } 885 886 // -------------------------------------------------------------------------- 887 // 888 // Make all copies requested from the currently open file into the new 889 // file. 890 // 891 Bool_t MWriteRootFile::MakeCopies(const char *fname) const 892 { 893 if (fCopies.GetEntries()==0) 894 return kTRUE; 895 896 TFile *file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(fname)); 897 if (!file) 898 { 899 *fLog << err << "ERROR - MakeCopies: File " << fname << " not found in gROOT->GetListOfFiles()... abort." << endl; 900 return kFALSE; 901 } 902 903 TIter Next(&fCopies); 904 TObject *o=0; 905 TTree *t=0; 906 907 fOut->cd(); 908 while ((o=Next())) 909 { 910 TTree *gettree = dynamic_cast<TTree*>(file->Get(o->GetName())); 911 if (!gettree) 912 continue; 913 914 gettree->SetBranchStatus(o->GetTitle(), 1); 915 916 // First Execution 917 if (t==gettree) 918 continue; 919 920 // Check if its the first call 921 if (t) 922 CopyTree(*t); 923 t = gettree; 924 } 925 926 if (t) 927 CopyTree(*t); 928 929 return kTRUE; 930 } 931 932 // -------------------------------------------------------------------------- 933 // 856 934 // ReInit. If file splitting is not allowed call MWriteFile::ReInit. 857 935 // … … 868 946 Bool_t MWriteRootFile::ReInit(MParList *pList) 869 947 { 870 if (fSplitRule.IsNull() || ! fOut)948 if (fSplitRule.IsNull() || !(fOut || TestBit(kIsNotOwner))) 871 949 return MWriteFile::ReInit(pList); 872 950 … … 883 961 } 884 962 885 const TString fname = GetNewFileName(read->GetFileName()); 886 if (!ChangeFile(fname)) 963 TString oldname = read->GetFileName(); 964 965 const TString newname = GetNewFileName(oldname); 966 if (!ChangeFile(newname)) 967 return kFALSE; 968 969 if (!MakeCopies(oldname)) 887 970 return kFALSE; 888 971 … … 930 1013 { 931 1014 if (obj==fOut && TestBit(kIsNotOwner)) 932 {933 ResetBit(kIsNotOwner);934 1015 fOut=0; 935 }936 1016 } 937 1017 -
trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h
r6459 r6499 78 78 TObjArray fBranches; // List of Branch setup (MRootFileBranch) 79 79 TObjArray fTrees; //! List of trees 80 TObjArray fCopies; // Branches and tree to copy 80 81 81 82 TString fSplitRule; // file splitting allowed if rule existing (done in ReInit) … … 92 93 // File handling 93 94 void Close(); 94 TString GetNewFileName( const char *fname) const;95 TString GetNewFileName(TString &inname) const; 95 96 Bool_t ChangeFile(const char *fname); 97 TFile *OpenFile(const char *name, Option_t *option, const char *title, Int_t comp); 98 void CopyTree(TTree &t); 99 Bool_t MakeCopies(const char *oldname) const; 96 100 97 101 // MWrite … … 126 130 void AddContainer(const char *cname, const char *tname=NULL, Bool_t must=kTRUE); 127 131 void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE); 132 void AddCopySource(const char *tname, const char *bname=NULL); 128 133 129 134 void Print(Option_t *t=NULL) const;
Note:
See TracChangeset
for help on using the changeset viewer.