StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEStructEventMaker.cxx
1 /**********************************************************************
2  *
3  * $Id: StEStructEventMaker.cxx,v 1.2 2006/04/10 23:43:10 porter Exp $
4  *
5  * Author: Jeff Porter rework of Jeff Reid's code
6  *
7  **********************************************************************
8  *
9  * Description: This is an maker designed to read a STAR dst and
10  * summarize it into an EStructEvent which contains only
11  * the information necessary for EbyE analysis.
12  *
13  **********************************************************************/
14 
15 #include "StEStructEventMaker.h"
16 #include "StChain.h"
17 #include "StMessMgr.h"
18 
19 
20 ClassImp(StEStructEventMaker)
21 
22 StEStructEventMaker::StEStructEventMaker(const Char_t *name, const Char_t *title) : StMaker(name, title) {
23 
24  mEStructEvent=0;
25  mfileList=0;
26  mfileCount=0;
27  moutFile=0;
28  mChain=0;
29  mEStructEventFile=0;
30  mEStructTree=0;
31 
32 }
33 
34 StEStructEventMaker::~StEStructEventMaker() { }
35 
36 //-----------------------------------------------------------------------
37 StEStructEvent* StEStructEventMaker::event(){
38  return new StEStructEvent(*mEStructEvent);
39 }
40 
41 //-----------------------------------------------------------------------
43 
44 if(!readEvent())return kStEOF;
45 return kStOK;
46 };
47 
48 //-----------------------------------------------------------------------
49 bool StEStructEventMaker::readEvent(){
50 
51  if(!openRead()) return false;
52  if(meventCount >= mChain->GetEntries() || mChain->GetEntry(meventCount++)==0) return false;
53  mEStructEvent->FillChargeCollections();
54 
55  return true;
56 };
57 
58 //-----------------------------------------------------------------------
59 bool StEStructEventMaker::openRead(){
60 
61 
62  if(!mfileList) return false;
63  if(mChain) return true;
64 
65  mEStructEvent=new StEStructEvent();
66 
67  mChain=new TChain("EStructDst");
68  mChain->SetDirectory(0);
69 
70  ifstream from(mfileList);
71  char line[512];
72  bool done=false;
73 
74  mfileCount=meventCount=0;
75  while(!done){
76  if(from.eof()){
77  done=true;
78  } else {
79  from.getline(line,512);
80  if(line[0]=='#')continue;
81  if(!strstr(line,".estruct.root")) continue;
82  mChain->Add(line);
83  mfileCount++;
84  }
85  }
86  mChain->SetBranchAddress("EStructEvent",&mEStructEvent);
87 
88  return true;
89 }
90 
91 //-----------------------------------------------------------------------
92 bool StEStructEventMaker::openWrite() {
93 
94 
95  if(mEStructEventFile) return true;
96  if(!moutFile) return false;
97  TBranch * branch;
98 
99  mEStructEventFile=new TFile(moutFile,"RECREATE","StEStructDst");
100  mEStructTree = new TTree("EStructDst","StEStructDst",99);
101  mEStructTree->SetAutoSave(1000000); // autosave when 1 Mbyte written
102  branch = mEStructTree->Branch("EStructEvent","StEStructEvent",&mEStructEvent,65526, 99);
103  if(!branch){
104  cout<<" EStructBranch not created !!! "<<endl;
105  return false;
106  }
107 
108  return true;
109 }
110 
111 //-----------------------------------------------------------------------
112 bool StEStructEventMaker::writeEvent(StEStructEvent* e){
113  if(!openWrite() || !e) return false;
114  mEStructEventFile->cd();
115  if(mEStructEvent) delete mEStructEvent;
116  mEStructEvent=e;
117  mEStructTree->Fill();
118  return true;
119 }
120 
121 //-----------------------------------------------------------------------
122 void StEStructEventMaker::setInputFileList(const char* f){return setName(f,0);};
123 
124 //-----------------------------------------------------------------------
125 void StEStructEventMaker::setOutputFile(const char* f){return setName(f,1); };
126 
127 
128 //-----------------------------------------------------------------------
129 void StEStructEventMaker::setName(const char* name, int opt){
130 
131  if(!name) return;
132 
133  char* tmp=new char[strlen(name)+1];
134  strcpy(tmp,name);
135 
136  switch(opt){
137  case 0:
138  {
139  mfileList=tmp;
140  break;
141  }
142  case 1:
143  {
144  moutFile=tmp;
145  break;
146  }
147  default:
148  {
149  delete [] tmp;
150  break;
151  }
152  }
153 }
154 
155 //-----------------------------------------------------------------------
156 Int_t StEStructEventMaker::Init() {
157  return kStOK;
158 }
159 
160 //-----------------------------------------------------------------------
161 void StEStructEventMaker::Clear(Option_t *opt) {
162  StMaker::Clear();
163 }
164 
165 //-----------------------------------------------------------------------
167  if(!mEStructEventFile) return kStOk;
168  mEStructEventFile->cd();
169  mEStructTree->Write();
170  mEStructEventFile->Close();
171  return kStOk;
172 }
173 
174 
175 /***********************************************************************
176  *
177  * $Log: StEStructEventMaker.cxx,v $
178  * Revision 1.2 2006/04/10 23:43:10 porter
179  * Protected our pico-dst writer from multiple calls to "Finish()"
180  *
181  * Revision 1.1 2003/10/15 18:20:51 porter
182  * initial check in of Estruct Analysis maker codes.
183  *
184  *
185  *********************************************************************/
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: Stypes.h:43
Definition: Stypes.h:40
void Clear(Option_t *option="")
User defined functions.
Definition: Stypes.h:41