32 dabc::DataInput (), fQueueMutex(false), fWaitingForCallback(false), fOverflowCount(0), fLastOverflowCount(0), fDevice(owner), fTimeout (1e-2),
33 fUseCallbackMode(false), fSubeventId (8),fEventNumber (0),fVerbose(false),fSingleEvents(false)
35 DOUT0(
"saftdabc::Input CTOR");
42 DOUT0(
"saftdabc::Input DTOR");
49 fTransport.SetObject(trans);
54 DOUT3(
"saftdabc::Input::Read_Init...");
70 if(
format.compare(std::string(
"RAW"))==0)
72 else if (
format.compare(std::string(
"MBS"))==0)
74 else if (
format.compare(std::string(
"HADAQ"))==0)
80 if (! (fSnoop_Ids.size () == fSnoop_Masks.size ()) &&
81 (fSnoop_Ids.size () == fSnoop_Offsets.size ()) &&
82 (fSnoop_Ids.size () == fSnoop_Flags.size ()))
85 "saftdabc::Input %s - numbers for snoop event ids %d, masks %d, offsets %d, flags %d differ!!! - Please check configuration.", wrk.
GetName(),
86 fSnoop_Ids.size(), fSnoop_Masks.size(), fSnoop_Offsets.size(), fSnoop_Flags.size());
92 "saftdabc::Input %s - Timeout = %e s, callbackmode:%s, format:%s, subevtid:%d, single event:%s, %d hardware inputs, %d snoop event ids, verbose=%s ",
93 wrk.
GetName(), fTimeout,
DBOOL(fUseCallbackMode),
format.c_str(), fSubeventId,
DBOOL(fSingleEvents), fInput_Names.size(), fSnoop_Ids.size(),
DBOOL(fVerbose));
97 bool rev=SetupConditions();
99 EOUT(
"Could not set up all conditions!");
122 DOUT1(
"Input::Close - Overflow counts:%lu, previous:%lu",fOverflowCount, fLastOverflowCount);
131 while(!fTimingEventQueue.empty()) fTimingEventQueue.pop();
139 DOUT3(
"saftdabc::Input::Read_Size...");
140 #ifdef DABC_SAFT_USE_2_0
141 saftlib::wait_for_signal();
148 bool nodata=fTimingEventQueue.empty();
151 if(nodata)
DOUT3(
"saftdabc::Input::Read_Size returns with timeout!");
160 catch (std::exception& ex)
162 EOUT(
" saftdabc::Input::Read_Size with std exception %s ", ex.what());
165 #ifdef DABC_SAFT_USE_2_0
166 catch (
const saftbus::Error& error)
169 EOUT(
"saftdabc::Input::Read_Size with SAFTbus error %s ", error.what().c_str());
182 if (fTimingEventQueue.empty ())
184 if (fUseCallbackMode)
186 fWaitingForCallback =
true;
187 DOUT1(
"saftdabc::Input::Read_Start sets fWaitingForCallback=%s",
DBOOL(fWaitingForCallback));
192 EOUT(
"saftdabc::Input::Read_Start() with empty queue in polling mode!");
200 catch (std::exception& ex)
202 EOUT(
" saftdabc::Input::Read_Start with std exception %s ", ex.what());
215 DOUT5(
"saftdabc::Input::Read_Complete...");
216 switch (fEventFormat)
219 return Write_Raw (buf);
221 return Write_Hadaq (buf);
224 return Write_Mbs (buf);
230 #ifdef DABC_SAFT_USE_2_0
231 catch (
const saftbus::Error& error)
233 EOUT(
"saftdabc::Input::Read_Complete with saftbus error %s", error.what().c_str());
237 catch (
const Glib::Error& error)
239 EOUT(
"saftdabc::Input::Read_Complete with Glib error %s", error.what().c_str());
244 catch (std::exception& ex)
246 EOUT(
" saftdabc::Input::Read_Complete with std exception %s ", ex.what());
256 DOUT5(
"saftdabc::Input::Write_Mbs...");
259 if(!iter.IsPlaceForEvent(
sizeof(Timing_Event),
true))
262 EOUT(
"saftdabc::Input::Write_Mbs: buffer too small for a single Timing Event!");
265 iter.NewEvent (fEventNumber++);
266 iter.NewSubevent2 (fSubeventId);
268 if(fVerbose)
DOUT0(
"saftdabc::Input::Write_Mbs begins new event %d, mutex=0x%x, instance=0x%x",
269 fEventNumber, &fQueueMutex, (
unsigned long)
this);
272 while (!fTimingEventQueue.empty ())
274 if(fSingleEvents && (ec==1))
277 DOUT0(
"saftdabc::Input::Write_Mbs has filled single event, closing container.");
284 if (!iter.IsPlaceForRawData(
sizeof(Timing_Event)))
291 uint32_t rest= iter.maxrawdatasize() - ec *
sizeof(Timing_Event);
292 DOUT0(
"saftdabc::Input::Write_Mbs - buffer remaining size is %d bytes too small for next timing event!",
300 Timing_Event theEvent = fTimingEventQueue.front ();
303 DOUT0(
"saftdabc::Input::Write_Mbswith queue length %u",fTimingEventQueue.size());
305 theEvent.InfoMessage(txt,1024);
306 DOUT0(
"saftdabc::Input::Write_Mbs sees event: %s",txt);
308 unsigned len =
sizeof(Timing_Event);
309 if (!iter.AddRawData (&theEvent, len)){
311 DOUT0(
"saftdabc::Input::Write_Mbs could not add data of len=%ld to subevent of maxraw=%ld, queuelen=%u",
312 len, iter.maxrawdatasize(), fTimingEventQueue.size());
315 fTimingEventQueue.pop ();
320 iter.FinishSubEvent();
325 if(fVerbose)
DOUT0(
"saftdabc::Input::Write_Mbs closes new event %d, read buffer size=%u", fEventNumber, buf.
GetTotalSize());
334 DOUT5(
"saftdabc::Input::Write_Hadaq...");
339 if(!iter.IsPlaceForEvent(
sizeof(Timing_Event)))
342 EOUT(
"saftdabc::Input::Write_Hadaq: buffer too small for a single Timing Event!");
347 if(!iter.NewEvent (fEventNumber++, fSubeventId,
sizeof(
hadaq::RawSubevent)+
sizeof(Timing_Event)))
350 EOUT(
"saftdabc::Input::Write_Hadaq: NewEvent fails to hold single Timing Event!");
355 char* rawbase= (
char*) iter.rawdata();
356 char* cursor=rawbase;
359 if(fVerbose)
DOUT0(
"saftdabc::Input::Write_Hadaq begins new event %d, mutex=0x%x, instance=0x%x",
360 fEventNumber, &fQueueMutex, (
unsigned long)
this);
363 while (!fTimingEventQueue.empty ())
365 if(fSingleEvents && (ec==1))
368 DOUT0(
"saftdabc::Input::Write_Hadaq has filled single event, closing container.");
375 if((cursor - rawbase +
sizeof(Timing_Event) ) > iter.maxrawdatasize())
379 uint32_t rest= iter.maxrawdatasize() - ec *
sizeof(Timing_Event);
380 DOUT0(
"saftdabc::Input::Write_Hadaq - buffer remaining size is %d bytes too small for next timing event!",
388 Timing_Event theEvent = fTimingEventQueue.front ();
391 DOUT0(
"saftdabc::Input::Write_Hadaq with queue length %u",fTimingEventQueue.size());
393 theEvent.InfoMessage(txt,1024);
394 DOUT0(
"saftdabc::Input::Write_Hadaq sees event: %s",txt);
397 unsigned len =
sizeof(Timing_Event);
398 memcpy(cursor, &theEvent,len);
402 fTimingEventQueue.pop ();
408 iter.FinishSubEvent(rawsize);
411 if(fVerbose)
DOUT0(
"saftdabc::Input::Write_Hadaq closes new event %d, read buffer size=%u", fEventNumber, buf.
GetTotalSize());
418 while (!fTimingEventQueue.empty ())
419 fTimingEventQueue.pop ();
436 for (std::vector<std::string>::iterator confit = fInput_Names.begin (); confit != fInput_Names.end (); ++confit)
438 bool rev = fDevice.RegisterInputCondition (
this, *confit);
443 DOUT0(
"SetupConditions with %d errors for input conditions.", errcnt);
448 for (std::vector<uint64_t>::iterator snit = fSnoop_Ids.begin (), mit = fSnoop_Masks.begin (), offit = fSnoop_Offsets
449 .begin (), flit = fSnoop_Flags.begin ();
450 snit != fSnoop_Ids.end (), mit != fSnoop_Masks.end (), offit != fSnoop_Offsets.end (), flit
451 != fSnoop_Flags.end (); ++snit, ++mit, ++offit, ++flit)
454 bool rev = fDevice.RegisterEventCondition (
this, *snit, *mit, *offit, (
unsigned char) *flit);
459 DOUT0(
"SetupConditions with %d errors for snoop conditions.", errcnt);
467 #ifdef DABC_SAFT_USE_2_0
468 catch (
const saftbus::Error& error)
470 EOUT(
"SAFTbus error %s in SetupConditions", error.what().c_str());
473 catch (
const Glib::Error& error)
475 EOUT(
"Glib error %s in SetupConditions", error.what().c_str());
480 catch (std::exception& ex)
482 EOUT(
"std exception %s in SetupConditions", ex.what());
489 #ifdef DABC_SAFT_USE_2_0
496 DOUT5(
"saftdabc::Input::EventHandler...");
501 std::string description = fDevice.GetInputDescription (event);
511 DOUT0(
"saftdabc::Input::EventHandler holds mutex 0x%x, instance=0x%x",(
unsigned long) &fQueueMutex, (
unsigned long)
this);
513 "Input::EventHandler sees event=0x%lx, param=0x%lx , deadline=0x%lx, executed=0x%lx, flags=0x%x, description:%s", event, param, deadline, executed, flags, description.c_str());
525 uint64_t doverflow= fOverflowCount-fLastOverflowCount;
528 DOUT0(
"saftdabc::Input::EventHandler sees overflowcount=%lu, previous=%lu, delta=%lu",fOverflowCount, fLastOverflowCount, doverflow);
531 fLastOverflowCount=fOverflowCount;
532 fTimingEventQueue.push (Timing_Event (event, param, deadline, executed, flags, doverflow, description.c_str ()));
533 DOUT3(
"TimingEventQueue is filled with %d elements", fTimingEventQueue.size());
534 DOUT3(
"saftdabc::Input::EventHandler with fWaitingForCallback=%s",
DBOOL(fWaitingForCallback));
535 if (fUseCallbackMode && fWaitingForCallback)
547 fWaitingForCallback =
false;
548 DOUT1(
"saftdabc::Input::EventHandler after Read_CallBack, fWaitingForCallback=%s",
DBOOL(fWaitingForCallback));
552 EOUT(
"Worker %p is not an InputTransport, can not Read_CallBack", fTransport());
559 #ifdef DABC_SAFT_USE_2_0
560 catch (
const saftbus::Error& error)
562 EOUT(
"saftdabc::Input::EventHandler with saftbus error %s", error.what().c_str());
565 catch (
const Glib::Error& error)
567 EOUT(
"saftdabc::Input::EventHandler with Glib error %s", error.what().c_str());
571 catch (std::exception& ex)
573 EOUT(
" saftdabc::Input::EventHandler with std exception %s ", ex.what());
581 #ifdef DABC_SAFT_USE_2_0
587 DOUT1(
"saftdabc::Input::OverflowHandler with counts=%lu",count);
589 fOverflowCount=count;
590 DOUT3(
"saftdabc::Input::OverflowHandler sees overflowcount=%lu, previous=%lu",fOverflowCount, fLastOverflowCount);
Reference on memory from memory pool.
BufferSize_t GetTotalSize() const
Return total size of all buffer segments.
Represents command with its arguments.
Lock guard for posix mutex.
std::vector< uint64_t > AsUIntVect() const
std::vector< std::string > AsStrVect() const
bool AsBool(bool dflt=false) const
std::string AsStr(const std::string &dflt="") const
int64_t AsInt(int64_t dflt=0) const
double AsDouble(double dflt=0.) const
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
Reference on dabc::Worker
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration record of specified name.
Write iterator for HADAQ events/subevents.
Write iterator for MBS events/subevents.
std::string format(const char *fmt,...)
const char * xmlCallbackMode
switch between polling for data or callback mode
const char * xmlOffsets
WR event offsets to snoop.
const char * xmlSaftVerbose
switch between silent or verbose event receiver mode
const char * xmlInputs
EXPLODER input name items that should be latched with timestamp.
const char * xmlAcceptFlags
WR event accept flags to snoop.
const char * xmlEventIds
WR event ids to snoop.
const char * xmlTimeout
time out for polling mode
const char * xmlSaftSubeventId
const guint32 PMODE_VERBOSE
std::string tr_formatDate(guint64 time, guint32 pmode)
const char * xmlMasks
WR event masks to snoop.
const char * xmlSaftSingleEvent
std::string tr_formatActionEvent(guint64 id, guint32 pmode)
const char * xmlEventFormat
const char * commandRunMainloop
Command to invoke the glib/dbus mainloop.
#define NON_IO_CONDITION_LABEL
this marks conditions that are not input conditions:
#define IO_CONDITION_OFFSET
#define SAFT_DABC_TRIGTYPE
tag the timing events with special trigger type.
Hadaq subevent structure.