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 |
|
// // |
597 |
|
"(%s): Can not add null object to output.", GetName()); |
598 |
|
} |
599 |
|
|
600 |
– |
|
601 |
– |
//______________________________________________________________________________ |
600 |
|
void TAMOutput::Print(Option_t *wildcard) const |
601 |
|
{ |
602 |
|
// Print the output objects inside this module and its submodules. |
611 |
|
TROOT::DecreaseDirLevel(); |
612 |
|
} |
613 |
|
|
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 |
– |
|
614 |
|
//______________________________________________________________________________ |
615 |
|
void TAMOutput::RemoveOutput(TObject* obj) |
616 |
|
{ |
747 |
|
// will be used instead of TAMOutput objects. |
748 |
|
|
749 |
|
if (option == -99) { |
750 |
< |
Int_t nbytes = fOutput.Write(name, 0, bsize); |
750 |
> |
Int_t nbytes = 0; |
751 |
> |
nbytes += WriteCol(&fOutput, name, 0, bsize); |
752 |
|
TIter nextMod(MakeIterator()); |
753 |
< |
TObject* obj=0; |
753 |
> |
TObject* obj = 0; |
754 |
|
while ( (obj = nextMod()) ) { |
755 |
< |
TDirectory *newdir = gDirectory->mkdir(obj->GetName()); |
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 |
|
} |
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 = 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()) ) { |
782 |
|
return nbytes; |
783 |
|
} |
784 |
|
} |
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 |
+ |
} |