00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4FileSource.h"
00017
00018 #include "Riostream.h"
00019
00020 #include "TKey.h"
00021 #include "snprintf.h"
00022 #include "TFile.h"
00023 #include "TTree.h"
00024
00025 #include "TGo4FileSourceParameter.h"
00026 #include "TGo4CompositeEvent.h"
00027
00028 #include "TGo4FileStore.h"
00029
00030 R__EXTERN TTree *gTree;
00031
00032 TGo4FileSource::TGo4FileSource(const char* name)
00033 : TGo4EventSource(name), fxFile(0), fxTree(0), fiMaxEvents(0), fiCurrentEvent(0),fbActivated(kFALSE),
00034 fxTopEvent(0)
00035 {
00036 Open();
00037 }
00038
00039 TGo4FileSource::TGo4FileSource(TGo4FileSourceParameter* par)
00040 : TGo4EventSource(par->GetName()), fxFile(0), fxTree(0), fiMaxEvents(0),
00041 fiCurrentEvent(0), fbActivated(kFALSE),
00042 fxTopEvent(0)
00043 {
00044 Open();
00045 }
00046
00047
00048 TGo4FileSource::TGo4FileSource()
00049 : TGo4EventSource("Go4FileSource"), fxFile(0), fxTree(0), fiMaxEvents(0), fiCurrentEvent(0), fbActivated(kFALSE),
00050 fxTopEvent(0)
00051 {
00052
00053 }
00054
00055 Int_t TGo4FileSource::Open()
00056 {
00057 TString buffer(GetName());
00058 if(strstr(buffer.Data(),TGo4FileStore::fgcFILESUF)==0)
00059 buffer+=TGo4FileStore::fgcFILESUF;
00060 fxFile = TFile::Open(buffer.Data(), "READ");
00061 if(! ( fxFile && fxFile->IsOpen() )) ThrowError(66,0,"!!! ERROR: FILE not found !!!");
00062
00063 TKey* kee=0;
00064 TIter iter(fxFile->GetListOfKeys());
00065 while ( ( kee=dynamic_cast<TKey*>(iter()) ) !=0 ) {
00066 fxTree = dynamic_cast<TTree*>(kee->ReadObj());
00067 if (fxTree)
00068 break;
00069 }
00070 if (fxTree==0)
00071 {
00072 ThrowError(77,0,"!!! ERROR: Tree not found !!!");
00073 }
00074 else
00075 {
00076 SetCreateStatus(0);
00077 fiMaxEvents= (Int_t )fxTree->GetEntries();
00078 }
00079 return 0;
00080 }
00081
00082 TGo4FileSource::~TGo4FileSource()
00083 {
00084 delete fxFile;
00085 }
00086
00087 Bool_t TGo4FileSource::BuildEvent(TGo4EventElement* dest)
00088 {
00089 Bool_t rev=kTRUE;
00090 if(dest==0) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
00091 if (fxTree==0) ThrowError(0,33,"!!! ERROR BuildEvent: no Tree !!!");
00092 if(!fbActivated)
00093 {
00094
00095
00096
00097 TString topname;
00098 Bool_t masterbranch=kFALSE;
00099 fxBranchName=dest->GetName();
00100 if(!fxBranchName.Contains("."))
00101 {
00102 fxBranchName+=".";
00103 masterbranch=kTRUE;
00104 }
00105 TObjArray* blist = fxTree->GetListOfBranches();
00106 TBranch* topb= (TBranch*) blist->At(0);
00107 if(topb)
00108 {
00109 topname=topb->GetName();
00110
00111 fxTopEvent=dest;
00112 fxTree->SetBranchAddress(topname.Data(),&fxTopEvent);
00113
00114 }
00115 fxTree->SetBranchStatus("*",0);
00116 fxTree->SetBranchStatus(topname.Data(),1);
00117 TString wildbranch=fxBranchName;
00118 wildbranch+="*";
00119 fxTree->SetBranchStatus(wildbranch.Data(),1);
00120
00121 wildbranch=fxBranchName;
00122 if(!masterbranch) wildbranch+=".";
00123 wildbranch+="*";
00124 fxTree->SetBranchStatus(wildbranch.Data(),1);
00125
00126 fbActivated=kTRUE;
00127 }
00128
00129 fxTree->GetEntry(fiCurrentEvent++);
00130 if(fiCurrentEvent>fiMaxEvents) ThrowError(0,44,"END OF TREE at event %d !!!",fiCurrentEvent);
00131 return rev;
00132 }
00133
00134 Bool_t TGo4FileSource::BuildCompositeEvent(TGo4CompositeEvent* dest){
00135 if(dest==0) ThrowError(0,22,"!!! ERROR BuildEvent: no destination event!!!");
00136 if (fxTree==0) ThrowError(0,33,"!!! ERROR BuildEvent: no Tree !!!");
00137
00138
00139
00140 gTree = fxTree;
00141
00142 if (!fbActivated ){
00143 dest->synchronizeWithTree( fxTree );
00144 fbActivated = kTRUE;
00145 }
00146 fxTree->GetEntry(fiCurrentEvent++);
00147
00148
00149 if(fiCurrentEvent>fiMaxEvents) ThrowError(0,44,"END OF TREE at event %d !!!",fiCurrentEvent);
00150
00151 return kTRUE;
00152 }
00153
00154
00155
00156
00157