00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4DynamicEntry.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TDataMember.h"
00021 #include "TBaseClass.h"
00022
00023 #include "Go4Log/TGo4Log.h"
00024 #include "Go4ConditionsBase/TGo4Condition.h"
00025 #include "Go4Event/TGo4EventElement.h"
00026 #include "Go4Analysis/TGo4AnalysisImp.h"
00027 #include "TGo4DynamicEntryStatus.h"
00028 #include "TGo4DynamicListException.h"
00029
00030 const Text_t TGo4DynamicEntry::fgcNOCONDITION[]="No Condition";
00031 const Text_t TGo4DynamicEntry::fgcNODATA[]="No Data";
00032 const Text_t TGo4DynamicEntry::fgcNOEVENT[]="No Event";
00033 const UInt_t TGo4DynamicEntry::fguMAXCONDIMENSION=__MAXCONDIM__;
00034
00035 TGo4DynamicEntry::TGo4DynamicEntry()
00036
00037 : fbProcessEntry(kTRUE),fbPointerInitDone(kFALSE),fxCondition(0)
00038 {
00039 TRACE((15,"TGo4DynamicEntry::TGo4DynamicEntry()",__LINE__, __FILE__));
00040
00041
00042
00043
00044
00045
00046
00047
00048 }
00049
00050
00051 TGo4DynamicEntry::TGo4DynamicEntry(const Text_t* name)
00052 : TNamed(const_cast <Text_t*> (name) ,"This is a Go4 dynamic entry"),
00053 fbProcessEntry(kTRUE), fbPointerInitDone(kFALSE), fxCondition(0)
00054 {
00055 TRACE((15,"TGo4DynamicEntry::TGo4DynamicEntry(Text_t *)",__LINE__, __FILE__));
00056 fxConditionName=fgcNOCONDITION;
00057 for (UInt_t t=0; t<fguMAXCONDIMENSION;++t)
00058 {
00059
00060 SetConEventName(t,fgcNOEVENT);
00061 SetConVarName(t,fgcNODATA);
00062 }
00063 Reset();
00064 }
00065
00066 TGo4DynamicEntry::~TGo4DynamicEntry()
00067 {
00068 TRACE((15,"TGo4DynamicEntry::~TGo4DynamicEntry()",__LINE__, __FILE__));
00069
00070
00071 }
00072
00073 void TGo4DynamicEntry::UpdateStatus(TGo4DynamicEntryStatus * state)
00074 {
00075 TRACE((12,"TGo4DynamicEntry::UpdateStatus(TGo4DynamicEntryStatus* )",__LINE__, __FILE__));
00076 if (state)
00077 {
00078 if(fxCondition)
00079 {
00080 state->SetCondition(fxCondition);
00081 }
00082 else
00083 {
00084 state->fxConditionName=fxConditionName;
00085 state->fxConditionClass="no pointer";
00086 }
00087 state->SetFlags(fbProcessEntry, fbPointerInitDone);
00088 state->SetConEventNames(fxConEventName);
00089 state->SetConVarNames(fxConVarName);
00090 }
00091 else
00092 { }
00093 }
00094
00095 void TGo4DynamicEntry::CleanupCondition(TGo4Condition * con)
00096 {
00097 TRACE((12,"TGo4DynamicEntry::CleanupCondition(TGo4Condition*)",__LINE__, __FILE__));
00098 if(fxCondition==con)
00099 TGo4DynamicEntry::Reset();
00100 }
00101
00102 void TGo4DynamicEntry::Reset()
00103 {
00104 TRACE((12,"TGo4DynamicEntry::Reset()",__LINE__, __FILE__));
00105 fxCondition=0;
00106 fbPointerInitDone=kFALSE;
00107 for(UInt_t t =0; t<fguMAXCONDIMENSION; ++t)
00108 {
00109 fxConDataFloat[t]=0;
00110 fxConDataDouble[t]=0;
00111 fxConDataInt[t]=0;
00112 fxConDataShort[t]=0;
00113 fxConDataChar[t]=0;
00114 fxConDataLong[t]=0;
00115 fxConDataBool[t]=0;
00116 fxConDataUInt[t]=0;
00117 fxConDataUShort[t]=0;
00118 fxConDataUChar[t]=0;
00119 fxConDataULong[t]=0;
00120 fxConEvent[t]=0;
00121 }
00122
00123 }
00124
00125 void TGo4DynamicEntry::InitPointers()
00126 {
00127 TRACE((42,"TGo4DynamicEntry::InitPointers()",__LINE__, __FILE__));
00128 Reset();
00129 TGo4Analysis* ana= TGo4Analysis::Instance();
00130 if(fxConditionName.Contains(fgcNOCONDITION))
00131 {
00132
00133 fxCondition=0;
00134 }
00135 else
00136 {
00137 fxCondition= ana->GetAnalysisCondition(fxConditionName.Data());
00138 }
00139 if(fxCondition)
00140 {
00141 for(UInt_t u=0; u< fguMAXCONDIMENSION; ++u)
00142 {
00143 if(fxConEventName[u].Contains(fgcNOEVENT))
00144 {
00145
00146 fxConEvent[u]=0;
00147 }
00148 else
00149 {
00150 fxConEvent[u]=ana->GetEventStructure(fxConEventName[u].Data());
00151
00152 }
00153
00154 if(fxConEvent[u])
00155 {
00156
00157
00158
00159
00160
00161 Long_t base = (Long_t) (fxConEvent[u]);
00162 Long_t offset=0;
00163 TClass* eventclass=fxConEvent[u]->IsA();
00164 if(eventclass)
00165 {
00166 TDataMember* eventmember;
00167 if(fxConVarName[u].Contains(fgcNODATA))
00168 {
00169
00170 eventmember=0;
00171 }
00172 else
00173 {
00174 const Text_t* memname=fxConVarName[u].Data();
00175
00176 eventmember=FindDataMember(eventclass,memname,&offset);
00177 }
00178 if(eventmember)
00179 {
00180 const Text_t* tname=eventmember->GetFullTypeName();
00181 if(!strcmp(tname,"Float_t"))
00182 {
00183
00184 fxConDataFloat[u]=(Float_t*) (base+offset);
00185 }
00186 else if (!strcmp(tname,"Double_t"))
00187 {
00188
00189 fxConDataDouble[u]=(Double_t*) (base+offset);
00190 }
00191 else if (!strcmp(tname,"Int_t"))
00192 {
00193
00194 fxConDataInt[u]=(Int_t*) (base+offset);
00195 }
00196 else if (!strcmp(tname,"Short_t"))
00197 {
00198
00199 fxConDataShort[u]=(Short_t*) (base+offset);
00200 }
00201 else if (!strcmp(tname,"Char_t"))
00202 {
00203
00204 fxConDataChar[u]=(Char_t*) (base+offset);
00205 }
00206 else if (!strcmp(tname,"Long_t"))
00207 {
00208
00209 fxConDataLong[u]=(Long_t*) (base+offset);
00210 }
00211 else if (!strcmp(tname,"Bool_t"))
00212 {
00213
00214 fxConDataBool[u]=(Bool_t*) (base+offset);
00215 }
00216 else if (!strcmp(tname,"UInt_t"))
00217 {
00218
00219 fxConDataUInt[u]=(UInt_t*) (base+offset);
00220 }
00221 else if (!strcmp(tname,"UShort_t"))
00222 {
00223
00224 fxConDataUShort[u]=(UShort_t*) (base+offset);
00225 }
00226 else if (!strcmp(tname,"UChar_t"))
00227 {
00228
00229 fxConDataUChar[u]=(UChar_t*) (base+offset);
00230 }
00231 else if (!strcmp(tname,"ULong_t"))
00232 {
00233
00234 fxConDataULong[u]=(ULong_t*) (base+offset);
00235 }
00236 else
00237 {
00238 throw TGo4DynamicListException(this,
00239 "Dynamic Dynamic Entry %s failed to Init Data Pointers: Type %s of member %s is currently not supported !!!",
00240 GetName(), tname, eventmember->GetName());
00241 }
00242 }
00243 else
00244 {
00245
00246 }
00247 }
00248 }
00249 else
00250 {
00251
00252 }
00253 }
00254 }
00255 else
00256 {
00257
00258 }
00259 fbPointerInitDone=kTRUE;
00260 }
00261
00262 Bool_t TGo4DynamicEntry::TestCondition()
00263 {
00264 TRACE((12,"TGo4DynamicEntry::TestCondition()",__LINE__, __FILE__));
00265 Bool_t rev=kFALSE;
00266 if(!fbPointerInitDone) InitPointers();
00267 if(fxCondition)
00268 {
00269
00270
00271
00272
00273 Axis_t dat[fguMAXCONDIMENSION]={0};
00274 UInt_t j,dimension;
00275
00276 for(dimension=0;dimension<fguMAXCONDIMENSION; ++dimension)
00277 {
00278 if ( (fxConDataFloat[dimension]==0) &&
00279 (fxConDataDouble[dimension]==0) &&
00280 (fxConDataInt[dimension]==0) &&
00281 (fxConDataShort[dimension]==0) &&
00282 (fxConDataChar[dimension]==0) &&
00283 (fxConDataLong[dimension]==0) &&
00284 (fxConDataBool[dimension]==0) &&
00285 (fxConDataUInt[dimension]==0) &&
00286 (fxConDataUShort[dimension]==0) &&
00287 (fxConDataUChar[dimension]==0) &&
00288 (fxConDataULong[dimension]==0) )
00289 {
00290 break;
00291
00292 }
00293 }
00294
00295
00296
00297 for(j=0;j<dimension; ++j)
00298 {
00299 if(fxConDataFloat[j]) dat[j] = (*fxConDataFloat[j]);
00300 else if (fxConDataDouble[j]) dat[j] = (*fxConDataDouble[j]);
00301 else if (fxConDataInt[j]) dat[j] = (*fxConDataInt[j]);
00302 else if (fxConDataShort[j]) dat[j] = (*fxConDataShort[j]);
00303 else if (fxConDataChar[j]) dat[j] = (*fxConDataChar[j]);
00304 else if (fxConDataLong[j]) dat[j] = (*fxConDataLong[j]);
00305 else if (fxConDataBool[j]) dat[j] = (*fxConDataBool[j]);
00306 else if (fxConDataUInt[j]) dat[j] = (*fxConDataUInt[j]);
00307 else if (fxConDataUShort[j]) dat[j] = (*fxConDataUShort[j]);
00308 else if (fxConDataUChar[j]) dat[j] = (*fxConDataUChar[j]);
00309 else if (fxConDataULong[j]) dat[j] = (*fxConDataULong[j]);
00310
00311 else throw TGo4DynamicListException(this,
00312 "Dynamic Dynamic Entry %s Process error: condition value pointer not initialized for axis %d !!!",
00313 GetName(), j);
00314 }
00315
00316 switch(dimension)
00317 {
00318 case 0:
00319 rev=fxCondition->GetLast();
00320
00321 break;
00322 case 1:
00323 rev=fxCondition->Test(dat[0]);
00324
00325 break;
00326 case 2:
00327 rev=fxCondition->Test(dat[0], dat[1]);
00328
00329 break;
00330 default:
00331 rev=fxCondition->GetLast();
00332 break;
00333 }
00334 }
00335 else
00336 {
00337 rev=kTRUE;
00338 }
00339 return rev;
00340 }
00341
00342 void TGo4DynamicEntry::SetConVarName(UInt_t ix, const Text_t * name)
00343 {
00344 TRACE((12,"TGo4DynamicEntry::SetConVarName(UInt_t, Text_t*)",__LINE__, __FILE__));
00345 if(ix>=fguMAXCONDIMENSION) return;
00346 fxConVarName[ix]=name;
00347 }
00348 void TGo4DynamicEntry::SetConEventName(UInt_t ix, const Text_t * name)
00349 {
00350 TRACE((12,"TGo4DynamicEntry::SetConEventName(UInt_t, Text_t*)",__LINE__, __FILE__));
00351 if(ix>=fguMAXCONDIMENSION) return;
00352 fxConEventName[ix]=name;
00353 }
00354 void TGo4DynamicEntry::SetConditionName(const Text_t * name)
00355 {
00356 fxConditionName=name;
00357 }
00358
00359 void TGo4DynamicEntry::SetStatus(TGo4DynamicEntryStatus * state)
00360 {
00361 TRACE((12,"TGo4DynamicEntry::SetStatus(TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
00362 if(state==0) return;
00363 SetName(state->GetName());
00364 EnableProcessing(state->AutoProcessIsEnabled());
00365 SetConditionName(state->GetConditionName());
00366 for(UInt_t i=0; i< fguMAXCONDIMENSION; ++i)
00367 {
00368 SetConEventName(i,state->GetConEventName(i));
00369 SetConVarName(i,state->GetConVarName(i));
00370 }
00371 Reset();
00372 }
00373
00374 void TGo4DynamicEntry::CleanupEvent(TGo4EventElement * ev)
00375 {
00376 TRACE((12,"TGo4DynamicEntry::CleanupEvent(TGo4EventElement*)",__LINE__, __FILE__));
00377 for(UInt_t t =0; t<fguMAXCONDIMENSION; ++t)
00378 {
00379 if(fxConEvent[t]==ev)
00380 {
00381 TGo4DynamicEntry::Reset();
00382 break;
00383 }
00384 }
00385 }
00386
00387 void TGo4DynamicEntry::CleanupHistogram(TH1 * his)
00388 {
00389
00390 }
00391
00392
00393 TDataMember* TGo4DynamicEntry::FindDataMember(TClass* eventclass,
00394 const Text_t* memname,
00395 Long_t* totaloffset)
00396 {
00397 TRACE((12,"TGo4DynamicEntry::FindDataMember(TClass*)",__LINE__, __FILE__));
00398 if(!eventclass) return 0;
00399
00400
00402
00403 Long_t indexoffset=0;
00404 Text_t ixtext[256];
00405 Text_t* ixbegin=strstr(memname,"[");
00406 if(ixbegin)
00407 {
00408
00409
00410 ixbegin++;
00411 Text_t* ixend=strstr(ixbegin,"]");
00412 if(ixend)
00413 {
00414 Int_t ixlen=ixend-ixbegin;
00415 snprintf(ixtext,ixlen+1,"%s",ixbegin);
00416 indexoffset=atoi(ixtext);
00417 if(indexoffset<0) indexoffset=0;
00418 }
00419 else {}
00420 }
00421 else {}
00423
00424 TDataMember* eventmember= eventclass->GetDataMember(memname);
00425 if(eventmember)
00426 {
00427 *totaloffset+=eventmember->GetOffset();
00428 }
00429 else
00430 {
00431
00432 TList* baselist=eventclass->GetListOfBases();
00433 TIterator* baseiter=baselist->MakeIterator();
00434 TObject* ob=0;
00435 while((ob=baseiter->Next()) !=0)
00436 {
00437 TBaseClass* baseclass=dynamic_cast<TBaseClass*>(ob);
00438 if(baseclass)
00439 {
00440
00441 TClass* bclass=baseclass->GetClassPointer();
00442
00443 eventmember=FindDataMember(bclass,memname,totaloffset);
00444 if(eventmember)
00445 {
00446
00447 *totaloffset+=baseclass->GetDelta();
00448
00449
00450
00451
00452 break;
00453 } else{ }
00454 }
00455 }
00456 delete baseiter;
00457 }
00458
00459
00460
00461 if(eventmember)
00462 {
00463 const Text_t* tname=eventmember->GetFullTypeName();
00464
00465
00466 Int_t maxindex=eventmember->GetMaxIndex(0);
00467 if(maxindex<0) maxindex=1;
00468 if(indexoffset<maxindex)
00469 {
00470 *totaloffset+=indexoffset*Membersize(tname);
00471
00472 }
00473 else
00474 {
00475 throw TGo4DynamicListException(this,
00476 "Index %d for array member:%s out of range %s[%d]",
00477 indexoffset, memname, tname, maxindex);
00478 }
00479
00480
00481
00482
00483
00484
00485
00486 }
00487
00488
00489
00490 return eventmember;
00491 }
00492
00493 Int_t TGo4DynamicEntry::Membersize(const Text_t* tname)
00494 {
00495 Int_t rev=0;
00496 if(!strcmp(tname,"Float_t")) rev=sizeof(Float_t);
00497 else if (!strcmp(tname,"Double_t")) rev=sizeof(Double_t);
00498 else if (!strcmp(tname,"Int_t")) rev=sizeof(Int_t);
00499 else if (!strcmp(tname,"Short_t")) rev=sizeof(Short_t);
00500 else if (!strcmp(tname,"Char_t")) rev=sizeof(Char_t);
00501 else if (!strcmp(tname,"Long_t")) rev=sizeof(Long_t);
00502 else if (!strcmp(tname,"Bool_t")) rev=sizeof(Bool_t);
00503 else if (!strcmp(tname,"UInt_t")) rev=sizeof(UInt_t);
00504 else if (!strcmp(tname,"UShort_t")) rev=sizeof(UShort_t);
00505 else if (!strcmp(tname,"UChar_t")) rev=sizeof(UChar_t);
00506 else if (!strcmp(tname,"ULong_t")) rev=sizeof(ULong_t);
00507 else rev=0;
00508 return rev;
00509 }
00510
00511
00512
00513 ClassImp(TGo4DynamicEntry)
00514
00515
00516
00517
00518