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