StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtTagReader.cxx
1 #include "StHbtMaker/Reader/StHbtTagReader.h"
2 #ifdef HPUX
3 #include <Stiostream.h>
4 #include <string.h>
5 #else
6 #include "Stiostream.h"
7 #include <string>
8 #endif
9 
10 #include "TFile.h"
11 #include "TTree.h"
12 
13 ClassImp(StHbtTagReader)
14 
15 StHbtTagReader::StHbtTagReader(const char* tagFileName) : mTagFileName(""), mDstFileName(""), mTFile(0), mTTree(0) {
16  cout << " StHbtTagReader::StHbtTagReader(const char* tagFileName)" << endl;
17  mTagFileName = string(tagFileName);
18  init();
19 }
20 
21 StHbtTagReader::StHbtTagReader(const StIOMaker* ioMaker) : mTagFileName(""), mDstFileName(""), mTFile(0), mTTree(0) {
22  cout << " StHbtTagReader::StHbtTagReader(const StIOMaker* ioMaker)" << endl;
23  mIOMaker = ioMaker;
24 }
25 
26 void StHbtTagReader::init() {
27  cout << " StHbtTagReader::init()" << endl;
28  if (mTFile) {
29  if ( mTFile->IsOpen() ) {
30  cout << " StHbtTagReader::init() - closing file " << endl;
31  mTFile->Close();
32  }
33  delete mTFile;
34  }
35  mTFile = new TFile(mTagFileName.c_str(),"r");
36  if ( mTFile->IsOpen() ) {
37  cout << " StHbtTagReader::init() - new tags file opend : -" << mTagFileName.c_str() << "-" << endl;
38  mDstFileName = mIOMaker->GetFile();
39  mTTree = (TTree*)mTFile->Get("Tag");
40  mNEvents = (int)mTTree->GetEntries();
41  }
42  else {
43  cout << " StHbtTagReader::init() - coundn't open new tags file : -" << mTagFileName.c_str() << "-" << endl;
44  }
45 }
46 
47 StHbtTagReader::~StHbtTagReader(){
48  if (mTFile) mTFile->Close();
49 }
50 
51 int StHbtTagReader::EventMatch(int runNumber, int eventNumber) {
52  //cout << " StHbtTagReader::EventMatch(int runNumber, int eventNumber)" << endl;
53  if (mIOMaker) {
54  cout << " mIOMaker " << mIOMaker << " " << mDstFileName.c_str() << " " << mIOMaker->GetFile() << endl;
55  if (strcmp(mDstFileName.c_str(),mIOMaker->GetFile()) ) {// file names doesn't match
56  cout << " new file " << endl;
57  mTagFileName = mIOMaker->GetFile();
58  if (mTagFileName.find(".dst.") != string::npos)
59  mTagFileName.replace(mTagFileName.find(".dst."),5,".tags.");
60  else if (mTagFileName.find(".event.") != string::npos)
61  mTagFileName.replace(mTagFileName.find(".event."),7,".tags.");
62  init();
63  }
64  }
65  return (GetEventIndex(runNumber,eventNumber)!=-1) ? 1 : 0;
66 }
67 
68 int StHbtTagReader::GetEventIndex(int runNumber, int eventNumber){
69  cout << " StHbtTagReader::GetEventIndex(int runNumber, int eventNumber)" << endl;
70  mRunNumber = -1;
71  mEventNumber = -1;
72  mEventIndex = -1;
73  for ( int i=0; i<mNEvents; i++) {
74  mIret = mTTree->GetEntry(i);
75  if ( mTTree->GetBranch("EvtHddr.mEventNumber")->GetLeaf("mEventNumber")->GetValue() == eventNumber &&
76  mTTree->GetBranch("EvtHddr.mRunNumber")->GetLeaf("mRunNumber")->GetValue() == runNumber ) {
77  mEventIndex = i;
78  mRunNumber = (int)mTTree->GetBranch("EvtHddr.mRunNumber")->GetLeaf("mRunNumber")->GetValue();
79  mEventNumber = (int)mTTree->GetBranch("EvtHddr.mEventNumber")->GetLeaf("mEventNumber")->GetValue();
80  break;
81  }
82  }
83  return mEventIndex;
84 }
85 
86