ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChannelContByteStreamTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
9
13
18
25
26#include <Gaudi/Property.h>
27#include <GaudiKernel/IProperty.h>
28#include <GaudiKernel/SmartIF.h>
29
30#include <functional>
31#include <map>
32#include <stdint.h>
33
34static const InterfaceID IID_ITileRawChannelContByteStreamTool("TileRawChannelContByteStreamTool", 1, 0);
35
39
40// default constructor
41
43 const std::string& name, const IInterface* parent)
44 : AthAlgTool(type, name, parent)
45 , m_tileHWID(0)
46 , m_verbose(false)
47 , m_maxChannels(TileCalibUtils::MAX_CHAN)
48{
49 declareInterface<TileRawChannelContByteStreamTool>(this);
50}
51
52// destructor
53
56
58
59 ATH_MSG_INFO ("Initializing TileRawChannelContByteStreamTool");
60
61 ATH_CHECK( detStore()->retrieve(m_tileHWID, "TileHWID") );
62
63 ToolHandle<TileROD_Decoder> dec("TileROD_Decoder");
64 ATH_CHECK( dec.retrieve() );
65
66 const Gaudi::Details::PropertyBase& demoFragIDsProperty = SmartIF<IProperty>(dec.get())->getProperty("DemoFragIDs");
67 const IntegerArrayProperty& demoFragIDs = dynamic_cast<const IntegerArrayProperty&>(demoFragIDsProperty);
68
69 m_demoFragIDs.reserve(demoFragIDs.size());
70 for (const auto fragID : demoFragIDs.value()) {
71 m_demoFragIDs.push_back(fragID);
72 }
73
74 if ( !m_demoFragIDs.empty() ) {
75 std::ostringstream os;
77 os << " (frag IDs):";
78 for (int fragID : m_demoFragIDs) {
79 if (fragID > 0)
80 os << " 0x" << std::hex << fragID << std::dec;
81 else
82 os << " " << fragID;
83 }
84 ATH_MSG_INFO("Enable channel remapping for demonstrator modules" << os.str());
85 }
86
87
88 // Prepare legacy to Demonstrator channel mapping for LB and EB
89 // (vice versa to the one in the Tile ROD Decoder)
90 std::vector<std::pair<std::reference_wrapper<std::vector<int>>,
91 std::reference_wrapper<const std::vector<int>>>>
92 legacyAndDemoChanMaps{{m_legacy2DemoChannelLB, dec->getDemoChannelMapLB()},
93 {m_legacy2DemoChannelEB, dec->getDemoChannelMapEB()}};
94
95 for (std::pair<std::reference_wrapper<std::vector<int>>,
96 std::reference_wrapper<const std::vector<int>>>
97 legacyAndDemoChanMap : legacyAndDemoChanMaps) {
98
99 std::vector<int>& legacy2DemoChannel = legacyAndDemoChanMap.first;
100 const std::vector<int>& demoChanMap = legacyAndDemoChanMap.second;
101 if (!demoChanMap.empty()) {
102 legacy2DemoChannel.resize(m_maxChannels);
103 for (unsigned int demoChannel = 0; demoChannel < demoChanMap.size(); ++demoChannel) {
104 int legacyChannel = demoChanMap[demoChannel];
105 if ((legacyChannel >= 0) && (legacyChannel < m_maxChannels)) {
106 legacy2DemoChannel[legacyChannel] = demoChannel;
107 }
108 }
109 }
110 }
111
112
113 // get TileCondToolEmscale
114 ATH_CHECK( m_tileToolEmscale.retrieve() );
115
116 // get TileBadChanTool
117 ATH_CHECK( m_tileBadChanTool.retrieve() );
118
120
122
123 return StatusCode::SUCCESS;
124}
125
127 ATH_MSG_INFO ("Finalizing TileRawChannelContByteStreamTool successfuly");
128 return StatusCode::SUCCESS;
129}
130
132{
133 const EventContext& ctx = Gaudi::Hive::currentContext();
134 bool isTMDB = evtStore()->proxy(rawChannelContainer)->name() == "MuRcvRawChCnt";
135
136 TileFragHash::TYPE contType = rawChannelContainer->get_type();
137 TileRawChannelUnit::UNIT inputUnit = rawChannelContainer->get_unit();
138 TileRawChannelUnit::UNIT outputUnit = inputUnit;
139
140 bool oflCont = (inputUnit < TileRawChannelUnit::OnlineOffset);
141
144
145 ATH_MSG_DEBUG( " Number of raw channel collections... " << rawChannelContainer->size() << " " << evtStore()->proxy(rawChannelContainer)->name());
146
147 std::map<uint32_t, TileROD_Encoder> mapEncoder;
148 std::vector<TileFastRawChannel> channels;
149 channels.reserve (m_tileHWID->channel_hash_max());
150
151 uint32_t reid = 0x0;
152
153 for (const TileRawChannelCollection* rawChannelCollection : *rawChannelContainer) {
154
155 TileRawChannelCollection::ID frag_id = rawChannelCollection->identify();
156
157 if (isTMDB) reid = hid2re->getRodTileMuRcvID(frag_id);
158 else reid = hid2re->getRodID(frag_id);
159
160 TileROD_Encoder& encoder = mapEncoder[reid];
161
162 encoder.setTileHWID(m_tileHWID, m_verbose, 4);
163 encoder.setTypeAndUnit(contType, outputUnit);
165
166 HWIdentifier drawer_id = m_tileHWID->drawer_id(frag_id);
167
168 int ros = m_tileHWID->ros(drawer_id);
169 int drawer = m_tileHWID->drawer(drawer_id);
170 int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
171
172 const std::vector<uint32_t> & drawer_info = hid2re->getDrawerInfo(frag_id);
173 int drawer_type = drawer_info.size() > 2 ? static_cast<int>(drawer_info[2]) : -1;
174 bool remap = (drawer_type > 0) || std::binary_search(m_demoFragIDs.begin(), m_demoFragIDs.end(), frag_id);
175 const std::vector<int>& legacy2DemoChannel = (ros < 3) ? m_legacy2DemoChannelLB : m_legacy2DemoChannelEB;
176
177 int nChannels = 0;
178 std::vector<std::reference_wrapper<TileFastRawChannel>> drawerChannels;
179 drawerChannels.reserve(rawChannelCollection->size());
180
181 for (const TileRawChannel* rawChannel : *rawChannelCollection) {
182
183 HWIdentifier adc_id = rawChannel->adc_HWID();
184 int channel = m_tileHWID->channel(adc_id);
185 int adc = m_tileHWID->adc(adc_id);
186 float amplitude = rawChannel->amplitude();
187 float time = rawChannel->time();
188 float quality = rawChannel->quality();
189 if (isTMDB) {
190 channels.emplace_back (frag_id, channel, adc, amplitude, 0., 0.);
191 } else {
192 if (oflCont) {
193 if (quality > 15.0) quality = 15.0;
194 if (m_tileBadChanTool->getAdcStatus(drawerIdx, channel, adc, ctx).isBad()) quality += 16.;
195 }
196 //amplitude = m_tileToolEmscale->channelCalib(drawerIdx, channel, adc, amplitude, inputUnit, outputUnit);
197
198 if (remap && (channel >= 0) && (channel < m_maxChannels)) {
199 ATH_MSG_VERBOSE("Change channel [" << TileCalibUtils::getDrawerString(ros, drawer) << "]: "
200 << channel << " -> " << legacy2DemoChannel[channel]);
201 channel = legacy2DemoChannel[channel];
202 }
203
204 channels.emplace_back (frag_id, channel, adc, amplitude, time, quality);
205 drawerChannels.push_back(channels.back());
206 }
207
208 ++nChannels;
209 }
210
211 if (remap) {
212 std::sort(drawerChannels.begin(), drawerChannels.end(),
213 [] (const TileFastRawChannel& a, const TileFastRawChannel& b ) {
214 return a.channel() < b.channel();
215 });
216
217 }
218
219 for (const TileFastRawChannel& channel : drawerChannels){
220 // Don't need to worry about these moving due to the reserve() above.
221 encoder.add(&channel);
222 }
223
224 ATH_MSG_DEBUG( " Collection " << MSG::hex << "0x" << frag_id
225 << " ROD " << "0x" << reid
226 << " number of channels " << MSG::dec << nChannels );
227 }
228
229 // TileROD_Encoder has collected all the channels, now can fill the
230 // ROD block data.
231
232 for (std::pair<const uint32_t, TileROD_Encoder>& reidAndEncoder: mapEncoder) {
233
234 theROD = fea->getRodData(reidAndEncoder.first);
235 TileROD_Encoder& theEncoder = reidAndEncoder.second;
236
237 if ((reidAndEncoder.first & 0xf00)) {
238 theEncoder.fillRODTileMuRcvRawChannel(*theROD);
239 } else {
240 if (m_doFragType4) theEncoder.fillROD4(*theROD);
241 if (m_doFragType5) theEncoder.fillROD5(*theROD);
242 }
243 ATH_MSG_DEBUG( " Number of TileRawChannel words in ROD " << MSG::hex << " 0x" << reidAndEncoder.first << MSG::dec << " : " << theROD->size() );
244 }
245
246 return StatusCode::SUCCESS;
247}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
static Double_t a
static const InterfaceID IID_ITileRawChannelContByteStreamTool("TileRawChannelContByteStreamTool", 1, 0)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
Template class for assembling a full atlas raw event from subfragments.
std::vector< uint32_t > RODDATA
ROD data as a vector of unsigned int.
RODDATA * getRodData(uint32_t id)
get a block of ROD data
static const TileCablingService * getInstance()
get pointer to service instance
int getMaxChannels(void) const
Static class providing several utility functions and constants.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
TYPE
initialize
Provides conversion from TileRawChannel, TileL2 and TMDB (digits,MF raw channel,decision) to ROD form...
void setMaxChannels(int maxChannels)
set maximum number of channels in a drawer
void fillROD5(std::vector< uint32_t > &v)
void setTypeAndUnit(TileFragHash::TYPE type, TileRawChannelUnit::UNIT unit)
set OF algorigtm type and amplitude units for a drawer
void fillRODTileMuRcvRawChannel(std::vector< uint32_t > &v)
void setTileHWID(const TileHWID *tileHWID, bool verbose, unsigned int type=4)
set all necessary parameters for the encoder
void fillROD4(std::vector< uint32_t > &v)
void add(const TileFastRawChannel *rc)
add TileRawChannels to the current list
static const InterfaceID & interfaceID()
AlgTool InterfaceID.
StatusCode convert(CONTAINER *cont, FullEventAssembler< TileHid2RESrcID > *fea) const
Provides conversion from TileRawChannelContainer to BS.
ToolHandle< ITileBadChanTool > m_tileBadChanTool
Handle to Tile bad channel tool.
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
Handle to Tile calibration tool.
SG::ReadCondHandleKey< TileHid2RESrcID > m_hid2RESrcIDKey
TileRawChannelContByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
constructor
int m_maxChannels
maximum number of channels in a drawer
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition hcg.cxx:97
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.