00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00026 #include "StFlowMaker/StFlowMaker.h"
00027 #include "StFlowMaker/StFlowEvent.h"
00028 #include "StFlowAnalysisMaker/StFlowAnalysisMaker.h"
00029 #include "StFlowMaker/StFlowSelection.h"
00030
00031 #include "StHbtMaker/Infrastructure/StHbtIOBinary.hh"
00032 #include "StHbtMaker/Reader/StHbtBinaryReader.h"
00033
00034 #ifdef __ROOT__
00035 ClassImp(StHbtBinaryReader)
00036 #endif
00037
00038
00039 StHbtBinaryReader::StHbtBinaryReader(const char* dir, const char* file, const char* appendix) {
00040 init(dir, file, appendix);
00041 #ifdef __ROOT__
00042 mIOMaker =0;
00043 #endif
00044 mFlowMaker = 0;
00045 mFlowAnalysisMaker = 0;
00046 }
00047
00048 #ifdef __ROOT__
00049 StHbtBinaryReader::StHbtBinaryReader(StIOMaker* ioMaker, const char* dir, const char* file, const char* appendix) {
00050 init(dir, file, appendix);
00051 mRetrieve = 1;
00052 mIOMaker = ioMaker;
00053 if (mDebug) cout << " StHbtBinaryReader::StHbtBinaryReader() - mIOMaker : " << mIOMaker << endl;
00054 mFlowMaker = 0;
00055 mFlowAnalysisMaker = 0;
00056 }
00057 #endif
00058
00059 void StHbtBinaryReader::init(const char* dir, const char* file, const char* appendix) {
00060 if (mDebug) cout << dir << " " << file << " " << appendix << endl;
00061 mDirName=dir;
00062 mFileName=file;
00063 mAppendix=appendix;
00064 if ( strstr(mFileName,".lis") ) {
00065 if (mDebug) cout << " AddFileList " << endl;
00066 AddFileList(file);
00067 }
00068
00069 mReaderStatus = ioOK;
00070 mRetrieve = 0;
00071 mStHbtEventVersion = 2;
00072 mStHbtTrackVersion = 2,
00073 mStHbtV0Version = 3;
00074 mFlowMaker = 0;
00075 mFlowAnalysisMaker = 0;
00076 }
00077
00078 StHbtBinaryReader::~StHbtBinaryReader(){
00079 if (mFileList) delete mFileList;
00080 }
00081
00082 StHbtEvent* StHbtBinaryReader::ReturnHbtEvent(){
00083 if (mDebug>1) cout << " StHbtBinaryReader::ReturnHbtEvent() " << endl;
00084 StHbtEvent* event = new StHbtEvent;
00085 if (mReaderStatus == ioOK ) mReaderStatus = binaryIO->read(*event,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
00086 if (mReaderStatus != ioOK) {
00087 if (mDebug>1) cout << " StHbtBinaryReader::ReturnHbtEvent() - event read with status " << mReaderStatus << endl;
00088 if (mDebug>1) cout << " StHbtBinaryReader::ReturnHbtEvent() - fileName: " << mFileName << endl;
00089 }
00090 if (mReaderStatus == ioEOF || mReaderStatus == ioERR ) {
00091 if (mFileList) {
00092 while (mReaderStatus !=ioEOL && mReaderStatus !=ioOK ) {
00093 if (event) delete event; event = new StHbtEvent;
00094 if ( binaryIO ) delete binaryIO;
00095 mReaderStatus = NextFile();
00096 if (mDebug>1) cout << mReaderStatus << endl;
00097 if (mReaderStatus == ioOK ) mReaderStatus = Init("r",mTheMessage);
00098 if (mReaderStatus == ioOK ) mReaderStatus = binaryIO->read(*event,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
00099 }
00100 }
00101 }
00102 if (mReaderStatus != ioOK) {
00103 if (mDebug>1) cout << " StHbtBinaryReader::ReturnHbtEvent() - event read with status " << mReaderStatus << endl;
00104 if (mDebug>1) cout << " StHbtBinaryReader::ReturnHbtEvent() - fileName: " << mFileName << endl;
00105 if (event) delete event; event=0;
00106 return 0;
00107 }
00108
00109 if (mEventCut && event ) {
00110 if ( mEventCut->Pass(event)==0 ) {
00111 delete event;
00112 event=0;
00113 }
00114 }
00115
00116
00117 if( mTrackCut && event){
00118 StHbtTrackIterator pIter;
00119 StHbtTrack* pParticle;
00120 StHbtTrackCollection NewTrackCollection;
00121
00122 for (pIter=event->TrackCollection()->begin();
00123 pIter!=event->TrackCollection()->end();pIter++){
00124 pParticle = *pIter;
00125 bool tmpPassParticle = mTrackCut->Pass(pParticle);
00126 if (tmpPassParticle){
00127 NewTrackCollection.push_back(pParticle);
00128 }
00129 else{
00130 delete *pIter;
00131 }
00132 }
00133 event->TrackCollection()->clear();
00134
00135 for (pIter=NewTrackCollection.begin();
00136 pIter!=NewTrackCollection.end();pIter++){
00137 event->TrackCollection()->push_back(*pIter);
00138 }
00139 NewTrackCollection.clear();
00140 }
00141
00142
00143 if( mV0Cut && event){
00144 StHbtV0Iterator pIter;
00145 StHbtV0* pParticle;
00146 StHbtV0Collection NewV0Collection;
00147
00148 for (pIter=event->V0Collection()->begin();
00149 pIter!=event->V0Collection()->end();pIter++){
00150 pParticle = *pIter;
00151 bool tmpPassParticle = mV0Cut->Pass(pParticle);
00152 if (tmpPassParticle){
00153 NewV0Collection.push_back(pParticle);
00154 }
00155 else{
00156 delete *pIter;
00157 }
00158 }
00159 event->V0Collection()->clear();
00160 for (pIter=NewV0Collection.begin();
00161 pIter!=NewV0Collection.end();pIter++){
00162 event->V0Collection()->push_back(*pIter);
00163 }
00164 NewV0Collection.clear();
00165 }
00166
00167
00168 if ( mFlowMaker && event ) {
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 }
00183
00184 if (mDebug>1) {
00185 cout << " StHbtBinaryReader::ReturnHbtEvent() - current filename: " << mFileName << endl;
00186 cout << " StHbtBinaryReader::ReturnHbtEvent() - bytes read : " << binaryIO->bytesRead() << endl;
00187 if (event){
00188 cout << " StHbtBinaryReader::ReturnHbtEvent() - #tracks/#V0s : " << event->TrackCollection()->size() << "/";
00189 cout << event->V0Collection()->size() << endl;
00190 }
00191 else{
00192 cout << "StHbtBinaryReader::ReturnHbtEvent() - failed cut - no StHbtEvent returned" << endl;
00193 }
00194 }
00195 return event;
00196 }
00197
00198
00199 int StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event){
00200 #ifdef __ROOT__
00201 if (mIOMaker && mRetrieve==1) {
00202 if ( strcmp(mCurrentFile.c_str(),mIOMaker->GetFile()) ) {
00203 if (mDebug) {
00204 cout << " StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) " << endl;
00205 cout << " current file : " << mCurrentFile.c_str() << endl;
00206 cout << " new file : " << mIOMaker->GetFile() << endl;
00207 }
00208 mCurrentFile = mIOMaker->GetFile();
00209 mFileName = (mCurrentFile).c_str();
00210 if (mDebug) cout << " open file : " << mFileName << endl;
00211 if ( binaryIO ) delete binaryIO;
00212 mReaderStatus = Init("w",mTheMessage);
00213 }
00214 }
00215 #endif
00216 if (mReaderStatus == ioOK ) {
00217 if (!mEventCut || mEventCut->Pass(event)) {
00218 if (mDebug>1) cout << " StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - eventCut passed" << endl;
00219
00220
00221
00222 StHbtEvent newEvent(*event, mTrackCut, mV0Cut);
00223 mReaderStatus = binaryIO->write(newEvent,mStHbtEventVersion,mStHbtTrackVersion,mStHbtV0Version);
00224 }
00225 }
00226 if (mReaderStatus != ioOK) {
00227 if (mDebug) cout << " StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - error# ";
00228 if (mDebug) cout << mReaderStatus << " while writing" << endl;
00229 }
00230 if (mDebug>1) cout << " StHbtBinaryReader::WriteHbtEvent(StHbtEvent* event) - bytes written : " << binaryIO->bytesWritten() << endl;
00231 return (mReaderStatus);
00232 }
00233
00234
00235 int StHbtBinaryReader::Init(const char* ReadWrite, StHbtString& Message){
00236 if (mDebug>1) cout << " StHbtBinaryReader::Init(const char* ReadWrite, StHbtString& Message) - being called with filename: ";
00237 cout << mFileName << endl;
00238 mReaderStatus = ioOK;
00239 if (((*ReadWrite)=='r')|| ((*ReadWrite)=='R')){
00240 binaryIO = new StHbtIOBinary( mDirName,mFileName, mAppendix ,"r");
00241 if (mDebug>1) cout << " StHbtBinaryReader::Init() - inputStreamStatus = " << binaryIO->inputStreamStatus();
00242 if (mDebug>1) cout << " StHbtBinaryReader::Init() - now read message " << endl;
00243 mReaderStatus = binaryIO->readHeader(Message);
00244 if (mTheMessage!=Message) {
00245 mTheMessage = Message;
00246 cout << Message.c_str() << endl;
00247 }
00248 if (mDebug>1) cout << " mReaderStatus " << binaryIO->outputStreamStatus() << endl;
00249
00250 if (mDebug>1) cout << " StHbtBinaryReader::Init() - now read versions " << endl;
00251 mReaderStatus = binaryIO->read(mStHbtEventVersion);
00252 if (mDebug>1) cout << " mReaderStatus " << binaryIO->outputStreamStatus();
00253 mReaderStatus = binaryIO->read(mStHbtTrackVersion);
00254 if (mDebug>1) cout << " mReaderStatus " << binaryIO->outputStreamStatus();
00255 mReaderStatus = binaryIO->read(mStHbtV0Version);
00256 if (mDebug>1) {
00257 cout << " mReaderStatus " << binaryIO->outputStreamStatus();
00258 cout << " StHbtEventVersion=" << mStHbtEventVersion;
00259 cout << " StHbtTrackVersion=" << mStHbtTrackVersion;
00260 cout << " StHbtV0Version=" << mStHbtV0Version << endl;
00261 }
00262 }
00263 else{
00264 mTheMessage = Message;
00265 binaryIO = new StHbtIOBinary(mDirName, mFileName, mAppendix,"w");
00266 if (mDebug>1) cout << " mReaderStatus " << binaryIO->outputStreamStatus();
00267 mReaderStatus = binaryIO->writeHeader(Message);
00268 if (mDebug>1) cout << " mReaderStatus " << mReaderStatus << endl;
00269 mReaderStatus = binaryIO->write(mStHbtEventVersion);
00270 if (mDebug>1) cout << " mReaderStatus " << mReaderStatus << endl;
00271 mReaderStatus = binaryIO->write(mStHbtTrackVersion);
00272 if (mDebug>1) cout << " mReaderStatus " << mReaderStatus << endl;
00273 mReaderStatus = binaryIO->write(mStHbtV0Version);
00274 if (mDebug>1) {
00275 cout << " mReaderStatus " << mReaderStatus << endl;
00276 cout << " StHbtEventVersion=" << mStHbtEventVersion;
00277 cout << " StHbtTrackVersion=" << mStHbtTrackVersion;
00278 cout << " StHbtV0Version=" << mStHbtV0Version << endl;
00279 }
00280 }
00281 if (mDebug>1) cout << " StHbtBinaryReader::Init(const char* ReadWrite, StHbtString& Message) - mReaderStatus: " << mReaderStatus << endl;
00282 return mReaderStatus;
00283 }
00284
00285
00286 void StHbtBinaryReader::Finish(){
00287 }
00288
00289 int StHbtBinaryReader::NextFile() {
00290 mFileName="\0";
00291 delete (mFileList->front());
00292 mFileList->pop_front();
00293 if ( mFileList->empty() ) return ioEOL;
00294 mFileName = mFileList->front()->c_str();
00295 if (mDebug) cout << " StHbtBinaryReader::NextFile() - mFileName: " << mFileName << endl;
00296 return ioOK;
00297 }
00298
00299 void StHbtBinaryReader::SetFileName(const char* file){mFileName=(char*)file;}
00300 void StHbtBinaryReader::SetDirName(const char* dir){mDirName=(char*)dir;}
00301 void StHbtBinaryReader::SetAppendix(const char* appendix){mAppendix=(char*)appendix;}
00302
00303 void StHbtBinaryReader::AddFileList(const char* fileList) {
00304 if (mDebug>1) cout << " StHbtBinaryReader::AddFileList(char* fileList)"<< endl;
00305 if (!mFileList) mFileList = new fileCollection;
00306 ifstream* inputStream = new ifstream;
00307 inputStream->open(fileList);
00308 if (!(inputStream)){
00309 if (mDebug) cout << " StHbtBinaryReader::AddFileList(char* fileList) - Cannot open input file! " << endl;
00310 mReaderStatus = ioERROpen;
00311 return;
00312 }
00313 char* temp;
00314 if (mDebug>1) cout << " inputStream->good() : " << inputStream->good() << endl;
00315 for (;inputStream->good();) {
00316 temp = new char[200];
00317 inputStream->getline(temp,200);
00318 cout << temp << endl;
00319 StHbtString* newFile = new StHbtString(temp);
00320 if ( newFile->length()>0 ) {
00321 mFileList->push_back(newFile);
00322 if (mDebug>1) cout << " file " << newFile->c_str() << " added to file list " << endl;
00323 }
00324 }
00325 if (mDebug) cout << " StHbtBinaryReader::FillFileList(char* fileList) - " << mFileList->empty() << " files in list " << endl;
00326 if (!mFileList->empty())
00327 mFileName = mFileList->front()->c_str();
00328 }
00329
00330
00331 StHbtString StHbtBinaryReader::Report(){
00332 StHbtString temp = "\n This is the StHbtBinaryEventReader\n";
00333 temp += "---> EventCuts in Reader: ";
00334 if (mEventCut) {
00335 temp += mEventCut->Report();
00336 }
00337 else {
00338 temp += "NONE";
00339 }
00340 temp += "\n---> TrackCuts in Reader: ";
00341 if (mTrackCut) {
00342 temp += mTrackCut->Report();
00343 }
00344 else {
00345 temp += "NONE";
00346 }
00347 temp += "\n---> V0Cuts in Reader: ";
00348 if (mV0Cut) {
00349 temp += mV0Cut->Report();
00350 }
00351 else {
00352 temp += "NONE";
00353 }
00354 temp += "\n";
00355 return temp;
00356 }
00357