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