00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4CompositeEvent.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TTree.h"
00021 #include "TROOT.h"
00022
00023 ClassImp(TGo4CompositeEvent)
00024
00025 TGo4CompositeEvent::TGo4CompositeEvent() :
00026 TGo4EventElement(),
00027 fNElements(0),
00028 fEventElements(0)
00029 {
00030 isComposite=kTRUE;
00031 }
00032
00033 TGo4CompositeEvent::TGo4CompositeEvent(const char*aName, const char* aTitle, Short_t aBaseCat) :
00034 TGo4EventElement(aName,aTitle, aBaseCat),
00035 fNElements(0),
00036 fEventElements(0)
00037 {
00038 fEventElements = new TObjArray(12);
00039 isComposite=kTRUE;
00040 }
00041
00042 TGo4CompositeEvent::~TGo4CompositeEvent()
00043 {
00044
00045 if(fEventElements!=0) {
00046 fEventElements->Sort();
00047
00048 if(!fEventElements->IsEmpty()){
00049 fEventElements->Delete();
00050
00051 }
00052 delete fEventElements;
00053 }
00054
00055 }
00056
00057
00058 void TGo4CompositeEvent::makeBranch(TBranch *parent)
00059 {
00060
00061 TGo4EventElement **par;
00062 char buffer[256];
00063 TBranch *b=NULL;
00064 Int_t i=0;
00065
00066 TObjArray &vector=*fEventElements;
00067 for(i=0;i<=fEventElements->GetLast();i++) {
00068 par=(TGo4EventElement **)&(vector[i]);
00069 if ((*par)!=NULL) {
00070 snprintf(buffer,255,"%s.",(*par)->GetName());
00071 b=gTree->TTree::Branch(buffer, (*par)->ClassName(),par,4000,99);
00072 (*par)->makeBranch(b);
00073 }
00074 }
00075 TGo4EventElement::makeBranch( parent );
00076 }
00077
00078
00079 Int_t TGo4CompositeEvent::activateBranch( TBranch *branch, Int_t splitLevel, Int_t init){
00080
00081
00082 if ( branch ){
00083 TString cad=branch->GetName();
00084 TTree *tree = branch->GetTree();
00085
00086 TGo4CompositeEvent *dump=this;
00087 tree->SetBranchStatus(cad.Data(),1);
00088 tree->SetBranchAddress(cad.Data(), &dump);
00089 cad+="*";
00090 tree->SetBranchStatus(cad.Data(),1);
00091
00092 TGo4EventElement::activateBranch(branch,splitLevel);
00093
00094 if (fDebug)
00095 printf("##### TGo4CompositeEvent::activateBranch called from obj:%s \n",this->GetName());
00096
00097 TObjArray *br = tree->GetListOfBranches();
00098 TBranch* b=NULL;
00099 TClass* cl=NULL;
00100 char* obj=NULL;
00101
00102 Int_t i=init;
00103
00104 if (fDebug)
00105 printf("-I-TGo4CompositeEvent::activateBranch from obj:%s bname%s Elements :%i index:%i\n",
00106 this->GetName(),cad.Data(), fNElements,init);
00107
00108 int max = init+fNElements;
00109 while ( i < init+fNElements ){
00110 i++;
00111 TGo4EventElement *par = NULL;
00112 b = (TBranch*) br->At(i);
00113 if(b){
00114
00115 if (fDebug)
00116 printf("-I TGo4CompositeEvent::activateBranch from obj:%s (while) bname:%s cname:%s init:%i elem:%i \n",
00117 this->GetName(), b->GetName(), b->GetClassName(), init, fNElements);
00118
00119 cl=gROOT->GetClass(b->GetClassName());
00120 obj= (char*) cl->New();
00121 par= (TGo4EventElement*) obj;
00122 if(par) {
00123 Int_t offset=par->activateBranch(b, splitLevel,i);
00124 if (fDebug)
00125 printf("-I activate from obj:%s elems:%i index:%i adding:%s\n",
00126 this->GetName(), max , i, par->GetName());
00127
00128 addEventElement(par,1);
00129 i+=offset;
00130 fNElements+=offset;
00131 if (fDebug)
00132 printf("-I from obj:%s activate indexing after offset:%i index:%i elems:%i\n",
00133 this->GetName(),
00134 offset,i,max);
00135 }
00136 }
00137
00138 }
00139 Clear();
00140 }
00141
00142 if (fDebug)
00143 printf("-I activate return value from obj:%s offset:%i \n", this->GetName(),
00144 fNElements);
00145 return fNElements;
00146
00147 }
00148
00149
00150
00151
00152 void TGo4CompositeEvent::synchronizeWithTree( TTree *tree, Int_t splitLevel)
00153 {
00154
00155
00156
00157
00158 if (tree==0) return;
00159
00160 if (fEventElements==0)
00161 fEventElements = new TObjArray(12);
00162
00163 TGo4CompositeEvent *dump=this;
00164
00165
00166 TBranch* b=NULL;
00167 TObjArray *br = tree->GetListOfBranches();
00168 b=(TBranch*) br->At(0);
00169 TString cad=b->GetName();
00170
00171 tree->SetBranchStatus(cad.Data(),1);
00172 tree->SetBranchAddress(cad.Data(), &dump);
00173 cad+="*";
00174 tree->SetBranchStatus(cad.Data(),1);
00175
00176
00177 TGo4EventElement::activateBranch(b,splitLevel);
00178
00179 TClass* cl=NULL;
00180 char* obj=NULL;
00181
00182 if(fDebug)
00183 printf("-I- TGo4CompositeEvent::synchronize(tree): Elements :%i Id:%i branch:%s \n", fNElements ,fIdentifier,cad.Data());
00184
00185
00186 Int_t i=0;
00187 while( i<fNElements ){
00188 i++;
00189 TGo4EventElement *par = NULL;
00190 b = (TBranch*) br->At(i);
00191 if(b){
00192
00193 if (fDebug)
00194 printf("-I TGo4CompositeEvent::synchronize(tree) bname:%s cname:%s Elem:%i\n",
00195 b->GetName(), b->GetClassName(), fNElements);
00196
00197 cl=gROOT->GetClass(b->GetClassName());
00198 obj= (char*) cl->New();
00199 par= (TGo4EventElement*) obj;
00200 if(par) {
00201 Int_t offset=par->activateBranch(b, splitLevel,i);
00202 if (fDebug)
00203 printf("-I synchronize index:%i from:%s adding:%s\n",
00204 i, this->GetName(), par->GetName());
00205 addEventElement(par,1);
00206 i+=offset;
00207 fNElements+=offset;
00208
00209 if (fDebug)
00210 printf("-I synchronize indexing after offset:%i index:%i elem:%i \n",
00211 offset,i,fNElements);
00212 }
00213
00214 }
00215
00216 }
00217 Clear();
00218
00219
00220 tree->GetEntry(0);
00221 }
00222
00223
00224
00225
00226 void TGo4CompositeEvent::Clear(Option_t *) {
00227
00228
00229 TIter next(fEventElements);
00230 TGo4EventElement *ev;
00231 while ( (ev=(TGo4EventElement *)next())!=NULL) {
00232 ev->Clear();
00233 }
00234 }
00235
00236
00237
00238 void TGo4CompositeEvent::clearAll(Int_t level) {
00239
00240
00241
00242
00243 if (level==0) {
00244
00245 } else {
00246 TIter next(fEventElements);
00247 TGo4EventElement *ev;
00248 while ((ev=( TGo4EventElement *)next())!=NULL) {
00249 ev->clearAll(level);
00250 }
00251 }
00252 }
00253
00254
00255 void TGo4CompositeEvent::addEventElement( TGo4EventElement* aElement, Int_t reading){
00256
00257
00258
00259
00260
00261
00262 if (getEventElement(aElement->GetName(),1)){
00263 printf("-E-1 <TGo4CompositeEvent::addEventElement> object:%s already in structure => not added ! \n",
00264 aElement->GetName());
00265 return;
00266 }
00267
00268 if ( aElement->getId() < 0 ) {
00269 printf("-E-2 <TGo4CompositeEvent::addEventElement> object:%s with invalid Id:%i => not added ! \n",
00270 aElement->GetName(), aElement->getId());
00271 return;
00272 }
00273
00274 if ( getEventElement( aElement->getId() ) ){
00275 printf("-E-3 <TGo4CompositeEvent::addEventElement> object:%s with Id:%i already used => not added ! \n",
00276 aElement->GetName(), aElement->getId());
00277 }
00278
00279 if (fDebug)
00280 printf("-I adding element in :%s :%p at location:%i \n",GetName(),aElement, aElement->getId());
00281 fEventElements->AddAtAndExpand (aElement, aElement->getId());
00282 if( reading == 0 ) fNElements++;
00283
00284 }
00285
00286
00287 TGo4EventElement* TGo4CompositeEvent::getEventElement(Int_t idx) {
00288
00289
00290 if ( idx > fEventElements->GetLast() ) return NULL;
00291 return ( ( TGo4EventElement*) fEventElements->At(idx) );
00292 }
00293
00294
00295 TGo4EventElement* TGo4CompositeEvent::getEventElement(const char* name,Int_t final) {
00296
00297 TIter next(fEventElements);
00298 TGo4EventElement *ev=NULL,*inter=NULL;
00299 while ((ev=( TGo4EventElement *)next())!=NULL) {
00300 if(strcmp(name,ev->GetName())==0) return ev;
00301 inter=NULL;
00302 if (ev->isComposed()) {
00303 inter= ((TGo4CompositeEvent*) ev)->getEventElement(name,1);
00304 if (inter !=0 ) return inter;
00305 }
00306 }
00307 if(final==0)
00308 printf("-E- TGo4CompositeEvent => Element:%s not found in Composite:%s \n",name,this->GetName());
00309 return NULL;
00310 }
00311
00312 void TGo4CompositeEvent::deactivate(){
00313
00314
00315 TIter next(fEventElements);
00316 TGo4EventElement *ev=NULL;
00317
00318 while ((ev=( TGo4EventElement *)next())!=NULL) {
00319 ev->deactivate();
00320 }
00321 }
00322
00323 void TGo4CompositeEvent::activate(){
00324
00325 TIter next(fEventElements);
00326 TGo4EventElement *ev=NULL;
00327
00328 while ((ev=( TGo4EventElement *)next())!=NULL) {
00329 ev->activate();
00330 }
00331 }
00332
00333
00334
00335
00336 TObjArray* TGo4CompositeEvent::getListOfComposites(Bool_t toplevel){
00337
00338 TObjArray *comp = new TObjArray(12);
00339 TObjArray *dump = NULL;
00340 TIter next(fEventElements);
00341 TGo4EventElement *ev,*ev2;
00342
00343 if (toplevel) {
00344 comp->Add(this);
00345
00346 }
00347
00348 ev=NULL;
00349 while ((ev=( TGo4EventElement *)next())!=NULL) {
00350 if ( ev->isComposed() ) {
00351 comp->Add( ev );
00352 dump = ((TGo4CompositeEvent*) ev)->getListOfComposites(kFALSE);
00353 TIter next2( dump);
00354 ev2=NULL;
00355 while( (ev2=( TGo4EventElement *)next2())!=NULL) {
00356 comp->Add( ev2 );
00357 }
00358 }
00359 }
00360 return comp;
00361 }
00362
00363
00364
00365
00366
00367
00368 void TGo4CompositeEvent::Streamer(TBuffer &R__b)
00369 {
00370
00371
00372
00373 if (R__b.IsReading()) {
00374
00375 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
00376 TGo4EventElement::Streamer(R__b);
00377 R__b >> fEventElements;
00378 R__b >> fNElements;
00379
00380 } else {
00381
00382 TGo4EventElement::Streamer(R__b);
00383 R__b << fEventElements;
00384 R__b << fNElements;
00385 }
00386 }
00387
00388
00389
00390
00391