ATLAS Offline Software
AlgoJiveXML.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "JiveXML/AlgoJiveXML.h"
11 
13 
14 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/ServiceHandle.h"
16 
17 #include <algorithm>
18 
19 namespace JiveXML{
20 
21  AlgoJiveXML::AlgoJiveXML(const std::string& name, ISvcLocator* pSvcLocator) :
22  AthAlgorithm(name, pSvcLocator) {}
23 
32 
33  //be verbose
34  ATH_MSG_VERBOSE("Initialize()");
35 
39  if(m_writeGeometry){
40 
41  ATH_MSG_DEBUG("Writing geometry to file");
42 
44  std::vector<std::string>::iterator GeoWriterNameItr = m_GeoWriterNames.begin();
45  for ( ; GeoWriterNameItr != m_GeoWriterNames.end(); ++GeoWriterNameItr){
46 
48 
49  ToolHandle<IGeometryWriter> GeometryWriter(*GeoWriterNameItr);
50  if ( GeometryWriter.retrieve().isFailure() ){
51  ATH_MSG_WARNING("Unable to locate "<<GeometryWriter.name()<<" tool");
52  } else {
54  if ( GeometryWriter->writeGeometry().isFailure() ){
55  ATH_MSG_WARNING("Unable to write geometry");
56  }
58  if ( GeometryWriter.release().isFailure() ){
59  ATH_MSG_WARNING("Unable to release tool GeometryWriter");
60  }
61  }
62  }
63  }
64 
68  ATH_MSG_DEBUG("Retrieving XML format tool");
69 
70  //Retrieve the format tool
71  ATH_CHECK(m_FormatTool.retrieve());
72 
73  //Setting the tags
74  if ( m_FormatTool->SetTag( TagType("Release",m_AtlasRelease)).isFailure() ){
75  ATH_MSG_WARNING( "Couldn't set Release version" );
76  }
77 
81  ATH_MSG_DEBUG("Retrieving streaming tools");
82  if (m_writeToFile){
83  ATH_MSG_INFO("Retrieving default file streaming tool");
84  ATH_CHECK(m_StreamToFileTool.retrieve());
85  }
86  ATH_MSG_INFO("online " << m_onlineMode);
88  if (m_onlineMode){
89  ATH_MSG_INFO("Retrieving default server streaming tool");
90  ATH_CHECK(m_StreamToServerTool.retrieve());
91  }
92 
93 
94  ATH_MSG_INFO("Retrieving data from " << m_DataRetrieverTools.size() << " tools" );
95 
96  ATH_MSG_INFO("List property settings: ");
97  ATH_MSG_INFO("AtlasRelease: " << m_AtlasRelease);
98  ATH_MSG_INFO("WriteToFile: " << m_writeToFile);
99  ATH_MSG_INFO("OnlineMode: " << m_onlineMode);
100  ATH_MSG_INFO("WriteGeometry: " << m_writeGeometry);
101  ATH_MSG_INFO("GeometryVersion: " << m_geometryVersionIn);
102  ATH_MSG_INFO("GeoWriterNames: " << m_GeoWriterNames );
103 
104  return StatusCode::SUCCESS;
105  }
106 
114 
118  //The run and event number of the current event
119  unsigned int runNo = 0, lumiBlock = 0;
120  uint64_t eventNo=0;
121  //Date and time string of the current event
122  char dateTime[32];
123  //general event property, unused yet
124  std::string eventProperty = "default";
125 
126  // geometry-version/geometry-tag from Athena (sourced via jOs)
127  std::string geometryVersion = "default";
129 
130  //Retrieve eventInfo from StoreGate
131  const xAOD::EventInfo* eventInfo = nullptr;
132  if (evtStore()->retrieve(eventInfo).isFailure()){
133  ATH_MSG_FATAL("Could not find xAODEventInfo" );
134  return StatusCode::FAILURE;
135  }else{
136  // Event/xAOD/xAODEventInfo/trunk/xAODEventInfo/versions/EventInfo_v1.h
137  ATH_MSG_DEBUG(" xAODEventInfo: runNumber: " << eventInfo->runNumber() // is '222222' for mc events ?
138  << ", eventNumber: " << eventInfo->eventNumber()
139  << ", mcChannelNumber: " << eventInfo->mcChannelNumber()
140  << ", mcEventNumber: " << eventInfo->mcEventNumber() // MC: use this instead of runNumber
141  << ", lumiBlock: " << eventInfo->lumiBlock()
142  << ", timeStamp: " << eventInfo->timeStamp()
143  << ", bcid: " << eventInfo->bcid()
144  << ", eventTypeBitmask: " << eventInfo->eventTypeBitmask()
145  << ", actualInteractionsPerCrossing: " << eventInfo->actualInteractionsPerCrossing()
146  << ", averageInteractionsPerCrossing: " << eventInfo->averageInteractionsPerCrossing()
147  );
148  }
149 
150  // new treatment of mc_channel_number for mc12
151  // from: https://twiki.cern.ch/twiki/bin/viewauth/Atlas/PileupDigitization#Contents_of_Pileup_RDO
152  unsigned int mcChannelNo = 0;
153  bool firstEv = true;
154 
155  //+++ Get sub-event info object
156  ATH_MSG_DEBUG( "Sub Event Infos: " );
157  for (const xAOD::EventInfo::SubEvent& subevt : eventInfo->subEvents()) {
158  const xAOD::EventInfo* sevt = subevt.ptr();
159  if (sevt) {
160  if (firstEv){
161  mcChannelNo = sevt->mcChannelNumber(); // the 'real' mc-channel
162  ATH_MSG_DEBUG( " mc_channel from SubEvent : " << sevt->mcChannelNumber() );
163  firstEv = false;
164  }
165  ATH_MSG_VERBOSE("Sub Event Info:\n Time : " << subevt.time()
166  << " Index : " << subevt.index()
167  << " Provenance : " << subevt.type() // This is the provenance stuff: signal, minbias, cavern, etc
168  << " Run Number : " << sevt->runNumber()
169  << " Event Number : " << sevt->eventNumber()
170  << " ns Offset : " << sevt->timeStampNSOffset()
171  << " Lumi Block : " << sevt->lumiBlock()
172  << " mc_channel : " << sevt->mcChannelNumber()
173  << " BCID : " << sevt->bcid()
174  << " Geo version : " << m_geometryVersionIn
175  );
176  }
177  else ATH_MSG_VERBOSE("Subevent is null ptr ");
178  }
179 
180  //Get run and event numbers
181  runNo = eventInfo->runNumber();
182  eventNo = eventInfo->eventNumber();
183 
184 // Note: 4294967293 is the maximum value for a unsigned long
185 
186  if ( mcChannelNo != 0 ){ runNo = mcChannelNo + 140000000; } // indicating 'mc14'
187  ATH_MSG_DEBUG( " runNumber for filename: " << runNo << ", eventNumber: " << eventNo);
188 
189  if ( eventInfo->lumiBlock() ){
190  lumiBlock = eventInfo->lumiBlock();
191  }else{
192  lumiBlock = -1; // placeholder
193  }
194  if ( mcChannelNo != 0 ) lumiBlock = -1; // mask for mc11a
195 
196  // lumiBlock from mc can be just huge number, ignore then
197  if ( lumiBlock > 1000000 ) { lumiBlock = 0; }
198 
199  //Get timestamp of the event
200  //If Grid job not running in CEST or CET, change to UTC
201  //Only option to avoid odd timezones. jpt 29Mar11
202  size_t found1;
203  size_t found2;
204  if (eventInfo->timeStamp() > 0) {
205  time_t unixtime = (time_t) eventInfo->timeStamp();
206  struct tm time;
207  localtime_r(&unixtime, &time);
208  strftime(dateTime, 32, "%Y-%m-%d %H:%M:%S %Z", &time);
209  struct tm utctime;
210  gmtime_r(&unixtime, &utctime);
211  found1 = (DataType(dateTime).toString().find("CEST"));
212  found2 = (DataType(dateTime).toString().find("CET"));
213  if ( int(found1)<0 && int(found2)<0 ){ // not found is -1
214  strftime(dateTime, 32, "%Y-%m-%d %H:%M:%S UTC", &utctime);
215  ATH_MSG_DEBUG( " TIME NOT CET/CEST. Adjusted to:" << dateTime );
216  }
217  } else {
218  dateTime[0] = '\0'; // empty string
219  }
220  if ( mcChannelNo != 0 ){ dateTime[0] = '\0'; } // mask for mc11a
221 
225  if ( m_FormatTool->StartEvent(eventNo, runNo, dateTime, lumiBlock, eventProperty, geometryVersion).isFailure() ){
226  ATH_MSG_FATAL("Couldn't start event in FormatTool");
227  return StatusCode::FAILURE;
228  }
229 
234  ATH_MSG_DEBUG("Starting loop over data retrievers" );
235  //Loop over data retrievers
237  for(; DataRetrieverItr != m_DataRetrieverTools.end(); ++DataRetrieverItr) {
238  //Add try-catch to avoid retrieval to fail on single retriever
239  try {
240  //Retrieve information and pass it to formatting tool object
241  if ((*DataRetrieverItr)->retrieve(m_FormatTool).isFailure()) {
242  ATH_MSG_WARNING( "Failed to fill " << (*DataRetrieverItr)->dataTypeName() );
243  } else {
244  ATH_MSG_DEBUG("Filled: " << (*DataRetrieverItr)->dataTypeName() );
245  }
246  //Only catch std::exception
247  } catch ( std::exception& ex ){
248  //Now show some message
249  ATH_MSG_FATAL("Caught exception in " << (*DataRetrieverItr)->name()
250  << " while retrieving data for " << (*DataRetrieverItr)->dataTypeName()
251  << " : " << ex.what() );
252  //and return with an error
253  return StatusCode::FAILURE;
254  }
255  }
256  ATH_MSG_DEBUG( "Finished loop over data retrievers" );
257 
261  if ( m_FormatTool->EndEvent().isFailure() ){
262  ATH_MSG_WARNING( "Couldn't end event in FormatTool" );
263  return StatusCode::FAILURE;
264  }
265 
269  if(m_writeToFile){
270  ATH_MSG_DEBUG("Streaming event to file");
271  if ( (m_StreamToFileTool->StreamEvent(eventNo, runNo, m_FormatTool->getFormattedEvent()).isFailure() )){
272  ATH_MSG_WARNING( "Could not stream event to file" );
273  }
274  }
275  if(m_onlineMode){
276  ATH_MSG_DEBUG("Streaming event to server");
277  if ( (m_StreamToServerTool->StreamEvent(eventNo, runNo, m_FormatTool->getFormattedEvent()).isFailure() )){
278  ATH_MSG_WARNING( "Could not stream event to server" );
279  }
280  }
281 
282  return StatusCode::SUCCESS;
283  }
284 
290 
291  ATH_MSG_VERBOSE( "finalize()" );
292 
294  m_DataRetrieverTools.release().ignore();
295  m_FormatTool.release().ignore();
296  m_StreamToFileTool.release().ignore();
297  m_StreamToServerTool.release().ignore();
298 
299  return StatusCode::SUCCESS;
300  }
301 } //namespace
JiveXML::AlgoJiveXML::m_writeToFile
Gaudi::Property< bool > m_writeToFile
Definition: AlgoJiveXML.h:46
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
JiveXML::GeometryWriter::writeGeometry
virtual StatusCode writeGeometry() override
Writes the inner detector and calorimeter geometry to an XML file.
Definition: GeometryWriter.cxx:35
JiveXML::AlgoJiveXML::m_GeoWriterNames
Gaudi::Property< std::vector< std::string > > m_GeoWriterNames
Definition: AlgoJiveXML.h:50
jetMakeRefSamples.geometryVersion
string geometryVersion
Definition: jetMakeRefSamples.py:68
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
JiveXML::AlgoJiveXML::m_DataRetrieverTools
ToolHandleArray< JiveXML::IDataRetriever > m_DataRetrieverTools
The list of DataRetrievers.
Definition: AlgoJiveXML.h:56
IGeometryWriter.h
JiveXML::AlgoJiveXML::m_onlineMode
Gaudi::Property< bool > m_onlineMode
Definition: AlgoJiveXML.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
JiveXML::AlgoJiveXML::m_FormatTool
ToolHandle< JiveXML::IFormatTool > m_FormatTool
Handle to the formatting tool, which is passed on to the data retrievers and converts the data into X...
Definition: AlgoJiveXML.h:62
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
StreamToServerTool.h
JiveXML::AlgoJiveXML::AlgoJiveXML
AlgoJiveXML(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AlgoJiveXML.cxx:21
xAOD::EventInfo_v1::eventTypeBitmask
uint32_t eventTypeBitmask() const
The event type bitmask.
JiveXML::AlgoJiveXML::execute
StatusCode execute()
Execute - called for every event.
Definition: AlgoJiveXML.cxx:113
JiveXML::AlgoJiveXML::finalize
StatusCode finalize()
Finalize called once in the end.
Definition: AlgoJiveXML.cxx:289
JiveXML::AlgoJiveXML::m_geometryVersionIn
Gaudi::Property< std::string > m_geometryVersionIn
Definition: AlgoJiveXML.h:49
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::EventInfo_v1::timeStampNSOffset
uint32_t timeStampNSOffset() const
Nanosecond time offset wrt. the time stamp.
JiveXML::AlgoJiveXML::m_AtlasRelease
Gaudi::Property< std::string > m_AtlasRelease
Definition: AlgoJiveXML.h:45
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
StreamToFileTool.h
xAOD::EventInfo_v1::mcChannelNumber
uint32_t mcChannelNumber() const
The MC generator's channel number.
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
JiveXML::AlgoJiveXML::initialize
StatusCode initialize()
Initialize - called once in the beginning.
Definition: AlgoJiveXML.cxx:31
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
calibdata.exception
exception
Definition: calibdata.py:496
AlgoJiveXML.h
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
AthAlgorithm
Definition: AthAlgorithm.h:47
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
SCT_Cabling::dateTime
std::string dateTime()
Definition: SCT_CablingXmlTags.h:55
JiveXML::AlgoJiveXML::m_StreamToServerTool
ToolHandle< JiveXML::IStreamTool > m_StreamToServerTool
Definition: AlgoJiveXML.h:69
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
JiveXML::AlgoJiveXML::m_StreamToFileTool
ToolHandle< JiveXML::IStreamTool > m_StreamToFileTool
Streaming tools that pass the formatted XML text into a file, to a server, etc.
Definition: AlgoJiveXML.h:68
XMLFormatTool.h
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JiveXML::GeometryWriter
Writes the inner detector and calorimeter geometry to an XML file for use with Atlantis.
Definition: GeometryWriter.h:37
xAOD::EventInfo_v1::timeStamp
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
JiveXML::TagType
std::pair< std::string, std::string > TagType
Defines a tag as a pair of strings.
Definition: DataType.h:62
JiveXML::AlgoJiveXML::m_writeGeometry
Gaudi::Property< bool > m_writeGeometry
Definition: AlgoJiveXML.h:48
xAOD::EventInfo_v1::subEvents
const std::vector< SubEvent > & subEvents() const
Get the pileup events that were used in the simulation.
Definition: EventInfo_v1.cxx:596
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
xAOD::EventInfo_v1::SubEvent
Class describing the properties of one pileup sub-event.
Definition: EventInfo_v1.h:286
IDataRetriever.h
xAOD::EventInfo_v1::mcEventNumber
uint64_t mcEventNumber() const
The MC generator's event number.
xAOD::EventInfo_v1::actualInteractionsPerCrossing
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
Definition: EventInfo_v1.cxx:380