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