Changeset 9036 for trunk/MagicSoft/Mars/mfileio
- Timestamp:
- 07/22/08 19:56:42 (17 years ago)
- Location:
- trunk/MagicSoft/Mars/mfileio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mfileio/MReadTree.cc
r9034 r9036 60 60 #include <TFile.h> // TFile::GetName 61 61 #include <TSystem.h> // gSystem->ExpandPath 62 #include <TLeaf Element.h>62 #include <TLeaf.h> 63 63 #include <TChainElement.h> 64 64 #include <TFriendElement.h> … … 70 70 #include "MTaskList.h" 71 71 #include "MParameters.h" 72 #include "MParEmulated.h" 72 73 #include "MStatusDisplay.h" 73 74 … … 226 227 } 227 228 229 void MReadTree::GetListOfBranches(TList &list) const 230 { 231 list.AddAll(fTree->GetListOfBranches()); 232 233 TIter NextF(fTree->GetListOfFriends()); 234 TFriendElement *e = 0; 235 while ((e=(TFriendElement*)NextF())) 236 list.AddAll(e->GetTree()->GetListOfBranches()); 237 } 238 228 239 // -------------------------------------------------------------------------- 229 240 // … … 234 245 Bool_t MReadTree::CheckBranchSize() 235 246 { 236 TArrayI entries(fTree->GetListOfBranches()->GetSize()); 237 Int_t num=0; 238 239 TIter Next(fTree->GetListOfBranches()); 240 241 TBranch *element = NULL; 242 while ((element=(TBranch*)Next())) 243 entries[num++] = (Int_t)element->GetEntries(); 244 245 // Check the number of entries of the branches pair-wise 246 for (int i=0; i<num; i++) 247 for (int j=i; j<num; j++) 247 Int_t entries = -1; 248 249 TList list; 250 GetListOfBranches(list); 251 252 TIter Next(&list); 253 TBranch *b = NULL; 254 while ((b=(TBranch*)Next())) 255 { 256 if (entries>=0 && entries!=(Int_t)b->GetEntries()) 248 257 { 249 if (entries[i]==entries[j])250 continue;251 252 258 *fLog << err << "ERROR - File corruption detected:" << endl; 253 *fLog << " Due to several circumstances (such at a bug in MReadTree or wrong" << endl; 254 *fLog << " usage of the file UPDATE mode) you may have produced a file in which" << endl; 255 *fLog << " at least two branches in the same tree (" << fTree->GetName() << ") have different" << endl; 256 *fLog << " number of entries. Sorry, but this file (" << GetFileName() << ")" << endl; 257 *fLog << " is unusable." << endl; 259 *fLog << " Due to several circumstances (such at a bug in MReadTree or wrong usgae of" << endl; 260 *fLog << " the file UPDATE mode) you may have produced a file in which at least two" << endl; 261 *fLog << " branches have different number of entries. Sorry, but this combination of" << endl; 262 *fLog << " branches, trees and files is unusable." << endl; 258 263 return kFALSE; 259 264 } 265 266 entries = (Int_t)b->GetEntries(); 267 } 260 268 261 269 return kTRUE; … … 678 686 679 687 SetBranchStatus(branch->GetListOfBranches(), kFALSE); 688 } 689 690 MParContainer *MReadTree::FindCreateObj(MParList &plist, const char *cname, const char *name) 691 { 692 MParContainer *pcont=plist.FindCreateObj(cname, name); 693 if (!pcont) 694 { 695 // 696 // if class is not existing in the (root) environment 697 // we cannot proceed reading this branch 698 // 699 *fLog << err << dbginf << "ERROR - Class '" << cname; 700 *fLog << "' for " << name << " not existing in dictionary. Branch skipped." << endl; 701 return 0; 702 } 703 704 fParList.Add(pcont); 705 return pcont; 706 } 707 708 void *MReadTree::GetParameterPtr(MParList &plist, const TString &name, const char *parname) 709 { 710 if (name=="Int_t" || name=="UInt_t" || 711 name=="Short_t" || name=="UShort_t" || 712 name=="Char_t" || name=="UChar_t" || 713 name=="Bool_t") 714 { 715 MParameterI *par = (MParameterI*)FindCreateObj(plist, "MParameterI", parname); 716 return par ? par->GetPtr() : 0; 717 } 718 719 if (name=="Float_t" || name=="Double_t") 720 { 721 MParameterD *par = (MParameterD*)FindCreateObj(plist, "MParameterD", parname); 722 return par ? par->GetPtr() : 0; 723 } 724 725 // MParContainer **pcont= new MParContainer*; 726 // return FindCreateObj(plist, name, parname); 727 728 MParEmulated *par = (MParEmulated*)FindCreateObj(plist, "MParEmulated", parname); 729 if (!par) 730 return 0; 731 732 par->SetClassName(name); 733 return par->GetPtr(); 734 } 735 736 Bool_t MReadTree::SetBranchAddress(TBranch &b, void *ptr, const char *prefix, const char *type) 737 { 738 if (!ptr) 739 { 740 DisableSubBranches(&b); 741 return kFALSE; 742 } 743 744 if (fChain) 745 { 746 TChainElement *element = (TChainElement*)fChain->GetStatus()->FindObject(b.GetName()); 747 if (element && IsOwned(*element)) 748 *fLog << warn << "WARNING - Branch address for " << b.GetName() << " was already setup by the user." << endl; 749 } 750 751 const TString bname = b.GetName(); 752 const TString cname = type ? type : b.GetClassName(); 753 754 fTree->SetBranchAddress(bname, ptr); 755 756 *fLog << inf2 << prefix << " address '" << bname << "' "; 757 if (bname!=cname) 758 *fLog << "[" << cname << "] "; 759 *fLog << "setup for reading." << endl; 760 761 return kTRUE; 680 762 } 681 763 … … 751 833 *fLog << inf << fNumEntries << " entries found in file(s)." << endl; 752 834 835 // Get all branches of this tree and all friends 836 TList blist; 837 GetListOfBranches(blist); 838 753 839 // 754 840 // Get all branches of this tree and 755 841 // create the Iterator to loop over all branches 756 842 // 757 TIter Next( fTree->GetListOfBranches()); // *CHANGED-fChain-to-fTree*843 TIter Next(&blist); // *CHANGED-fChain-to-fTree* 758 844 TBranch *branch=NULL; 759 845 … … 784 870 } 785 871 786 // 787 // Create a pointer to the pointer to the object in which the 788 // branch data is stored. The pointers are stored in the TChain 789 // object and we get the pointers from there to delete it. 790 // 791 MParContainer **pcont= new MParContainer*; 792 793 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06) 794 const char *classname = oname; 795 #else 796 const char *classname = branch->GetClassName(); 797 #endif 798 799 // 800 // check if object is existing in the list 801 // 802 *pcont=pList->FindCreateObj(classname, oname); 803 804 if (!*pcont) 872 // Branch already setup/ FIXME: WHAT IF THIS IS A TREE??? 873 if (fChain && fChain->GetStatus()->FindObject(branch->GetName())) 805 874 { 806 // 807 // if class is not existing in the (root) environment 808 // we cannot proceed reading this branch 809 // 810 *fLog << warn << dbginf << "Warning: Class '" << classname; 811 *fLog << "' for " << oname << " not existing in dictionary. Branch skipped." << endl; 812 DisableSubBranches(branch); 875 *fLog << warn << "WARNING - Branch " << branch->GetName() << " already setup." << endl; 813 876 continue; 814 877 } 815 878 816 // 817 // Check whether a Pointer to a pointer already exists. 818 // If we created one already, delete it. 819 // 820 // *CHANGED-fChain-to-fTree* 821 if (fChain) 879 // Get the corresponding class 880 const TString classname = branch->GetClassName(); 881 882 TClass *cls = gROOT->GetClass(classname); 883 if (!cls) 822 884 { 823 TChainElement *element = (TChainElement*)fChain->GetStatus()->FindObject(bname); 824 if (element) 825 delete (MParContainer**)element->GetBaddress(); 885 // FIXME: With or without dot? 886 TLeaf *l = branch->GetLeaf(branch->GetName()); // FIXME: 1st leaf? 887 if (!l) 888 continue; 889 890 void *ptr = GetParameterPtr(*pList, l->GetTypeName(), oname); 891 if (SetBranchAddress(*branch, ptr, "Leaf", l->GetTypeName())) 892 num++; 893 894 continue; 826 895 } 827 /* This can't be done here for memory trees - see 828 PostProcess for more details. 896 897 // The class is known in the dictionary and loaded! 898 if (!cls->IsLoaded() || !cls->InheritsFrom(MParContainer::Class())) 899 { 900 void *ptr = GetParameterPtr(*pList, classname, oname); 901 if (SetBranchAddress(*branch, ptr, "Emulated branch")) 902 num++; 903 } 829 904 else 830 905 { 831 TBranch *branch = (TBranch*)fTree->GetBranch(bname); 832 if (branch) 833 { 834 *fLog << bname << " " << (void*)branch->GetAddress() << " " << pcont << endl; 835 delete (MParContainer**)branch->GetAddress(); 836 } 906 MParContainer **pcont= new MParContainer*; 907 *pcont=FindCreateObj(*pList, classname, oname); 908 if (SetBranchAddress(*branch, pcont, "Master branch")) 909 num++; 837 910 } 838 */839 840 //841 // here pcont is a pointer the to container in which the data from842 // the actual branch should be stored - enable branch.843 //844 fTree->SetBranchAddress(bname, pcont); // *CHANGED-fChain-to-fTree*845 846 *fLog << inf2 << "Master branch address '" << bname << "' ";847 if ((TString)bname!=(TString)classname)848 *fLog << "[" << classname << "] ";849 *fLog << "setup for reading." << endl;850 851 //*fLog << "Branch " << bname << " autodel: " << (int)branch->IsAutoDelete() << endl;852 //branch->SetAutoDelete();853 854 num++;855 911 } 856 912 … … 889 945 void MReadTree::SetReadyToSave(Bool_t flag) 890 946 { 891 if (!fChain) 892 return; 893 894 TIter Next(fChain->GetStatus()); 895 896 TChainElement *element = NULL; 897 while ((element=(TChainElement*)Next())) 898 { 899 // 900 // Check whether the branch is enabled 901 // 902 if (!element->GetStatus()) 903 continue; 904 905 // 906 // Get the pointer to the pointer of the corresponding container 907 // 908 MParContainer **pcont = (MParContainer**)element->GetBaddress(); 909 910 // 911 // Check whether the pointer is not NULL 912 // 913 if (!pcont || !*pcont) 914 continue; 915 916 // 917 // Set the ready to save status of the container. 918 // 919 (*pcont)->SetReadyToSave(flag); 920 } 947 fParList.R__FOR_EACH(MParContainer, SetReadyToSave)(flag); 921 948 922 949 MTask::SetReadyToSave(flag); -
trunk/MagicSoft/Mars/mfileio/MReadTree.h
r9034 r9036 31 31 32 32 MTaskList *fTaskList; // Tasklist to set StreamId 33 TList fParList; 33 34 34 35 enum { kChainWasChanged = BIT(14) }; … … 42 43 43 44 Bool_t IsOwned(const TChainElement &e) const; 45 46 void GetListOfBranches(TList &list) const; 47 MParContainer *FindCreateObj(MParList &plist, const char *cname, const char *name); 48 void *GetParameterPtr(MParList &plist, const TString &bb, const char *parname); 49 Bool_t SetBranchAddress(TBranch &b, void *ptr, const char *prefix, const char *type=0); 44 50 45 51 void DisableSubBranches(TBranch *b); … … 103 109 104 110 #endif 105 -
trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
r8999 r9036 469 469 } 470 470 471 *fLog << inf << "Unnecessary parameter container '" << cname << "' not found..." << endl;471 *fLog << inf2 << "Unnecessary parameter container '" << cname << "' not found..." << endl; 472 472 delete fBranches.Remove(entry); 473 473 continue;
Note:
See TracChangeset
for help on using the changeset viewer.