JANA2
C++ framework for multi-threaded data processing
JEventSource Class Reference
Inheritance diagram for JEventSource:
[legend]
Collaboration diagram for JEventSource:
[legend]

Public Types

enum class  Result {
  Success ,
  FailureTryAgain ,
  FailureFinished
}
 Result describes what happened the last time a GetEvent() was attempted. More...
 
enum class  RETURN_STATUS {
  kSUCCESS ,
  kNO_MORE_EVENTS ,
  kBUSY ,
  kTRY_AGAIN ,
  kERROR ,
  kUNKNOWN
}
 The user is supposed to throw RETURN_STATUS::kNO_MORE_EVENTS or kBUSY from GetEvent()
 
- Public Types inherited from jana::components::JComponent
enum class  Status {
  Uninitialized ,
  Initialized ,
  Opened ,
  Closed ,
  Finalized
}
 
enum class  CallbackStyle {
  LegacyMode ,
  ExpertMode ,
  DeclarativeMode
}
 

Public Member Functions

 JEventSource (std::string resource_name, JApplication *app=nullptr)
 
virtual void Init ()
 
virtual void Open ()
 Open is called by JANA when it is ready to accept events from this event source. More...
 
virtual Result Emit (JEvent &)
 
virtual void Preprocess (const JEvent &) const
 For work that should be done in parallel on a JEvent, but is tightly coupled to the JEventSource for some reason. More...
 
virtual void FinishEvent (JEvent &)
 FinishEvent is used to notify the JEventSource that an event has been completely processed. More...
 
virtual void Close ()
 Close is called by JANA when it is finished accepting events from this event source. More...
 
virtual void GetEvent (std::shared_ptr< JEvent >)
 GetEvent is called by JANA in order to emit a fresh event into the stream. More...
 
virtual bool GetObjects (const std::shared_ptr< const JEvent > &, JFactory *)
 GetObjects was historically used for lazily unpacking data from a JEvent and putting it into a "dummy" JFactory. More...
 
std::string GetResourceName () const
 
uint64_t GetEventCount () const
 
uint64_t GetEmittedEventCount () const
 
uint64_t GetFinishedEventCount () const
 
virtual std::string GetType () const
 
std::string GetName () const
 
bool IsGetObjectsEnabled () const
 
bool IsFinishEventEnabled () const
 
bool IsPreprocessEnabled () const
 
uint64_t GetNSkip ()
 
uint64_t GetNEvents ()
 
virtual std::string GetVDescription () const
 Optional for getting description via source rather than JEventSourceGenerator.
 
void SetResourceName (std::string resource_name)
 
void EnableFinishEvent (bool enable=true)
 EnableFinishEvent() is intended to be called by the user in the constructor in order to tell JANA to call the provided FinishEvent method after all JEventProcessors have finished with a given event. More...
 
void EnableGetObjects (bool enable=true)
 
void EnablePreprocess (bool enable=true)
 
void SetNEvents (uint64_t nevents)
 
void SetNSkip (uint64_t nskip)
 
void DoInitialize ()
 
virtual void DoInit ()
 
void DoOpen (bool with_lock=true)
 
void DoClose (bool with_lock=true)
 
Result DoNext (std::shared_ptr< JEvent > event)
 
Result DoNextCompatibility (std::shared_ptr< JEvent > event)
 
void DoFinish (JEvent &event)
 
void Summarize (JComponentSummary &summary) const override
 
- Public Member Functions inherited from jana::components::JComponent
void SetLevel (JEventLevel level)
 
void SetCallbackStyle (CallbackStyle style)
 
void SetPrefix (std::string prefix)
 
void SetTypeName (std::string type_name)
 For convenience, we provide a NAME_OF_THIS macro so that the user doesn't have to store the type name as a string, because that could get out of sync if automatic refactoring tools are used.
 
JApplicationGetApplication () const
 
JLoggerGetLogger ()
 
std::string GetPrefix () const
 
JEventLevel GetLevel () const
 
std::string GetLoggerName () const
 
std::string GetPluginName () const
 
void SetLoggerName (std::string logger_name)
 
void SetPluginName (std::string plugin_name)
 
std::string GetTypeName () const
 
CallbackStyle GetCallbackStyle () const
 
Status GetStatus () const
 
void SetApplication (JApplication *app)
 
void SetLogger (JLogger logger)
 
template<typename F >
void CallWithJExceptionWrapper (std::string func_name, F func)
 
void RegisterParameter (ParameterBase *parameter)
 
void RegisterService (ServiceBase *service)
 
void ConfigureAllParameters (std::map< std::string, std::string > fields)
 

Additional Inherited Members

- Protected Member Functions inherited from jana::components::JHasOutputs
void RegisterOutput (OutputBase *output)
 
- Protected Attributes inherited from jana::components::JComponent
std::vector< ParameterBase * > m_parameters
 
