2 |
|
// $Id$ |
3 |
|
// |
4 |
|
|
5 |
< |
#include "TAMOutput.h" |
5 |
> |
#include "MitAna/TAM/interface/TAMOutput.h" |
6 |
|
|
7 |
|
|
8 |
|
#ifndef G__API_H |
32 |
|
#ifndef ROOT_TDataMember |
33 |
|
#include "TDataMember.h" |
34 |
|
#endif |
35 |
< |
#ifndef TAM_TAModule |
36 |
< |
#include "TAModule.h" |
37 |
< |
#endif |
38 |
< |
#ifndef TAM_TDirectory |
35 |
> |
#ifndef ROOT_TDirectory |
36 |
|
#include "TDirectory.h" |
37 |
|
#endif |
38 |
+ |
#ifndef TAM_TAModule |
39 |
+ |
#include "MitAna/TAM/interface/TAModule.h" |
40 |
+ |
#endif |
41 |
|
|
42 |
|
////////////////////////////////////////////////////////////////////////// |
43 |
|
// // |
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. |
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) |
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 |
575 |
|
DeleteIterators(slaveIters); |
576 |
|
} |
577 |
|
|
578 |
+ |
return list->GetEntries(); |
579 |
|
} |
580 |
|
|
581 |
|
|
599 |
|
"(%s): Can not add null object to output.", GetName()); |
600 |
|
} |
601 |
|
|
600 |
– |
|
601 |
– |
//______________________________________________________________________________ |
602 |
|
void TAMOutput::Print(Option_t *wildcard) const |
603 |
|
{ |
604 |
|
// Print the output objects inside this module and its submodules. |
613 |
|
TROOT::DecreaseDirLevel(); |
614 |
|
} |
615 |
|
|
616 |
– |
|
617 |
– |
//______________________________________________________________________________ |
618 |
– |
void TAMOutput::Print(Option_t* wildcard, Option_t* option) const |
619 |
– |
{ |
620 |
– |
// Print the output objects inside this module and its submodules. |
621 |
– |
|
622 |
– |
#if ROOT_VERSION_CODE > ROOT_VERSION(4,0,8) |
623 |
– |
cout << "Output of " << GetName() << ":" << endl; |
624 |
– |
fOutput.Print(wildcard,option); |
625 |
– |
TList::Print(wildcard,option); |
626 |
– |
#else |
627 |
– |
// backward compatible |
628 |
– |
Warning("Print","This version of Root does not handle wildcards."); |
629 |
– |
Print(option); |
630 |
– |
#endif |
631 |
– |
} |
632 |
– |
|
633 |
– |
|
616 |
|
//______________________________________________________________________________ |
617 |
|
void TAMOutput::RemoveOutput(TObject* obj) |
618 |
|
{ |
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 |
749 |
|
// will be used instead of TAMOutput objects. |
750 |
|
|
751 |
|
if (option == -99) { |
752 |
< |
Int_t nbytes = fOutput.Write(name, 0, bsize); |
752 |
> |
Int_t nbytes = 0; |
753 |
> |
nbytes += WriteCol(&fOutput, name, 0, bsize); |
754 |
|
TIter nextMod(MakeIterator()); |
755 |
< |
TObject* obj=0; |
755 |
> |
TObject* obj = 0; |
756 |
|
while ( (obj = nextMod()) ) { |
757 |
< |
TDirectory *newdir = gDirectory->mkdir(obj->GetName()); |
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 |
|
} |
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 = 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()) ) { |
784 |
|
return nbytes; |
785 |
|
} |
786 |
|
} |
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 |
+ |
} |