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.2 by loizides, Sat Sep 27 06:03:36 2008 UTC vs.
Revision 1.8 by paus, Fri Mar 30 01:08:39 2012 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 489 | Line 491 | void TAMOutput::ls(Option_t* option) con
491  
492  
493   //______________________________________________________________________________
494 < void TAMOutput::Merge(TCollection* list)
494 > Long64_t TAMOutput::Merge(TCollection* list)
495   {
496     // Called by Proof after SlaveTerminate() and before Terminate()
497     // to merge the output objects from each worker ("slave") computer.
# Line 497 | Line 499 | void TAMOutput::Merge(TCollection* list)
499     // recursively proceed through the sub modules to merge their objects.
500    
501     // merge this module's output objects
502 <   MergeOutput(list);
502 >   Long64_t mergeCount = MergeOutput(list);
503  
504     // then merge its sub modules' objects:
505     if (!IsEmpty()) { // (if we have any sub modules)
# Line 530 | Line 532 | void TAMOutput::Merge(TCollection* list)
532        DeleteIterators(slaveIters);
533     }
534  
535 +   return mergeCount;
536   }
537  
538  
539   //______________________________________________________________________________
540 < void TAMOutput::MergeOutput(TCollection* list)
540 > Long64_t TAMOutput::MergeOutput(TCollection* list)
541   {
542     // Merges the actual output objects in fCurOutput given a list of
543     // all the TAMOutput objects from the worker computers that
# Line 572 | Line 575 | void TAMOutput::MergeOutput(TCollection*
575        DeleteIterators(slaveIters);
576     }
577  
578 +   return list->GetEntries();
579   }
580  
581  
# Line 595 | Line 599 | void TAMOutput::NullObjInAddOutput() con
599           "(%s): Can not add null object to output.", GetName());
600   }
601  
598
599 //______________________________________________________________________________
602   void TAMOutput::Print(Option_t *wildcard) const
603   {
604     // Print the output objects inside this module and its submodules.
# Line 611 | Line 613 | void TAMOutput::Print(Option_t *wildcard
613     TROOT::DecreaseDirLevel();
614   }
615  
614
615 //______________________________________________________________________________
616 void TAMOutput::Print(Option_t* wildcard, Option_t* option) const
617 {
618   // Print the output objects inside this module and its submodules.
619
620 #if ROOT_VERSION_CODE > ROOT_VERSION(4,0,8)
621   cout << "Output of " << GetName() << ":" << endl;
622   fOutput.Print(wildcard,option);
623   TList::Print(wildcard,option);
624 #else
625   // backward compatible
626   Warning("Print","This version of Root does not handle wildcards.");
627   Print(option);
628 #endif
629 }
630
631
616   //______________________________________________________________________________
617   void TAMOutput::RemoveOutput(TObject* obj)
618   {
# Line 666 | Line 650 | void TAMOutput::SetOutputMembers(const B
650     // first update the addresses of the members
651     Char_t parent[kParentStrLen];
652     memset(parent, 0, kParentStrLen * sizeof(Char_t));
653 <   fMod->ShowMembers(fInspector, parent);
653 >   fMod->ShowMembers(fInspector);
654    
655     if (setAddresses) {
656        // loop through output objects and set the corresponding members
# Line 761 | Line 745 | Int_t TAMOutput::Write(const char* name,
745     // write all the output objects, flattening the module hierarchy.
746     // If the 'TObject::kSingleKey' option is specified, the TAMOutput
747     // objects themselves will be written, thus preserving the module hierarchy.
748 <  
749 <   if ( (option & TObject::kSingleKey) ) {
748 >   // If option==-99, the module hierarchy will be preserved, but TDirectories
749 >   // will be used instead of TAMOutput objects.
750 >
751 >   if (option == -99) {
752 >      Int_t nbytes = 0;
753 >      nbytes += WriteCol(&fOutput, name, 0, bsize);
754 >      TIter nextMod(MakeIterator());
755 >      TObject* obj = 0;
756 >      while ( (obj = nextMod()) ) {
757 >         TDirectory* newdir = 0;
758 >         Int_t counter = 0;
759 >         TString dirname(obj->GetName());
760 >         while (gDirectory->GetListOfKeys()->FindObject(dirname)) {
761 >            if (counter>0) {
762 >               dirname=Form("%s_%d",obj->GetName(),counter);
763 >            }
764 >            ++counter;
765 >         }
766 >         newdir = gDirectory->mkdir(dirname);
767 >         TDirectory::TContext context(newdir);
768 >         nbytes += obj->Write(name, option, bsize);
769 >      }
770 >      return nbytes;
771 >   } else if ( (option & TObject::kSingleKey) ) {
772        // here, the TList write will work just fine since it will actually
773        // call the streamer on the module output objects
774        // (through TObject::Write)
775        return TList::Write(name, option, bsize);
776     } else {
777        // flatten the module hierarchy and dump all output objects to the file
778 <      Int_t nbytes = 0;
773 <      fOutput.Write(name, option, bsize);
778 >      Int_t nbytes = WriteCol(&fOutput, name, option, bsize);
779        TIter nextMod(MakeIterator());
780        TObject* obj=0;
781        while ( (obj = nextMod()) ) {
# Line 779 | Line 784 | Int_t TAMOutput::Write(const char* name,
784        return nbytes;
785     }
786   }
787 <
787 >
788 >
789 > //______________________________________________________________________________
790 > Int_t TAMOutput::WriteCol(const TCollection *col, const char* name,
791 >                          Int_t option, Int_t bsize) const
792 > {
793 >   // Write elements of collection. Check and solve name collisions.
794 >  
795 >   Int_t nbytes = 0;
796 >   TObject *obj = 0;
797 >   TIter next(col);
798 >   while ((obj = next())) {
799 >      TCollection *col2 = dynamic_cast<TCollection*>(obj);
800 >      if (col2) {
801 >         nbytes += WriteCol(col2, name, option, bsize);
802 >         continue;
803 >      }
804 >      TString tmpname(obj->GetName());
805 >      if (name)
806 >        tmpname = name;
807 >      TString oname(tmpname);
808 >      Int_t counter = 0;
809 >      if (GetMod()->GetUseName()) { //if true always append module name
810 >        oname=Form("%s_%s",GetMod()->GetName(), tmpname.Data());
811 >        counter = 1;
812 >      }
813 >      while (gDirectory->GetListOfKeys()->FindObject(oname)) {
814 >         if (counter==0) {
815 >            oname=Form("%s_%s",GetMod()->GetName(), tmpname.Data());
816 >         } else {
817 >            oname=Form("%s_%s_%d",GetMod()->GetName(), tmpname.Data(), counter);
818 >         }
819 >         ++counter;
820 >      }
821 >      if (counter>0) {
822 >         Warning("Write", "Renamed output object from \"%s\" to \"%s\"",
823 >                 tmpname.Data(), oname.Data());
824 >      }
825 >
826 >      nbytes += obj->Write(oname, option, bsize);
827 >   }
828 >   return nbytes;
829 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines