00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TYYYEventSource.h"
00017
00018 #include "Riostream.h"
00019 #include <stdlib.h>
00020 #include "snprintf.h"
00021
00022 #include "TGo4EventErrorException.h"
00023 #include "TGo4EventTimeoutException.h"
00024 #include "TGo4UserSourceParameter.h"
00025 #include "TYYYRawEvent.h"
00026
00027 TYYYEventSource::TYYYEventSource(const char* name,
00028 const char* args, Int_t port)
00029 : TGo4EventSource(name),
00030 fbIsOpen(kFALSE), fxArgs(args), fiPort(port), fxFile(0)
00031 {
00032 Open();
00033 }
00034
00035 TYYYEventSource::TYYYEventSource(TGo4UserSourceParameter* par)
00036 : TGo4EventSource(" "),
00037 fbIsOpen(kFALSE), fxArgs(" "), fiPort(0),fxFile(0)
00038 {
00039 if(par)
00040 {
00041 SetName(par->GetName());
00042 SetPort(par->GetPort());
00043 SetArgs(par->GetExpression());
00044 Open();
00045 }
00046 else
00047 {
00048 cout <<"TYYYEventSource constructor with zero parameter!" << endl;
00049 }
00050 }
00051
00052
00053
00054 TYYYEventSource::TYYYEventSource()
00055 : TGo4EventSource("default YYY source"),
00056 fbIsOpen(kFALSE), fxArgs(" "), fiPort(0),fxFile(0)
00057 {
00058
00059 }
00060
00061 TYYYEventSource::~TYYYEventSource()
00062 {
00063 Close();
00064 }
00065
00066 void TYYYEventSource::BuildYYYEvent(TYYYRawEvent* target)
00067 {
00068 Int_t status=1;
00069
00070
00071 Text_t buffer[TGo4EventSource::fguTXTLEN];
00072 Int_t scanresult=0;
00073 Int_t numval=0;
00074 const char* cursor = fxNextline.Data();
00075 do{
00076 target->ReAllocate(numval+1);
00077 scanresult=sscanf(cursor,"%s",buffer);
00078
00079
00080 if(scanresult!=0 && scanresult!=-1)
00081 {
00082 target->fdData[numval]=atof(buffer);
00083
00084 status=0;
00085 }
00086 numval++;
00087 cursor+=strlen(buffer)+1;
00088
00089 } while( scanresult!=0 && scanresult!=-1);
00090
00091
00092
00093
00094
00095 if(status==0)
00096 {
00097 target->SetValid(kTRUE);
00098
00099 }
00100 else
00101 {
00102 target->SetValid(kFALSE);
00103
00104 SetErrMess("YYY Event Source -- ERROR !!!");
00105 throw TGo4EventErrorException(this);
00106 }
00107 }
00108
00109 Int_t TYYYEventSource::NextEvent()
00110 {
00111
00112 do{
00113 fxFile->getline(const_cast<Text_t*>(fxNextline.Data()),
00114 TGo4EventSource::fguTXTLEN,
00115 '\n' );
00116 if(fxFile->eof() || !fxFile->good())
00117 {
00118
00119 SetCreateStatus(1);
00120 Text_t buffer[TGo4EventSource::fguTXTLEN];
00121 snprintf(buffer,TGo4EventSource::fguTXTLEN,
00122 "End of input file %s", GetName());
00123 SetErrMess(buffer);
00124 throw TGo4EventErrorException(this);
00125 }
00126
00127 }while(strstr(fxNextline.Data(),"#") || strstr(fxNextline.Data(),"!") );
00128
00129 return 0;
00130 }
00131
00132 Int_t TYYYEventSource::Open()
00133 {
00134 if(fbIsOpen)
00135 return -1;
00136 cout << "Open of TYYYEventSource"<< endl;
00137
00138 fxNextline.Capacity(TGo4EventSource::fguTXTLEN);
00139 Int_t status=0;
00140 fxFile=new std::ifstream(GetName());
00141 if(fxFile==0)
00142 {
00143 status=1;
00144 SetCreateStatus(status);
00145 Text_t buffer[TGo4EventSource::fguTXTLEN];
00146 snprintf(buffer,TGo4EventSource::fguTXTLEN,
00147 "Eror opening user file:%s",GetName());
00148 SetErrMess(buffer);
00149 throw TGo4EventErrorException(this);
00150 }
00151 fbIsOpen=kTRUE;
00152 return status;
00153 }
00154
00155 Int_t TYYYEventSource::Close()
00156 {
00157 if(!fbIsOpen)
00158 return -1;
00159
00160 cout << "Close of TYYYEventSource"<< endl;
00161 Int_t status=0;
00162 delete fxFile;
00163 fbIsOpen=kFALSE;
00164 return status;
00165
00166 }
00167
00168