ATLAS Offline Software
gFexByteStreamTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //***************************************************************************
6 // gFexByteStreamTool - description
7 // -------------------
8 // begin : 20 07 2022
9 // email : cecilia.tosciri@cern.ch
10 // ***************************************************************************/
11 
12 #include "gFexByteStreamTool.h"
13 #include "gFexPos.h"
14 #include "eformat/SourceIdentifier.h"
15 #include "eformat/Status.h"
16 
17 #include <span>
18 
21 
22 namespace gPos = LVL1::gFEXPos;
23 
25  const std::string& name,
26  const IInterface* parent)
27  : base_class(type, name, parent) {}
28 
30  // Conversion mode for gRho TOBs
31  ATH_MSG_DEBUG(" ROB IDs: " << MSG::hex << m_robIds.value() << MSG::dec);
32 
33  ConversionMode gRhomode = getConversionMode(m_gFexRhoReadKey, m_gFexRhoWriteKey, msg());
36  ATH_CHECK(m_gFexRhoReadKey.initialize(gRhomode==ConversionMode::Encoding));
37  ATH_MSG_DEBUG((gRhomode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gRho ");
38 
39  // Conversion mode for gSJ TOBs
40  ConversionMode gSJmode = getConversionMode(m_gFexBlockReadKey, m_gFexBlockWriteKey, msg());
43  ATH_CHECK(m_gFexBlockReadKey.initialize(gSJmode==ConversionMode::Encoding));
44  ATH_MSG_DEBUG((gSJmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gSJ ");
45 
46  // Conversion mode for gLJ TOBs
47  ConversionMode gLJmode = getConversionMode(m_gFexJetReadKey, m_gFexJetWriteKey, msg());
50  ATH_CHECK(m_gFexJetReadKey.initialize(gLJmode==ConversionMode::Encoding));
51  ATH_MSG_DEBUG((gLJmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gLJ ");
52 
53  // Conversion mode for gScalarEJwoj TOBs
54  ConversionMode gScalarEJwojmode = getConversionMode(m_gScalarEJwojReadKey, m_gScalarEJwojWriteKey, msg());
55  ATH_CHECK(gScalarEJwojmode!=ConversionMode::Undefined);
56  ATH_CHECK(m_gScalarEJwojWriteKey.initialize(gScalarEJwojmode==ConversionMode::Decoding));
57  ATH_CHECK(m_gScalarEJwojReadKey.initialize(gScalarEJwojmode==ConversionMode::Encoding));
58  ATH_MSG_DEBUG((gScalarEJwojmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gScalarEJwoj ");
59 
60  // Conversion mode for gMETComponentsJwoj TOBs
61  ConversionMode gMETComponentsJwojmode = getConversionMode(m_gMETComponentsJwojReadKey, m_gMETComponentsJwojWriteKey, msg());
62  ATH_CHECK(gMETComponentsJwojmode!=ConversionMode::Undefined);
63  ATH_CHECK(m_gMETComponentsJwojWriteKey.initialize(gMETComponentsJwojmode==ConversionMode::Decoding));
64  ATH_CHECK(m_gMETComponentsJwojReadKey.initialize(gMETComponentsJwojmode==ConversionMode::Encoding));
65  ATH_MSG_DEBUG((gMETComponentsJwojmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gMETComponentsJwoj ");
66 
67  // Conversion mode for gMHTComponentsJwoj TOBs
68  ConversionMode gMHTComponentsJwojmode = getConversionMode(m_gMHTComponentsJwojReadKey, m_gMHTComponentsJwojWriteKey, msg());
69  ATH_CHECK(gMHTComponentsJwojmode!=ConversionMode::Undefined);
70  ATH_CHECK(m_gMHTComponentsJwojWriteKey.initialize(gMHTComponentsJwojmode==ConversionMode::Decoding));
71  ATH_CHECK(m_gMHTComponentsJwojReadKey.initialize(gMHTComponentsJwojmode==ConversionMode::Encoding));
72  ATH_MSG_DEBUG((gMHTComponentsJwojmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gMHTComponentsJwoj ");
73 
74  // Conversion mode for gMSTComponentsJwoj TOBs
75  ConversionMode gMSTComponentsJwojmode = getConversionMode(m_gMSTComponentsJwojReadKey, m_gMSTComponentsJwojWriteKey, msg());
76  ATH_CHECK(gMSTComponentsJwojmode!=ConversionMode::Undefined);
77  ATH_CHECK(m_gMSTComponentsJwojWriteKey.initialize(gMSTComponentsJwojmode==ConversionMode::Decoding));
78  ATH_CHECK(m_gMSTComponentsJwojReadKey.initialize(gMSTComponentsJwojmode==ConversionMode::Encoding));
79  ATH_MSG_DEBUG((gMSTComponentsJwojmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gMSTComponentsJwoj ");
80 
81  // Conversion mode for gMETComponentsNoiseCut TOBs
82  ConversionMode gMETComponentsNoiseCutmode = getConversionMode(m_gMETComponentsNoiseCutReadKey, m_gMETComponentsNoiseCutWriteKey, msg());
83  ATH_CHECK(gMETComponentsNoiseCutmode!=ConversionMode::Undefined);
84  ATH_CHECK(m_gMETComponentsNoiseCutWriteKey.initialize(gMETComponentsNoiseCutmode==ConversionMode::Decoding));
85  ATH_CHECK(m_gMETComponentsNoiseCutReadKey.initialize(gMETComponentsNoiseCutmode==ConversionMode::Encoding));
86  ATH_MSG_DEBUG((gMETComponentsNoiseCutmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gMETComponentsNoiseCut ");
87 
88  // Conversion mode for gMETRms TOBs
89  ConversionMode gMETComponentsRmsmode = getConversionMode(m_gMETComponentsRmsReadKey, m_gMETComponentsRmsWriteKey, msg());
90  ATH_CHECK(gMETComponentsRmsmode!=ConversionMode::Undefined);
91  ATH_CHECK(m_gMETComponentsRmsWriteKey.initialize(gMETComponentsRmsmode==ConversionMode::Decoding));
92  ATH_CHECK(m_gMETComponentsRmsReadKey.initialize(gMETComponentsRmsmode==ConversionMode::Encoding));
93  ATH_MSG_DEBUG((gMETComponentsRmsmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gMETComponentsRms ");
94 
95  // Conversion mode for gScalarENoiseCut TOBs
96  ConversionMode gScalarENoiseCutmode = getConversionMode(m_gScalarENoiseCutReadKey, m_gScalarENoiseCutWriteKey, msg());
97  ATH_CHECK(gScalarENoiseCutmode!=ConversionMode::Undefined);
98  ATH_CHECK(m_gScalarENoiseCutWriteKey.initialize(gScalarENoiseCutmode==ConversionMode::Decoding));
99  ATH_CHECK(m_gScalarENoiseCutReadKey.initialize(gScalarENoiseCutmode==ConversionMode::Encoding));
100  ATH_MSG_DEBUG((gScalarENoiseCutmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gScalarENoiseCut ");
101 
102  // Conversion mode for gScalarERms TOBs
103  ConversionMode gScalarERmsmode = getConversionMode(m_gScalarERmsReadKey, m_gScalarERmsWriteKey, msg());
104  ATH_CHECK(gScalarERmsmode!=ConversionMode::Undefined);
105  ATH_CHECK(m_gScalarERmsWriteKey.initialize(gScalarERmsmode==ConversionMode::Decoding));
106  ATH_CHECK(m_gScalarERmsReadKey.initialize(gScalarERmsmode==ConversionMode::Encoding));
107  ATH_MSG_DEBUG((gScalarERmsmode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " gScalarERms ");
108 
109  //checking all Conversion modes.. avoid misconfigurations
110  const std::array<ConversionMode,2> modes{gSJmode,gLJmode};
111  if (std::any_of(modes.begin(),modes.end(),[&gRhomode](ConversionMode m) { return m!=gRhomode; } )) {
112  ATH_MSG_ERROR("Inconsistent conversion modes");
113  return StatusCode::FAILURE;
114  }
115 
117 
118  if (!m_monTool.empty()) {
119  ATH_CHECK(m_monTool.retrieve());
120  ATH_MSG_INFO("Logging errors to " << m_monTool.name() << " monitoring tool");
121  m_UseMonitoring = true;
122  }
123 
124 
125  return StatusCode::SUCCESS;
126 }
127 
129  // Retrieve the L1 menu configuration
131  ATH_CHECK(l1Menu.isValid());
132 
133  try {
134  const auto & l1Menu_gJ = l1Menu->thrExtraInfo().gJ();
135  const auto & l1Menu_gLJ = l1Menu->thrExtraInfo().gLJ();
136  const auto & l1Menu_gXE = l1Menu->thrExtraInfo().gXE();
137  const auto & l1Menu_gTE = l1Menu->thrExtraInfo().gTE();
138 
139  ATH_CHECK(l1Menu_gJ.isValid());
140  ATH_CHECK(l1Menu_gLJ.isValid());
141  ATH_CHECK(l1Menu_gXE.isValid());
142  ATH_CHECK(l1Menu_gTE.isValid());
143 
144  m_gJ_scale = l1Menu_gJ.resolutionMeV();
145  m_gLJ_scale = l1Menu_gLJ.resolutionMeV();
146  m_gXE_scale = l1Menu_gXE.resolutionMeV();
147  m_gTE_scale = l1Menu_gTE.resolutionMeV();
148  } catch (const std::exception& e) {
149  ATH_MSG_ERROR("Exception reading L1Menu: " << e.what());
150  return StatusCode::FAILURE;
151  }
152 
153  return StatusCode::SUCCESS;
154 
155 }
156 
157 // BS->xAOD conversion
158 StatusCode gFexByteStreamTool::convertFromBS(const std::vector<const ROBF*>& vrobf, const EventContext& ctx) const {
159 
160  //WriteHandle for gFEX EDMs
161 
162  //---Rho Container
164  ATH_CHECK(gRhoContainer.record(std::make_unique<xAOD::gFexJetRoIContainer>(), std::make_unique<xAOD::gFexJetRoIAuxContainer>()));
165  ATH_MSG_DEBUG("Recorded gFexJetRoIContainer with key " << gRhoContainer.key());
166 
167  //---Small Jets Container
169  ATH_CHECK(gSJContainer.record(std::make_unique<xAOD::gFexJetRoIContainer>(), std::make_unique<xAOD::gFexJetRoIAuxContainer>()));
170  ATH_MSG_DEBUG("Recorded gFexJetRoIContainer with key " << gSJContainer.key());
171 
172  //---Large Jets Container
174  ATH_CHECK(gLJContainer.record(std::make_unique<xAOD::gFexJetRoIContainer>(), std::make_unique<xAOD::gFexJetRoIAuxContainer>()));
175  ATH_MSG_DEBUG("Recorded gFexJetRoIContainer with key " << gLJContainer.key());
176 
177  //---Scalar MET and SumET JwoJ Container
179  ATH_CHECK(gScalarEJwojContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
180  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gScalarEJwojContainer.key());
181 
182  //---MET Components JwoJ Container
184  ATH_CHECK(gMETComponentsJwojContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
185  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gMETComponentsJwojContainer.key());
186 
187  //---MHT Components JwoJ Container
189  ATH_CHECK(gMHTComponentsJwojContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
190  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gMHTComponentsJwojContainer.key());
191 
192  //---MST Components JwoJ Container
194  ATH_CHECK(gMSTComponentsJwojContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
195  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gMSTComponentsJwojContainer.key());
196 
197  //---MET Components NoiseCut Container
199  ATH_CHECK(gMETComponentsNoiseCutContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
200  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gMETComponentsNoiseCutContainer.key());
201 
202  //---MET Components Rms Container
204  ATH_CHECK(gMETComponentsRmsContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
205  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gMETComponentsRmsContainer.key());
206 
207  //---Scalar MET and SumET NoiseCut Container
209  ATH_CHECK(gScalarENoiseCutContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
210  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gScalarENoiseCutContainer.key());
211 
212  //---Scalar MET and SumET Rms Container
214  ATH_CHECK(gScalarERmsContainer.record(std::make_unique<xAOD::gFexGlobalRoIContainer>(), std::make_unique<xAOD::gFexGlobalRoIAuxContainer>()));
215  ATH_MSG_DEBUG("Recorded gFexJetGlobalContainer with key " << gScalarERmsContainer.key());
216 
217 
218  // Iterate over ROBFragments to decode
219  for (const ROBF* rob : vrobf) {
220  // Iterate over ROD words and decode
221 
222 
223  ATH_MSG_DEBUG("Starting to decode " << rob->rod_ndata() << " ROD words from ROB 0x" << std::hex << rob->rob_source_id());
224 
225  //There is no data to decode.. not even the ROD trailers
226  if(rob->rod_ndata() <= 0){
227  continue;
228  }
229 
230  const auto dataArray = std::span{rob->rod_data(), rob->rod_ndata()};
231 
232 
233  // Starting to loop over the gFEX words
234 
235  unsigned int n_words = rob->rod_ndata();
236 
237  //saving Jet TOBs into the EDM container
238  for(unsigned int iWord=0; iWord<n_words; iWord++) {
239  ATH_MSG_DEBUG("Raw word 0x" << std::hex << dataArray[iWord] << " " << std::bitset<32> (dataArray[iWord]));
240  }
241 
242  // Vectors to temporarily store global tob before their are summed together
243  int global_counter = 0;
244  std::vector<uint32_t> JWOJ_MHT(3, 0);
245  std::vector<uint32_t> JWOJ_MST(3, 0);
246  std::vector<uint32_t> JWOJ_MET(3, 0);
247  std::vector<uint32_t> JWOJ_SCALAR(3, 0);
248  std::vector<uint32_t> NC_MET(3, 0);
249  std::vector<uint32_t> NC_SCALAR(3, 0);
250  std::vector<uint32_t> RMS_MET(3, 0);
251  std::vector<uint32_t> RMS_SCALAR(3, 0);
252 
253  size_t index = 0;
254  while ( index < n_words ) {
255  const uint32_t headerWord = dataArray[index];//Identify the header words. The first is a header word.
257  const uint32_t headerSize = (headerWord >> gPos::HEADER_SIZE_BIT) & gPos::HEADER_SIZE_MASK;
258  const uint32_t errorFlags = (headerWord >> gPos::ERROR_FLAG_BIT) & gPos::ERROR_FLAG_MASK;
259  const uint32_t dataSize = headerWord & gPos::DATA_SIZE_MASK;
260 
261  ATH_MSG_DEBUG( "index "<< index );
262  ATH_MSG_DEBUG( "word "<< std::bitset<32> (dataArray[index]) );
263  ATH_MSG_DEBUG( "headerWord "<< std::bitset<32> (headerWord) );
264  ATH_MSG_DEBUG( "blockType "<< std::bitset<4> (blockType) );
265  ATH_MSG_DEBUG( "headerSize "<< std::bitset<2> (headerSize) );
266  ATH_MSG_DEBUG( "errorFlags "<< std::bitset<1> (errorFlags) );
267  ATH_MSG_DEBUG( "dataSize "<< std::bitset<12> (dataSize) );
268 
269  const uint32_t blockSize = headerSize + dataSize;
270  if ( (index + blockSize) > n_words ) {
271 
272  std::stringstream sdetail;
273  sdetail << "Remaining block size " << (n_words - index) << " is too small for subblock of type " << blockType << " with headerSize " << headerSize << " and dataSize " << dataSize ;
274  std::stringstream slocation;
275  slocation << "0x"<< std::hex << rob->rob_source_id() << std::dec << " type:"<<blockType;
276  std::stringstream stitle;
277  stitle << "Small subblock size " ;
278  printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
279 
280  }
281 
282  index += headerSize;
283 
284  const uint32_t numSlices = dataSize / gPos::WORDS_PER_SLICE;
285  ATH_MSG_DEBUG( "numSlices " << numSlices );
286 
287  if ( numSlices * gPos::WORDS_PER_SLICE != dataSize ) {
288 
289  std::stringstream sdetail;
290  sdetail << "L1CaloBsDecoderRun3::decodeGfexTobs: subblock type " << blockType << " with dataSize " << dataSize << " is not a multiple of " << gPos::WORDS_PER_SLICE << " words" ;
291  std::stringstream slocation;
292  slocation << "0x"<< std::hex << rob->rob_source_id()<< std::dec << " type:"<<blockType;
293  std::stringstream stitle;
294  stitle << "Wrong dataSize" ;
295  printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
296 
297  //skip decode of this fragment
298  index+=dataSize;
299  continue;
300 
301  }
302 
303  // The subblock type is 0xA,B,C for jet TOBs from FPGA A,B,C
304  // and 0x1,2,3 for global (MET) TOBs.
305  bool isMet = (blockType >= 0x1 && blockType <= 0x3);
306  bool isJet = (blockType >= 0xA && blockType <= 0xC);
307 
308 
309  for (uint32_t sliceNumber = 0; sliceNumber < numSlices; sliceNumber++) {
310  if (sliceNumber == 0){
311  if ( !isJet && !isMet ) {
312 
313  std::stringstream sdetail;
314  sdetail << "gFexByteStreamTool::decodeGfexTobSlice: Invalid block type " << blockType ;
315  std::stringstream slocation;
316  slocation << "0x"<< std::hex << rob->rob_source_id();
317  std::stringstream stitle;
318  stitle << "Invalid block type" ;
319  printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
320 
321  }
322 
323  for(unsigned int iWord=0; iWord<gPos::WORDS_PER_SLICE; iWord++) {
324 
325  if (isJet) {
326  //Skipping the unused words
328  continue;
329  }
330  //Skipping the trailer words
332  continue;
333  }
334  //Saving gRho TOBs into the EDM container
335  if (iWord == gPos::GRHO_POSITION){
336  std::unique_ptr<xAOD::gFexJetRoI> myEDM (new xAOD::gFexJetRoI());
337  gRhoContainer->push_back(std::move(myEDM));
338  gRhoContainer->back()->initialize(dataArray[index+iWord], m_gJ_scale);
339  }
340  //Saving gBlock TOBs into the EDM container
342  std::unique_ptr<xAOD::gFexJetRoI> myEDM (new xAOD::gFexJetRoI());
343  gSJContainer->push_back(std::move(myEDM));
344  gSJContainer->back()->initialize(dataArray[index+iWord], m_gJ_scale);
345  }
346  //Saving gJet TOBs into the EDM container
348  std::unique_ptr<xAOD::gFexJetRoI> myEDM (new xAOD::gFexJetRoI());
349  gLJContainer->push_back(std::move(myEDM));
350  gLJContainer->back()->initialize(dataArray[index+iWord], m_gLJ_scale);
351  }
352 
353  }
354 
355  if (isMet){
356  //Skipping the unused words
358  continue;
359  }
360  //Skipping the trailer words
362  continue;
363  }
364  //Saving jwoj MHT TOBs into the EDM container
365  if (iWord == gPos::JWOJ_MHT_POSITION){
366  global_counter ++;
367  if (blockType == 0x1) {JWOJ_MHT[0] = dataArray[index+iWord];}
368  if (blockType == 0x2) {JWOJ_MHT[1] = dataArray[index+iWord];}
369  if (blockType == 0x3) {JWOJ_MHT[2] = dataArray[index+iWord];}
370  }
371  //Saving jwoj MST TOBs into the EDM container
372  if (iWord == gPos::JWOJ_MST_POSITION){
373  if (blockType == 0x1) {JWOJ_MST[0] = dataArray[index+iWord];}
374  if (blockType == 0x2) {JWOJ_MST[1] = dataArray[index+iWord];}
375  if (blockType == 0x3) {JWOJ_MST[2] = dataArray[index+iWord];}
376  }
377  //Saving jwoj MET TOBs into the EDM container
378  if (iWord == gPos::JWOJ_MET_POSITION){
379  if (blockType == 0x1) {JWOJ_MET[0] = dataArray[index+iWord];}
380  if (blockType == 0x2) {JWOJ_MET[1] = dataArray[index+iWord];}
381  if (blockType == 0x3) {JWOJ_MET[2] = dataArray[index+iWord];}
382  }
383  //Saving jwoj Scalar TOBs into the EDM container
384  if (iWord == gPos::JWOJ_SCALAR_POSITION){
385  if (blockType == 0x1) {JWOJ_SCALAR[0] = dataArray[index+iWord];}
386  if (blockType == 0x2) {JWOJ_SCALAR[1] = dataArray[index+iWord];}
387  if (blockType == 0x3) {JWOJ_SCALAR[2] = dataArray[index+iWord];}
388  }
389  //Saving Noise Cut MET TOBs into the EDM container
390  if (iWord == gPos::NC_MET_POSITION){
391  if (blockType == 0x1) {NC_MET[0] = dataArray[index+iWord];}
392  if (blockType == 0x2) {NC_MET[1] = dataArray[index+iWord];}
393  if (blockType == 0x3) {NC_MET[2] = dataArray[index+iWord];}
394  }
395  //Saving Noise Cut Scalar TOBs into the EDM container
396  if (iWord == gPos::NC_SCALAR_POSITION){
397  if (blockType == 0x1) {NC_SCALAR[0] = dataArray[index+iWord];}
398  if (blockType == 0x2) {NC_SCALAR[1] = dataArray[index+iWord];}
399  if (blockType == 0x3) {NC_SCALAR[2] = dataArray[index+iWord];}
400  }
401  //Saving Rho+RMS MET TOBs into the EDM container
402  if (iWord == gPos::RMS_MET_POSITION){
403  if (blockType == 0x1) {RMS_MET[0] = dataArray[index+iWord];}
404  if (blockType == 0x2) {RMS_MET[1] = dataArray[index+iWord];}
405  if (blockType == 0x3) {RMS_MET[2] = dataArray[index+iWord];}
406  }
407  //Saving Rho+RMS Scalar TOBs into the EDM container
408  if (iWord == gPos::RMS_SCALAR_POSITION){
409  if (blockType == 0x1) {RMS_SCALAR[0] = dataArray[index+iWord];}
410  if (blockType == 0x2) {RMS_SCALAR[1] = dataArray[index+iWord];}
411  if (blockType == 0x3) {RMS_SCALAR[2] = dataArray[index+iWord];}
412  }
413 
414  }
415 
416  }
417 
418  }
420  }
421 
422  ATH_MSG_DEBUG("global_counter is " << global_counter);
423  if (global_counter == 3) {
424 
425  fillGlobal(JWOJ_MHT, 3, gMHTComponentsJwojContainer);
426  fillGlobal(JWOJ_MST, 4, gMSTComponentsJwojContainer);
427  int16_t scalar = fillGlobal(JWOJ_MET, 2, gMETComponentsJwojContainer);
428  fillGlobal(JWOJ_SCALAR, 1, gScalarEJwojContainer, scalar);
429 
430  scalar = fillGlobal(NC_MET, 2, gMETComponentsNoiseCutContainer);
431  fillGlobal(NC_SCALAR, 1, gScalarENoiseCutContainer, scalar);
432 
433  scalar = fillGlobal(RMS_MET, 2, gMETComponentsRmsContainer);
434  fillGlobal(RMS_SCALAR, 1, gScalarERmsContainer, scalar);
435 
436  global_counter = 0;
437  }
438 
439  }
440  }
441  return StatusCode::SUCCESS;
442 }
443 
444 // For MHT, MST, and MET, it sums the x and y components across FPGAs, and also returnes
445 // the sum in quadrature (which is actually only used for MET, and discared for MHT and MST)
446 // This function also accepts "scalar" as optional variable, which is used to fill the X
447 // component of the SCALAR tob.
448 int16_t gFexByteStreamTool::fillGlobal(const std::vector<uint32_t> &tob, const int type,
450  int16_t scalar/* = -1*/) const {
451 
452  ATH_MSG_DEBUG("fillGlobal with type " << type);
453 
454  int16_t sum_x = 0;
455  int16_t sum_y = 0;
456 
457  // Extract the x and y components and sum them for the three FPGAs
458  for (size_t fpga = 0; fpga < 3; fpga++) {
461  if (x & 0x00080000) { x = 0xFFFF0000 | x; }
462  if (y & 0x00080000) { y = 0xFFFF0000 | y; }
463  sum_x += x;
464  sum_y += y;
465  }
466 
467  if (type == 1) {//we are considering the scalar case (sum_x = MET and sum_y = SumEt)
468  ATH_MSG_DEBUG(" scalar tob, saving " << scalar << " in X component");
469  sum_x = scalar; //Total MET
470  if( sum_y > 0x000FFF) sum_y = 0x000FFF; //Overflow control for SumEt
471  if( sum_y < 0) sum_y = 0;
472 
473  } else {
474  if (sum_x < -0x0007FF) sum_x = -0x0007FF;
475  if (sum_x > 0x0007FF) sum_x = 0x0007FF;
476 
477  if (sum_y < -0x0007FF) sum_y = -0x0007FF;
478  if (sum_y > 0x0007FF) sum_y = 0x0007FF;
479  }
480 
481  ATH_MSG_DEBUG(" fillGlobal type " << type << std::dec << " sum_x " << sum_x << " sum_y " << sum_y);
482 
483  uint32_t METword = 0;
484 
485  METword = (sum_y & 0x00000FFF) << 0; //set the Quantity2 to the corresponding slot (LSB)
486  METword = METword | (sum_x & 0x00000FFF) << 12;//Quantity 1 (in bit number 12)
487  if (sum_y != 0) METword = METword | 0x00000001 << 24;//Status bit for Quantity 2 (0 if quantity is null)
488  if (sum_x != 0) METword = METword | 0x00000001 << 25;//Status bit for Quantity 1 (0 if quantity is null)
489  METword = METword | (type & 0x0000001F) << 26;//TOB ID (5 bits starting at 26)
490 
491  // Save to the EDM
492  std::unique_ptr<xAOD::gFexGlobalRoI> myEDM (new xAOD::gFexGlobalRoI());
493  container->push_back(std::move(myEDM));
494  container->back()->setWord(METword);
495  container->back()->setQuantityOne(sum_x);
496  container->back()->setQuantityTwo(sum_y);
497  container->back()->setScaleOne(m_gXE_scale);
498  container->back()->setScaleTwo(m_gTE_scale);
499  container->back()->setStatusOne(1);
500  container->back()->setStatusTwo(1);
501  container->back()->setSaturated(0);
502  container->back()->setGlobalType(type);
503 
504 
505  int MET2 = sum_x * sum_x + sum_y * sum_y;
506  int16_t MET = std::sqrt(MET2);
507  if (MET > 0x000FFF) MET = 0x000FFF;
508 
509  return MET;
510 
511 }
512 
513 
515 StatusCode gFexByteStreamTool::convertToBS(std::vector<WROBF*>& /*vrobf*/, const EventContext& /*eventContext*/) {
516 
517  return StatusCode::SUCCESS;
518 
519 }
520 
521 
522 void gFexByteStreamTool::printError(const std::string& location, const std::string& title, MSG::Level type, const std::string& detail) const{
523 
524  if(m_UseMonitoring){
526  Monitored::Scalar("gfexDecoderErrorLocation",location.empty() ? std::string("UNKNOWN") : location),
527  Monitored::Scalar("gfexDecoderErrorTitle" ,title.empty() ? std::string("UNKNOWN") : title)
528  );
529  }
530  else {
531  msg() << type << detail << endmsg;
532  }
533 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
gFexByteStreamTool::m_gScalarERmsReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarERmsReadKey
Definition: gFexByteStreamTool.h:100
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
Undefined
@ Undefined
Definition: MaterialTypes.h:8
LVL1::gFEXPos::ERROR_FLAG_MASK
constexpr unsigned int ERROR_FLAG_MASK
Definition: gFexPos.h:19
LVL1::gFEXPos::HEADER_SIZE_BIT
constexpr unsigned int HEADER_SIZE_BIT
Definition: gFexPos.h:16
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
LVL1::gFEXPos::BLOCK_TYPE_BIT
constexpr unsigned int BLOCK_TYPE_BIT
Definition: gFexPos.h:14
gFexByteStreamTool::fillGlobal
int16_t fillGlobal(const std::vector< uint32_t > &tob, const int type, SG::WriteHandle< xAOD::gFexGlobalRoIContainer > &container, int16_t scalar=-1) const
Definition: gFexByteStreamTool.cxx:448
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
LVL1::gFEXPos::GJET_POSITION
constexpr std::array< unsigned int, 2 > GJET_POSITION
Definition: gFexPos.h:32
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1::gFEXPos::TRAILER_POSITION
constexpr std::array< unsigned int, 2 > TRAILER_POSITION
Definition: gFexPos.h:27
LVL1::gFEXPos::BLOCK_TYPE_MASK
constexpr unsigned int BLOCK_TYPE_MASK
Definition: gFexPos.h:15
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
LVL1::gFEXPos::JWOJ_MST_POSITION
constexpr unsigned int JWOJ_MST_POSITION
Definition: gFexPos.h:36
LVL1::gFEXPos::DATA_SIZE_MASK
constexpr unsigned int DATA_SIZE_MASK
Definition: gFexPos.h:20
gFexByteStreamTool::m_gScalarENoiseCutWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarENoiseCutWriteKey
Definition: gFexByteStreamTool.h:85
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
TrigConf::L1Menu::thrExtraInfo
const L1ThrExtraInfo & thrExtraInfo() const
Access to extra info for threshold types.
Definition: L1Menu.cxx:307
TrigConf::L1ThrExtraInfo::gXE
const L1ThrExtraInfo_gXE & gXE() const
Definition: L1ThrExtraInfo.cxx:178
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
LVL1::gFEXPos::RMS_SCALAR_POSITION
constexpr unsigned int RMS_SCALAR_POSITION
Definition: gFexPos.h:44
L1Topo::blockType
L1Topo::BlockTypes blockType(const uint32_t word, uint32_t offset=28, uint32_t size=0x0f)
Function to return the block type of a data word from L1Topo
Definition: BlockTypes.cxx:9
xAOD::gFexGlobalRoI_v1
Class describing properties of a LVL1 gFEX global Trigger Object (TOB) in the xAOD format.
Definition: gFexGlobalRoI_v1.h:25
gFexPos.h
gFexByteStreamTool::m_gMETComponentsNoiseCutReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsNoiseCutReadKey
Definition: gFexByteStreamTool.h:97
detail
Definition: extract_histogram_tag.cxx:14
PixelByteStreamErrors::Decoding
@ Decoding
Definition: PixelByteStreamErrors.h:14
LVL1::gFEXPos::JET_UNUSED_POSITION
constexpr std::array< unsigned int, 5 > JET_UNUSED_POSITION
Definition: gFexPos.h:28
LVL1::gFEXPos::NC_SCALAR_POSITION
constexpr unsigned int NC_SCALAR_POSITION
Definition: gFexPos.h:41
gFexByteStreamTool::m_gScalarEJwojWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarEJwojWriteKey
Definition: gFexByteStreamTool.h:79
x
#define x
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
LVL1::gFEXPos::GRHO_POSITION
constexpr unsigned int GRHO_POSITION
Definition: gFexPos.h:33
gFexByteStreamTool::m_gMHTComponentsJwojWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gMHTComponentsJwojWriteKey
Definition: gFexByteStreamTool.h:81
gFexByteStreamTool::m_gMETComponentsNoiseCutWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsNoiseCutWriteKey
Definition: gFexByteStreamTool.h:83
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
gFexByteStreamTool::m_gFexBlockReadKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexBlockReadKey
Definition: gFexByteStreamTool.h:91
gFexByteStreamTool.h
LVL1::gFEXPos::JWOJ_MET_POSITION
constexpr unsigned int JWOJ_MET_POSITION
Definition: gFexPos.h:37
ROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
Definition: ByteStreamMergeOutputSvc.cxx:16
gFexByteStreamTool::convertToBS
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
Definition: gFexByteStreamTool.cxx:515
Muon::nsw::STGTPPad::n_words
constexpr std::size_t n_words
Definition: NSWSTGTPDecodeBitmaps.h:62
gFexByteStreamTool::m_gFexRhoWriteKey
SG::WriteHandleKey< xAOD::gFexJetRoIContainer > m_gFexRhoWriteKey
Definition: gFexByteStreamTool.h:76
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
gFexByteStreamTool::m_gFexBlockWriteKey
SG::WriteHandleKey< xAOD::gFexJetRoIContainer > m_gFexBlockWriteKey
Definition: gFexByteStreamTool.h:77
gFexByteStreamTool::m_gXE_scale
int m_gXE_scale
Definition: gFexByteStreamTool.h:72
TrigConf::L1ThrExtraInfo::gLJ
const L1ThrExtraInfo_gLJ & gLJ() const
Definition: L1ThrExtraInfo.cxx:163
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LVL1::gFEXPos::GLOBAL_X_MASK
constexpr unsigned int GLOBAL_X_MASK
Definition: gFexPos.h:46
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::gFexJetRoI_v1
Class describing properties of a LVL1 gFEX jet Trigger Object (TOB) in the xAOD format.
Definition: gFexJetRoI_v1.h:25
covarianceTool.title
title
Definition: covarianceTool.py:542
calibdata.exception
exception
Definition: calibdata.py:496
TCS::MET
@ MET
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:16
test_pyathena.parent
parent
Definition: test_pyathena.py:15
gFexByteStreamTool::m_gFexJetReadKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexJetReadKey
Definition: gFexByteStreamTool.h:92
gFexByteStreamTool::m_gMHTComponentsJwojReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gMHTComponentsJwojReadKey
Definition: gFexByteStreamTool.h:95
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
gFexByteStreamTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: gFexByteStreamTool.h:62
gFexByteStreamTool::m_l1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_l1MenuKey
Definition: gFexByteStreamTool.h:103
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
gFexByteStreamTool::m_gFexRhoReadKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexRhoReadKey
Definition: gFexByteStreamTool.h:90
gFexByteStreamTool::convertFromBS
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
Definition: gFexByteStreamTool.cxx:158
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
gFexByteStreamTool::printError
void printError(const std::string &location, const std::string &title, MSG::Level type, const std::string &detail) const
Definition: gFexByteStreamTool.cxx:522
gFexByteStreamTool::m_gFexJetWriteKey
SG::WriteHandleKey< xAOD::gFexJetRoIContainer > m_gFexJetWriteKey
Definition: gFexByteStreamTool.h:78
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LVL1::gFEXPos::GLOBAL_Y_MASK
constexpr unsigned int GLOBAL_Y_MASK
Definition: gFexPos.h:47
LVL1::gFEXPos::GLOBAL_UNUSED_POSITION
constexpr std::array< unsigned int, 4 > GLOBAL_UNUSED_POSITION
Definition: gFexPos.h:29
gFexByteStreamTool::m_gTE_scale
int m_gTE_scale
Definition: gFexByteStreamTool.h:73
gFexByteStreamTool::m_gLJ_scale
int m_gLJ_scale
Definition: gFexByteStreamTool.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MET
Definition: MET.py:1
PayloadHelpers::dataSize
size_t dataSize(TDA::PayloadIterator start)
Size in bytes of the buffer that is needed to decode next fragment data content.
Definition: TriggerEDMDeserialiserAlg.cxx:188
LVL1::gFEXPos::WORDS_PER_SLICE
constexpr unsigned int WORDS_PER_SLICE
Definition: gFexPos.h:22
LVL1::gFEXPos::ERROR_FLAG_BIT
constexpr unsigned int ERROR_FLAG_BIT
Definition: gFexPos.h:18
gFexByteStreamTool::m_gMETComponentsRmsWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsRmsWriteKey
Definition: gFexByteStreamTool.h:84
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
gFexByteStreamTool::gFexByteStreamTool
gFexByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: gFexByteStreamTool.cxx:24
gFexByteStreamTool::m_gMSTComponentsJwojReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gMSTComponentsJwojReadKey
Definition: gFexByteStreamTool.h:96
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
LVL1::gFEXPos::GLOBAL_Y_BIT
constexpr unsigned int GLOBAL_Y_BIT
Definition: gFexPos.h:49
gFexByteStreamTool::m_robIds
Gaudi::Property< std::vector< uint32_t > > m_robIds
Definition: gFexByteStreamTool.h:67
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
gFexByteStreamTool::initialize
virtual StatusCode initialize() override
Definition: gFexByteStreamTool.cxx:29
DeMoScan.index
string index
Definition: DeMoScan.py:364
LVL1::gFEXPos::HEADER_SIZE_MASK
constexpr unsigned int HEADER_SIZE_MASK
Definition: gFexPos.h:17
y
#define y
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
gFexByteStreamTool::m_gScalarERmsWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarERmsWriteKey
Definition: gFexByteStreamTool.h:86
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
WROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
Definition: eFexByteStreamTool.cxx:27
gFexByteStreamTool::m_UseMonitoring
bool m_UseMonitoring
Definition: gFexByteStreamTool.h:63
TrigConf::L1ThrExtraInfo::gTE
const L1ThrExtraInfo_gTE & gTE() const
Definition: L1ThrExtraInfo.cxx:183
DEBUG
#define DEBUG
Definition: page_access.h:11
LVL1::gFEXPos::JWOJ_MHT_POSITION
constexpr unsigned int JWOJ_MHT_POSITION
Definition: gFexPos.h:35
gFexByteStreamTool::m_gMETComponentsRmsReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsRmsReadKey
Definition: gFexByteStreamTool.h:98
LVL1::gFEXPos
Definition: gFexPos.h:11
gFexByteStreamTool::m_gMSTComponentsJwojWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gMSTComponentsJwojWriteKey
Definition: gFexByteStreamTool.h:82
gFexByteStreamTool::m_gMETComponentsJwojWriteKey
SG::WriteHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsJwojWriteKey
Definition: gFexByteStreamTool.h:80
LVL1::gFEXPos::JWOJ_SCALAR_POSITION
constexpr unsigned int JWOJ_SCALAR_POSITION
Definition: gFexPos.h:38
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
gFexByteStreamTool::m_gMETComponentsJwojReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gMETComponentsJwojReadKey
Definition: gFexByteStreamTool.h:94
LVL1::gFEXPos::GLOBAL_X_BIT
constexpr unsigned int GLOBAL_X_BIT
Definition: gFexPos.h:48
gFexByteStreamTool::m_gScalarEJwojReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarEJwojReadKey
Definition: gFexByteStreamTool.h:93
gFexByteStreamTool::m_gScalarENoiseCutReadKey
SG::ReadHandleKey< xAOD::gFexGlobalRoIContainer > m_gScalarENoiseCutReadKey
Definition: gFexByteStreamTool.h:99
gFexByteStreamTool::m_gJ_scale
int m_gJ_scale
Definition: gFexByteStreamTool.h:70
TrigConf::L1ThrExtraInfo::gJ
const L1ThrExtraInfo_gJ & gJ() const
Definition: L1ThrExtraInfo.cxx:158
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
gFexByteStreamTool::start
virtual StatusCode start() override
Definition: gFexByteStreamTool.cxx:128
LVL1::gFEXPos::GBLOCK_POSITION
constexpr std::array< unsigned int, 4 > GBLOCK_POSITION
Definition: gFexPos.h:31
LVL1::gFEXPos::RMS_MET_POSITION
constexpr unsigned int RMS_MET_POSITION
Definition: gFexPos.h:43
LVL1::gFEXPos::NC_MET_POSITION
constexpr unsigned int NC_MET_POSITION
Definition: gFexPos.h:40