ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TAM/src/TAMOutput.cxx
(Generate patch)

Comparing UserCode/MitAna/TAM/src/TAMOutput.cxx (file contents):
Revision 1.1 by loizides, Tue May 27 19:13:21 2008 UTC vs.
Revision 1.7 by bendavid, Fri Mar 11 04:03:54 2011 UTC

# Line 2 | Line 2
2   // $Id$
3   //
4  
5 < #include "TAMOutput.h"
5 > #include "MitAna/TAM/interface/TAMOutput.h"
6  
7  
8   #ifndef G__API_H
# Line 32 | Line 32
32   #ifndef ROOT_TDataMember
33   #include "TDataMember.h"
34   #endif
35 + #ifndef ROOT_TDirectory
36 + #include "TDirectory.h"
37 + #endif
38   #ifndef TAM_TAModule
39 < #include "TAModule.h"
39 > #include "MitAna/TAM/interface/TAModule.h"
40   #endif
41  
39
42   //////////////////////////////////////////////////////////////////////////
43   //                                                                      //
44   // TAMOutput                                                            //
# Line 75 | Line 77 | ClassImp(TAMOutput::TAMModInspector::TAM
77  
78  
79   //______________________________________________________________________________
80 < TAMOutput::TAMModInspector::TAMModInspector()
80 > TAMOutput::TAMModInspector::TAMModInspector() :
81 >   fOutputMembers(TCollection::kInitHashTableCapacity, 1)
82   {
83     // Default constructor.
84  
# Line 594 | Line 597 | void TAMOutput::NullObjInAddOutput() con
597           "(%s): Can not add null object to output.", GetName());
598   }
599  
597
598 //______________________________________________________________________________
600   void TAMOutput::Print(Option_t *wildcard) const
601   {
602     // Print the output objects inside this module and its submodules.
# Line 610 | Line 611 | void TAMOutput::Print(Option_t *wildcard
611     TROOT::DecreaseDirLevel();
612   }
613  
613
614 //______________________________________________________________________________
615 void TAMOutput::Print(Option_t* wildcard, Option_t* option) const
616 {
617   // Print the output objects inside this module and its submodules.
618
619 #if ROOT_VERSION_CODE > ROOT_VERSION(4,0,8)
620   cout << "Output of " << GetName() << ":" << endl;
621   fOutput.Print(wildcard,option);
622   TList::Print(wildcard,option);
623 #else
624   // backward compatible
625   Warning("Print","This version of Root does not handle wildcards.");
626   Print(option);
627 #endif
628 }
629
630
614   //______________________________________________________________________________
615   void TAMOutput::RemoveOutput(TObject* obj)
616   {
# Line 665 | Line 648 | void TAMOutput::SetOutputMembers(const B
648     // first update the addresses of the members
649     Char_t parent[kParentStrLen];
650     memset(parent, 0, kParentStrLen * sizeof(Char_t));
651 <   fMod->ShowMembers(fInspector, parent);
651 >   fMod->ShowMembers(fInspector);
652    
653     if (setAddresses) {
654        // loop through output objects and set the corresponding members
# Line 760 | Line 743 | Int_t TAMOutput::Write(const char* name,
743     // write all the output objects, flattening the module hierarchy.
744     // If the 'TObject::kSingleKey' option is specified, the TAMOutput
745     // objects themselves will be written, thus preserving the module hierarchy.
746 <  
747 <   if ( (option & TObject::kSingleKey) ) {
746 >   // If option==-99, the module hierarchy will be preserved, but TDirectories
747 >   // will be used instead of TAMOutput objects.
748 >
749 >   if (option == -99) {
750 >      Int_t nbytes = 0;
751 >      nbytes += WriteCol(&fOutput, name, 0, bsize);
752 >      TIter nextMod(MakeIterator());
753 >      TObject* obj = 0;
754 >      while ( (obj = nextMod()) ) {
755 >         TDirectory* newdir = 0;
756 >         Int_t counter = 0;
757 >         TString dirname(obj->GetName());
758 >         while (gDirectory->GetListOfKeys()->FindObject(dirname)) {
759 >            if (counter>0) {
760 >               dirname=Form("%s_%d",obj->GetName(),counter);
761 >            }
762 >            ++counter;
763 >         }
764 >         newdir = gDirectory->mkdir(dirname);
765 >         TDirectory::TContext context(newdir);
766 >         nbytes += obj->Write(name, option, bsize);
767 >      }
768 >      return nbytes;
769 >   } else if ( (option & TObject::kSingleKey) ) {
770        // here, the TList write will work just fine since it will actually
771        // call the streamer on the module output objects
772        // (through TObject::Write)
773        return TList::Write(name, option, bsize);
774     } else {
775        // flatten the module hierarchy and dump all output objects to the file
776 <      Int_t nbytes = 0;
772 <      fOutput.Write(name, option, bsize);
776 >      Int_t nbytes = WriteCol(&fOutput, name, option, bsize);
777        TIter nextMod(MakeIterator());
778        TObject* obj=0;
779        while ( (obj = nextMod()) ) {
# Line 778 | Line 782 | Int_t TAMOutput::Write(const char* name,
782        return nbytes;
783     }
784   }
785 <
785 >
786 >
787 > //______________________________________________________________________________
788 > Int_t TAMOutput::WriteCol(const TCollection *col, const char* name,
789 >                          Int_t option, Int_t bsize) const
790 > {
791 >   // Write elements of collection. Check and solve name collisions.
792 >  
793 >   Int_t nbytes = 0;
794 >   TObject *obj = 0;
795 >   TIter next(col);
796 >   while ((obj = next())) {
797 >      TCollection *col2 = dynamic_cast<TCollection*>(obj);
798 >      if (col2) {
799 >         nbytes += WriteCol(col2, name, option, bsize);
800 >         continue;
801 >      }
802 >      TString tmpname(obj->GetName());
803 >      if (name)
804 >        tmpname = name;
805 >      TString oname(tmpname);
806 >      Int_t counter = 0;
807 >      if (GetMod()->GetUseName()) { //if true always append module name
808 >        oname=Form("%s_%s",GetMod()->GetName(), tmpname.Data());
809 >        counter = 1;
810 >      }
811 >      while (gDirectory->GetListOfKeys()->FindObject(oname)) {
812 >         if (counter==0) {
813 >            oname=Form("%s_%s",GetMod()->GetName(), tmpname.Data());
814 >         } else {
815 >            oname=Form("%s_%s_%d",GetMod()->GetName(), tmpname.Data(), counter);
816 >         }
817 >         ++counter;
818 >      }
819 >      if (counter>0) {
820 >         Warning("Write", "Renamed output object from \"%s\" to \"%s\"",
821 >                 tmpname.Data(), oname.Data());
822 >      }
823 >
824 >      nbytes += obj->Write(oname, option, bsize);
825 >   }
826 >   return nbytes;
827 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines