Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TYYYEventSource.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "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    // process on event information in our buffer
00070    // scan the last input line for values:
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); // check if realloc necessary
00077       scanresult=sscanf(cursor,"%s",buffer);
00078       //cout <<"BuildYYYEvent got buffer:"<<buffer<<", scanresult:";
00079       //cout << scanresult << endl;
00080       if(scanresult!=0 && scanresult!=-1)
00081          {
00082            target->fdData[numval]=atof(buffer);
00083            //cout <<"filled data:"<<target->fdData[numval] << endl;
00084             status=0; // only ok if at least one value scanned
00085          }
00086       numval++;
00087       cursor+=strlen(buffer)+1;
00088       //cout <<"cursor set to:"<<cursor << endl;
00089    } while( scanresult!=0 && scanresult!=-1);
00090 
00091 
00092 
00093    // test here for error in input event
00094 
00095    if(status==0)
00096       {
00097       target->SetValid(kTRUE); // reset target if previously was set to false
00098       // here build event from source!
00099       }
00100    else
00101       {
00102          target->SetValid(kFALSE);
00103          // somethings wrong, display error message from f_evt_error()
00104             SetErrMess("YYY Event Source --  ERROR !!!");
00105             throw TGo4EventErrorException(this);
00106       }
00107 }
00108 
00109 Int_t TYYYEventSource::NextEvent()
00110 {
00111 // read another event from open file into our buffer
00112 do{
00113         fxFile->getline(const_cast<Text_t*>(fxNextline.Data()),
00114                         TGo4EventSource::fguTXTLEN,
00115                         '\n' ); // read whole line
00116         if(fxFile->eof() || !fxFile->good())
00117           {
00118               // reached last line or read error?
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       //cout <<"read line:"<<fxNextline.Data() << endl;
00127 }while(strstr(fxNextline.Data(),"#") || strstr(fxNextline.Data(),"!") ); // skip any comments
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 // open connection/file
00138 fxNextline.Capacity(TGo4EventSource::fguTXTLEN);
00139 Int_t status=0; // openstatus of source
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; // closestatus of source
00162 delete fxFile;
00163 fbIsOpen=kFALSE;
00164 return status;
00165 
00166 }
00167 
00168 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:11 2008 for Go4-v3.04-1 by  doxygen 1.4.2