72 static char station[ET_STATNAME_LENGTH];
73 if(!mystation||strlen(mystation)>=ET_STATNAME_LENGTH){
74 cout <<
"THaEtClient: bad station name\n";
77 strcpy(station,mystation);
78 et_openconfig openconfig{};
79 et_open_config_init(&openconfig);
80 et_open_config_sethost(openconfig,
daqhost);
81 et_open_config_setcast(openconfig, ET_DIRECT);
82 if (et_open(&
id,
etfile, openconfig) != ET_OK) {
84 cout <<
"THaEtClient: cannot open ET system"<<endl;
85 cout <<
"Likely causes: "<<endl;
86 cout <<
" 1. Incorrect SESSION environment variable (it can also be passed to codaOpen)"<<endl;
87 cout <<
" 2. ET not running (CODA not running) on specified computer"<<endl;
90 et_open_config_destroy(openconfig);
91 et_statconfig sconfig{};
92 et_station_config_init(&sconfig);
93 et_station_config_setuser(sconfig, ET_STATION_USER_MULTI);
94 et_station_config_setrestore(sconfig, ET_STATION_RESTORE_OUT);
95 et_station_config_setprescale(sconfig, 1);
96 et_station_config_setcue(sconfig, 100);
97 et_station_config_setselect(sconfig, ET_STATION_SELECT_ALL);
98 et_station_config_setblock(sconfig, ET_STATION_NONBLOCKING);
100 Int_t status = et_station_create(
id, &my_stat, station, sconfig);
101 if (status < ET_OK) {
102 if (status == ET_ERROR_EXISTS) {
105 else if (status == ET_ERROR_TOOMANY) {
106 cout <<
"THaEtClient: too many stations created"<<endl;
109 else if (status == ET_ERROR_REMOTE) {
110 cout <<
"THaEtClient: memory or improper arg problems"<<endl;
113 else if (status == ET_ERROR_READ) {
114 cout <<
"THaEtClient: network reading problem"<<endl;
117 else if (status == ET_ERROR_WRITE) {
118 cout <<
"THaEtClient: network writing problem"<<endl;
122 cout <<
"THaEtClient: error in station creation"<<endl;
126 et_station_config_destroy(sconfig);
127 if (et_station_attach(
id, my_stat, &
my_att) < 0) {
128 cout <<
"THaEtClient: error in station attach"<<endl;
155 uint32_t *
data =
nullptr;
156#if ET_SYSTEM_NSTATS > 10
159 const size_t bpi =
sizeof(
UInt_t);
169 cout <<
"THaEtClient: ERROR: codaRead, cannot connect to CODA"<<endl;
181 struct timespec twait{};
187 if (err == ET_ERROR_TIMEOUT) {
188 printf(
"et_netclient: timeout calling et_events_get\n");
189 printf(
"Probably means CODA is not running...\n");
192 printf(
"et_netclient: error calling et_events_get, %d\n", err);
202 int swapflg = ET_NOSWAP;
203 et_event_getdata(evs[j], (
void **) &
data);
204 et_event_needtoswap(evs[j], &swapflg);
205 if (swapflg == ET_SWAP) {
208 evioswap(
data, 1,
nullptr);
210 et_event_CODAswap(evs[j]);
214 uint32_t event_size = *
data + 1;
216 throw runtime_error(
"THaEtClient: Maximum event buffer size reached");
218 cout<<
"\n\n===== Event "<<j<<
" length "<<event_size<<endl;
220 for (
UInt_t i=0; i < event_size; i++, pdata++) {
221 cout<<
"evbuff["<<dec<<i<<
"] = "<<*pdata<<
" = 0x"<<hex<<*pdata<<endl;
231 time_t daqt2 =
time(
nullptr);
232 double tdiff = difftime(daqt2,
daqt1);
234 if ((tdiff > 4) && (
evsum > 30)) {
235 double daqrate =
static_cast<double>(
evsum)/tdiff;
241 printf(
"ET rate %4.1f Hz in %2.0f sec, avg %4.1f Hz\n",
242 daqrate, tdiff, avgrate);
253 et_event_getdata(evs[
nused], (
void **) &
data);
254 et_event_getlength(evs[
nused], &nbytes);
256 throw runtime_error(
"THaEtClient: Maximum event buffer size reached");
265 cout<<
"THaEtClient::codaRead: ERROR: calling et_events_put"<<endl;
266 cout<<
"This is potentially very bad !!\n"<<endl;
267 cout<<
"best not continue.... exiting... \n"<<endl;