00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <Stiostream.h>
00019 #include "Stiostream.h"
00020 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
00021 #include "StHbtMaker/Base/StHbtEventCut.h"
00022 #include "StHbtMaker/Base/StHbtTrackCut.h"
00023 #include "StHbtMaker/Base/StHbtV0Cut.h"
00024 #include "StHbtMaker/Base/StHbtKinkCut.h"
00025 #include "StHbtMaker/Reader/StHbtAsciiReader.h"
00026
00027 #ifdef __ROOT__
00028 ClassImp(StHbtAsciiReader)
00029 #endif
00030
00031
00032
00033 StHbtAsciiReader::StHbtAsciiReader() : mInputStream(0), mOutputStream(0){
00034 mFileName = "HbtAsciiFile";
00035 mReaderStatus = 0;
00036 mStHbtEventVersion = mStHbtTrackVersion = mStHbtV0Version = 1;
00037 }
00038
00039
00040 StHbtAsciiReader::StHbtAsciiReader(char* file) : mInputStream(0), mOutputStream(0), mFileName(file)
00041 {
00042 mReaderStatus = 0;
00043 mStHbtEventVersion = mStHbtTrackVersion = mStHbtV0Version = 1;
00044 }
00045
00046
00047 StHbtAsciiReader::~StHbtAsciiReader(){
00048 if (!mInputStream){
00049 delete mInputStream;
00050 mInputStream = 0;
00051 }
00052 if (!mOutputStream){
00053 delete mOutputStream;
00054 mOutputStream = 0;
00055 }
00056 }
00057
00058
00059 StHbtEvent* StHbtAsciiReader::ReturnHbtEvent(){
00060 if (!mInputStream){
00061 cout << "StHbtAsciiReader::ReturnHbtEvent() - there is no input stream!";
00062 mReaderStatus = 1;
00063 return (0);
00064 }
00065 if (!(*mInputStream)){
00066 cout << "StHbtAsciiReader::ReturnHbtEvent() - input stream in bad state!" << endl;
00067 cout << "State is " << mInputStream->rdstate() << endl;
00068 mReaderStatus = 1;
00069 return (0);
00070 }
00071 StHbtEvent* event = new StHbtEvent;
00072 (*mInputStream) >> (*event);
00073 if (!(mInputStream->good())){
00074 cout << "StHbtAsciiReader::ReturnHbtEvent() - input stream in bad state!" <<endl;
00075 cout << "State is " << mInputStream->rdstate() << endl;
00076 mReaderStatus = 1;
00077 return (0);
00078
00079 }
00080 return event;
00081 }
00082
00083 int StHbtAsciiReader::WriteHbtEvent(StHbtEvent* event){
00084
00085 if (!mOutputStream){
00086 cout << "\n StHbtAsciiReader::WriteHbtEvent() - There is no Output Stream -- I am NOT writing !!! \n\n";
00087 return (1);
00088 }
00089
00090 if (!(*mOutputStream)){
00091 cout << "\n StHbtAsciiReader::WriteHbtEvent() - Output Stream in bad state -- I am NOT writing !!! \n\n";
00092 return (2);
00093 }
00094
00095
00096 if ( !mEventCut || mEventCut->Pass(event) ) {
00097 cout << "StHbtAsciiReader: eventCut passed" << endl;
00098 StHbtEvent newEvent(*event, mTrackCut, mV0Cut);
00099 (*mOutputStream) << (newEvent);
00100 }
00101 return (0);
00102 }
00103
00104
00105
00106
00108
00109
00110
00111 int StHbtAsciiReader::Init(const char* ReadWrite, StHbtString& Message){
00112 cout << " *\n *\n *\n StHbtAsciiReader::Init() being called*\n *\n";
00113 mReaderStatus = 0;
00114
00115 if (((*ReadWrite)=='r')|| ((*ReadWrite)=='R')){
00116 mInputStream = new ifstream;
00117 mInputStream->open(mFileName);
00118 if (!(*mInputStream)){
00119 cout << "StHbtAsciiReader::Init() - Cannot open input file! " << endl;
00120 return (1);
00121 }
00122 cout << "StHbtAsciiReader::Init() - being configured as a Reader" << ReadWrite << endl;
00123
00124 char temp[200] = "";
00125 string stemp;
00126 do {
00127 Message += temp;
00128 Message += "\n";
00129 mInputStream->getline(temp,200);
00130 stemp = temp;
00131 } while (stemp != "-*-*-*-* End of Input Reader Report");
00132 cout << "Here is the message that was at the beginning of the file...\n";
00133 cout << Message.c_str();
00134 (*mInputStream) >> mStHbtEventVersion >> mStHbtTrackVersion >> mStHbtV0Version;
00135 cout << " StHbtEventVersion=" << mStHbtEventVersion;
00136 cout << " StHbtTrackVersion=" << mStHbtTrackVersion;
00137 cout << " StHbtV0Version=" << mStHbtV0Version << endl;
00138 }
00139 else{
00140 mOutputStream = new ofstream;
00141
00142
00143 mOutputStream->open(mFileName);
00144 if (!(*mOutputStream)){
00145 cout << "StHbtAsciiReader::Init() - Cannot open output file! " << endl;
00146 return (1);
00147 }
00148 cout << "StHbtAsciiReader::Init() - being configured as a Writer" << ReadWrite << endl;
00149 (*mOutputStream) << Message.c_str();
00150 (*mOutputStream) << endl;
00151 (*mOutputStream) << "-*-*-*-* End of Input Reader Report" << endl;
00152 (*mOutputStream) << mStHbtEventVersion << " " << mStHbtTrackVersion << " " << mStHbtV0Version << endl;
00153 }
00154 return (0);
00155 }
00156
00157
00158 void StHbtAsciiReader::Finish(){
00159 if (mInputStream) mInputStream->close();
00160 if (mOutputStream) mOutputStream->close();
00161 }
00162