From fe4b847c695c2a4a38bddce4540c358c3fd73f13 Mon Sep 17 00:00:00 2001
From: Aleksandra Poreba <aleksandra.poreba@cern.ch>
Date: Wed, 27 Jan 2021 18:51:26 +0100
Subject: [PATCH] Handle ROB status flags

- remove SCHEDULED (prefetched)
- rename DISABLED -> UNDEFINED

Also save robs status with unsigned short to avoid type
misinterpretation issues
---
 .../src/HltROBDataProviderSvc.cxx             |  4 +-
 .../TableConstructors/ROSTableConstructor.cxx | 18 ++++-----
 .../src/counters/CounterROS.cxx               | 17 ++++-----
 .../TrigDataAccessMonitoring/ROBDataMonitor.h | 37 +++++++------------
 .../src/ROBDataMonitor.cxx                    | 23 +++---------
 .../test/Methods_test.cxx                     |  4 +-
 .../TrigCostMonitor/src/TrigNtRobsTool.cxx    |  4 +-
 .../TrigCostMonitorMT/src/TrigCostMTSvc.cxx   |  6 +--
 .../TrigSteerMonitor/src/TrigROBMoni.cxx      |  9 ++---
 9 files changed, 47 insertions(+), 75 deletions(-)

diff --git a/HLT/Trigger/TrigControl/TrigServices/src/HltROBDataProviderSvc.cxx b/HLT/Trigger/TrigControl/TrigServices/src/HltROBDataProviderSvc.cxx
index 8d12be750c08..28075fa455a1 100644
--- a/HLT/Trigger/TrigControl/TrigServices/src/HltROBDataProviderSvc.cxx
+++ b/HLT/Trigger/TrigControl/TrigServices/src/HltROBDataProviderSvc.cxx
@@ -405,10 +405,10 @@ void HltROBDataProviderSvc::getROBData(const EventContext& context,
     std::set<uint32_t> robIds_disabled;
     eventCache_checkRobListToCache(cache, robIds, robFragments, robIds_missing, robIds_disabled);
 
-    // Fill disabled ROBs
+    // Fill undefined (not enabled) ROBs
     for (uint32_t robId : robIds_disabled) {
         monitorData.requested_ROBs[robId] = robmonitor::ROBDataStruct(robId);
-        monitorData.requested_ROBs[robId].rob_history = robmonitor::DISABLED;
+        monitorData.requested_ROBs[robId].rob_history = robmonitor::UNDEFINED;
     }
   }
   else {
diff --git a/Trigger/TrigCost/TrigCostAnalysis/Root/TableConstructors/ROSTableConstructor.cxx b/Trigger/TrigCost/TrigCostAnalysis/Root/TableConstructors/ROSTableConstructor.cxx
index 526594b4003b..2f105b715f11 100644
--- a/Trigger/TrigCost/TrigCostAnalysis/Root/TableConstructors/ROSTableConstructor.cxx
+++ b/Trigger/TrigCost/TrigCostAnalysis/Root/TableConstructors/ROSTableConstructor.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "../../TrigCostAnalysis/TableConstructors/ROSTableConstructor.h"
@@ -24,12 +24,11 @@ ROSTableConstructor::ROSTableConstructor(const std::string& name) : TableConstru
   getBaseEntry().addColumn("cachedSizeRate", "Cached ROB Data Rate [kB/s]", "Amount of cached data requested from the ROBs in kB/s.");
   getBaseEntry().addColumn("time", "Time Per Event [ms]", "Average time for all requests and retrievals per event.");
   getBaseEntry().addColumn("robsUnclassified", "Unclassified ROBs/Event", "ROB calls which were flagged unclassified.");
-  getBaseEntry().addColumn("robsScheduled", "Prefetched ROBs/Event", "ROB calls which were flagged as prefetched.");
   getBaseEntry().addColumn("robsRetrieved","Retrieved ROBs/Event","Total number of fetched ROB calls.");
   getBaseEntry().addColumn("robsHLTCached","Cached HLT ROBs/Event","Total number of HLT cached ROB calls.");
   getBaseEntry().addColumn("robsDCMCached","Cached DCM ROBs/Event","Total number of DCM cached ROB calls.");
   getBaseEntry().addColumn("robsIgnored", "Ignored ROBs/Event", "ROB calls which were flagged as ignored.");
-  getBaseEntry().addColumn("robsDisabled", "Disabled ROBs/Event", "ROB calls which were flagged as disabled.");
+  getBaseEntry().addColumn("robsUndefined", "Undefined ROBs/Event", "ROB calls which were not enabled.");
   getBaseEntry().addColumn("robsNotOk","Not OK ROBs/Event", "ROB calls in which the is OK bit was false.");
 
 }
@@ -48,13 +47,12 @@ TableEntry ROSTableConstructor::getTableEntry(const std::string name) {
   tableEntry.setEntry("time", hist("Time_perEvent")->GetMean());
 
   tableEntry.setEntry("robsUnclassified", hist("ROBStatus_perCall")->GetBinContent(1));
-  tableEntry.setEntry("robsScheduled", hist("ROBStatus_perCall")->GetBinContent(2));
-  tableEntry.setEntry("robsRetrieved", hist("ROBStatus_perCall")->GetBinContent(3));
-  tableEntry.setEntry("robsHLTCached", hist("ROBStatus_perCall")->GetBinContent(4));
-  tableEntry.setEntry("robsDCMCached", hist("ROBStatus_perCall")->GetBinContent(5));
-  tableEntry.setEntry("robsIgnored", hist("ROBStatus_perCall")->GetBinContent(6));
-  tableEntry.setEntry("robsDisabled", hist("ROBStatus_perCall")->GetBinContent(7)); 
-  tableEntry.setEntry("robsNotOk", hist("ROBStatus_perCall")->GetBinContent(8)); 
+  tableEntry.setEntry("robsRetrieved", hist("ROBStatus_perCall")->GetBinContent(2));
+  tableEntry.setEntry("robsHLTCached", hist("ROBStatus_perCall")->GetBinContent(3));
+  tableEntry.setEntry("robsDCMCached", hist("ROBStatus_perCall")->GetBinContent(4));
+  tableEntry.setEntry("robsIgnored", hist("ROBStatus_perCall")->GetBinContent(5));
+  tableEntry.setEntry("robsUndefined", hist("ROBStatus_perCall")->GetBinContent(6)); 
+  tableEntry.setEntry("robsNotOk", hist("ROBStatus_perCall")->GetBinContent(7)); 
 
   return tableEntry;
 }
