00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4DynamicList.h"
00017
00018 #include <iostream.h>
00019 #include <stdexcept>
00020
00021 #include "TFolder.h"
00022 #include "TMutex.h"
00023
00024
00025 #include "Go4Log/TGo4Log.h"
00026 #include "TGo4DynamicListStatus.h"
00027 #include "TGo4DynamicListException.h"
00028 #include "TGo4HistogramEntry.h"
00029
00030
00031 TGo4DynamicList::TGo4DynamicList(const Text_t* name)
00032 :TGo4DynamicEntry(name),fxList(0), fxListMutex(0), fxListIterator(0), fxTempFolder(0)
00033 {
00034 TRACE((15,"TGo4DynamicList::TGo4DynamicList(Text_t*, TGo4Condition*)",__LINE__, __FILE__));
00035 fxList=new TObjArray;
00036 fxListMutex=new TMutex(kTRUE);
00037 fxListIterator = fxList->MakeIterator();
00038 fxTempFolder=gROOT->GetRootFolder()->AddFolder("Go4Dynlist-tmp","The Go4 dynamic list temporary folder");
00039 fxTempFolder->SetOwner(kFALSE);
00040 }
00041
00042
00043 TGo4DynamicList::TGo4DynamicList()
00044 :fxList(0), fxListMutex(0), fxListIterator(0), fxTempFolder(0)
00045 {
00046 TRACE((15,"TGo4DynamicList::TGo4DynamicList()",__LINE__, __FILE__));
00047 }
00048
00049
00050
00051 TGo4DynamicList::~TGo4DynamicList()
00052 {
00053 TRACE((15,"TGo4DynamicList::~TGo4DynamicList()",__LINE__, __FILE__));
00054
00055 if(fxTempFolder)
00056 {
00057
00058
00059 gROOT->GetRootFolder()->Remove(fxTempFolder);
00060 delete fxTempFolder;
00061 fxTempFolder=0;
00062 }
00063 delete fxListIterator;
00064 delete fxListMutex;
00065 fxList->Delete();
00066 delete fxList;
00067
00068 }
00069
00070
00071 Int_t TGo4DynamicList::Process()
00072 {
00073 TRACE((12,"TGo4DynamicList::Process()",__LINE__, __FILE__));
00074 Int_t rev=0;
00075 TGo4DynamicEntry* entry=0;
00076
00077 try{
00078 TGo4DynamicEntry* errorentry=0;
00079 ResetIterator();
00080 while((entry= NextEntry() ) !=0)
00081 {
00082 try{ entry->Process();}
00083 catch(TGo4DynamicListException& ex)
00084 {
00085 ex.Handle();
00086 errorentry= (TGo4DynamicEntry*) entry;
00087 }
00088 }
00089 if(errorentry) throw TGo4DynamicListException(errorentry,
00090 "!!!Dynamic List %s exception in process loop!!!", GetName());
00091 }
00092
00093 catch(std::exception& ex)
00094 {
00095 throw TGo4DynamicListException(entry,
00096 "!!!STD exception %s was raised processing dynamic entry of List %s!!!",
00097 ex.what(), GetName());
00098 }
00099 return rev;
00100 }
00101
00102
00103 Bool_t TGo4DynamicList::AddEntry(TGo4DynamicEntry* en)
00104 {
00105 TRACE((12,"TGo4DynamicList::AddEntry(TGo4DynamicEntry*)",__LINE__, __FILE__));
00106 if(en==0)
00107 return kFALSE;
00108
00109 const Text_t* newentryname= en->GetName();
00110 TGo4DynamicEntry* oldentry=GetEntry(newentryname);
00111 if(oldentry)
00112 {
00113
00114 return kFALSE;
00115 }
00116 else
00117 {
00118
00119
00120 fxList->AddLast(en);
00121 return kTRUE;
00122 }
00123
00124 }
00125
00126
00127 void TGo4DynamicList::DeleteEntry(const Text_t* name)
00128 {
00129 TRACE((12,"TGo4DynamicList::DeleteEntry(Text_t*)",__LINE__, __FILE__));
00130
00131 TObject* ob= fxList->FindObject(name);
00132 fxList->Remove(ob);
00133 delete ob;
00134 }
00135
00136 TGo4DynamicEntry * TGo4DynamicList::GetEntry(const Text_t* name)
00137 {
00138 TRACE((12,"TGo4DynamicList::GetEntry(Text_t*)",__LINE__, __FILE__));
00139
00140 TObject* ob = fxList->FindObject(name);
00141 TGo4DynamicEntry * ent=dynamic_cast<TGo4DynamicEntry*>(ob);
00142 return ent;
00143 }
00144
00145
00146 TNamed * TGo4DynamicList::GetObject(const Text_t * name)
00147 {
00148 TRACE((12,"TGo4DynamicList::GetObject(Text_t*)",__LINE__, __FILE__));
00149
00150 TNamed* ob=0;
00151
00152
00153 return ob;
00154 }
00155
00156
00157 void TGo4DynamicList::Clear(Option_t* option)
00158 {
00159 TRACE((12,"TGo4DynamicList::Clear(Option_t)",__LINE__, __FILE__));
00160
00161 TString opt=option;
00162 if(opt.Contains("del"))
00163 fxList->Delete(option);
00164 else
00165 Reset();
00166 }
00167
00168
00169
00170 void TGo4DynamicList::UpdateStatus(TGo4DynamicEntryStatus * state)
00171 {
00172 TRACE((12,"TGo4DynamicList::UpdateStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00173 if(!state)
00174 return;
00175 TGo4DynamicEntry::UpdateStatus(state);
00176 TGo4DynamicListStatus* liststate= dynamic_cast<TGo4DynamicListStatus*> (state);
00177 if (liststate)
00178 {
00179 TGo4DynamicEntry* entry=0;
00180 TList* nameslist= new TList;
00181
00182 ResetIterator();
00183 while((entry= NextEntry() ) !=0)
00184 {
00185 TGo4DynamicEntryStatus* entrystate = entry->CreateStatus();
00186 nameslist->AddLast(entrystate);
00187 }
00188 if(fxTempFolder==0)
00189 {
00190 fxTempFolder=gROOT->GetRootFolder()->AddFolder("Go4Dynlist-tmp","The Go4 dynamic list temporary folder");
00191 fxTempFolder->SetOwner(kFALSE);
00192
00193 }
00194
00195 liststate->fxFolder=fxTempFolder->AddFolder(GetName(), GetTitle(), nameslist);
00196 liststate->fxFolder->SetOwner(kTRUE);
00197 fxTempFolder->Remove(liststate->fxFolder);
00198 }
00199 else
00200 {
00201
00202 throw TGo4DynamicListException(this,
00203 "Dynamic List %s failed to Update Status: wrong status class %s !!!",
00204 GetName(), state->ClassName());
00205 }
00206
00207
00208 }
00209
00210 TGo4DynamicEntryStatus* TGo4DynamicList::CreateStatus()
00211 {
00212 TRACE((12,"TGo4DynamicList::CreateStatus()",__LINE__, __FILE__));
00213
00214 TGo4DynamicListStatus* state=new TGo4DynamicListStatus(GetName());
00215 UpdateStatus(state);
00216 return state;
00217 }
00218
00219 void TGo4DynamicList::Reset()
00220 {
00221 TRACE((12,"TGo4DynamicList::Reset()",__LINE__, __FILE__));
00222 TGo4DynamicEntry::Reset();
00223 TGo4DynamicEntry* entry=0;
00224
00225 ResetIterator();
00226 while((entry= NextEntry() ) !=0)
00227 {
00228 entry->Reset();
00229 }
00230 }
00231
00232 void TGo4DynamicList::CleanupCondition(TGo4Condition * con)
00233 {
00234 TRACE((12,"TGo4DynamicList::CleanupConditin(TGo4Condition*)",__LINE__, __FILE__));
00235 TGo4DynamicEntry::CleanupCondition(con);
00236 TGo4DynamicEntry* entry=0;
00237
00238 ResetIterator();
00239 while((entry= NextEntry() ) !=0)
00240 {
00241 entry->CleanupCondition(con);
00242 }
00243 }
00244
00245 void TGo4DynamicList::CleanupHistogram(TH1 * his)
00246 {
00247 TGo4DynamicEntry::CleanupHistogram(his);
00248 TGo4DynamicEntry* entry=0;
00249
00250 ResetIterator();
00251 while((entry= NextEntry() ) !=0)
00252 {
00253 entry->CleanupHistogram(his);
00254 }
00255 }
00256
00257 void TGo4DynamicList::SetStatus(TGo4DynamicEntryStatus * state)
00258 {
00259 if(state==0) return;
00260 if(state->InheritsFrom("TGo4DynamicListStatus"))
00261 {
00262
00263 TGo4DynamicEntry::SetStatus(state);
00264 TGo4DynamicListStatus* liststate= dynamic_cast<TGo4DynamicListStatus*>(state);
00265 TGo4DynamicEntryStatus* state=0;
00266 TList* statuslist= dynamic_cast<TList*>( liststate->GetTopFolder()->GetListOfFolders());
00267 TIterator* listiterator= statuslist->MakeIterator();
00268 while((state= dynamic_cast<TGo4DynamicEntryStatus*>( listiterator->Next() ) ) !=0)
00269 {
00270 SetEntryStatus(state->GetName(), state);
00271 }
00272 delete listiterator;
00273 TGo4DynamicEntry::SetStatus(liststate);
00274 }
00275 else
00276 {
00277 throw TGo4DynamicListException(this,
00278 "Dynamic List %s failed to SetStatus: wrong status class %s !!!",
00279 GetName(), state->ClassName());
00280 }
00281
00282
00283 }
00284
00285 Bool_t TGo4DynamicList::SetEntryStatus(const Text_t* name, TGo4DynamicEntryStatus * state)
00286 {
00287 TRACE((12,"TGo4DynamicList::SetEntryStatus(Text_t*,TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00288 if(state==0) return kFALSE;
00289 Bool_t rev=kFALSE;
00290 TGo4DynamicEntry * ent=GetEntry(name);
00291 if(ent)
00292 {
00293 ent->SetStatus(state);
00294 rev=kTRUE;
00295 }
00296 else
00297 {
00298 ent=state->CreateDynamicEntry();
00299 rev=AddEntry(ent);
00300 }
00301 return rev;
00302 }
00303
00304 TGo4DynamicEntryStatus * TGo4DynamicList::CreateEntryStatus(const Text_t * name)
00305 {
00306 TRACE((12,"TGo4DynamicList::CreateEntryStatus(Text_t*)",__LINE__, __FILE__));
00307 TGo4DynamicEntry * ent=GetEntry(name);
00308 if(ent)
00309 return (ent->CreateStatus());
00310 else
00311 return 0;
00312 }
00313
00314 void TGo4DynamicList::CleanupEvent(TGo4EventElement * ev)
00315 {
00316 TRACE((12,"TGo4DynamicList::CleanupEvent(TGo4Eventelement*)",__LINE__, __FILE__));
00317 TGo4DynamicEntry::CleanupEvent(ev);
00318 TGo4DynamicEntry* entry=0;
00319
00320 ResetIterator();
00321 while((entry= NextEntry())!=0)
00322 {
00323 entry->CleanupEvent(ev);
00324 }
00325
00326 }
00327
00328 void TGo4DynamicList::ResetIterator()
00329 {
00330
00331 if(fxList==0) return;
00332 if(fxListIterator)
00333 fxListIterator->Reset();
00334 else
00335 fxListIterator=fxList->MakeIterator();
00336 }
00337
00338 TGo4DynamicEntry* TGo4DynamicList::NextEntry()
00339 {
00340
00341 if(fxListIterator==0) return 0;
00342 return ( dynamic_cast<TGo4DynamicEntry*>( fxListIterator->Next() ));
00343 }
00344
00345
00346
00347 ClassImp(TGo4DynamicList)
00348
00349
00350
00351
00352