ATLAS Offline Software
Loading...
Searching...
No Matches
EFInterfaceSvc Class Reference

A service managing all the communication with the df_ef interface, for online use. More...

#include <EFInterfaceSvc.h>

Inheritance diagram for EFInterfaceSvc:
Collaboration diagram for EFInterfaceSvc:

Public Types

enum class  Status { OK = 0 , NO_EVENT , STOP }

Public Member Functions

 EFInterfaceSvc (const std::string &name, ISvcLocator *svc)
virtual ~EFInterfaceSvc () noexcept override
virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE () override
virtual StatusCode stop () override
virtual StatusCode finalize () override
virtual void handle (const Incident &incident) override
virtual Status getNext (std::unique_ptr< uint32_t[]> &rawEventPtr)
void eventDone (std::unique_ptr< uint32_t[]> rawEventPtr)
boost::property_tree::ptree prepInterfacePTree ()

Public Attributes

uint32_t m_acceptedEvents {0}
uint32_t m_rejectedEvents {0}
uint32_t m_processedEvents {0}

Private Attributes

boost::dll::shared_library m_efdfinterface_library
 Library with the df_ef_interface implementation.
std::unique_ptr< daq::df_ef_interface::EventHandler > m_eventHandler
std::queue< std::future< std::unique_ptr< uint32_t[]> > > m_getNextFuture
std::mutex m_queueMutex
 Mutex for future queue.
Gaudi::Property< std::string > m_interface_library_name
Gaudi::Property< int > m_getNextTimeout
Gaudi::Property< int > m_stride
Gaudi::Property< int > m_fileOffset
Gaudi::Property< int > m_numEvents
Gaudi::Property< int > m_skipEvents
Gaudi::Property< bool > m_loopOverFiles
Gaudi::Property< std::string > m_outputFileName
Gaudi::Property< std::vector< std::string > > m_files
Gaudi::Property< int > m_runNumber
Gaudi::Property< int > m_triggerType
Gaudi::Property< int > m_beamType
Gaudi::Property< int > m_beamEnergy
Gaudi::Property< std::string > m_detMask
Gaudi::Property< std::string > m_T0_project_tag
Gaudi::Property< std::string > m_stream
Gaudi::Property< int > m_lumiblock

Detailed Description

A service managing all the communication with the df_ef interface, for online use.

This service replaces the use of hltinterface::DataCollector in the online HLT dynamically loads proper implementation library calls interface methods for event retrieval or accept/reject decision manages the pTree for configuring the interface

Definition at line 28 of file EFInterfaceSvc.h.

Member Enumeration Documentation

◆ Status

enum class EFInterfaceSvc::Status
strong
Enumerator
OK 

event returned

NO_EVENT 

no event available

STOP 

stop transition (no more events)

Definition at line 32 of file EFInterfaceSvc.h.

32 {
33 OK = 0,
34 NO_EVENT,
35 STOP
36 };

Constructor & Destructor Documentation

◆ EFInterfaceSvc()

EFInterfaceSvc::EFInterfaceSvc ( const std::string & name,
ISvcLocator * svc )

Definition at line 13 of file EFInterfaceSvc.cxx.

14 : base_class(name, svc)
15{
16}

◆ ~EFInterfaceSvc()

virtual EFInterfaceSvc::~EFInterfaceSvc ( )
inlineoverridevirtualnoexcept

Definition at line 39 of file EFInterfaceSvc.h.

39{}

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

virtual StatusCode initialize EFInterfaceSvc::ATLAS_NOT_THREAD_SAFE ( )
overridevirtual

◆ eventDone()

void EFInterfaceSvc::eventDone ( std::unique_ptr< uint32_t[]> rawEventPtr)

Definition at line 115 of file EFInterfaceSvc.cxx.

