ATLAS Offline Software
ByteStreamMergeOutputSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 #include "GaudiKernel/GenericAddress.h"
9 #include "GaudiKernel/MsgStream.h"
10 #include "GaudiKernel/ISvcLocator.h"
11 
12 #include "eformat/SourceIdentifier.h"
13 
14 #include <map>
15 
17 typedef std::map<uint32_t, ROBF*> ROBMAP;
18 
19 // Constructor.
20 ByteStreamMergeOutputSvc::ByteStreamMergeOutputSvc(const std::string& name, ISvcLocator* svcloc) :
21  ByteStreamOutputSvc(name,svcloc),
22  m_inSvc(0),
23  m_outSvc(0)
24 {
25  declareProperty("ByteStreamOutputSvc", m_outSvcName);
26  declareProperty("ByteStreamInputSvc", m_inSvcName);
27  declareProperty("overWriteHeader", m_overwriteHeader = false);
28  declareProperty("BSOutputStreamName", m_bsOutputStreamName = name);
29 }
30 
31 // Destructor.
33 }
34 
35 // setup input and output paths
38  if (sc != StatusCode::SUCCESS) {
39  ATH_MSG_ERROR("Failed to initialize ByteStreamOutputSvc base class");
40  return(sc);
41  }
42  IService* svc;
43  sc = service(m_outSvcName.value(), svc);
44  if (sc != StatusCode::SUCCESS) {
45  ATH_MSG_ERROR("Cannot get ByteStreamOutputSvc");
46  return(sc);
47  }
48  m_outSvc = dynamic_cast<ByteStreamOutputSvc*>(svc);
49  if (m_outSvc == 0) {
50  ATH_MSG_ERROR("Cannot cast " << m_outSvcName << " to ByteStreamOutputSvc");
51  return(StatusCode::FAILURE);
52  }
53 
54  sc = service(m_inSvcName.value(), svc);
55  if (sc != StatusCode::SUCCESS) {
56  ATH_MSG_ERROR("Cannot get ByteStreamInputSvc");
57  return(sc);
58  }
59  m_inSvc = dynamic_cast<ByteStreamInputSvc*>(svc);
60  if (m_inSvc == 0) {
61  ATH_MSG_ERROR("Cannot cast " << m_inSvcName << " to ByteStreamInputSvc");
62  return(StatusCode::FAILURE);
63  }
64  return(StatusCode::SUCCESS);
65 }
66 
67 // ROBs from the L2 and event filter needs to be treated specially since the module id
68 // is used online to identify which node processed an event and it therefore varies from
69 // event to event - here we remap it to have module id 0, since there should only be one per event
71  eformat::helper::SourceIdentifier id = eformat::helper::SourceIdentifier(source_id);
72  if (id.subdetector_id() == eformat::TDAQ_LVL2 || id.subdetector_id() == eformat::TDAQ_EVENT_FILTER) {
73  return(eformat::helper::SourceIdentifier(id.subdetector_id(), 0).code());
74  } else {
75  return(source_id);
76  }
77 }
78 
79 // Read the next event.
81  // get original event
82  const RawEvent* orgEvent = m_inSvc->currentEvent();
83 
84  ATH_MSG_DEBUG("original BS size = " << 4 * orgEvent->fragment_size_word());
85  ATH_MSG_DEBUG("athena BS size = " << 4 * newEvent->fragment_size_word());
86 
87  // do the merge...
88  // get all the ROBFragments
89  const size_t MAX_ROBFRAGMENTS = 2048;
90  OFFLINE_FRAGMENTS_NAMESPACE::PointerType orgRobF[MAX_ROBFRAGMENTS];
91  OFFLINE_FRAGMENTS_NAMESPACE::PointerType newRobF[MAX_ROBFRAGMENTS];
92  size_t orgrobcount = orgEvent->children(orgRobF, MAX_ROBFRAGMENTS);
93  if (orgrobcount == MAX_ROBFRAGMENTS) {
94  ATH_MSG_ERROR("ROB buffer overflow");
95  return false;
96  }
97  size_t newrobcount = newEvent->children(newRobF,MAX_ROBFRAGMENTS);
98  if (newrobcount == MAX_ROBFRAGMENTS) {
99  ATH_MSG_ERROR("ROB buffer overflow");
100  return false;
101  }
102 
103  ROBMAP robsToAdd;
104  // loop over all ROBs
105  for (size_t irob = 0; irob < orgrobcount; ++irob) {
106  ROBF* rob = new ROBF(orgRobF[irob]);
107  robsToAdd[reducedROBid(rob->source_id())] = rob;
108  ATH_MSG_DEBUG("original ROBFragment, src ID = " << std::hex << rob->source_id());
109  }
110  // now add/overwrite with newly created robs
111  for (size_t irob = 0; irob < newrobcount; ++irob) {
112  ROBF* rob = new ROBF(newRobF[irob]);
113  ROBMAP::const_iterator it = robsToAdd.find(reducedROBid(rob->source_id()));
114  if (it != robsToAdd.end()) {
115  delete it->second;
116  ATH_MSG_DEBUG("overwriting ROBFragment with src ID = " << std::hex << rob->source_id());
117  }
118  robsToAdd[reducedROBid(rob->source_id())] = rob;
119  ATH_MSG_DEBUG("new ROBFragment, src ID = " << std::hex << rob->source_id());
120  }
121  RawEventWrite* mergedEventWrite = new RawEventWrite();
122  // copy header
123  const RawEvent *event = orgEvent;
124  if (m_overwriteHeader) {
125  event = newEvent;
126  }
127  mergedEventWrite->source_id(event->source_id());
128  mergedEventWrite->bc_time_seconds(event->bc_time_seconds());
129  mergedEventWrite->bc_time_nanoseconds(event->bc_time_nanoseconds());
130  mergedEventWrite->global_id(event->global_id());
131  mergedEventWrite->run_type(event->run_type());
132  mergedEventWrite->run_no(event->run_no());
133  mergedEventWrite->lumi_block(event->lumi_block());
134  mergedEventWrite->lvl1_id(event->lvl1_id());
135  mergedEventWrite->bc_id(event->bc_id());
136  mergedEventWrite->lvl1_trigger_type(event->lvl1_trigger_type());
138  event->status(tmp);
139  mergedEventWrite->status(event->nstatus(), tmp);
140  event->lvl1_trigger_info(tmp);
141  mergedEventWrite->lvl1_trigger_info(event->nlvl1_trigger_info(), tmp);
142  event->lvl2_trigger_info(tmp);
143  mergedEventWrite->lvl2_trigger_info(event->nlvl2_trigger_info(), tmp);
144  event->event_filter_info(tmp);
145  mergedEventWrite->event_filter_info(event->nevent_filter_info(), tmp);
146  event->stream_tag(tmp);
147  mergedEventWrite->stream_tag(event->nstream_tag(), tmp);
148  mergedEventWrite->checksum_type(event->checksum_type());
149  // copy robs
150  for(ROBMAP::iterator it = robsToAdd.begin(), itEnd = robsToAdd.end(); it != itEnd; ++it) {
151  mergedEventWrite->append(it->second);
152  }
153  // convert RawEventWrite to RawEvent
154  uint32_t rawSize = mergedEventWrite->size_word();
156  uint32_t count = eformat::write::copy(*(mergedEventWrite->bind()), buffer, rawSize);
157  if (count != rawSize) {
158  ATH_MSG_ERROR("Memcopy failed " << count << " " << rawSize);
159  return false;
160  }
161  RawEvent newRawEvent(buffer);
162  StatusCode sc = m_outSvc->putEvent(&newRawEvent) ? StatusCode::SUCCESS : StatusCode::FAILURE;
163  for(ROBMAP::iterator it = robsToAdd.begin(), itEnd = robsToAdd.end(); it != itEnd; ++it) {
164  delete it->second; it->second = 0;
165  }
166  delete mergedEventWrite; mergedEventWrite = 0;
167  delete [] buffer;
168  if (sc != StatusCode::SUCCESS) {
169  ATH_MSG_ERROR("Failed to put RawEvent");
170  }
171  return(true);
172 }
173 
174 bool ByteStreamMergeOutputSvc::putEvent(const RawEvent* /*re*/, const EventContext& /*ctx*/) {
175  ATH_MSG_FATAL(name() << " does not implement the context-aware putEvent method");
176  return false;
177 }
178 
179 StatusCode ByteStreamMergeOutputSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
180  if (ByteStreamOutputSvc::interfaceID().versionMatch(riid)) {
181  *ppvInterface = dynamic_cast<ByteStreamOutputSvc*>(this);
182  } else {
183  // Interface is not directly available: try out a base class
184  return(::AthService::queryInterface(riid, ppvInterface));
185  }
186  addRef();
187  return(StatusCode::SUCCESS);
188 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
RawEventWrite
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
Definition: RawEvent.h:39
ByteStreamMergeOutputSvc::queryInterface
StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface) override
Required of all Gaudi services: see Gaudi documentation for details.
Definition: ByteStreamMergeOutputSvc.cxx:179
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
OFFLINE_FRAGMENTS_NAMESPACE::DataType
uint32_t DataType
Definition: RawEvent.h:24
ByteStreamInputSvc
This class provides the base class to services to read bytestream data. The concrete class can provid...
Definition: ByteStreamInputSvc.h:23
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ByteStreamOutputSvc::putEvent
virtual bool putEvent(const RawEvent *re)=0
virtual method for writing the event
initialize
void initialize()
Definition: run_EoverP.cxx:894
RawEvent
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition: RawEvent.h:37
skel.it
it
Definition: skel.GENtoEVGEN.py:423
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ByteStreamMergeOutputSvc::putEvent
virtual bool putEvent(const RawEvent *re) override
Implementation of the ByteStreamOutputSvc interface methods.
Definition: ByteStreamMergeOutputSvc.cxx:80
ByteStreamMergeOutputSvc::ByteStreamMergeOutputSvc
ByteStreamMergeOutputSvc(const std::string &name, ISvcLocator *svcloc)
Constructors:
Definition: ByteStreamMergeOutputSvc.cxx:20
ROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
Definition: ByteStreamMergeOutputSvc.cxx:16
ByteStreamMergeOutputSvc.h
This file contains the class definition for the ByteStreamMergeOutputSvc class.
OFFLINE_FRAGMENTS_NAMESPACE::PointerType
const DataType * PointerType
Definition: RawEvent.h:25
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
ByteStreamMergeOutputSvc::m_outSvc
ByteStreamOutputSvc * m_outSvc
Definition: ByteStreamMergeOutputSvc.h:44
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
ByteStreamMergeOutputSvc::initialize
virtual StatusCode initialize() override
Definition: ByteStreamMergeOutputSvc.cxx:36
ByteStreamMergeOutputSvc::~ByteStreamMergeOutputSvc
virtual ~ByteStreamMergeOutputSvc()
Destructor.
Definition: ByteStreamMergeOutputSvc.cxx:32
ByteStreamMergeOutputSvc::reducedROBid
uint32_t reducedROBid(uint32_t)
Definition: ByteStreamMergeOutputSvc.cxx:70
ByteStreamMergeOutputSvc::m_bsOutputStreamName
Gaudi::Property< std::string > m_bsOutputStreamName
stream name for multiple output
Definition: ByteStreamMergeOutputSvc.h:45
ByteStreamMergeOutputSvc::m_overwriteHeader
Gaudi::Property< bool > m_overwriteHeader
Definition: ByteStreamMergeOutputSvc.h:46
ByteStreamMergeOutputSvc::m_inSvc
ByteStreamInputSvc * m_inSvc
Definition: ByteStreamMergeOutputSvc.h:43
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ByteStreamMergeOutputSvc::m_outSvcName
Gaudi::Property< std::string > m_outSvcName
Definition: ByteStreamMergeOutputSvc.h:42
ByteStreamOutputSvc::interfaceID
static const InterfaceID & interfaceID()
Retrieve interface ID.
Definition: ByteStreamOutputSvc.h:43
pmontree.code
code
Definition: pmontree.py:443
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ByteStreamInputSvc::currentEvent
virtual const RawEvent * currentEvent() const =0
virtual method for accessing the current event
ByteStream.h
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
ByteStreamOutputSvc
This class provides the base class to services to write bytestream data. The concrete class can provi...
Definition: ByteStreamOutputSvc.h:25
calibdata.copy
bool copy
Definition: calibdata.py:27
ROBMAP
std::map< uint32_t, ROBF * > ROBMAP
Definition: ByteStreamMergeOutputSvc.cxx:17
ByteStreamMergeOutputSvc::m_inSvcName
Gaudi::Property< std::string > m_inSvcName
Definition: ByteStreamMergeOutputSvc.h:41