From a5f5574da72d23ce94e6e921954181008e751950 Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Mon, 22 Jun 2026 10:39:46 -0500
Subject: [PATCH 1/6] Added new reco table for Calorimeter baselines and new
 archive table for time calibration with cosmics

---
 DbTables/inc/CalBaselines.hh       | 73 +++++++++++++++++++++++++++
 DbTables/inc/CalCosmicTimeCalib.hh | 81 ++++++++++++++++++++++++++++++
 2 files changed, 154 insertions(+)
 create mode 100644 DbTables/inc/CalBaselines.hh
 create mode 100644 DbTables/inc/CalCosmicTimeCalib.hh

diff --git a/DbTables/inc/CalBaselines.hh b/DbTables/inc/CalBaselines.hh
new file mode 100644
index 0000000000..1111659b87
--- /dev/null
+++ b/DbTables/inc/CalBaselines.hh
@@ -0,0 +1,73 @@
+#ifndef DbTables_CalBaselines_hh
+#define DbTables_CalBaselines_hh
+
+#include <string>
+#include <iomanip>
+#include <sstream>
+#include <map>
+#include "cetlib_except/exception.h"
+#include "Offline/DbTables/inc/DbTable.hh"
+#include "Offline/DataProducts/inc/CaloSiPMId.hh"
+
+namespace mu2e {
+
+  class CalBaselines : public DbTable {
+  public:
+  typedef std::shared_ptr<CalBaselines> ptr_t;
+  typedef std::shared_ptr<const CalBaselines> cptr_t;
+
+    class Row {
+    public:
+      Row(CaloSiPMId  roid, float baseline, float threshold):_roid(roid),_baseline(baseline),_threshold(threshold) {}
+      CaloSiPMId   roid() const { return _roid;}
+      float baseline() const { return _baseline; }
+      float threshold() const { return _threshold; }
+
+    private:
+      CaloSiPMId _roid;
+      float _baseline;
+      float _threshold;
+    };
+
+    constexpr static const char* cxname = "CalBaselines";
+
+    CalBaselines():DbTable(cxname,"cal.baselines","roid,baseline,threshold"){}
+
+    const Row& row(CaloSiPMId id) const {
+                return _rows[id.id()];
+    }
+    std::vector<Row> const& rows() const {return _rows;}
+    std::size_t nrow() const override { return _rows.size(); };
+    size_t size() const override { return baseSize() + nrow()*sizeof(Row); };
+    virtual std::size_t nrowFix() const override { return CaloConst::_nChannelDB; };
+    const std::string orderBy() const { return std::string("roid"); }
+
+    void addRow(const std::vector<std::string>& columns) override {
+      std::uint16_t index = std::stoul(columns[0]);
+    // enforce order, so channels can be looked up by index
+    if (index!=int(_rows.size())) {
+        throw cet::exception("CALOBASELINES_BAD_INDEX")<<"CalBaselines::addRow found index out of order:"<<index << " != " << int(_rows.size()) <<"\n";
+      }
+       _rows.emplace_back(CaloSiPMId(index),
+       std::stof(columns[1]),
+       std::stof(columns[2]));
+    }
+
+
+    void rowToCsv(std::ostringstream& sstream, std::size_t irow) const override {
+      Row const& r = _rows.at(irow);
+      sstream << std::fixed << std::setprecision(5);
+      sstream << r.roid()<<",";
+      sstream << r.baseline()<<",";
+      sstream << r.threshold();
+    }
+
+    virtual void clear() override { baseClear(); _rows.clear();}
+
+  private:
+    std::vector<Row> _rows;
+
+  };
+
+}
+#endif
diff --git a/DbTables/inc/CalCosmicTimeCalib.hh b/DbTables/inc/CalCosmicTimeCalib.hh
new file mode 100644
index 0000000000..5d8b1f5d42
--- /dev/null
+++ b/DbTables/inc/CalCosmicTimeCalib.hh
@@ -0,0 +1,81 @@
+#ifndef DbTables_CalCosmicTimeCalib_hh
+#define DbTables_CalCosmicTimeCalib_hh
+
+// calorimater archive table for time study from a cosmic ray run
+
+#include <string>
+#include <iomanip>
+#include <sstream>
+#include <map>
+#include "Offline/DbTables/inc/DbTable.hh"
+#include "Offline/DataProducts/inc/CaloSiPMId.hh"
+
+namespace mu2e {
+
+  class CalCosmicTimeCalib : public DbTable {
+    public:
+
+      class Row {
+        public:
+        Row(CaloSiPMId  roid, double T0, double ErrT0, double chisq, int nev):
+          _roid(roid),_T0(T0),_ErrT0(ErrT0),_chisq(chisq),_nev(nev) {}
+        CaloSiPMId       roid()     const { return _roid;} // Offline ID
+        float     T0()     const { return _T0; }
+        float     ErrT0()  const { return _ErrT0; }
+        float     chisq()     const { return _chisq; }
+        int       nev()     const { return _nev; }
+
+      private:
+        CaloSiPMId _roid;
+        float _T0;
+        float _ErrT0;
+        float _chisq;
+        int   _nev;
+    };
+
+    constexpr static const char* cxname = "CalCosmicTimeCalib";
+
+    CalCosmicTimeCalib():DbTable(cxname,"calocosmictimecalib",
+    "roid,t0,errt0,chisq,nev") {}
+
+    const Row& row(CaloSiPMId  roid) const {
+                return _rows.at(roid.id()); }
+    std::vector<Row> const& rows() const {return _rows;}
+    std::size_t nrow() const override { return _rows.size(); };
+    size_t size() const override { return baseSize() + nrow()*sizeof(Row); };
+    virtual std::size_t nrowFix() const override { return CaloConst::_nChannelDB; };
+    const std::string orderBy() const { return std::string("roid"); }
+    void addRow(const std::vector<std::string>& columns) override {
+      std::uint16_t index = std::stoul(columns[0]);
+    // enforce order, so channels can be looked up by index
+    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+        throw cet::exception("CalCosmicTimeCalib_BAD_INDEX")
+        << "CalCosmicTimeTable::addRow found index out of order: "
+        <<index<< " != " << _rows.size() <<"\n";
+      }
+      _rows.emplace_back(CaloSiPMId(index),
+      std::stof(columns[1]),
+      std::stof(columns[2]),
+      std::stof(columns[3]),
+      std::stoi(columns[4]));
+    }
+
+    void rowToCsv(std::ostringstream& sstream, std::size_t irow) const override {
+      Row const& r = _rows.at(irow);
+      sstream << std::fixed << std::setprecision(5);
+      sstream << r.roid()<<",";
+      sstream << r.T0()<<",";
+      sstream << r.ErrT0()<<",";
+      sstream << r.chisq()<<",";
+      sstream << r.nev();
+    }
+
+    virtual void clear() override { baseClear(); _rows.clear();}
+
+    private:
+      std::vector<Row> _rows;
+      //std::map<int,std::size_t> _chanIndex;
+  };
+
+}
+#endif