116{
117 eformat::read::FullEventFragment ev(rawEventPtr.get());
119 bool accepted = ((ev.nstream_tag() > 0)?true:false);
120 ATH_MSG_DEBUG("Number of stream tags: " << ev.nstream_tag());
121 if(accepted){
122 ATH_MSG_DEBUG("Event " << ev.lvl1_id() << " accepted");
123 auto result = m_eventHandler->accept(ev.lvl1_id(), std::move(rawEventPtr));
125 //TODO: decide if we have to check for the future result
126 }else{
127 ATH_MSG_DEBUG("Event " << ev.lvl1_id() << " rejected");
128 auto result = m_eventHandler->reject(ev.lvl1_id());
130 }
131}
#define ATH_MSG_DEBUG(x)
uint32_t m_acceptedEvents
std::unique_ptr< daq::df_ef_interface::EventHandler > m_eventHandler
uint32_t m_processedEvents
uint32_t m_rejectedEvents
int ev
Definition globals.cxx:25

◆ finalize()

StatusCode EFInterfaceSvc::finalize ( )
overridevirtual

Definition at line 107 of file EFInterfaceSvc.cxx.

108{
109 ATH_MSG_DEBUG("EFInterfaceSvc finalized");
110 m_eventHandler.reset();
112 return StatusCode::SUCCESS;
113}
boost::dll::shared_library m_efdfinterface_library
Library with the df_ef_interface implementation.

◆ getNext()

EFInterfaceSvc::Status EFInterfaceSvc::getNext ( std::unique_ptr< uint32_t[]> & rawEventPtr)
virtual

Definition at line 133 of file EFInterfaceSvc.cxx.

134{
135 try{
136 //check if we have a getNext call already pending
137 std::future<std::unique_ptr<uint32_t []>> future;
138 {
139 std::lock_guard<std::mutex> lock(m_queueMutex);
140 if (m_getNextFuture.empty()){
141 ATH_MSG_DEBUG("No pending getNext call, creating a new one");
142 future = m_eventHandler->getNext();
143 } else {
144 ATH_MSG_DEBUG("Pending getNext call found, using it");
145 future = std::move(m_getNextFuture.front());
146 m_getNextFuture.pop();
147 }
148 }
149 // Wait for the future to be ready
150 auto status = future.wait_for(std::chrono::milliseconds(m_getNextTimeout));
151 if (status == std::future_status::ready) {
152 auto result = future.get();
153 rawEventPtr = std::move(result);
154 return Status::OK;
155 } else {
156 // Future is not ready, return NO_EVENT
157 ATH_MSG_DEBUG("getNext timed out, returning NO_EVENT");
158 rawEventPtr = nullptr;
159 {
160 //Add the future to the queue for later access
161 std::lock_guard<std::mutex> lock(m_queueMutex);
162 m_getNextFuture.push(std::move(future));
163 }
164 return Status::NO_EVENT;
165 }
166 }
167 catch (daq::df_ef_interface::NoMoreEvents &ex){
168 ATH_MSG_DEBUG("NoMoreEvents, returning");
169 return Status::STOP;
170 }
171 catch (daq::df_ef_interface::CommunicationError &ex){
172 ATH_MSG_DEBUG("CommunicationError received from EFInterface, returning NO_EVENT");
173 return Status::NO_EVENT;
174 }
175 catch (std::exception &ex){
176 ATH_MSG_ERROR("EFInterface: caught exception: \""<<ex.what()<<"\" throwing!");
177 throw;
178 }
179 catch(...) {
180 ATH_MSG_ERROR("EFInterface: caught very unknown exception");
181 throw;
182 }
183}
#define ATH_MSG_ERROR(x)
@ NO_EVENT
no event available
@ STOP
stop transition (no more events)
Gaudi::Property< int > m_getNextTimeout
std::queue< std::future< std::unique_ptr< uint32_t[]> > > m_getNextFuture
std::mutex m_queueMutex
Mutex for future queue.
status
Definition merge.py:16

◆ handle()

void EFInterfaceSvc::handle ( const Incident & incident)
overridevirtual

Definition at line 29 of file EFInterfaceSvc.cxx.

