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 207 of file OnlineEventDisplaysSvc.cxx.

207  {
208 
209  const char* char_dir = directory.c_str();
210 
211  if (access(char_dir, F_OK) == 0) {
212  struct stat directoryStat;
213  if (stat(char_dir, &directoryStat) == 0 && S_ISDIR(directoryStat.st_mode) &&
214  access(char_dir, W_OK) == 0) {
215  ATH_MSG_DEBUG("Going to write file to existing directory: " << directory);
216  if (directoryStat.st_gid != zpgid) {
217  ATH_MSG_DEBUG("Setting group to 'zp' for directory: " << directory);
218  chown(char_dir, -1, zpgid);
219  }
220  } else {
221  ATH_MSG_WARNING("Directory '" << directory << "' is not usable, trying next alternative");
222  }
223  } else {
224  try {
225  auto rc = mkdir(char_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
226  if (rc !=0){
227  ATH_MSG_ERROR("mkdir failed for directory: " << directory);
228  }
229  rc = chown(char_dir, -1, zpgid);
230  if (rc !=0){
231  ATH_MSG_ERROR( "chown failed for directory: " << directory);
232  }
233  ATH_MSG_DEBUG("Created output directory " << directory);
234  } catch (const std::system_error& err) {
235  ATH_MSG_ERROR( "Failed to create output directory " << directory << err.what());
236  }
237  }
238 }

◆ 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(m_BeamSplash){
168  std::string JiveXMLFileName ="JiveXML_"+ std::to_string(m_runNumber)+"_"+std::to_string(m_eventNumber)+".xml";
169  const char* JiveXMLFileName_cString = JiveXMLFileName.c_str();
170  PyObject* pJiveXMLFileName = PyUnicode_FromString(JiveXMLFileName_cString);
171  PyObject* pArgs_zip = PyTuple_Pack(2, pDirectory, pJiveXMLFileName);
172  PyObject* zipXMLFile = PyObject_GetAttrString(pModule, "zipXMLFile");
173  if (!zipXMLFile) {
174  PyErr_Print();
175  ATH_MSG_WARNING("Failed to import EventDisplaysOnline.EventUtils.zipXMLFile");
176  } else {
177  PyObject_CallObject(zipXMLFile, pArgs_zip);
178  }
179  if (anyNullPtr(pJiveXMLFileName, zipXMLFile, pArgs_zip)){
180  throw std::runtime_error("OnlineEventDisplaysSvc::endEvent: Py_DECREF on nullptr argument");
181  }
182  Py_DECREF(pJiveXMLFileName);
183  Py_DECREF(zipXMLFile);
184  Py_DECREF(pArgs_zip);
185  }
186  if (anyNullPtr(pModule, pArgs, pCheckPair, pMaxEvents, pDirectory)){
187  throw std::runtime_error("OnlineEventDisplaysSvc::endEvent: Py_DECREF on nullptr argument");
188  }
189  Py_DECREF(pModule);
190  Py_DECREF(pArgs);
191  Py_DECREF(pCheckPair);
192  Py_DECREF(pMaxEvents);
193  Py_DECREF(pDirectory);
194 }

◆ finalize()

StatusCode OnlineEventDisplaysSvc::finalize ( )
override

Definition at line 275 of file OnlineEventDisplaysSvc.cxx.

275  {
276 
277  ATH_MSG_DEBUG("Finalizing " << name());
278  return StatusCode::SUCCESS;
279 }

◆ getEntireOutputStr()

std::string OnlineEventDisplaysSvc::getEntireOutputStr ( )
override

Definition at line 200 of file OnlineEventDisplaysSvc.cxx.

200  {
201  return m_entireOutputStr;
202 }

◆ getFileNamePrefix()

std::string OnlineEventDisplaysSvc::getFileNamePrefix ( )
override

Definition at line 196 of file OnlineEventDisplaysSvc.cxx.

196  {
197  return m_FileNamePrefix;
198 }

◆ getStreamName()

std::string OnlineEventDisplaysSvc::getStreamName ( )
override

Definition at line 204 of file OnlineEventDisplaysSvc.cxx.

204  {
205  return m_outputStreamDir;
206 }

◆ handle()

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

Definition at line 281 of file OnlineEventDisplaysSvc.cxx.

281  {
282  ATH_MSG_DEBUG("Received incident " << incident.type() << " from " << incident.source() );
283  if ( incident.type() == IncidentType::BeginEvent && incident.source() == "BeginIncFiringAlg" ){
284  beginEvent();
285  }
286  if ( incident.type() == "StoreCleared" && incident.source() == "StoreGateSvc" ){
287  endEvent();
288  }
289 }

◆ initialize()

StatusCode OnlineEventDisplaysSvc::initialize ( )
override

Definition at line 255 of file OnlineEventDisplaysSvc.cxx.

255  {
256 
257  ATH_MSG_DEBUG("Initializing " << name());
258  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
259  ATH_CHECK( incSvc.retrieve() );
260  ATH_MSG_DEBUG("You have requested to only output JiveXML and ESD files when a trigger in the following streams was fired: ");
261  for (const std::string& stream : m_streamsWanted){
263  }
264  if(m_BeamSplash){
265  m_CheckPair = false;
266  }
267  incSvc->addListener( this, "BeginEvent");
268  incSvc->addListener( this, "StoreCleared");
269 
271 
272  return StatusCode::SUCCESS;
273 }

◆ setOwnershipToZpGrpOrDefault()

gid_t OnlineEventDisplaysSvc::setOwnershipToZpGrpOrDefault ( )

Definition at line 240 of file OnlineEventDisplaysSvc.cxx.

240  {
241  gid_t zpgid;
242  struct group grp;
243  struct group* grp_result;
244  char buf[1024]; // sysconf(_SC_GETGR_R_SIZE_MAX)
245  (void)getgrnam_r("zp", &grp, buf, sizeof(buf), &grp_result);
246  if (grp_result != nullptr) {
247  zpgid = grp.gr_gid;
248  } else {
249  ATH_MSG_DEBUG("If running on private machine, zp group might not exist. Just set to the likely value 1307.");
250  zpgid = 1307;
251  }
252  return zpgid;
253 }

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.zipXMLFile
def zipXMLFile(directory, filename)
Definition: EventUtils.py:195
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:16
python.outputTest_v2.streams
streams
Definition: outputTest_v2.py:55
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
OnlineEventDisplaysSvc::m_eventNumber
long m_eventNumber
Definition: OnlineEventDisplaysSvc.h:48
EventUtils.cleanDirectory
def cleanDirectory(directory, maxevents, checkpair, isBeamSplashMode)
Definition: EventUtils.py:116
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:240
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
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:80
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:266
python.dummyaccess.access
def access(filename, mode)
Definition: dummyaccess.py:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
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:60
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
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:207
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:355
ServiceHandle< IIncidentSvc >
OnlineEventDisplaysSvc::m_FileNamePrefix
std::string m_FileNamePrefix
Definition: OnlineEventDisplaysSvc.h:44