From 2c0ebf2906ac788f708375c43e93d7281e1ddfa1 Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Mon, 22 Jun 2026 10:43:21 -0500
Subject: [PATCH 2/6] Added tables in factory

---
 DbTables/src/DbTableFactory.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/DbTables/src/DbTableFactory.cc b/DbTables/src/DbTableFactory.cc
index 2e6bd545fe..51b30594cb 100644
--- a/DbTables/src/DbTableFactory.cc
+++ b/DbTables/src/DbTableFactory.cc
@@ -9,11 +9,13 @@
 #include "Offline/DbTables/inc/SimEfficiencies.hh"
 #include "Offline/DbTables/inc/SimEfficiencies2.hh"
 
+#include "Offline/DbTables/inc/CalBaselines.hh"
 #include "Offline/DbTables/inc/CalChannels.hh"
 #include "Offline/DbTables/inc/CalChannelStatus.hh"
 #include "Offline/DbTables/inc/CalSourceEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalCosmicEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalCosmicEnergyCalibInfo.hh"
+#include "Offline/DbTables/inc/CalCosmicTineCalib.hh"
 #include "Offline/DbTables/inc/CalCombinedEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalEnergyCalibInfo.hh"
 #include "Offline/DbTables/inc/CalLaserEnergyCalib.hh"
