20 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
21 #include "StHbtMaker/Base/StHbtEventCut.h"
22 #include "StHbtMaker/Base/StHbtTrackCut.h"
23 #include "StHbtMaker/Base/StHbtV0Cut.h"
24 #include "StHbtMaker/Base/StHbtKinkCut.h"
26 #include "StFlowMaker/StFlowMaker.h"
27 #include "StFlowMaker/StFlowEvent.h"
28 #include "StFlowAnalysisMaker/StFlowAnalysisMaker.h"
29 #include "StFlowMaker/StFlowSelection.h"
31 #include "StHbtMaker/Infrastructure/StHbtIOBinary.hh"
32 #include "StHbtMaker/Reader/StHbtBinaryReader.h"
39 StHbtBinaryReader::StHbtBinaryReader(
const char* dir,
const char* file,
const char* appendix) {
40 init(dir, file, appendix);
45 mFlowAnalysisMaker = 0;
49 StHbtBinaryReader::StHbtBinaryReader(
StIOMaker* ioMaker,
const char* dir,
const char* file,
const char* appendix) {
50 init(dir, file, appendix);
53 if (mDebug) cout <<
" StHbtBinaryReader::StHbtBinaryReader() - mIOMaker : " << mIOMaker << endl;
55 mFlowAnalysisMaker = 0;
59 void StHbtBinaryReader::init(
const char* dir,
const char* file,
const char* appendix) {
60 if (mDebug) cout << dir <<
" " << file <<
" " << appendix << endl;
64 if ( strstr(mFileName,
".lis") ) {
65 if (mDebug) cout <<
" AddFileList " << endl;
71 mStHbtEventVersion = 2;
72 mStHbtTrackVersion = 2,
75 mFlowAnalysisMaker = 0;
78 StHbtBinaryReader::~StHbtBinaryReader(){
79 if (mFileList)
delete mFileList;
82 StHbtEvent* StHbtBinaryReader::ReturnHbtEvent(){
83 if (mDebug>1) cout <<
" StHbtBinaryReader::ReturnHbtEvent() " << endl;
85 if (mReaderStatus == ioOK ) mReaderStatus = binaryIO->read(*event,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
86 if (mReaderStatus != ioOK) {
87 if (mDebug>1) cout <<
" StHbtBinaryReader::ReturnHbtEvent() - event read with status " << mReaderStatus << endl;
88 if (mDebug>1) cout <<
" StHbtBinaryReader::ReturnHbtEvent() - fileName: " << mFileName << endl;
90 if (mReaderStatus == ioEOF || mReaderStatus == ioERR ) {
92 while (mReaderStatus !=ioEOL && mReaderStatus !=ioOK ) {
93 if (event)
delete event;
event =
new StHbtEvent;
94 if ( binaryIO )
delete binaryIO;
95 mReaderStatus = NextFile();
96 if (mDebug>1) cout << mReaderStatus << endl;
97 if (mReaderStatus == ioOK ) mReaderStatus = Init(
"r",mTheMessage);
98 if (mReaderStatus == ioOK ) mReaderStatus = binaryIO->read(*event,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
102 if (mReaderStatus != ioOK) {
103 if (mDebug>1) cout <<
" StHbtBinaryReader::ReturnHbtEvent() - event read with status " << mReaderStatus << endl;
104 if (mDebug>1) cout <<
" StHbtBinaryReader::ReturnHbtEvent() - fileName: " << mFileName << endl;
105 if (event)
delete event;
event=0;
109 if (mEventCut && event ) {
110 if ( mEventCut->Pass(event)==0 ) {
117 if( mTrackCut && event){
118 StHbtTrackIterator pIter;
120 StHbtTrackCollection NewTrackCollection;
122 for (pIter=event->TrackCollection()->begin();
123 pIter!=
event->TrackCollection()->end();pIter++){
125 bool tmpPassParticle = mTrackCut->Pass(pParticle);
126 if (tmpPassParticle){
127 NewTrackCollection.push_back(pParticle);
133 event->TrackCollection()->clear();
135 for (pIter=NewTrackCollection.begin();
136 pIter!=NewTrackCollection.end();pIter++){
137 event->TrackCollection()->push_back(*pIter);
139 NewTrackCollection.clear();
143 if( mV0Cut && event){
144 StHbtV0Iterator pIter;
146 StHbtV0Collection NewV0Collection;
148 for (pIter=event->V0Collection()->begin();
149 pIter!=
event->V0Collection()->end();pIter++){
151 bool tmpPassParticle = mV0Cut->Pass(pParticle);
152 if (tmpPassParticle){
153 NewV0Collection.push_back(pParticle);
159 event->V0Collection()->clear();
160 for (pIter=NewV0Collection.begin();
161 pIter!=NewV0Collection.end();pIter++){
162 event->V0Collection()->push_back(*pIter);
164 NewV0Collection.clear();
168 if ( mFlowMaker && event ) {
185 cout <<
" StHbtBinaryReader::ReturnHbtEvent() - current filename: " << mFileName << endl;
186 cout <<
" StHbtBinaryReader::ReturnHbtEvent() - bytes read : " << binaryIO->bytesRead() << endl;
188 cout <<
" StHbtBinaryReader::ReturnHbtEvent() - #tracks/#V0s : " <<
event->TrackCollection()->size() <<
"/";
189 cout <<
event->V0Collection()->size() << endl;
192 cout <<
"StHbtBinaryReader::ReturnHbtEvent() - failed cut - no StHbtEvent returned" << endl;
199 int StHbtBinaryReader::WriteHbtEvent(
StHbtEvent* event){
201 if (mIOMaker && mRetrieve==1) {
202 if ( strcmp(mCurrentFile.c_str(),mIOMaker->GetFile()) ) {
204 cout <<
" StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) " << endl;
205 cout <<
" current file : " << mCurrentFile.c_str() << endl;
206 cout <<
" new file : " << mIOMaker->GetFile() << endl;
208 mCurrentFile = mIOMaker->GetFile();
209 mFileName = (mCurrentFile).c_str();
210 if (mDebug) cout <<
" open file : " << mFileName << endl;
211 if ( binaryIO )
delete binaryIO;
212 mReaderStatus = Init(
"w",mTheMessage);
216 if (mReaderStatus == ioOK ) {
217 if (!mEventCut || mEventCut->Pass(event)) {
218 if (mDebug>1) cout <<
" StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - eventCut passed" << endl;
222 StHbtEvent newEvent(*event, mTrackCut, mV0Cut);
223 mReaderStatus = binaryIO->write(newEvent,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
226 if (mReaderStatus != ioOK) {
227 if (mDebug) cout <<
" StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - error# ";
228 if (mDebug) cout << mReaderStatus <<
" while writing" << endl;
230 if (mDebug>1) cout <<
" StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - bytes written : " << binaryIO->bytesWritten() << endl;
231 return (mReaderStatus);
235 int StHbtBinaryReader::Init(
const char* ReadWrite, StHbtString& Message){
236 if (mDebug>1) cout <<
" StHbtBinaryReader::Init(const char* ReadWrite, StHbtString& Message) - being called with filename: ";
237 cout << mFileName << endl;
238 mReaderStatus = ioOK;
239 if (((*ReadWrite)==
'r')|| ((*ReadWrite)==
'R')){
240 binaryIO =
new StHbtIOBinary( mDirName,mFileName, mAppendix ,
"r");
241 if (mDebug>1) cout <<
" StHbtBinaryReader::Init() - inputStreamStatus = " << binaryIO->inputStreamStatus();
242 if (mDebug>1) cout <<
" StHbtBinaryReader::Init() - now read message " << endl;
243 mReaderStatus = binaryIO->readHeader(Message);
244 if (mTheMessage!=Message) {
245 mTheMessage = Message;
246 cout << Message.c_str() << endl;
248 if (mDebug>1) cout <<
" mReaderStatus " << binaryIO->outputStreamStatus() << endl;
250 if (mDebug>1) cout <<
" StHbtBinaryReader::Init() - now read versions " << endl;
251 mReaderStatus = binaryIO->read(mStHbtEventVersion);
252 if (mDebug>1) cout <<
" mReaderStatus " << binaryIO->outputStreamStatus();
253 mReaderStatus = binaryIO->read(mStHbtTrackVersion);
254 if (mDebug>1) cout <<
" mReaderStatus " << binaryIO->outputStreamStatus();
255 mReaderStatus = binaryIO->read(mStHbtV0Version);
257 cout <<
" mReaderStatus " << binaryIO->outputStreamStatus();
258 cout <<
" StHbtEventVersion=" << mStHbtEventVersion;
259 cout <<
" StHbtTrackVersion=" << mStHbtTrackVersion;
260 cout <<
" StHbtV0Version=" << mStHbtV0Version << endl;
264 mTheMessage = Message;
265 binaryIO =
new StHbtIOBinary(mDirName, mFileName, mAppendix,
"w");
266 if (mDebug>1) cout <<
" mReaderStatus " << binaryIO->outputStreamStatus();
267 mReaderStatus = binaryIO->writeHeader(Message);
268 if (mDebug>1) cout <<
" mReaderStatus " << mReaderStatus << endl;
269 mReaderStatus = binaryIO->write(mStHbtEventVersion);
270 if (mDebug>1) cout <<
" mReaderStatus " << mReaderStatus << endl;
271 mReaderStatus = binaryIO->write(mStHbtTrackVersion);
272 if (mDebug>1) cout <<
" mReaderStatus " << mReaderStatus << endl;
273 mReaderStatus = binaryIO->write(mStHbtV0Version);
275 cout <<
" mReaderStatus " << mReaderStatus << endl;
276 cout <<
" StHbtEventVersion=" << mStHbtEventVersion;
277 cout <<
" StHbtTrackVersion=" << mStHbtTrackVersion;
278 cout <<
" StHbtV0Version=" << mStHbtV0Version << endl;
281 if (mDebug>1) cout <<
" StHbtBinaryReader::Init(const char* ReadWrite, StHbtString& Message) - mReaderStatus: " << mReaderStatus << endl;
282 return mReaderStatus;
286 void StHbtBinaryReader::Finish(){
289 int StHbtBinaryReader::NextFile() {
291 delete (mFileList->front());
292 mFileList->pop_front();
293 if ( mFileList->empty() )
return ioEOL;
294 mFileName = mFileList->front()->c_str();
295 if (mDebug) cout <<
" StHbtBinaryReader::NextFile() - mFileName: " << mFileName << endl;
299 void StHbtBinaryReader::SetFileName(
const char* file){mFileName=(
char*)file;}
300 void StHbtBinaryReader::SetDirName(
const char* dir){mDirName=(
char*)dir;}
301 void StHbtBinaryReader::SetAppendix(
const char* appendix){mAppendix=(
char*)appendix;}
303 void StHbtBinaryReader::AddFileList(
const char* fileList) {
304 if (mDebug>1) cout <<
" StHbtBinaryReader::AddFileList(char* fileList)"<< endl;
305 if (!mFileList) mFileList =
new fileCollection;
306 ifstream* inputStream =
new ifstream;
307 inputStream->open(fileList);
309 if (mDebug) cout <<
" StHbtBinaryReader::AddFileList(char* fileList) - Cannot open input file! " << endl;
310 mReaderStatus = ioERROpen;
314 if (mDebug>1) cout <<
" inputStream->good() : " << inputStream->good() << endl;
315 for (;inputStream->good();) {
316 temp =
new char[200];
317 inputStream->getline(temp,200);
318 cout << temp << endl;
319 StHbtString* newFile =
new StHbtString(temp);
320 if ( newFile->length()>0 ) {
321 mFileList->push_back(newFile);
322 if (mDebug>1) cout <<
" file " << newFile->c_str() <<
" added to file list " << endl;
325 if (mDebug) cout <<
" StHbtBinaryReader::FillFileList(char* fileList) - " << mFileList->empty() <<
" files in list " << endl;
326 if (!mFileList->empty())
327 mFileName = mFileList->front()->c_str();
331 StHbtString StHbtBinaryReader::Report(){
332 StHbtString temp =
"\n This is the StHbtBinaryEventReader\n";
333 temp +=
"---> EventCuts in Reader: ";
335 temp += mEventCut->Report();
340 temp +=
"\n---> TrackCuts in Reader: ";
342 temp += mTrackCut->Report();
347 temp +=
"\n---> V0Cuts in Reader: ";
349 temp += mV0Cut->Report();