ATLAS Offline Software
FullEventAssembler.icc
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 "GaudiKernel/MsgStream.h"
6 #include "eformat/Status.h"
7 
8 #include <format>
9 
10 
11 template <class IDMAP>
12 FullEventAssembler<IDMAP>::FullEventAssembler():
13  m_runnum(0),
14  m_lvl1_id(0),
15  m_rod_version(0),
16  m_rob_version(0),
17  m_detEvtType(0),
18  m_lvl1_trigger_type(0),
19  m_bcid(0)
20 {
21 }
22 
23 
24 template <class IDMAP>
25 FullEventAssembler<IDMAP>::~FullEventAssembler()
26 {
27  clear();
28 }
29 
30 
31 template <class IDMAP>
32 void FullEventAssembler<IDMAP>::clear()
33 {
34  // clear stack
35  for(const auto& [id, rod] : m_rodMap) delete rod;
36  m_rodMap.clear();
37 
38  for(const auto& [id, rob] : m_robMap) delete rob;
39  m_robMap.clear();
40 }
41 
42 
43 template <class IDMAP>
44 void FullEventAssembler<IDMAP>::fill(RawEventWrite* re, MsgStream& log )
45 {
46  m_runnum = re->run_no() ;
47  m_lvl1_id = re->lvl1_id();
48  m_lvl1_trigger_type = re->lvl1_trigger_type();
49  m_bcid = re->bc_id();
50 
51  // ROD to ROB
52  RodToRob(m_rodMap,m_robMap,log);
53  // ROB to FullEventFragment
54  RobToEvt(m_robMap,re,log);
55 }
56 
57 
58 template <class IDMAP>
59 typename FullEventAssembler<IDMAP>::RODDATA*
60 FullEventAssembler<IDMAP>::getRodData(uint32_t id)
61 {
62  RODDATA* theROD = nullptr;
63 
64  RODMAP::const_iterator itr = m_rodMap.find(id);
65  if(itr!=m_rodMap.end())
66  {
67  theROD = itr->second;
68  }
69  else
70  {
71  theROD = new RODDATA();
72  m_rodMap.emplace(id, theROD);
73  }
74 
75  return theROD;
76 }
77 
78 
79 template <class IDMAP>
80 void
81 FullEventAssembler<IDMAP>::RodToRob(RODMAP& rodMap,
82  ROBMAP& robMap, MsgStream& log ) const
83 {
84  // loop over all the RODs
85  for(const auto& [rodid, rod] : rodMap)
86  {
87  if(log.level() <= MSG::DEBUG)
88  log << MSG::DEBUG << " Rod id = " << std::format("{:x}", rodid) << endmsg;
89 
90  // make an ROB id from an ROD id.
91  const uint32_t robid = m_idmap.getRobID(rodid);
92 
93  // find or make a ROS fragment
94  ROBMAP::const_iterator itr = robMap.find(robid);
95  if(itr!=robMap.end())
96  {
97  log << MSG::ERROR << " More than one ROD in ROB:" << std::format("{:x}", itr->first) << endmsg;
98  }
99  else
100  { // Make a new ROBFragment
101  auto theROB = new OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment(robid,m_runnum,m_lvl1_id,m_bcid,
102  m_lvl1_trigger_type,m_detEvtType,rod->size(),
103  &(*rod)[0],eformat::STATUS_BACK);
104  theROB->minor_version(m_rob_version);
105  theROB->rod_minor_version(m_rod_version);
106  robMap.emplace(robid, theROB);
107  }
108  }
109 }
110 
111 
112 template <class IDMAP>
113 void FullEventAssembler<IDMAP>::RobToEvt(ROBMAP& robMap, RawEventWrite* re, MsgStream& log ) const
114 {
115  const bool debug = log.level() <= MSG::DEBUG;
116  if(debug) log << MSG::DEBUG << " RobToEvt, number of ROBFrag= " << robMap.size() << endmsg;
117 
118  for(const auto& [robid, theROB] : robMap)
119  {
120  if(debug) log << MSG::DEBUG << " RobToEvt: adding ROB "
121  << std::format("{:x}", theROB->source_id()) << endmsg;
122  re->append(theROB);
123  }
124 
125  if(debug) log << MSG::DEBUG << " FullEventFragment is done " << re << endmsg;
126 }
127 
128 
129 template <class IDMAP>
130 FullEventAssembler<IDMAP>::RODMAP::const_iterator
131 FullEventAssembler<IDMAP>::begin() const
132 {
133  return m_rodMap.begin();
134 }
135 
136 
137 template <class IDMAP>
138 FullEventAssembler<IDMAP>::RODMAP::const_iterator
139 FullEventAssembler<IDMAP>::end() const
140 {
141  return m_rodMap.end();
142 }
143 
144 
145 template <class IDMAP>
146 void FullEventAssembler<IDMAP>::setRodMinorVersion(uint16_t m )
147 {
148  m_rod_version = m;
149 }
150 
151 
152 template <class IDMAP>
153 void FullEventAssembler<IDMAP>::setRobMinorVersion(uint16_t m )
154 {
155  m_rob_version = m;
156 }
157 
158 
159 template <class IDMAP>
160 void FullEventAssembler<IDMAP>::setDetEvtType(uint32_t m )
161 {
162  m_detEvtType = m;
163 }
164 
165 
166 template <class IDMAP>
167 void FullEventAssembler<IDMAP>::setLvl1TriggerType(uint8_t m )
168 {
169  m_lvl1_trigger_type = m;
170 }
171 
172 
173 template <class IDMAP>
174 typename FullEventAssembler<IDMAP>::IDMAP_t& FullEventAssembler<IDMAP>::idMap()
175 {
176  return m_idmap ;
177 }
178