@@ -98,6 +100,8 @@ mu2e::DbTable::ptr_t mu2e::DbTableFactory::newTable(std::string const& name) {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CRVSiPM());
   } else if (name == "CRVTime") {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CRVTime());
+  }  else if (name=="CalBaselines") {
+    return std::shared_ptr<mu2e::DbTable>(new mu2e::CalBaselines());
   }  else if (name=="CalChannels") {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CalChannels());
   }  else if (name=="CalChannelStatus") {
@@ -108,6 +112,8 @@ mu2e::DbTable::ptr_t mu2e::DbTableFactory::newTable(std::string const& name) {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CalCosmicEnergyCalib());
   } else if (name=="CalCosmicEnergyCalibInfo") {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CalCosmicEnergyCalibInfo());
+  } else if (name=="CalCosmicTimeCalib") {
+    return std::shared_ptr<mu2e::DbTable>(new mu2e::CalCosmicTimeCalib());
   } else if (name=="CalLaserEnergyCalib") {
     return std::shared_ptr<mu2e::DbTable>(new mu2e::CalLaserEnergyCalib());
   } else if (name=="CalLaserTimeCalib") {

From b091f88e664434687e708d70f5cbc83253533b54 Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Tue, 23 Jun 2026 10:11:08 -0500
Subject: [PATCH 3/6] typo

---
 DbTables/src/DbTableFactory.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DbTables/src/DbTableFactory.cc b/DbTables/src/DbTableFactory.cc
index 51b30594cb..4cb0ab9fee 100644
--- a/DbTables/src/DbTableFactory.cc
+++ b/DbTables/src/DbTableFactory.cc
@@ -15,7 +15,7 @@
 #include "Offline/DbTables/inc/CalSourceEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalCosmicEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalCosmicEnergyCalibInfo.hh"
-#include "Offline/DbTables/inc/CalCosmicTineCalib.hh"
+#include "Offline/DbTables/inc/CalCosmicTimeCalib.hh"
 #include "Offline/DbTables/inc/CalCombinedEnergyCalib.hh"
 #include "Offline/DbTables/inc/CalEnergyCalibInfo.hh"
 #include "Offline/DbTables/inc/CalLaserEnergyCalib.hh"

From 8398fb7085e5e91aeaabdec06e76be6c5bdca05f Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Wed, 24 Jun 2026 09:41:06 -0500
Subject: [PATCH 4/6] fix typos

---
 DbTables/inc/CalCosmicTimeCalib.hh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/DbTables/inc/CalCosmicTimeCalib.hh b/DbTables/inc/CalCosmicTimeCalib.hh
index 5d8b1f5d42..f3cc5ad173 100644
--- a/DbTables/inc/CalCosmicTimeCalib.hh
+++ b/DbTables/inc/CalCosmicTimeCalib.hh
@@ -17,7 +17,7 @@ namespace mu2e {
 
       class Row {
         public:
-        Row(CaloSiPMId  roid, double T0, double ErrT0, double chisq, int nev):
+        Row(CaloSiPMId  roid, float T0, float ErrT0, float chisq, int nev):
           _roid(roid),_T0(T0),_ErrT0(ErrT0),_chisq(chisq),_nev(nev) {}
         CaloSiPMId       roid()     const { return _roid;} // Offline ID
         float     T0()     const { return _T0; }
@@ -35,7 +35,7 @@ namespace mu2e {
 
     constexpr static const char* cxname = "CalCosmicTimeCalib";
 
-    CalCosmicTimeCalib():DbTable(cxname,"calocosmictimecalib",
+    CalCosmicTimeCalib():DbTable(cxname,"cal.cosmictimecalib",
     "roid,t0,errt0,chisq,nev") {}
 
     const Row& row(CaloSiPMId  roid) const {
@@ -74,7 +74,6 @@ namespace mu2e {
 
     private:
       std::vector<Row> _rows;
-      //std::map<int,std::size_t> _chanIndex;
   };
 
 }

From 23f0df0cbc05cf3884e6385675719dac9393f4cf Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Mon, 29 Jun 2026 03:27:58 -0500
Subject: [PATCH 5/6] Align checks and vector operators according to copilot
 review

---
 DbTables/inc/CalBaselines.hh         | 4 ++--
 DbTables/inc/CalChannelStatus.hh     | 4 ++--
 DbTables/inc/CalChannels.hh          | 2 +-
 DbTables/inc/CalCosmicEnergyCalib.hh | 2 +-
 DbTables/inc/CalCosmicT0Align.hh     | 2 +-
 DbTables/inc/CalCosmicTimeCalib.hh   | 2 +-
 DbTables/inc/CalEnergyCalib.hh       | 4 ++--
 DbTables/inc/CalLaserEnergyCalib.hh  | 2 +-
 DbTables/inc/CalLaserTimeCalib.hh    | 2 +-
 DbTables/inc/CalSourceEnergyCalib.hh | 2 +-
 DbTables/inc/CalTimeCalib.hh         | 4 ++--
 11 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/DbTables/inc/CalBaselines.hh b/DbTables/inc/CalBaselines.hh
index 1111659b87..41385c92dc 100644
--- a/DbTables/inc/CalBaselines.hh
+++ b/DbTables/inc/CalBaselines.hh
@@ -34,7 +34,7 @@ namespace mu2e {
     CalBaselines():DbTable(cxname,"cal.baselines","roid,baseline,threshold"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows[id.id()];
+                return _rows.at(rawid.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
@@ -45,7 +45,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index!=int(_rows.size())) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOBASELINES_BAD_INDEX")<<"CalBaselines::addRow found index out of order:"<<index << " != " << int(_rows.size()) <<"\n";
       }
        _rows.emplace_back(CaloSiPMId(index),
diff --git a/DbTables/inc/CalChannelStatus.hh b/DbTables/inc/CalChannelStatus.hh
index 1f8d7248db..4c157db454 100644
--- a/DbTables/inc/CalChannelStatus.hh
+++ b/DbTables/inc/CalChannelStatus.hh
@@ -32,7 +32,7 @@ namespace mu2e {
     CalChannelStatus():DbTable(cxname,"cal.channelstatus","roid,status"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows[id.id()];
+                return _rows.at(rawid.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
@@ -43,7 +43,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index!=int(_rows.size())) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOCHANNELSTATUS_BAD_INDEX")<<"CalChannelStatus::addRow found index out of order:"<<index << " != " << int(_rows.size()) <<"\n";
       }
        _rows.emplace_back(CaloSiPMId(index),columns[1]);
diff --git a/DbTables/inc/CalChannels.hh b/DbTables/inc/CalChannels.hh
index b033371a11..278b605385 100644
--- a/DbTables/inc/CalChannels.hh
+++ b/DbTables/inc/CalChannels.hh
@@ -43,7 +43,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
       // enforce order, so channels can be looked up by index
-      if (index >= CaloConst::_nRawChannel  || index != _rows.size()) {
+      if (index >= CaloConst::_nRawChannel || index != _rows.size()) {
         throw cet::exception("CALOCHANNELS_BAD_INDEX")
         << "CalChannels::addRow found index out of order: "
         <<index<< " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalCosmicEnergyCalib.hh b/DbTables/inc/CalCosmicEnergyCalib.hh
index 768e49d4b1..771d33e0f1 100644
--- a/DbTables/inc/CalCosmicEnergyCalib.hh
+++ b/DbTables/inc/CalCosmicEnergyCalib.hh
@@ -66,7 +66,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOCOSMICCALIB_BAD_INDEX")
         << "CalCosmicEnergyCalib::addRow found index out of order: "
         <<index<< " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalCosmicT0Align.hh b/DbTables/inc/CalCosmicT0Align.hh
index ab6d4311f8..3282737fdc 100644
--- a/DbTables/inc/CalCosmicT0Align.hh
+++ b/DbTables/inc/CalCosmicT0Align.hh
@@ -51,7 +51,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALCOSMICT0ALIGN_BAD_INDEX")
         << "CalCosmicT0Align::addRow found index out of order: "
         <<index<< " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalCosmicTimeCalib.hh b/DbTables/inc/CalCosmicTimeCalib.hh
index f3cc5ad173..49b685c2dd 100644
--- a/DbTables/inc/CalCosmicTimeCalib.hh
+++ b/DbTables/inc/CalCosmicTimeCalib.hh
@@ -48,7 +48,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CalCosmicTimeCalib_BAD_INDEX")
         << "CalCosmicTimeTable::addRow found index out of order: "
         <<index<< " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalEnergyCalib.hh b/DbTables/inc/CalEnergyCalib.hh
index 66e4173fb4..fd22845f24 100644
--- a/DbTables/inc/CalEnergyCalib.hh
+++ b/DbTables/inc/CalEnergyCalib.hh
@@ -39,7 +39,7 @@ namespace mu2e {
     CalEnergyCalib():DbTable(cxname,"cal.energycalib","roid,adc2mev"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows[id.id()];
+                return _rows.at(rawid.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
@@ -50,7 +50,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index!=int(_rows.size())) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOENERGYCALIB_BAD_INDEX")<<"CalEnergyCalib::addRow found index out of order:"<<index << " != " << int(_rows.size()) <<"\n";
       }
        _rows.emplace_back(CaloSiPMId(index),std::stof(columns[1]));
diff --git a/DbTables/inc/CalLaserEnergyCalib.hh b/DbTables/inc/CalLaserEnergyCalib.hh
index 00044fb874..2b824172cb 100644
--- a/DbTables/inc/CalLaserEnergyCalib.hh
+++ b/DbTables/inc/CalLaserEnergyCalib.hh
@@ -43,7 +43,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOLaserEnergyCALIB_BAD_INDEX")
         << "CalLaserEnergyCalib::addRow found index out of order: "
         <<index<< " != " <<  _rows.size() <<"\n";
diff --git a/DbTables/inc/CalLaserTimeCalib.hh b/DbTables/inc/CalLaserTimeCalib.hh
index b064bcdf91..102c9e0bca 100644
--- a/DbTables/inc/CalLaserTimeCalib.hh
+++ b/DbTables/inc/CalLaserTimeCalib.hh
@@ -48,7 +48,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CalLaserTimeCalib_BAD_INDEX")
         << "CalLaserTimeTable::addRow found index out of order: "
         <<index<< " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalSourceEnergyCalib.hh b/DbTables/inc/CalSourceEnergyCalib.hh
index 92e940a545..3a56f5dd32 100644
--- a/DbTables/inc/CalSourceEnergyCalib.hh
+++ b/DbTables/inc/CalSourceEnergyCalib.hh
@@ -76,7 +76,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index >= CaloConst::_nChannelDB  || index != _rows.size()) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
       throw cet::exception("CALOSOURCECALIB_BAD_INDEX")
       << "CalSourceEnergyCalib::addRow found index out of order: "
       <<index << " != " << _rows.size() <<"\n";
diff --git a/DbTables/inc/CalTimeCalib.hh b/DbTables/inc/CalTimeCalib.hh
index 258d414f6a..3ce61779b2 100644
--- a/DbTables/inc/CalTimeCalib.hh
+++ b/DbTables/inc/CalTimeCalib.hh
@@ -39,7 +39,7 @@ namespace mu2e {
     CalTimeCalib():DbTable(cxname,"cal.timecalib","roid,tcorr"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows[id.id()];
+                return _rows.at(rawid.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
@@ -50,7 +50,7 @@ namespace mu2e {
     void addRow(const std::vector<std::string>& columns) override {
       std::uint16_t index = std::stoul(columns[0]);
     // enforce order, so channels can be looked up by index
-    if (index!=int(_rows.size())) {
+    if (index >= CaloConst::_nChannelDB || index != _rows.size()) {
         throw cet::exception("CALOTIMECALIB_BAD_INDEX")<<"CalTimeCalib::addRow found index out of order:"<<index << " != " << int(_rows.size()) <<"\n";
       }
        _rows.emplace_back(CaloSiPMId(index),std::stof(columns[1]));

From 4c37908adf7c323b7744d80c6b1a8574bf99bf10 Mon Sep 17 00:00:00 2001
From: Paolo Girotti <giro94@libero.it>
Date: Mon, 29 Jun 2026 04:08:05 -0500
Subject: [PATCH 6/6] typos

---
 DbTables/inc/CalBaselines.hh     | 2 +-
 DbTables/inc/CalChannelStatus.hh | 2 +-
 DbTables/inc/CalEnergyCalib.hh   | 2 +-
 DbTables/inc/CalTimeCalib.hh     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/DbTables/inc/CalBaselines.hh b/DbTables/inc/CalBaselines.hh
index 41385c92dc..5170878e41 100644
--- a/DbTables/inc/CalBaselines.hh
+++ b/DbTables/inc/CalBaselines.hh
@@ -34,7 +34,7 @@ namespace mu2e {
     CalBaselines():DbTable(cxname,"cal.baselines","roid,baseline,threshold"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows.at(rawid.id());
+                return _rows.at(id.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
diff --git a/DbTables/inc/CalChannelStatus.hh b/DbTables/inc/CalChannelStatus.hh
index 4c157db454..27913cc7e5 100644
--- a/DbTables/inc/CalChannelStatus.hh
+++ b/DbTables/inc/CalChannelStatus.hh
@@ -32,7 +32,7 @@ namespace mu2e {
     CalChannelStatus():DbTable(cxname,"cal.channelstatus","roid,status"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows.at(rawid.id());
+                return _rows.at(id.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
diff --git a/DbTables/inc/CalEnergyCalib.hh b/DbTables/inc/CalEnergyCalib.hh
index fd22845f24..63c12f518a 100644
--- a/DbTables/inc/CalEnergyCalib.hh
+++ b/DbTables/inc/CalEnergyCalib.hh
@@ -39,7 +39,7 @@ namespace mu2e {
     CalEnergyCalib():DbTable(cxname,"cal.energycalib","roid,adc2mev"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows.at(rawid.id());
+                return _rows.at(id.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
diff --git a/DbTables/inc/CalTimeCalib.hh b/DbTables/inc/CalTimeCalib.hh
index 3ce61779b2..be8ef20b37 100644
--- a/DbTables/inc/CalTimeCalib.hh
+++ b/DbTables/inc/CalTimeCalib.hh
@@ -39,7 +39,7 @@ namespace mu2e {
     CalTimeCalib():DbTable(cxname,"cal.timecalib","roid,tcorr"){}
 
     const Row& row(CaloSiPMId id) const {
-                return _rows.at(rawid.id());
+                return _rows.at(id.id());
     }
     std::vector<Row> const& rows() const {return _rows;}
     std::size_t nrow() const override { return _rows.size(); };
