Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4DynamicList.h"
00015
00016 #include <stdexcept>
00017 #include <stdlib.h>
00018
00019 #include "TFolder.h"
00020 #include "TDataMember.h"
00021 #include "TDataType.h"
00022 #include "TBaseClass.h"
00023 #include "TClass.h"
00024 #include "TH1.h"
00025 #include "TList.h"
00026 #include "TROOT.h"
00027
00028 #include "TGo4Log.h"
00029 #include "TGo4DynamicListException.h"
00030 #include "TGo4HistogramEntry.h"
00031 #include "TGo4TreeHistogramEntry.h"
00032 #include "TGo4EventElement.h"
00033 #include "TGo4Status.h"
00034 #include "TGo4AnalysisImp.h"
00035
00036 void TGo4DynamicList::ResetEntries(TFolder* folder)
00037 {
00038 if (folder==0) return;
00039
00040 TIter iter(folder->GetListOfFolders());
00041 TObject* obj;
00042 while((obj = iter()) !=0) {
00043 TGo4DynamicEntry* entry = dynamic_cast<TGo4DynamicEntry*> (obj);
00044 if (entry!=0) entry->Reset();
00045 }
00046 }
00047
00048 void TGo4DynamicList::PrintEntries(TFolder* folder)
00049 {
00050 if (folder==0) return;
00051
00052 TIter iter(folder->GetListOfFolders());
00053 TObject* obj;
00054 while((obj = iter()) !=0) {
00055 TGo4DynamicEntry* entry = dynamic_cast<TGo4DynamicEntry*> (obj);
00056 if (entry!=0) entry->Print("*");
00057 }
00058 }
00059
00060 void TGo4DynamicList::CleanupPointerInEntries(TFolder* folder, TObject* objtoremove)
00061 {
00062 if (folder==0) return;
00063
00064 TIter iter(folder->GetListOfFolders());
00065 TObject* obj;
00066 while((obj = iter()) !=0) {
00067 TGo4DynamicEntry* entry = dynamic_cast<TGo4DynamicEntry*> (obj);
00068 if (entry!=0) entry->RecursiveRemove(objtoremove);
00069 }
00070 }
00071
00072
00073 void TGo4DynamicList::ProcessEntries(TFolder* folder, Bool_t processtrees, Int_t interval)
00074 {
00075 if (folder==0) return;
00076
00077 TGo4DynamicEntry* errorentry = 0;
00078 TIter iter(folder->GetListOfFolders());
00079 TObject* obj;
00080
00081 try {
00082 while((obj = iter()) !=0) {
00083 TGo4DynamicEntry* entry = dynamic_cast<TGo4DynamicEntry*> (obj);
00084 if (entry==0) continue;
00085
00086 try {
00087 if (!entry->IsEnabledProcessing()) continue;
00088
00089 if (!ProcessHEntry(dynamic_cast<TGo4HistogramEntry*> (entry))) {
00090 errorentry = entry;
00091 break;
00092 }
00093
00094 if (!ProcessTEntry(dynamic_cast<TGo4TreeHistogramEntry*> (entry), processtrees, interval)) {
00095 errorentry = entry;
00096 break;
00097
00098 }
00099 }
00100 catch(TGo4DynamicListException& ex) {
00101 ex.Handle();
00102 errorentry = (TGo4DynamicEntry*) entry;
00103 }
00104 }
00105
00106
00107
00108
00109 }
00110 catch(std::exception& ex) {
00111 throw TGo4DynamicListException(errorentry,
00112 "!!!STD exception %s was raised processing dynamic entry!!!",
00113 ex.what());
00114 }
00115 }
00116
00117 TDataMember* FindDataMember(TClass* eventclass,
00118 const char* memname,
00119 Long_t* totaloffset)
00120 {
00121 if(!eventclass) return 0;
00122
00123
00125
00126 Long_t indexoffset = 0;
00127 const char* ixbegin = strchr(memname,'[');
00128 if(ixbegin) {
00129
00130
00131 ixbegin++;
00132 const char* ixend = strchr(ixbegin,']');
00133 if(ixend) {
00134 TString buf(ixbegin, ixend-ixbegin);
00135 indexoffset = buf.Atoll();
00136 if(indexoffset<0) indexoffset=0;
00137 }
00138 }
00140
00141 TDataMember* eventmember= eventclass->GetDataMember(memname);
00142 if(eventmember) {
00143 *totaloffset+=eventmember->GetOffset();
00144 } else {
00145
00146 TIter baseiter(eventclass->GetListOfBases());
00147 TObject* ob=0;
00148 while((ob=baseiter()) !=0) {
00149 TBaseClass* baseclass=dynamic_cast<TBaseClass*>(ob);
00150 if(baseclass!=0)
00151 {
00152
00153 TClass* bclass=baseclass->GetClassPointer();
00154
00155 eventmember=FindDataMember(bclass,memname,totaloffset);
00156 if(eventmember)
00157 {
00158
00159 *totaloffset+=baseclass->GetDelta();
00160
00161
00162
00163
00164 break;
00165 } else{ }
00166 }
00167 }
00168 }
00169
00170
00171
00172 if(eventmember)
00173 {
00174 const char* tname = eventmember->GetFullTypeName();
00175
00176 Int_t maxindex=eventmember->GetMaxIndex(0);
00177 if(maxindex<0) maxindex=1;
00178 if(indexoffset<maxindex)
00179 {
00180 Int_t datasize = eventmember->GetDataType()->Size();
00181 *totaloffset += indexoffset*datasize;
00182
00183 }
00184 else
00185 {
00186 throw TGo4DynamicListException(0,
00187 "Index %d for array member:%s out of range %s[%d]",
00188 indexoffset, memname, tname, maxindex);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 }
00198
00199 return eventmember;
00200 }
00201
00202 bool TGo4DynamicList::ProcessHEntry(TGo4HistogramEntry* hentry)
00203 {
00204 if (hentry==0) return true;
00205
00206 if (hentry->NeedInitialisation()) {
00207 TGo4Analysis* ana= TGo4Analysis::Instance();
00208
00209 hentry->fxCondition = ana->GetAnalysisCondition(hentry->GetConditionName());
00210
00211 for(Int_t n=0; n<__MAXCONDIM__; n++) {
00212 TGo4EventElement* event = 0;
00213 TDataMember* eventmember = 0;
00214 Long_t offset=0;
00215
00216 const char* evname = hentry->GetConEventName(n);
00217 const char* memname = hentry->GetConVarName(n);
00218
00219 if (!TString(evname).Contains(TGo4HistogramEntry::Get_fgcNOEVENT()))
00220 event = ana->GetEventStructure(evname);
00221
00222 if(event!=0)
00223 if(!TString(memname).Contains(TGo4HistogramEntry::Get_fgcNODATA()))
00224 eventmember = FindDataMember(event->IsA(), memname, &offset);
00225
00226 hentry->InitCondPointer(n, event, eventmember, offset);
00227 }
00228
00229 hentry->fxHistogram = ana->GetHistogram(hentry->GetHistogramName());
00230
00231 for(Int_t n=0; n<__MAXHISDIM__; n++) {
00232 TGo4EventElement* event = 0;
00233 TDataMember* eventmember = 0;
00234 Long_t offset=0;
00235
00236 const char* evname = hentry->GetHistEventName(n);
00237 const char* memname = hentry->GetHistVarName(n);
00238
00239 if (!TString(evname).Contains(TGo4HistogramEntry::Get_fgcNOEVENT()))
00240 event = ana->GetEventStructure(evname);
00241
00242 if(event!=0)
00243 if(!TString(memname).Contains(TGo4HistogramEntry::Get_fgcNODATA()))
00244 eventmember = FindDataMember(event->IsA(), memname, &offset);
00245
00246 hentry->InitHistPointer(n, event, eventmember, offset);
00247 }
00248
00249 hentry->SetNeedInitialisation(kFALSE);
00250 }
00251
00252 Bool_t evvalid[__MAXHISDIM__];
00253 for (Int_t n=0;n<__MAXHISDIM__;n++) {
00254 evvalid[n] = kFALSE;
00255 TGo4EventElement* event = (TGo4EventElement*) hentry->fxHisEvents[n];
00256 if (event!=0)
00257 evvalid[n] = event->IsValid();
00258 }
00259
00260 hentry->ProcessNew(evvalid);
00261
00262 return true;
00263 }
00264
00265 bool TGo4DynamicList::ProcessTEntry(TGo4TreeHistogramEntry* tentry, Bool_t processtrees, Int_t interval)
00266 {
00267 if (tentry==0) return true;
00268
00269 tentry->SetDynListInterval(interval);
00270
00271 if(!processtrees) return true;
00272
00273 const char* hname = tentry->GetHistogramName();
00274
00275 TTree* tree = TGo4Analysis::Instance()->GetTree(tentry->GetTreeName());
00276 if (tree==0) {
00277 throw TGo4DynamicListException(tentry,
00278 "Tree Histogram Entry: !!! Could not find Tree %s ",tentry->GetTreeName());
00279 return kFALSE;
00280 }
00281
00282 TH1* histo = TGo4Analysis::Instance()->GetHistogram(hname);
00283
00284 if (!tentry->fbNewHistogram && (histo==0)) {
00285 throw TGo4DynamicListException(tentry,
00286 "Tree Histogram Entry: !!! Could not find Histogram %s ",hname);
00287 return kFALSE;
00288 }
00289
00290 if (histo!=0)
00291 tentry->fbNewHistogram = kFALSE;
00292
00293 tentry->ProcessTreeNew(tree, TGo4Analysis::Instance()->GetDynListInterval());
00294
00295 if (tentry->fbNewHistogram) {
00297
00298
00299 histo = dynamic_cast<TH1*>(gROOT->FindObject(hname));
00300 if(histo==0)
00301 {
00302
00303 histo = dynamic_cast<TH1*>(gROOT->FindObjectAny(hname));
00304 }
00305
00306
00307
00308
00309 if(histo!=0) {
00310
00311 TGo4Analysis::Instance()->AddHistogram(histo);
00312 histo->SetBit(TGo4Status::kGo4CanDelete);
00313 tentry->fbNewHistogram=kFALSE;
00314 }
00315 }
00316
00317 return true;
00318 }