diff --git a/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterROS.cxx b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterROS.cxx
index 1a165d64cb59..ba5e8bd35185 100644
--- a/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterROS.cxx
+++ b/Trigger/TrigCost/TrigCostAnalysis/src/counters/CounterROS.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "xAODTrigger/TrigCompositeContainer.h"
@@ -29,7 +29,7 @@ StatusCode CounterROS::newEvent(const CostData& data, size_t index, const float
   const std::vector<uint32_t> robIdsPerRequest = tc->getDetail<std::vector<uint32_t>>("robs_id");
   const std::vector<uint32_t> robs_size = tc->getDetail<std::vector<uint32_t>>("robs_size");
   const std::vector<unsigned> robs_history = tc->getDetail<std::vector<unsigned>>("robs_history");
-  const std::vector<uint8_t> robs_status = tc->getDetail<std::vector<uint8_t>>("robs_status");
+  const std::vector<unsigned short> robs_status = tc->getDetail<std::vector<unsigned short>>("robs_status");
 
   if (m_robIdsPerROS.size() == 0) {
     m_robIdsPerROS = data.rosToRobMap().at(getName());
@@ -72,24 +72,21 @@ StatusCode CounterROS::newEvent(const CostData& data, size_t index, const float
 int CounterROS::getROBHistoryBin(const unsigned history){
   int history_bin;
   switch (history) {
-    case robmonitor::SCHEDULED:
+    case robmonitor::RETRIEVED:
       history_bin = 1;
       break;
-    case robmonitor::RETRIEVED:
+    case robmonitor::HLT_CACHED:
       history_bin = 2;
       break;
-    case robmonitor::HLT_CACHED:
+    case robmonitor::DCM_CACHED:
       history_bin = 3;
       break;
-    case robmonitor::DCM_CACHED:
+    case robmonitor::IGNORED:
       history_bin = 4;
       break;
-    case robmonitor::IGNORED:
+    case robmonitor::UNDEFINED:
       history_bin = 5;
       break;
-    case robmonitor::DISABLED:
-      history_bin = 6;
-      break;
     default: // UNCLASSIFIED 
       history_bin = 0;
       break;
diff --git a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/TrigDataAccessMonitoring/ROBDataMonitor.h b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/TrigDataAccessMonitoring/ROBDataMonitor.h
index 013709a34f01..6408390abd30 100644
--- a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/TrigDataAccessMonitoring/ROBDataMonitor.h
+++ b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/TrigDataAccessMonitoring/ROBDataMonitor.h
@@ -1,7 +1,7 @@
 //Dear emacs, this is -*- c++ -*-
 
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 
@@ -25,13 +25,12 @@ namespace robmonitor {
    */
   enum ROBHistory { 
     UNCLASSIFIED      = 0,  // ROB was requested but never arrived at processor. History unknown. 
-    SCHEDULED         = 1,  // ROB was scheduled before retrieveing
-    RETRIEVED         = 2,  // ROB was retrieved from ROS by DataCollector
-    HLT_CACHED        = 4,  // ROB was found already in the internal cache of the ROBDataProviderSvc
-    DCM_CACHED        = 8,  // ROB was found already in the internal cache of the DCM
-    IGNORED           = 16,  // ROB was on the "ignore" list and therefore not retrieved 
-    DISABLED          = 32,  // ROB was disabled in OKS and therefore not retrieved
-    NUM_ROBHIST_CODES = 7   // number of different history codes
+    RETRIEVED         = 1,  // ROB was retrieved from ROS by DataCollector
+    HLT_CACHED        = 2,  // ROB was found already in the internal cache of the ROBDataProviderSvc
+    DCM_CACHED        = 4,  // ROB was found already in the internal cache of the DCM
+    IGNORED           = 8,  // ROB was on the "ignore" list and therefore not retrieved 
+    UNDEFINED         = 16, // ROB was not on the "enabled" list, should not happen
+    NUM_ROBHIST_CODES = 6   // number of different history codes
   };
 
   /**
@@ -66,10 +65,8 @@ namespace robmonitor {
     bool isRetrieved() const;
     /** @brief ROB was ignored */
     bool isIgnored() const;
-    /** @brief ROB was disabled in OKS */
-    bool isDisabled() const;
-    /** @brief ROB was scheduled over network */
-    bool isScheduled() const;
+    /** @brief ROB was not enabled */
+    bool isUndefined() const;
     /** @brief ROB has no status words set */
     bool isStatusOk() const;
 
@@ -134,10 +131,8 @@ namespace robmonitor {
     unsigned retrievedROBs() const;
     /** @brief number of ignored ROBs in structure */
     unsigned ignoredROBs() const;
-    /** @brief number of disabled ROBs in structure */
-    unsigned disabledROBs() const;
-    /** @brief number of scheduled ROBs in structure */
-    unsigned scheduledROBs() const;
+    /** @brief number of undefined ROBs in structure */
+    unsigned undefinedROBs() const;
     /** @brief number of ROBs with no status words set in structure */
     unsigned statusOkROBs() const;
 
@@ -165,11 +160,8 @@ namespace robmonitor {
       os << "DCM_CACHED";
     }else if (rhs.rob_history == robmonitor::IGNORED) {
       os << "IGNORED";
-    } else if (rhs.rob_history == robmonitor::DISABLED) {
-      os << "DISABLED";
-   } else if (rhs.rob_history == robmonitor::SCHEDULED) {
-      os << "SCHEDULED";
-
+    } else if (rhs.rob_history == robmonitor::UNDEFINED) {
+      os << "UNDEFINED";
     } else {
       os << "invalid code";
     }
@@ -207,8 +199,7 @@ namespace robmonitor {
     os << "\n" << prefix << prefix2 << "DCM Cached   " << rhs.DCMcachedROBs()    ;
     os << "\n" << prefix << prefix2 << "Retrieved    " << rhs.retrievedROBs()    ;
     os << "\n" << prefix << prefix2 << "Ignored      " << rhs.ignoredROBs()      ;
-    os << "\n" << prefix << prefix2 << "Disabled     " << rhs.disabledROBs()     ;
-    os << "\n" << prefix << prefix2 << "Scheduled     " << rhs.scheduledROBs()     ;
+    os << "\n" << prefix << prefix2 << "Undefined    " << rhs.undefinedROBs()    ;
     os << "\n" << prefix << prefix2 << "Status OK    " << rhs.statusOkROBs()     ;
     for (std::map<const uint32_t,robmonitor::ROBDataStruct>::const_iterator it=rhs.requested_ROBs.begin();
 	 it != rhs.requested_ROBs.end(); ++it) {
diff --git a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/src/ROBDataMonitor.cxx b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/src/ROBDataMonitor.cxx
index aa4d0091af71..ca09012dd9e4 100644
--- a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/src/ROBDataMonitor.cxx
+++ b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/src/ROBDataMonitor.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #include <functional>
@@ -45,12 +45,8 @@ bool ROBDataStruct::isIgnored() const {
   return ((rob_history == robmonitor::IGNORED) ? true : false);
 }
 
-bool ROBDataStruct::isDisabled() const {
-  return ((rob_history == robmonitor::DISABLED) ? true : false);
-}
-
-bool ROBDataStruct::isScheduled() const {
-  return ((rob_history == robmonitor::SCHEDULED) ? true : false);
+bool ROBDataStruct::isUndefined() const {
+  return ((rob_history == robmonitor::UNDEFINED) ? true : false);
 }
 
 bool ROBDataStruct::isStatusOk() const {
@@ -139,20 +135,11 @@ unsigned ROBDataMonitorStruct::ignoredROBs() const {
   return ret;
 }
 
-unsigned ROBDataMonitorStruct::disabledROBs() const {
-  ptrdiff_t ret=0;
-  for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::const_iterator it = requested_ROBs.begin();
-        it != requested_ROBs.end(); it++ ) {
-    if ((*it).second.isDisabled()) ++ret;
-  }     
-  return ret;
-}
-
-unsigned ROBDataMonitorStruct::scheduledROBs() const {
+unsigned ROBDataMonitorStruct::undefinedROBs() const {
   ptrdiff_t ret=0;
   for ( std::map<const uint32_t,robmonitor::ROBDataStruct>::const_iterator it = requested_ROBs.begin();
         it != requested_ROBs.end(); it++ ) {
-    if ((*it).second.isScheduled()) ++ret;
+    if ((*it).second.isUndefined()) ++ret;
   }     
   return ret;
 }
diff --git a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/test/Methods_test.cxx b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/test/Methods_test.cxx
index d9236ae10dce..c870186dd3ed 100644
--- a/Trigger/TrigDataAccess/TrigDataAccessMonitoring/test/Methods_test.cxx
+++ b/Trigger/TrigDataAccess/TrigDataAccessMonitoring/test/Methods_test.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #include <iostream>
@@ -34,7 +34,7 @@ int main() {
   r.rob_history = robmonitor::RETRIEVED;
   r.rob_status_word = 0x04;
   ROBDataStruct d(0x730001);
-  d.rob_history = robmonitor::DISABLED;
+  d.rob_history = robmonitor::UNDEFINED;
 
   // fill ROBDataMonitorStruct with ROB requests
   req.requested_ROBs[u.rob_id]  = u;
diff --git a/Trigger/TrigMonitoring/TrigCostMonitor/src/TrigNtRobsTool.cxx b/Trigger/TrigMonitoring/TrigCostMonitor/src/TrigNtRobsTool.cxx
index 6020ce543ddf..adf178e8a0fc 100644
--- a/Trigger/TrigMonitoring/TrigCostMonitor/src/TrigNtRobsTool.cxx
+++ b/Trigger/TrigMonitoring/TrigCostMonitor/src/TrigNtRobsTool.cxx
@@ -203,7 +203,7 @@ for(unsigned int i = 0; i < m_config->size<TrigConfSeq>(); ++i) {
       if(data.rob_history==robmonitor::RETRIEVED)    myhist = TrigMonROBData::kRETRIEVED;
       if(data.rob_history==robmonitor::HLT_CACHED)   myhist = TrigMonROBData::kCACHED;
       if(data.rob_history==robmonitor::IGNORED)      myhist = TrigMonROBData::kIGNORED;
-      if(data.rob_history==robmonitor::DISABLED)     myhist = TrigMonROBData::kDISABLED;
+      if(data.rob_history==robmonitor::UNDEFINED)     myhist = TrigMonROBData::kDISABLED;
 
       TrigMonROBData mydata(data.rob_id, data.rob_size);
       mydata.setHistory(myhist);
@@ -369,7 +369,7 @@ void Trig::TrigNtRobsTool::CheckROB(const TrigMonROB &data,
     if(robData.rob_history==robmonitor::RETRIEVED)    myhist = TrigMonROBData::kRETRIEVED;
     if(robData.rob_history==robmonitor::HLT_CACHED)   myhist = TrigMonROBData::kCACHED;
     if(robData.rob_history==robmonitor::IGNORED)      myhist = TrigMonROBData::kIGNORED;
-    if(robData.rob_history==robmonitor::DISABLED)     myhist = TrigMonROBData::kDISABLED;
+    if(robData.rob_history==robmonitor::UNDEFINED)     myhist = TrigMonROBData::kDISABLED;
     
     Tmp::RobSum &sum = sum_robs[myhist];
     
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
index eaa48f77932f..da12a0d07be5 100644
--- a/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "GaudiKernel/ConcurrencyFlags.h"
@@ -364,7 +364,7 @@ StatusCode TrigCostMTSvc::endEvent(const EventContext& context, SG::WriteHandle<
       std::vector<uint32_t> robs_id;
       std::vector<uint32_t> robs_size;
       std::vector<unsigned> robs_history;
-      std::vector<uint8_t> robs_status;
+      std::vector<unsigned short> robs_status;
 
       robs_id.reserve(robData.requested_ROBs.size());
       robs_size.reserve(robData.requested_ROBs.size());
@@ -384,7 +384,7 @@ StatusCode TrigCostMTSvc::endEvent(const EventContext& context, SG::WriteHandle<
       result &= tc->setDetail<std::vector<uint32_t>>("robs_id", robs_id);
       result &= tc->setDetail<std::vector<uint32_t>>("robs_size", robs_size);
       result &= tc->setDetail<std::vector<unsigned>>("robs_history", robs_history);
-      result &= tc->setDetail<std::vector<uint8_t>>("robs_status", robs_status);
+      result &= tc->setDetail<std::vector<unsigned short>>("robs_status", robs_status);
       result &= tc->setDetail("start", robData.start_time);
       result &= tc->setDetail("stop", robData.end_time);
 
diff --git a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigROBMoni.cxx b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigROBMoni.cxx
index afa020b905ae..4193e2343a0f 100644
--- a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigROBMoni.cxx
+++ b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigROBMoni.cxx
@@ -62,11 +62,10 @@ TrigROBMoni::TrigROBMoni(const std::string& type,
 
   // Bin assignment for ROB history
   m_ROBHistoryToBin[robmonitor::UNCLASSIFIED] = 1;
-  m_ROBHistoryToBin[robmonitor::SCHEDULED]    = 2;
-  m_ROBHistoryToBin[robmonitor::RETRIEVED]    = 3;
-  m_ROBHistoryToBin[robmonitor::HLT_CACHED]   = 4;
-  m_ROBHistoryToBin[robmonitor::IGNORED]      = 5;
-  m_ROBHistoryToBin[robmonitor::DISABLED]     = 6;
+  m_ROBHistoryToBin[robmonitor::RETRIEVED]    = 2;
+  m_ROBHistoryToBin[robmonitor::HLT_CACHED]   = 3;
+  m_ROBHistoryToBin[robmonitor::IGNORED]      = 4;
+  m_ROBHistoryToBin[robmonitor::UNDEFINED]    = 5;
 
 }
 
-- 
GitLab