00001 //*-- Author : Valeri Fine (fine@bnl.gov) 00002 // 00003 // $Id: StHistCollectorMaker.cxx,v 2.7 2007/05/29 20:46:19 fine Exp $ 00004 // 00006 // // 00007 // StHistCollectorMaker is to collect the histBranch staff from the several // 00008 // files // 00009 // // 00010 // use $STAR/StRoot/macro/analysis/doHists.C macro to see hot it works // 00011 // // 00012 // This maker collects non-empty histograms from histBranch // 00013 // calling GetDataSet("hist") // 00014 // and accumulates it under ".const/Merged" sub-dataset. // 00015 // The "Merged" dataset preserves the dataset structure of the original // 00016 // histBrach. Namely, it contains the one level of heirarchy with // 00017 // the maker names and TList object contaoins the list of histogram // 00018 // producing by the maker with the several reconstruction sessions // 00019 // // 00020 // See: $STAR/StRoot/macros/analysis/doHists.C macro as example. // 00021 // doHist.C macro is derived from doEvents.C. It preserves doEvents.C 00022 // user interface. 00023 // // 00024 // Submit any problem with this code via begin_html <A HREF="http://www.star.bnl.gov/STARAFS/comp/sofi/bugs/send-pr.html"><B><I>"STAR Problem Report Form"</I></B></A> end_html // 00025 // // 00027 00028 #include "StHistCollectorMaker.h" 00029 #include "TDataSetIter.h" 00030 #include "TH1.h" 00031 00032 ClassImp(StHistCollectorMaker) 00033 00034 //_____________________________________________________________________________ 00035 StHistCollectorMaker::StHistCollectorMaker(const char *name):StMaker(name){ 00036 // StHistCollectorMaker constructor 00037 // const char *name - the name of the maker 00038 fMergedSet = 0; 00039 } 00040 //_____________________________________________________________________________ 00041 StHistCollectorMaker::~StHistCollectorMaker(){ } 00042 //_____________________________________________________________________________ 00043 Int_t StHistCollectorMaker::Init(){ 00044 // Create the dataset to merger the coming histograms 00045 if (fMergedSet) delete fMergedSet; 00046 fMergedSet = 0; 00047 return StMaker::Init(); 00048 } 00049 //_____________________________________________________________________________ 00050 Int_t StHistCollectorMaker::Make(){ 00051 // Make - this methoid is called in loop for each event 00052 static const char *datasetName = "Merged"; 00053 if (!fMergedSet) { 00054 // Qurey one's "Mergeg" dataset (assuming I/O maker) 00055 // to take over 00056 fMergedSet = GetDataSet(datasetName); 00057 if (!fMergedSet) fMergedSet = new TDataSet(datasetName); 00058 fMergedSet->Shunt(0); 00059 AddConst(fMergedSet); 00060 } 00061 AddHists(); 00062 return kStOK; 00063 } 00064 00065 //_____________________________________________________________________________ 00066 TDataSet *StHistCollectorMaker::AddHists() 00067 { 00068 // Update dataset fMergedSet with "histBranch" staff 00069 TDataSet *rec = fMergedSet; 00070 TDataSet *histBranch = GetDataSet("hist"); 00071 if (!histBranch) { 00072 LOG_INFO << "No hist" << endm; 00073 return 0;} 00074 TDataSetIter nextDonor(histBranch); 00075 TDataSet *donor = 0; 00076 while((donor = nextDonor())) { 00077 Bool_t found = kFALSE; 00078 TDataSetIter nextOld(rec); 00079 const Char_t *newname = donor->GetName(); 00080 TDataSet *oldset = 0; 00081 while ( (oldset = nextOld()) && !found) { 00082 // if the "new" set does contain the dataset 00083 // with the same name as ours update it too 00084 if (oldset->IsThisDir(newname)) { 00085 UpdateHists((TObjectSet *)oldset,(TObjectSet *)donor); 00086 found = kTRUE; 00087 } 00088 } 00089 // If the new "set" contains some new dataset with brand-new name 00090 // move it into the our dataset and remove it from its old location 00091 if (!found) { 00092 // Take in account the non-empty list only 00093 TList *newList = (TList *)donor->GetObject(); 00094 if (newList && newList->GetSize() > 0) { 00095 // remove the histogram from its directories 00096 TIter nextDonor(newList); 00097 TH1 *donorHist = 0; 00098 Int_t count = 0; 00099 while ( (donorHist = (TH1 *)nextDonor()) ) { 00100 if (donorHist->GetEntries() > 0) { 00101 donorHist->SetDirectory(0); 00102 count++; // count non-empty histograms 00103 } else { 00104 newList->Remove(donorHist); 00105 } 00106 } 00107 if (count) donor->Shunt(rec); // accept this if it contains one non-empty hist at least 00108 } 00109 } 00110 } 00111 return 0; 00112 } 00113 //_____________________________________________________________________________ 00114 void StHistCollectorMaker::UpdateHists(TObjectSet *oldSet,TObjectSet *newSet) 00115 { 00116 // Merge two sets of the histograms 00117 if (oldSet && newSet) { 00118 // Get the list of the new histograms 00119 TList *newList = (TList *)newSet->GetObject(); 00120 TList *oldList = (TList *)oldSet->GetObject(); 00121 TIter nextDonor(newList); 00122 TIter nextOld(oldList); 00123 00124 TH1 *donor = 0; 00125 while ( (donor = (TH1 *)nextDonor()) ) { 00126 Bool_t found = kFALSE; 00127 if (donor->GetEntries() > 0 ) { 00128 const Char_t *newname = donor->GetName(); 00129 TH1 *oldHist = 0; 00130 while ( (oldHist = (TH1 *)nextOld()) && !found) { 00131 // if the "new" set does contain the dataset 00132 // with the same name as ours update it too 00133 if (!strcmp(oldHist->GetName(),newname)) { 00134 found = kTRUE; 00135 oldHist->Add(donor); // merge histograms 00136 } 00137 }; nextOld.Reset(); // old histograms has been looked up 00138 00139 // If the new "set" contains some new dataset with brand-new name 00140 // move it into the our dataset and remove it from its old location 00141 if (!found) { // move histogram to this 00142 oldList->Add(donor); 00143 newList->Remove(donor); 00144 donor->SetDirectory(0); 00145 } 00146 } 00147 } 00148 } 00149 } 00150 00151 // $Log: StHistCollectorMaker.cxx,v $ 00152 // Revision 2.7 2007/05/29 20:46:19 fine 00153 // Introduce logger-based output 00154 // 00155 // Revision 2.6 2007/04/28 20:36:14 perev 00156 // Redundant StChain.h removed 00157 // 00158 // Revision 2.5 2000/12/02 01:03:10 fine 00159 // Recursive collection of histogram introduced 00160 // 00161 // Revision 2.4 2000/12/01 02:16:42 fine 00162 // the performance issue resolved 00163 // 00164 // Revision 2.3 2000/11/30 20:13:27 fine 00165 // Get rid of the empty histograms (thanks Fisyak) 00166 // 00167 // Revision 2.2 2000/11/30 19:37:26 fine 00168 // Reference to doHists.C macro has been added 00169 // 00170 // Revision 2.1 2000/11/30 19:35:14 fine 00171 // New analysis utility to collect all histogram from all histBranh production branches 00172 // 00173
1.5.9