ATLAS Offline Software
FullEventAssembler.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // using namespace EventFormat::RawMemory ;
6 
7 #include "GaudiKernel/MsgStream.h"
8 #include "eformat/Status.h"
9 
10 //using namespace OFFLINE_FRAGMENTS_NAMESPACE ;
11 
12 template <class IDMAP>
13 FullEventAssembler<IDMAP>::FullEventAssembler():
14  m_runnum(0),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 
32 template <class IDMAP>
33 void FullEventAssembler<IDMAP>::clear()
34 {
35  // clear stack
36  RODMAP::iterator it_rod = m_rodMap.begin();
37  RODMAP::iterator it_rod_end = m_rodMap.end();
38  for(; it_rod!=it_rod_end; ++it_rod)
39  delete it_rod->second;
40  m_rodMap.clear();
41 
42  ROBMAP::iterator it_rob = m_robMap.begin();
43  ROBMAP::iterator it_rob_end = m_robMap.end();
44  for(; it_rob!=it_rob_end; ++it_rob)
45  delete it_rob->second;
46  m_robMap.clear();
47 
48 }
49 
50 template <class IDMAP>
51 void FullEventAssembler<IDMAP>::fill(RawEventWrite* re, MsgStream& log )
52 {
53  m_runnum = re->run_no() ;
54  m_lvl1_id = re->lvl1_id();
55  m_lvl1_trigger_type = re->lvl1_trigger_type();
56  m_bcid = re->bc_id();
57 
58  // ROD to ROB
59  RodToRob(m_rodMap,m_robMap,log);
60  // ROB to FullEventFragment
61  RobToEvt(m_robMap,re,log);
62 }
63 
64 
65 template <class IDMAP>
66 typename FullEventAssembler<IDMAP>::RODDATA*
67 FullEventAssembler<IDMAP>::getRodData(uint32_t id)
68 {
69  RODMAP::iterator itr = m_rodMap.find(id);
70 
71  RODDATA* theROD = 0;
72  if(itr!=m_rodMap.end())
73  {
74  theROD = (*itr).second;
75  }
76  else
77  {
78  theROD = new RODDATA();
79  m_rodMap.insert(RODMAP::value_type(id,theROD)) ;
80  }
81 
82  return theROD ;
83 }
84 
85 
86 template <class IDMAP>
87 void
88 FullEventAssembler<IDMAP>::RodToRob(RODMAP& rodMap,
89  ROBMAP& robMap, MsgStream& log )
90 {
91  log << MSG::DEBUG << " RodToRob " << endmsg;
92 
93  // loop over all the RODs
94  RODMAP::iterator it_rod = rodMap.begin();
95  RODMAP::iterator it_rod_end = rodMap.end();
96  for(; it_rod!=it_rod_end; ++it_rod)
97  {
98  uint32_t rodid = (*it_rod).first;
99  RODDATA* intv = (*it_rod).second;
100 
101  std::ios_base::fmtflags oflags=log.stream().flags();
102  log << MSG::DEBUG << " Rod id = " << MSG::hex << rodid << endmsg;
103  log.flags(oflags); // reset precision after use of hex
104 
105  // make an ROB id from an ROD id.
106  uint32_t robid = m_idmap.getRobID(rodid);
107 
108  // find or make a ROS fragment
109  ROBMAP::iterator itr2 = robMap.find(robid);
110  if(itr2!=robMap.end())
111  {
112  oflags=log.stream().flags();
113  log << MSG::ERROR << " More than one RODs in ROB:" << MSG::hex << (*itr2).first << endmsg;
114  log.flags(oflags); // reset precision after use of hex
115  }
116  else
117  { // Make a new ROBFragment
118  OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment* theROB
119  = new OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment(robid,m_runnum,m_lvl1_id,m_bcid,
120  m_lvl1_trigger_type,m_detEvtType,intv->size(),
121  &(*intv)[0],eformat::STATUS_BACK);
122  theROB->minor_version(m_rob_version);
123  theROB->rod_minor_version(m_rod_version);
124  robMap.insert(ROBMAP::value_type(robid,theROB)) ;
125  }
126  }
127 }
128 
129 
130 template <class IDMAP>
131 void FullEventAssembler<IDMAP>::RobToEvt(ROBMAP& robMap, RawEventWrite* re, MsgStream& log )
132 {
133  log << MSG::DEBUG<< " RobToEvt, number of ROBFrag= " << robMap.size() << endmsg;
134  OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment* theROB;
135 
136  ROBMAP::iterator it_rob = robMap.begin();
137  ROBMAP::iterator it_rob_end = robMap.end();
138  for(; it_rob!= it_rob_end;++it_rob)
139  {
140  theROB = (*it_rob).second;
141  std::ios_base::fmtflags oflags=log.stream().flags();
142  log << MSG::DEBUG << " RobToEvt: adding ROB " << MSG::hex <<
143  theROB->source_id() << endmsg;
144  log.flags(oflags); // reset precision after use of hex
145  re->append((*it_rob).second);
146  }
147 
148  log << MSG::DEBUG << " FullEventFragment is done " << re << endmsg;
149 }
150 
151 
152 template <class IDMAP>
153 FullEventAssembler<IDMAP>::RODMAP::const_iterator
154 FullEventAssembler<IDMAP>::begin() const
155 {
156  return m_rodMap.begin();
157 }
158 
159 
160 template <class IDMAP>
161 FullEventAssembler<IDMAP>::RODMAP::const_iterator
162 FullEventAssembler<IDMAP>::end() const
163 {
164  return m_rodMap.end();
165 }
166 
167 
168 template <class IDMAP>
169 void FullEventAssembler<IDMAP>::setRodMinorVersion(uint16_t m )
170 {
171  m_rod_version = m;
172 }
173 
174 
175 template <class IDMAP>
176 void FullEventAssembler<IDMAP>::setRobMinorVersion(uint16_t m )
177 {
178  m_rob_version = m;
179 }
180 
181 
182 template <class IDMAP>
183 void FullEventAssembler<IDMAP>::setDetEvtType(uint32_t m )
184 {
185  m_detEvtType = m;
186 }
187 
188 
189 template <class IDMAP>
190 void FullEventAssembler<IDMAP>::setLvl1TriggerType(uint8_t m )
191 {
192  m_lvl1_trigger_type = m;
193 }
194 
195 
196 template <class IDMAP>
197 typename FullEventAssembler<IDMAP>::IDMAP_t& FullEventAssembler<IDMAP>::idMap()
198 {
199  return m_idmap ;
200 }
201