30{
31 if (incident.type() == AthenaInterprocess::UpdateAfterFork::type())
32 {
33 ATH_MSG_DEBUG("Going to initialize the EFInterface");
34 std::string full_libname = "lib" + m_interface_library_name + ".so";
35 m_efdfinterface_library = boost::dll::shared_library(full_libname, boost::dll::load_mode::type::search_system_folders | boost::dll::load_mode::type::rtld_global);
36 using cEventHandler = std::unique_ptr<daq::df_ef_interface::EventHandler> (const boost::property_tree::ptree&);
37 std::function<cEventHandler> cs;
38 try {
39 cs = m_efdfinterface_library.get<cEventHandler>("createEventHandler");
40 } catch (std::exception & ex) {
41 ATH_MSG_ERROR("Cant load function createEventHandler. Are you trying to use incorrect library? - " << ex.what());
42 throw;
43 }
44 //Add Tree
45 boost::property_tree::ptree configTree = prepInterfacePTree();
46 std::ostringstream oss;
47 boost::property_tree::write_json(oss, configTree, true);
48 ATH_MSG_INFO("EFInterface configuration:\n" << oss.str());
49 try {
50 m_eventHandler = cs(configTree);
51 } catch (std::exception & ex) {
52 ATH_MSG_ERROR("Cant create EventHandler from DataSource library. Are you trying to use incorrect configuration? - " << ex.what());
53 throw;
54 }
55 // Going to open the EventHandler connection
56 try {
57 ATH_MSG_DEBUG("Opening EventHandler");
58 m_eventHandler->open();
59 }
60 catch (daq::df_ef_interface::CommunicationError & ex) {
61 ATH_MSG_ERROR("CommunicationError while opening EventHandler: " << ex.what());
62 throw;
63 }
64 catch (std::exception & ex) {
65 ATH_MSG_ERROR("Exception while opening EventHandler: " << ex.what());
66 throw;
67 }
68 catch (...) {
69 ATH_MSG_ERROR("Unknown exception while opening EventHandler");
70 throw;
71 }
72 }
73}
#define ATH_MSG_INFO(x)
static const std::string & type()
Incident type.
Definition Incidents.h:49
Gaudi::Property< std::string > m_interface_library_name
boost::property_tree::ptree prepInterfacePTree()

◆ prepInterfacePTree()

boost::property_tree::ptree EFInterfaceSvc::prepInterfacePTree ( )

Definition at line 185 of file EFInterfaceSvc.cxx.

186{
187 boost::property_tree::ptree configTree;
188 // Top-level values
189 configTree.put("name", "DFEFInterfaceSvc");
190 configTree.put("stride", m_stride.value()); // NB: if this is set to 0 it will cause a seg fault!
191 configTree.put("fileOffset", m_fileOffset.value());
192 configTree.put("numEvents", m_numEvents.value());
193 configTree.put("skipEvents", m_skipEvents.value());
194 configTree.put("loopOverFiles", m_loopOverFiles.value() ? "true" : "false"); // as string
195 configTree.put("outputFileName", m_outputFileName.value());
196 // File list
197 boost::property_tree::ptree fileList;
198 for (const std::string& fname : m_files.value()) {
199 boost::property_tree::ptree fileNode;
200 fileNode.put("", fname);
201 fileList.push_back(std::make_pair("file", fileNode));
202 }
203 configTree.add_child("fileList", fileList);
204 // Run parameters
205 boost::property_tree::ptree runParams;
206 runParams.put("run_number", m_runNumber.value());
207 runParams.put("trigger_type", m_triggerType.value());
208 runParams.put("beam_type", m_beamType.value());
209 runParams.put("beam_energy", m_beamEnergy.value());
210 runParams.put("det_mask", m_detMask.value());
211 runParams.put("T0_project_tag", m_T0_project_tag.value());
212 runParams.put("stream", m_stream.value());
213 runParams.put("lumiblock", m_lumiblock.value());
214 configTree.add_child("RunParams", runParams);
215
216 return configTree;
217}
Gaudi::Property< std::string > m_outputFileName
Gaudi::Property< int > m_beamType
Gaudi::Property< std::string > m_stream
Gaudi::Property< std::string > m_detMask
Gaudi::Property< int > m_triggerType
Gaudi::Property< int > m_numEvents
Gaudi::Property< bool > m_loopOverFiles
Gaudi::Property< std::vector< std::string > > m_files
Gaudi::Property< int > m_fileOffset
Gaudi::Property< int > m_runNumber
Gaudi::Property< std::string > m_T0_project_tag
Gaudi::Property< int > m_beamEnergy
Gaudi::Property< int > m_lumiblock
Gaudi::Property< int > m_stride
Gaudi::Property< int > m_skipEvents

◆ stop()

StatusCode EFInterfaceSvc::stop ( )
overridevirtual

Definition at line 75 of file EFInterfaceSvc.cxx.

76{
77 ATH_MSG_DEBUG("EFInterfaceSvc stopped");
78 // Close the EventHandler connection
79 if (!m_eventHandler) {
80 ATH_MSG_DEBUG("EventHandler is not initialized, probably I'm in the mother process.");
81 }
82 else
83 {
84 try {
85 m_eventHandler->close();
86 }
87 catch (daq::df_ef_interface::CommunicationError & ex) {
88 ATH_MSG_ERROR("CommunicationError while closing EventHandler: " << ex.what());
89 throw;
90 }
91 catch (std::exception & ex) {
92 ATH_MSG_ERROR("Exception while closing EventHandler: " << ex.what());
93 throw;
94 }
95 catch (...) {
96 ATH_MSG_ERROR("Unknown exception while closing EventHandler");
97 throw;
98 }
99 }
100 ATH_MSG_INFO("EFInterfaceSvc Stopping. Event processing summary:");
101 ATH_MSG_INFO("Processed Events: " << m_processedEvents);
102 ATH_MSG_INFO("Accepted Events: " << m_acceptedEvents);
103 ATH_MSG_INFO("Rejected Events: " << m_rejectedEvents);
104 return StatusCode::SUCCESS;
105}

Member Data Documentation

◆ m_acceptedEvents

uint32_t EFInterfaceSvc::m_acceptedEvents {0}

Definition at line 51 of file EFInterfaceSvc.h.

51{0};

◆ m_beamEnergy

Gaudi::Property<int> EFInterfaceSvc::m_beamEnergy
private
Initial value:
{this, "BeamEnergy", 0,
"Beam energy"}

Definition at line 86 of file EFInterfaceSvc.h.

86 {this, "BeamEnergy", 0,
87 "Beam energy"};

◆ m_beamType

Gaudi::Property<int> EFInterfaceSvc::m_beamType
private
Initial value:
{this, "BeamType", 0,
"Beam type"}

Definition at line 84 of file EFInterfaceSvc.h.

84 {this, "BeamType", 0,
85 "Beam type"};

◆ m_detMask

Gaudi::Property<std::string> EFInterfaceSvc::m_detMask
private
Initial value:
{this, "DetMask", "00000000000000000000000000000000",
"Detector mask"}

Definition at line 88 of file EFInterfaceSvc.h.

88 {this, "DetMask", "00000000000000000000000000000000",
89 "Detector mask"};

◆ m_efdfinterface_library

boost::dll::shared_library EFInterfaceSvc::m_efdfinterface_library
private

Library with the df_ef_interface implementation.

Definition at line 56 of file EFInterfaceSvc.h.

◆ m_eventHandler

std::unique_ptr<daq::df_ef_interface::EventHandler> EFInterfaceSvc::m_eventHandler
private

Definition at line 57 of file EFInterfaceSvc.h.

◆ m_fileOffset

Gaudi::Property<int> EFInterfaceSvc::m_fileOffset
private
Initial value:
{this, "FileOffset", 0,
"File offset for the event retrieval"}

Definition at line 68 of file EFInterfaceSvc.h.

68 {this, "FileOffset", 0,
69 "File offset for the event retrieval"};

◆ m_files

Gaudi::Property<std::vector<std::string> > EFInterfaceSvc::m_files
private
Initial value:
{this, "Files", {""},
"List of input files"}

Definition at line 78 of file EFInterfaceSvc.h.

78 {this, "Files", {""},
79 "List of input files"};

◆ m_getNextFuture

std::queue<std::future<std::unique_ptr<uint32_t []> > > EFInterfaceSvc::m_getNextFuture
private

Definition at line 58 of file EFInterfaceSvc.h.

◆ m_getNextTimeout

Gaudi::Property<int> EFInterfaceSvc::m_getNextTimeout
private
Initial value:
{this, "GetNextTimeout", 1000,
"Timeout for getting the next event (in milliseconds)"}

Definition at line 64 of file EFInterfaceSvc.h.

64 {this, "GetNextTimeout", 1000,
65 "Timeout for getting the next event (in milliseconds)"};

◆ m_interface_library_name

Gaudi::Property<std::string> EFInterfaceSvc::m_interface_library_name
private
Initial value:
{this, "EFDFInterfaceLibraryName", "TrigDFEmulator",
"Name of the EFDF interface shared library to load"}

Definition at line 62 of file EFInterfaceSvc.h.

62 {this, "EFDFInterfaceLibraryName", "TrigDFEmulator",
63 "Name of the EFDF interface shared library to load"};

◆ m_loopOverFiles

Gaudi::Property<bool> EFInterfaceSvc::m_loopOverFiles
private
Initial value:
{this, "LoopOverFiles", true,
"Flag to enable looping over files"}

Definition at line 74 of file EFInterfaceSvc.h.

74 {this, "LoopOverFiles", true,
75 "Flag to enable looping over files"};

◆ m_lumiblock

Gaudi::Property<int> EFInterfaceSvc::m_lumiblock
private
Initial value:
{this, "Lumiblock", 0,
"Lumiblock"}

Definition at line 94 of file EFInterfaceSvc.h.

94 {this, "Lumiblock", 0,
95 "Lumiblock"};

◆ m_numEvents

Gaudi::Property<int> EFInterfaceSvc::m_numEvents
private
Initial value:
{this, "NumEvents", 100,
"Number of events to process"}

Definition at line 70 of file EFInterfaceSvc.h.

70 {this, "NumEvents", 100,
71 "Number of events to process"};

◆ m_outputFileName

Gaudi::Property<std::string> EFInterfaceSvc::m_outputFileName
private
Initial value:
{this, "OutputFileName", "test_output.data",
"Name of the output file"}

Definition at line 76 of file EFInterfaceSvc.h.

76 {this, "OutputFileName", "test_output.data",
77 "Name of the output file"};

◆ m_processedEvents

uint32_t EFInterfaceSvc::m_processedEvents {0}

Definition at line 53 of file EFInterfaceSvc.h.

53{0};

◆ m_queueMutex

std::mutex EFInterfaceSvc::m_queueMutex
private

Mutex for future queue.

Definition at line 59 of file EFInterfaceSvc.h.

◆ m_rejectedEvents

uint32_t EFInterfaceSvc::m_rejectedEvents {0}

Definition at line 52 of file EFInterfaceSvc.h.

52{0};

◆ m_runNumber

Gaudi::Property<int> EFInterfaceSvc::m_runNumber
private
Initial value:
{this, "RunNumber", 0,
"Run number for the events processing"}

Definition at line 80 of file EFInterfaceSvc.h.

80 {this, "RunNumber", 0,
81 "Run number for the events processing"};

◆ m_skipEvents

Gaudi::Property<int> EFInterfaceSvc::m_skipEvents
private
Initial value:
{this, "SkipEvents", 0,
"Number of events to skip"}

Definition at line 72 of file EFInterfaceSvc.h.

72 {this, "SkipEvents", 0,
73 "Number of events to skip"};

◆ m_stream

Gaudi::Property<std::string> EFInterfaceSvc::m_stream
private
Initial value:
{this, "Stream", "stream",
"Stream name"}

Definition at line 92 of file EFInterfaceSvc.h.

92 {this, "Stream", "stream",
93 "Stream name"};

◆ m_stride

Gaudi::Property<int> EFInterfaceSvc::m_stride
private
Initial value:
{this, "Stride", 1,
"Stride for the event retrieval"}

Definition at line 66 of file EFInterfaceSvc.h.

66 {this, "Stride", 1,
67 "Stride for the event retrieval"};

◆ m_T0_project_tag

Gaudi::Property<std::string> EFInterfaceSvc::m_T0_project_tag
private
Initial value:
{this, "T0ProjectTag", "T0_project_tag",
"T0 project tag"}

Definition at line 90 of file EFInterfaceSvc.h.

90 {this, "T0ProjectTag", "T0_project_tag",
91 "T0 project tag"};

◆ m_triggerType

Gaudi::Property<int> EFInterfaceSvc::m_triggerType
private
Initial value:
{this, "TriggerType", 0,
"Trigger type for the events processing"}

Definition at line 82 of file EFInterfaceSvc.h.

82 {this, "TriggerType", 0,
83 "Trigger type for the events processing"};

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