GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TYYYEventSource.cxx
Go to the documentation of this file.
1 // $Id: TYYYEventSource.cxx 2768 2020-04-16 14:49:34Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TYYYEventSource.h"
15 
16 #include "TClass.h"
17 
18 #include "TGo4Log.h"
20 #include "TGo4EventEndException.h"
22 #include "TYYYRawEvent.h"
23 
25  const char* args,
26  Int_t port) :
27  TGo4EventSource(name),
28  fbIsOpen(kFALSE),
29  fxArgs(args),
30  fiPort(port),
31  fxFile(0)
32 {
33  Open();
34 }
35 
37  TGo4EventSource(" "),
38  fbIsOpen(kFALSE),
39  fxArgs(),
40  fiPort(0),
41  fxFile(0)
42 {
43  if(par) {
44  SetName(par->GetName());
45  SetPort(par->GetPort());
46  SetArgs(par->GetExpression());
47  Open();
48  } else {
49  TGo4Log::Error("TYYYEventSource constructor with zero parameter!");
50  }
51 }
52 
54  TGo4EventSource("default YYY source"),
55  fbIsOpen(kFALSE),
56  fxArgs(),
57  fiPort(0),
58  fxFile(0)
59 {
60 }
61 
63 {
64  Close();
65 }
66 
68 {
69  return cl->InheritsFrom(TYYYRawEvent::Class());
70 }
71 
73 {
74  TYYYRawEvent* evnt = (TYYYRawEvent*) dest;
75  if (evnt==0) return kFALSE;
76 
77  char sbuf[1024], buffer[1024];
78 
79  // read another event from open file into our buffer
80  do {
81  fxFile->getline(sbuf, sizeof(sbuf), '\n' ); // read whole line
82  if(fxFile->eof() || !fxFile->good()) {
83  // reached last line or read error?
84  SetCreateStatus(1);
85  SetErrMess(Form("End of input file %s", GetName()));
86  SetEventStatus(1);
87  throw TGo4EventEndException(this);
88  }
89  } while(strstr(sbuf,"#") || strstr(sbuf,"!") ); // skip any comments
90 
91  Int_t status=1;
92  // process on event information in our buffer
93  // scan the last input line for values:
94  Int_t scanresult=0;
95  Int_t numval=0;
96  const char* cursor = sbuf;
97  do {
98  evnt->ReAllocate(numval+1); // check if realloc necessary
99  scanresult = sscanf(cursor,"%s",buffer);
100  //std::cout <<"BuildYYYEvent got buffer:"<<buffer<<", scanresult:";
101  //std::cout << scanresult << std::endl;
102  if(scanresult!=0 && scanresult!=-1) {
103  evnt->fdData[numval] = atof(buffer);
104  status=0; // only ok if at least one value scanned
105  }
106  numval++;
107  cursor+=strlen(buffer)+1;
108  //std::cout <<"cursor set to:"<<cursor << std::endl;
109  } while( scanresult!=0 && scanresult!=-1);
110 
111  // test here for error in input event
112 
113  if(status!=0) {
114  evnt->SetValid(kFALSE);
115  // somethings wrong, display error message from f_evt_error()
116  SetErrMess("YYY Event Source -- ERROR !!!");
117  throw TGo4EventErrorException(this);
118  }
119 
120  return kTRUE;
121 }
122 
124 {
125  if(fbIsOpen) return -1;
126  TGo4Log::Info("Open of TYYYEventSource %s", GetName());
127  // open connection/file
128  fxFile = new std::ifstream(GetName());
129  if((fxFile==0) || !fxFile->good()) {
130  delete fxFile; fxFile = 0;
131  SetCreateStatus(1);
132  SetErrMess(Form("Eror opening user file:%s",GetName()));
133  throw TGo4EventErrorException(this);
134  }
135  fbIsOpen = kTRUE;
136  return 0;
137 }
138 
140 {
141  if(!fbIsOpen) return -1;
142  TGo4Log::Info("Close of TYYYEventSource");
143  Int_t status = 0; // closestatus of source
144  if (fxFile) {
145  delete fxFile;
146  fxFile = 0;
147  }
148  fbIsOpen = kFALSE;
149  return status;
150 }
void SetArgs(const char *arg)
void ReAllocate(Int_t newsize)
virtual Bool_t BuildEvent(TGo4EventElement *dest)
void SetPort(Int_t val)
void SetValid(Bool_t on)
std::ifstream * fxFile
void SetCreateStatus(Int_t status)
virtual ~TYYYEventSource()
void SetErrMess(const char *txt)
Double_t * fdData
Definition: TYYYRawEvent.h:49
virtual Bool_t CheckEventClass(TClass *cl)
const char * GetExpression() const
void SetEventStatus(Int_t status)
virtual Int_t Close()
virtual Int_t Open()
static void Error(const char *text,...)
Definition: TGo4Log.cxx:313
static void Info(const char *text,...)
Definition: TGo4Log.cxx:287