GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TYYYEventSource.cxx
Go to the documentation of this file.
1// $Id$
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"
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{
32 Open();
33}
34
36 TGo4EventSource(" "),
37 fbIsOpen(kFALSE),
38 fxArgs(),
39 fiPort(0)
40{
41 if(par) {
42 SetName(par->GetName());
43 SetPort(par->GetPort());
44 SetArgs(par->GetExpression());
45 Open();
46 } else {
47 TGo4Log::Error("TYYYEventSource constructor with zero parameter!");
48 }
49}
50
52 TGo4EventSource("default YYY source"),
53 fbIsOpen(kFALSE),
54 fxArgs(),
55 fiPort(0)
56{
57}
58
63
65{
66 return cl->InheritsFrom(TYYYRawEvent::Class());
67}
68
70{
71 auto evnt = static_cast<TYYYRawEvent *>(dest);
72 if (!evnt) return kFALSE;
73
74 char sbuf[1024], buffer[1024];
75
76 // read another event from open file into our buffer
77 do {
78 fxFile->getline(sbuf, sizeof(sbuf), '\n' ); // read whole line
79 if(fxFile->eof() || !fxFile->good()) {
80 // reached last line or read error?
82 TString errmsg = TString::Format("End of input file %s", GetName());
83 SetErrMess(errmsg.Data());
85 throw TGo4EventEndException(this);
86 }
87 } while(strstr(sbuf,"#") || strstr(sbuf,"!") ); // skip any comments
88
89 Int_t status = 1;
90 // process on event information in our buffer
91 // scan the last input line for values:
92 Int_t scanresult = 0;
93 Int_t numval = 0;
94 const char *cursor = sbuf;
95 do {
96 evnt->ReAllocate(numval+1); // check if realloc necessary
97 scanresult = sscanf(cursor,"%s",buffer);
98 if(scanresult != 0 && scanresult != -1) {
99 evnt->fdData[numval] = atof(buffer);
100 status = 0; // only ok if at least one value scanned
101 }
102 numval++;
103 cursor += strlen(buffer)+1;
104 } while( scanresult != 0 && scanresult != -1);
105
106 // test here for error in input event
107
108 if(status != 0) {
109 evnt->SetValid(kFALSE);
110 // somethings wrong, display error message from f_evt_error()
111 SetErrMess("YYY Event Source -- ERROR !!!");
112 throw TGo4EventErrorException(this);
113 }
114
115 return kTRUE;
116}
117
119{
120 if(fbIsOpen) return -1;
121 TGo4Log::Info("Open of TYYYEventSource %s", GetName());
122 // open connection/file
123 fxFile = new std::ifstream(GetName());
124 if(!fxFile || !fxFile->good()) {
125 delete fxFile;
126 fxFile = nullptr;
127 TString errmsg = TString::Format("Eror opening user file:%s",GetName());
129 SetErrMess(errmsg.Data());
130 throw TGo4EventErrorException(this);
131 }
132 fbIsOpen = kTRUE;
133 return 0;
134}
135
137{
138 if(!fbIsOpen) return -1;
139 TGo4Log::Info("Close of TYYYEventSource");
140 Int_t status = 0; // closestatus of source
141 if (fxFile) {
142 delete fxFile;
143 fxFile = nullptr;
144 }
145 fbIsOpen = kFALSE;
146 return status;
147}
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Exception to throw on event source timeout.
Exception to be thrown on error of event source.
void SetErrMess(const char *txt)
To be used for modification of the message by the event source implementation.
void SetEventStatus(Int_t status)
Status of the last event.
void SetCreateStatus(Int_t status)
Status value of event source init (file/server open).
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
Definition TGo4Log.cxx:294
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
const char * GetExpression() const
User expression as string.
Int_t fiPort
Optional port number.
Bool_t BuildEvent(TGo4EventElement *dest) override
This methods actually fills the target event class which is passed as pointer.
void SetPort(Int_t val)
std::ifstream * fxFile
file that contains the data in ascii format.
virtual Int_t Open()
Open the file or connection.
TString fxArgs
Optional argument string.
Bool_t CheckEventClass(TClass *cl) override
This method checks if event class is suited for the source.
virtual ~TYYYEventSource()
void SetArgs(const char *arg)
virtual Int_t Close()
Close the file or connection.
Example for user defined raw event class.