Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ExampleUserSource/TYYYEventSource.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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    // process on event information in our buffer
00068    // scan the last input line for values:
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); // check if realloc necessary
00075       scanresult=sscanf(cursor,"%s",buffer);
00076       //cout <<"BuildYYYEvent got buffer:"<<buffer<<", scanresult:";
00077       //cout << scanresult << endl;
00078       if(scanresult!=0 && scanresult!=-1)
00079          {
00080            target->fdData[numval]=atof(buffer);
00081            //cout <<"filled data:"<<target->fdData[numval] << endl;
00082             status=0; // only ok if at least one value scanned
00083          }
00084       numval++;
00085       cursor+=strlen(buffer)+1;
00086       //cout <<"cursor set to:"<<cursor << endl;
00087    } while( scanresult!=0 && scanresult!=-1);
00088 
00089 
00090 
00091    // test here for error in input event
00092 
00093    if(status==0)
00094       {
00095       target->SetValid(kTRUE); // reset target if previously was set to false
00096       // here build event from source!
00097       }
00098    else
00099       {
00100          target->SetValid(kFALSE);
00101          // somethings wrong, display error message from f_evt_error()
00102             SetErrMess("YYY Event Source --  ERROR !!!");
00103             throw TGo4EventErrorException(this);
00104       }
00105 }
00106 
00107 Int_t TYYYEventSource::NextEvent()
00108 {
00109 // read another event from open file into our buffer
00110 do{
00111         fxFile->getline(const_cast<Text_t*>(fxNextline.Data()),
00112                         TGo4EventSource::fguTXTLEN,
00113                         '\n' ); // read whole line
00114         if(fxFile->eof() || !fxFile->good())
00115           {
00116               // reached last line or read error?
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       //cout <<"read line:"<<fxNextline.Data() << endl;
00125 }while(strstr(fxNextline.Data(),"#") || strstr(fxNextline.Data(),"!") ); // skip any comments
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 // open connection/file
00136 fxNextline.Capacity(TGo4EventSource::fguTXTLEN);
00137 Int_t status=0; // openstatus of source
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; // closestatus of source
00160 delete fxFile;
00161 fbIsOpen=kFALSE;
00162 return status;
00163 
00164 }
00165 ClassImp(TYYYEventSource)
00166 
00167 
00168 
00169 
00170 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:55 2005 for Go4-v2.10-5 by doxygen1.2.15