00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4TreeSource.h"
00017
00018 #include <iostream.h>
00019
00020 #include "TTree.h"
00021
00022 #include "Go4Log/TGo4Log.h"
00023 #include "Go4EventServer/TGo4MainTree.h"
00024 #include "Go4EventServer/TGo4TreeSourceParameter.h"
00025
00026 TGo4TreeSource::TGo4TreeSource(const char* name)
00027 : TGo4EventSource(name), fxTree(0), fxBranch(0)
00028 {
00029 TRACE((15,"TGo4TreeSource::TGo4TreeSource(const char*)",__LINE__, __FILE__));
00030 Open();
00031 }
00032
00033 TGo4TreeSource::TGo4TreeSource(TGo4TreeSourceParameter* par)
00034 : TGo4EventSource(par->GetName()), fxTree(0), fxBranch(0)
00035 {
00036 TRACE((15,"TGo4TreeSource::TGo4TreeSource(TGo4TreeSourceParameter*)",__LINE__, __FILE__));
00037 Open();
00038 }
00039
00040
00041 TGo4TreeSource::TGo4TreeSource()
00042 : TGo4EventSource("Go4TreeSource"), fxTree(0), fxBranch(0)
00043 {
00044 TRACE((15,"TGo4TreeSource::TGo4TreeSource()",__LINE__, __FILE__));
00045 }
00046
00047 TGo4TreeSource::~TGo4TreeSource()
00048 {
00049 TRACE((15,"TGo4TreeSource::~TGo4TreeSource()",__LINE__, __FILE__));
00050
00051 Int_t current=fxSingletonTree->GetCurrentIndex();
00052 Int_t max=fxSingletonTree->GetMaxIndex();
00053 Int_t z=0;
00054 for(Int_t ix=current; ix< max; ++ix)
00055 {
00056 z++;
00057 if( fxBranch->GetEntry(ix) == 0)
00058 {
00059 cout << "reached end of branch after "<< z << " dummy event retrieves"<<endl;
00060 break;
00061 }
00062 else { }
00063
00064 }
00065 cout << "treesource "<< GetName() << " is destroyed after "<< z <<"dummy retrieves."<< endl;
00066 }
00067
00068 Int_t TGo4TreeSource::Open()
00069 {
00070 TRACE((15,"TGo4TreeSource::Open()",__LINE__, __FILE__));
00071
00072 Text_t buffer [TGo4EventSource::fguTXTLEN];
00073 snprintf(buffer,TGo4EventSource::fguTXTLEN -5, GetName());
00074 strcat(buffer,".");
00075
00076 fxSingletonTree=TGo4MainTree::Instance();
00077 fxTree= fxSingletonTree->GetTree();
00078 fxBranch= fxTree->GetBranch(buffer);
00079 if(fxBranch)
00080 {
00081 TGo4Log::Debug(" TreeSource: Found existing branch %s ", buffer);
00082 }
00083 else
00084 {
00085 ThrowError(77,0,"!!! ERROR: Branch %s not found!!!",buffer);
00086
00087 }
00088
00089 return 0;
00090 }
00091
00092
00093
00094 Bool_t TGo4TreeSource::BuildEvent(TGo4EventElement* dest)
00095 {
00096 TRACE((12,"TGo4TreeSource::BuildEvent(TGo4EventElement*)",__LINE__, __FILE__));
00097
00098 Bool_t rev=kTRUE;
00099 if(dest==0) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
00100 if(fxBranch==0) ThrowError(0,23,"!!! ERROR BuildEvent: branch was not initialized !!!");
00101 fxBranch->SetAddress(&dest);
00102 Int_t current=fxSingletonTree->GetCurrentIndex();
00103 if( fxBranch->GetEntry(current) == 0)
00104 {
00105 ThrowError(0,24,"!!! ERROR BuildEvent: getting branch entry failed !!!");
00106 }
00107 else
00108 {
00109
00110 rev=kTRUE;
00111 }
00112 return rev;
00113 }
00114
00115 ClassImp(TGo4TreeSource)
00116
00117