std::vector< ServiceBase * > m_services
 
JEventLevel m_level = JEventLevel::PhysicsEvent
 
CallbackStyle m_callback_style = CallbackStyle::LegacyMode
 
std::string m_prefix
 
std::string m_plugin_name
 
std::string m_logger_name
 
std::string m_type_name
 
Status m_status = Status::Uninitialized
 
std::mutex m_mutex
 
JApplicationm_app = nullptr
 
JLogger m_logger
 
- Protected Attributes inherited from jana::components::JHasOutputs
std::vector< OutputBase * > m_outputs
 

Member Enumeration Documentation

◆ Result

enum JEventSource::Result
strong

Result describes what happened the last time a GetEvent() was attempted.

If Emit() or GetEvent() reaches an error state, it should throw a JException instead.

Member Function Documentation

◆ Close()

virtual void JEventSource::Close ( )
inlinevirtual

Close is called by JANA when it is finished accepting events from this event source.

Here is where you should cleanly close files, sockets, etc. Although GetEvent() knows when (for instance) there are no more events in a file, the logic for closing needs to live here because there are other ways a computation may end besides running out of events in a file. For instance, the user may want to process a limited number of events using the jana:nevents parameter, or they may want to terminate the computation manually using Ctrl-C.

◆ EnableFinishEvent()

void JEventSource::EnableFinishEvent ( bool  enable = true)
inline

EnableFinishEvent() is intended to be called by the user in the constructor in order to tell JANA to call the provided FinishEvent method after all JEventProcessors have finished with a given event.

This should only be enabled when absolutely necessary (e.g. for backwards compatibility) because it introduces contention for the JEventSource mutex, which will hurt performance. Conceptually, FinishEvent isn't great, and so should be avoided when possible.

◆ FinishEvent()

virtual void JEventSource::FinishEvent ( JEvent )
inlinevirtual

FinishEvent is used to notify the JEventSource that an event has been completely processed.

This is the final chance to interact with the JEvent before it is either cleared and recycled, or deleted. Although it is possible to use this for freeing JObjects stored in the JEvent , this is strongly discouraged in favor of putting that logic on the destructor, RAII-style. Instead, this callback should be used for updating and freeing state owned by the JEventSource, e.g. raw data which is keyed off of run number and therefore shared among multiple JEvents. FinishEvent is also well-suited for use with EventGroups, e.g. to notify someone that a batch of events has finished, or to implement "barrier events".

◆ GetEvent()

virtual void JEventSource::GetEvent ( std::shared_ptr< JEvent )
inlinevirtual

GetEvent is called by JANA in order to emit a fresh event into the stream.

JANA manages the entire lifetime of the JEvent. The JEvent being passed in is empty and merely needs to hydrated as follows:

  1. SetRunNumber()
  2. SetEventNumber()
  3. Insert<T>() raw data of type T into the JEvent container. Note that T should be a child class, such as FADC250DigiHit, not a parent class such as JObject or TObject. Also note that Insert transfers ownership of the data to that JEvent. If the data is shared among multiple JEvents, e.g. BOR data, use SetFactoryFlags(JFactory::NOT_OBJECT_OWNER) Note that JEvents are usually recycled. Although all reconstruction data is cleared before GetEvent is called, the constituent JFactories may retain some state, e.g. statistics, or calibration data keyed off of run number. If an event cannot be emitted, either because the resource is not ready or because we have reached the end of the event stream, the implementor should throw the corresponding RETURN_STATUS. The user should NEVER throw RETURN_STATUS SUCCESS because this will hurt performance. Instead, they should simply return normally.

◆ GetObjects()

virtual bool JEventSource::GetObjects ( const std::shared_ptr< const JEvent > &  ,
JFactory  
)
inlinevirtual

GetObjects was historically used for lazily unpacking data from a JEvent and putting it into a "dummy" JFactory.

This mechanism has been replaced by JEvent::Insert. All lazy evaluation should happen in a (non-dummy) JFactory, whereas eager evaluation should happen in JEventSource::GetEvent via JEvent::Insert.

◆ Open()

virtual void JEventSource::Open ( )
inlinevirtual

Open is called by JANA when it is ready to accept events from this event source.

The implementor should open file pointers or sockets here, instead of in the constructor. This is because the implementor won't know how many or which event sources the user will decide to activate within one job. Thus the implementor can avoid problems such as running out of file pointers, or multiple event sources attempting to bind to the same socket.

Reimplemented in JStreamingEventSource< MessageT >, JEventBuilder< T >, and JDiscreteJoin< T >.

◆ Preprocess()

virtual void JEventSource::Preprocess ( const JEvent ) const
inlinevirtual

For work that should be done in parallel on a JEvent, but is tightly coupled to the JEventSource for some reason.

Called after Emit() by JEventMapArrow


The documentation for this class was generated from the following files: