ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
OnlineEventDisplaysSvc Class Reference

#include <OnlineEventDisplaysSvc.h>

Inheritance diagram for OnlineEventDisplaysSvc:
Collaboration diagram for OnlineEventDisplaysSvc:

Public Member Functions

 OnlineEventDisplaysSvc (const std::string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize () override
 
StatusCode finalize () override
 
void beginEvent ()
 
void endEvent ()
 
void handle (const Incident &incident) override
 
void createWriteableDir (const std::string &directory, gid_t zpgid)
 
gid_t setOwnershipToZpGrpOrDefault ()
 
std::string getFileNamePrefix () override
 
std::string getEntireOutputStr () override
 
std::string getStreamName () override
 

Private Member Functions

 OnlineEventDisplaysSvc ()
 

Private Attributes

SG::ReadHandleKey< xAOD::EventInfom_evt {this, "EventInfo", "EventInfo", "Input event information"}
 
Gaudi::Property< std::string > m_outputDirectory {this, "OutputDirectory", "/atlas/EventDisplayEvents", "Output Directory"}
 
Gaudi::Property< std::vector< std::string > > m_streamsWanted {this, "StreamsWanted", {}, "Desired trigger streams"}
 
Gaudi::Property< std::vector< std::string > > m_publicStreams {this, "PublicStreams", {}, "Streams that can be seen by the public"}
 
Gaudi::Property< std::string > m_projectTag {this, "ProjectTag", "", "Is needed to add streams to the Public trigger streams"}
 
Gaudi::Property< bool > m_BeamSplash {this, "BeamSplash", false, "Is a beam splash event"}
 
Gaudi::Property< bool > m_CheckPair {this, "CheckPair", false, "Check for matching ESD and JiveXML files"}
 
Gaudi::Property< int > m_maxEvents {this, "MaxEvents", 200, "Number of events to keep per stream"}
 
std::string m_FileNamePrefix = "JiveXML"
 
std::string m_outputStreamDir = ".Unknown"
 
std::string m_entireOutputStr = "."
 
int m_runNumber {}
 
long m_eventNumber {}
 

Detailed Description

Definition at line 16 of file OnlineEventDisplaysSvc.h.

Constructor & Destructor Documentation

◆ OnlineEventDisplaysSvc() [1/2]

OnlineEventDisplaysSvc::OnlineEventDisplaysSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 30 of file OnlineEventDisplaysSvc.cxx.

31  :
32  base_class(name, pSvcLocator){}

◆ OnlineEventDisplaysSvc() [2/2]

OnlineEventDisplaysSvc::OnlineEventDisplaysSvc ( )
private

Member Function Documentation

◆ beginEvent()

void OnlineEventDisplaysSvc::beginEvent ( )

Definition at line 34 of file OnlineEventDisplaysSvc.cxx.

34  {
35 
37  if (!evt.isValid()) {
38  ATH_MSG_FATAL("Could not find event info");
39  }
40  std::vector<std::string> streams;
41 
42  m_eventNumber = evt->eventNumber();
43  m_runNumber = evt->runNumber();
44 
45  //Check what trigger streams were fired, if in list of desired
46  //streams to be reconstructed pick one randomly
47  for (const xAOD::EventInfo::StreamTag& tag : evt->streamTags()){
48  ATH_MSG_DEBUG("A trigger in stream " << tag.type() << "_" << tag.name() << " was fired in this event.");
49  std::string stream_fullname = tag.type() + "_" + tag.name();
50 
51  if (m_streamsWanted.empty()) {
52  ATH_MSG_WARNING("You have not requested any specific streams, going to allow all streams");
53  streams.emplace_back(stream_fullname);
54  }
55 
56  else{
57  //If the stream is in the list of streams requested, add it
58  if(std::find(m_streamsWanted.begin(), m_streamsWanted.end(), tag.name()) != m_streamsWanted.end()){
59  streams.emplace_back(stream_fullname);
60  }
61  bool isPublic = false;
62  //if the stream is not in the list of public streams wanted, continue
63  if(std::find(m_publicStreams.begin(), m_publicStreams.end(), tag.name()) == m_publicStreams.end()) continue;
64  // Acquire the Global Interpreter Lock (GIL) to ensure thread safety when interacting with Python objects
66  // Convert the project tag string to a Python Unicode object
67  std::string tag = m_projectTag;
68  PyObject* pProjectTag = PyUnicode_FromString(tag.c_str());
69  if (!pProjectTag) {
70  // Error handling: Print Python exception if conversion fails
71  PyErr_Print();
72  ATH_MSG_WARNING("Failed to create Python Unicode object from project tag");
73  } else {
74  // Import the Python module
75  PyObject* pHelper = PyImport_ImportModule("EventDisplaysOnline.EventDisplaysOnlineHelpers");
76  if (!pHelper) {
77  // Error handling: Print Python exception if import fails
78  PyErr_Print();
79  ATH_MSG_WARNING("Failed to import EventDisplaysOnline.EventDisplaysOnlineHelpers module");
80  } else {
81  // Get the "EventCanBeSeenByPublic" function from the module
82  PyObject* EventCanBeSeenByPublic = PyObject_GetAttrString(pHelper, "EventCanBeSeenByPublic");
83  if (!EventCanBeSeenByPublic || !PyCallable_Check(EventCanBeSeenByPublic)) {
84  // Error handling: Print warning if function not found or not callable
85  ATH_MSG_WARNING("Could not find or call EventCanBeSeenByPublic function in EventDisplaysOnline.EventDisplaysOnlineHelpers module");
86  } else {
87  // Call the "EventCanBeSeenByPublic" function with the project tag as argument
88  PyObject* result = PyObject_CallFunctionObjArgs(EventCanBeSeenByPublic, pProjectTag, NULL);
89  if (!result) {
90  PyErr_Print();
91  ATH_MSG_WARNING("Failed to call EventCanBeSeenByPublic function");
92  } else {
93  // Convert the result to a boolean value
94  isPublic = PyObject_IsTrue(result);
95  Py_DECREF(result); // Decrement reference count of the result object
96  }
97  }
98  Py_XDECREF(EventCanBeSeenByPublic);
99  Py_DECREF(pHelper);
100  }
101  Py_DECREF(pProjectTag);
102  }
103  if(isPublic){
104  streams.emplace_back("Public");
105  ATH_MSG_DEBUG("Can send event to public stream");
106  }
107  }
108  }
109  for (const std::string& stream : streams){
110  ATH_MSG_DEBUG("streams where a trigger fired and in your desired streams list: " << stream);
111  }
112  std::random_shuffle(streams.begin(), streams.end());
113  //Pick the first stream as the output directory
114  if(!streams.empty()){
116  }
117  else{
118  ATH_MSG_WARNING("Cannot find a stream adding to .Unknown directory");
119  m_outputStreamDir = ".Unknown";
120  }
121 
123  m_FileNamePrefix = m_entireOutputStr + "/JiveXML";;
124 
125  gid_t zpgid = setOwnershipToZpGrpOrDefault();
128 }

◆ createWriteableDir()

void OnlineEventDisplaysSvc::createWriteableDir ( const std::string &  directory,
gid_t  zpgid 
)

Definition at line 188 of file OnlineEventDisplaysSvc.cxx.

188  {
189 
190  const char* char_dir = directory.c_str();
191 
192  if (access(char_dir, F_OK) == 0) {
193  struct stat directoryStat;
194  if (stat(char_dir, &directoryStat) == 0 && S_ISDIR(directoryStat.st_mode) &&
195  access(char_dir, W_OK) == 0) {
196  ATH_MSG_DEBUG("Going to write file to existing directory: " << directory);
197  if (directoryStat.st_gid != zpgid) {
198  ATH_MSG_DEBUG("Setting group to 'zp' for directory: " << directory);
199  chown(char_dir, -1, zpgid);
200  }
201  } else {
202  ATH_MSG_WARNING("Directory '" << directory << "' is not usable, trying next alternative");
203  }
204  } else {
205  try {
206  auto rc = mkdir(char_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
207  if (rc !=0){
208  ATH_MSG_ERROR("mkdir failed for directory: " << directory);
209  }
210  rc = chown(char_dir, -1, zpgid);
211  if (rc !=0){
212  ATH_MSG_ERROR( "chown failed for directory: " << directory);
213  }
214  ATH_MSG_DEBUG("Created output directory " << directory);
215  } catch (const std::system_error& err) {
216  ATH_MSG_ERROR( "Failed to create output directory " << directory << err.what());
217  }
218  }
219 }

◆ endEvent()

void OnlineEventDisplaysSvc::endEvent ( )

Definition at line 130 of file OnlineEventDisplaysSvc.cxx.

130  {
132  PyObject* pCheckPair = PyBool_FromLong(m_CheckPair);
133  PyObject* pBeamSplash = PyBool_FromLong(m_BeamSplash);
134  PyObject* pMaxEvents = PyLong_FromLong(m_maxEvents);
135  const char* cString = m_entireOutputStr.c_str();
136  PyObject* pDirectory = PyUnicode_FromString(cString);
137  PyObject* pArgs = PyTuple_Pack(4, pDirectory, pMaxEvents, pCheckPair,pBeamSplash);
138  PyObject* pModule = PyImport_ImportModule(const_cast< char* >("EventDisplaysOnline.EventUtils"));
139  if(!pCheckPair || !pBeamSplash || !pMaxEvents || !pDirectory || !pArgs){
140  PyErr_Print();
141  ATH_MSG_WARNING("Failed to create Python Unicode object");}
142  if (!pModule) {
143  PyErr_Print();
144  ATH_MSG_WARNING("Failed to import EventDisplaysOnline.EventUtils module");
145  } else {
146  ATH_MSG_DEBUG("Successfully imported EventDisplaysOnline.EventUtils module");
147 
148  // Get the "cleanDirectory" function from the module
149  PyObject* cleanDirectory = PyObject_GetAttrString(pModule, "cleanDirectory");
150  if (!cleanDirectory || !PyCallable_Check(cleanDirectory)) {
151  ATH_MSG_WARNING("Could not find or call cleanDirectory function in EventDisplaysOnline.EventUtils module");
152  } else {
153  ATH_MSG_DEBUG("Found cleanDirectory function in EventDisplaysOnline.EventUtils module");
154 
155  // Call the "cleanDirectory" function with the provided arguments
156  PyObject_CallObject(cleanDirectory, pArgs);
157  if (PyErr_Occurred()) {
158  PyErr_Print();
159  }
160  }
161  if (anyNullPtr(cleanDirectory)){
162  throw std::runtime_error("OnlineEventDisplaysSvc::endEvent: Py_DECREF on nullptr argument");
163  }
164  Py_DECREF(cleanDirectory);
165  }
166 
167  if (anyNullPtr(pModule, pArgs, pCheckPair, pMaxEvents, pDirectory)){
168  throw std::runtime_error("OnlineEventDisplaysSvc::endEvent: Py_DECREF on nullptr argument");
169  }
170  Py_DECREF(pModule);
171  Py_DECREF(pArgs);
172  Py_DECREF(pCheckPair);
173  Py_DECREF(pMaxEvents);
174  Py_DECREF(pDirectory);
175 }

◆ finalize()

StatusCode OnlineEventDisplaysSvc::finalize ( )
override

Definition at line 256 of file OnlineEventDisplaysSvc.cxx.

256  {
257 
258  ATH_MSG_DEBUG("Finalizing " << name());
259  return StatusCode::SUCCESS;
260 }

◆ getEntireOutputStr()

std::string OnlineEventDisplaysSvc::getEntireOutputStr ( )
override

Definition at line 181 of file OnlineEventDisplaysSvc.cxx.

181  {
182  return m_entireOutputStr;
183 }

◆ getFileNamePrefix()

std::string OnlineEventDisplaysSvc::getFileNamePrefix ( )
override

Definition at line 177 of file OnlineEventDisplaysSvc.cxx.

177  {
178  return m_FileNamePrefix;
179 }

◆ getStreamName()

std::string OnlineEventDisplaysSvc::getStreamName ( )
override

Definition at line 185 of file OnlineEventDisplaysSvc.cxx.

185  {
186  return m_outputStreamDir;
187 }

◆ handle()

void OnlineEventDisplaysSvc::handle ( const Incident &  incident)
override

Definition at line 262 of file OnlineEventDisplaysSvc.cxx.

262  {
263  ATH_MSG_DEBUG("Received incident " << incident.type() << " from " << incident.source() );
264  if ( incident.type() == IncidentType::BeginEvent && incident.source() == "BeginIncFiringAlg" ){
265  beginEvent();
266  }
267  if ( incident.type() == "StoreCleared" && incident.source() == "StoreGateSvc" ){
268  endEvent();
269  }
270 }

◆ initialize()

StatusCode OnlineEventDisplaysSvc::initialize ( )
override

Definition at line 236 of file OnlineEventDisplaysSvc.cxx.

236  {
237 
238  ATH_MSG_DEBUG("Initializing " << name());
239  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
240  ATH_CHECK( incSvc.retrieve() );
241  ATH_MSG_DEBUG("You have requested to only output JiveXML and ESD files when a trigger in the following streams was fired: ");
242  for (const std::string& stream : m_streamsWanted){
244  }
245  if(m_BeamSplash){
246  m_CheckPair = false;
247  }
248  incSvc->addListener( this, "BeginEvent");
249  incSvc->addListener( this, "StoreCleared");
250 
252 
253  return StatusCode::SUCCESS;
254 }

◆ setOwnershipToZpGrpOrDefault()

gid_t OnlineEventDisplaysSvc::setOwnershipToZpGrpOrDefault ( )

Definition at line 221 of file OnlineEventDisplaysSvc.cxx.

221  {
222  gid_t zpgid;
223  struct group grp;
224  struct group* grp_result;
225  char buf[1024]; // sysconf(_SC_GETGR_R_SIZE_MAX)
226  (void)getgrnam_r("zp", &grp, buf, sizeof(buf), &grp_result);
227  if (grp_result != nullptr) {
228  zpgid = grp.gr_gid;
229  } else {
230  ATH_MSG_DEBUG("If running on private machine, zp group might not exist. Just set to the likely value 1307.");
231  zpgid = 1307;
232  }
233  return zpgid;
234 }

Member Data Documentation

◆ m_BeamSplash

Gaudi::Property<bool> OnlineEventDisplaysSvc::m_BeamSplash {this, "BeamSplash", false, "Is a beam splash event"}
private

Definition at line 41 of file OnlineEventDisplaysSvc.h.

◆ m_CheckPair

Gaudi::Property<bool> OnlineEventDisplaysSvc::m_CheckPair {this, "CheckPair", false, "Check for matching ESD and JiveXML files"}
private

Definition at line 42 of file OnlineEventDisplaysSvc.h.

◆ m_entireOutputStr

std::string OnlineEventDisplaysSvc::m_entireOutputStr = "."
private

Definition at line 46 of file OnlineEventDisplaysSvc.h.

◆ m_eventNumber

long OnlineEventDisplaysSvc::m_eventNumber {}
private

Definition at line 48 of file OnlineEventDisplaysSvc.h.

◆ m_evt

SG::ReadHandleKey<xAOD::EventInfo> OnlineEventDisplaysSvc::m_evt {this, "EventInfo", "EventInfo", "Input event information"}
private

Definition at line 36 of file OnlineEventDisplaysSvc.h.

◆ m_FileNamePrefix

std::string OnlineEventDisplaysSvc::m_FileNamePrefix = "JiveXML"
private

Definition at line 44 of file OnlineEventDisplaysSvc.h.

◆ m_maxEvents

Gaudi::Property<int> OnlineEventDisplaysSvc::m_maxEvents {this, "MaxEvents", 200, "Number of events to keep per stream"}
private

Definition at line 43 of file OnlineEventDisplaysSvc.h.

◆ m_outputDirectory

Gaudi::Property<std::string> OnlineEventDisplaysSvc::m_outputDirectory {this, "OutputDirectory", "/atlas/EventDisplayEvents", "Output Directory"}
private

Definition at line 37 of file OnlineEventDisplaysSvc.h.

◆ m_outputStreamDir

std::string OnlineEventDisplaysSvc::m_outputStreamDir = ".Unknown"
private

Definition at line 45 of file OnlineEventDisplaysSvc.h.

◆ m_projectTag

Gaudi::Property<std::string> OnlineEventDisplaysSvc::m_projectTag {this, "ProjectTag", "", "Is needed to add streams to the Public trigger streams"}
private

Definition at line 40 of file OnlineEventDisplaysSvc.h.

◆ m_publicStreams

Gaudi::Property<std::vector<std::string> > OnlineEventDisplaysSvc::m_publicStreams {this, "PublicStreams", {}, "Streams that can be seen by the public"}
private

Definition at line 39 of file OnlineEventDisplaysSvc.h.

◆ m_runNumber

int OnlineEventDisplaysSvc::m_runNumber {}
private

Definition at line 47 of file OnlineEventDisplaysSvc.h.

◆ m_streamsWanted

Gaudi::Property<std::vector<std::string> > OnlineEventDisplaysSvc::m_streamsWanted {this, "StreamsWanted", {}, "Desired trigger streams"}
private

Definition at line 38 of file OnlineEventDisplaysSvc.h.


The documentation for this class was generated from the following files:
EventUtils.cleanDirectory
def cleanDirectory(directory, max_pairs, check_pair, is_beam_splash_mode)
Definition: EventUtils.py:17
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
OnlineEventDisplaysSvc::m_CheckPair
Gaudi::Property< bool > m_CheckPair
Definition: OnlineEventDisplaysSvc.h:42
get_generator_info.result
result
Definition: get_generator_info.py:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
plot_material.mkdir
def mkdir(path, recursive=True)
Definition: plot_material.py:15
python.outputTest_v2.streams
streams
Definition: outputTest_v2.py:55
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
OnlineEventDisplaysSvc::m_eventNumber
long m_eventNumber
Definition: OnlineEventDisplaysSvc.h:48
OnlineEventDisplaysSvc::m_outputStreamDir
std::string m_outputStreamDir
Definition: OnlineEventDisplaysSvc.h:45
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
OnlineEventDisplaysSvc::m_outputDirectory
Gaudi::Property< std::string > m_outputDirectory
Definition: OnlineEventDisplaysSvc.h:37
OnlineEventDisplaysSvc::beginEvent
void beginEvent()
Definition: OnlineEventDisplaysSvc.cxx:34
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
OnlineEventDisplaysSvc::setOwnershipToZpGrpOrDefault
gid_t setOwnershipToZpGrpOrDefault()
Definition: OnlineEventDisplaysSvc.cxx:221
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:183
OnlineEventDisplaysSvc::m_runNumber
int m_runNumber
Definition: OnlineEventDisplaysSvc.h:47
OnlineEventDisplaysSvc::m_maxEvents
Gaudi::Property< int > m_maxEvents
Definition: OnlineEventDisplaysSvc.h:43
DeMoScan.directory
string directory
Definition: DeMoScan.py:78
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:27
OnlineEventDisplaysSvc::endEvent
void endEvent()
Definition: OnlineEventDisplaysSvc.cxx:130
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
OnlineEventDisplaysSvc::m_entireOutputStr
std::string m_entireOutputStr
Definition: OnlineEventDisplaysSvc.h:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
beamspotman.stat
stat
Definition: beamspotman.py:264
python.dummyaccess.access
def access(filename, mode)
Definition: dummyaccess.py:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
OnlineEventDisplaysSvc::m_projectTag
Gaudi::Property< std::string > m_projectTag
Definition: OnlineEventDisplaysSvc.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
OnlineEventDisplaysSvc::m_streamsWanted
Gaudi::Property< std::vector< std::string > > m_streamsWanted
Definition: OnlineEventDisplaysSvc.h:38
EventDisplaysOnlineHelpers.EventCanBeSeenByPublic
def EventCanBeSeenByPublic(projectTags)
Definition: EventDisplaysOnlineHelpers.py:72
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
OnlineEventDisplaysSvc::m_BeamSplash
Gaudi::Property< bool > m_BeamSplash
Definition: OnlineEventDisplaysSvc.h:41
OnlineEventDisplaysSvc::createWriteableDir
void createWriteableDir(const std::string &directory, gid_t zpgid)
Definition: OnlineEventDisplaysSvc.cxx:188
OnlineEventDisplaysSvc::m_evt
SG::ReadHandleKey< xAOD::EventInfo > m_evt
Definition: OnlineEventDisplaysSvc.h:36
OnlineEventDisplaysSvc::m_publicStreams
Gaudi::Property< std::vector< std::string > > m_publicStreams
Definition: OnlineEventDisplaysSvc.h:39
PyObject
_object PyObject
Definition: IPyComponent.h:26
xAOD::EventInfo_v1::StreamTag
Class describing a stream tag on the event.
Definition: EventInfo_v1.h:190
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:375
ServiceHandle< IIncidentSvc >
OnlineEventDisplaysSvc::m_FileNamePrefix
std::string m_FileNamePrefix
Definition: OnlineEventDisplaysSvc.h:44