From 72360c0fcf9fd4e7733ebf0ffd9bea069ee6596a Mon Sep 17 00:00:00 2001
From: Simon Spannagel <simon.spannagel@cern.ch>
Date: Wed, 16 Nov 2022 19:37:07 +0100
Subject: [PATCH] Attempt to resolve signed/unsigned mixups

---
 .../EventLoaderALiBaVa/ALiBaVa/AsciiRoot.cpp  |  5 +-
 .../EventLoaderALiBaVa/ALiBaVa/AsciiRoot.h    |  8 +--
 .../ALiBaVa/DataFileRoot.cpp                  | 36 ++++++-------
 .../EventLoaderALiBaVa/ALiBaVa/DataFileRoot.h | 53 ++++++++++---------
 .../EventLoaderALiBaVa/ALiBaVa/HDFRoot.cpp    |  8 +--
 .../EventLoaderALiBaVa/ALiBaVa/HDFRoot.h      |  2 +-
 .../EventLoaderALiBaVa/EventLoaderALiBaVa.cpp |  2 +-
 7 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.cpp b/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.cpp
index 9d555498b..2c7b3b276 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.cpp
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.cpp
@@ -20,8 +20,9 @@ struct AsciiRootPriv {
 };
 
 // decodes the header and returns a vector with the integers found
-std::vector<int> decode_header(const std::string& h, AsciiRoot::XtraValues& xtra) {
-    std::vector<int> vout;
+std::vector<unsigned int> decode_header(const std::string& h, AsciiRoot::XtraValues& xtra);
+std::vector<unsigned int> decode_header(const std::string& h, AsciiRoot::XtraValues& xtra) {
+    std::vector<unsigned int> vout;
     std::istringstream istr(h);
     char* endptr;
     char buf[256];
diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.h b/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.h
index 038cbcbca..618057a22 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.h
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/AsciiRoot.h
@@ -16,8 +16,8 @@ public:
 
 private:
     AsciiRootPriv* priv;
-    unsigned long data_start;
-    unsigned long saved_state;
+    long data_start;
+    long saved_state;
     XtraValues _xtra; // extra values from header
 
 public:
@@ -43,8 +43,8 @@ public:
 
     void get_scan_values(short& delay, short& charge);
 
-    int nxtra() const { return _xtra.size(); }
-    const std::string xtra(int i) const { return _xtra[i]; }
+    size_t nxtra() const { return _xtra.size(); }
+    const std::string xtra(size_t i) const { return _xtra[i]; }
     void add_xtra(const std::string& x) { _xtra.push_back(x); }
     void add_xtra(const char* x) { _xtra.push_back(x); }
 };
diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.cpp b/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.cpp
index abf3ce866..1a6cdb5d7 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.cpp
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.cpp
@@ -44,12 +44,12 @@ void _A_got_intr(int) {
     _A_do_run = false;
 }
 
-DataFileRoot::DataFileRoot(const char* nam, const char* pedfile, const char* gainfile)
-    : _nchan(max_nchan), _seedcut(5.), _neighcut(3.), _average_gain(1.), _version(2), _polarity(1), _t1(0.0), _t2(99999.),
+DataFileRoot::DataFileRoot(const char*, const char* pedfile, const char*)
+    : _nchan(MAX_NCHAN), _seedcut(5.), _neighcut(3.), _average_gain(1.), _version(2), _polarity(1), _t1(0.0), _t2(99999.),
       _roi({}) {
     int i;
 
-    for(i = 0; i < max_nchan; i++) {
+    for(i = 0; i < MAX_NCHAN; i++) {
         _ped[i] = 0.;
         _gain[i] = 1.;
         _noise[i] = 1.;
@@ -106,10 +106,10 @@ bool DataFileRoot::valid_time(double tim) const {
 void DataFileRoot::compute_pedestals_alternative() {
     int mxevts = 10000000;
 
-    int i, ievt;
-    std::vector<double> pedestal_data[max_nchan];
-    double pedestal_average[max_nchan];
-    double pedestal_stdev[max_nchan];
+    int ievt;
+    std::vector<double> pedestal_data[MAX_NCHAN];
+    double pedestal_average[MAX_NCHAN];
+    double pedestal_stdev[MAX_NCHAN];
 
     if(!valid())
         return;
@@ -142,17 +142,16 @@ void DataFileRoot::compute_pedestals_alternative() {
 
 void DataFileRoot::compute_cmmd_alternative() {
     int mxevts = 10000000;
-    int max_nchan = _nchan; // was 128 originally
     int nEvents = 0;
 
-    int i, ievt;
+    int ievt;
 
     double event_bias = 0; // common mode noise per pedestal events
     double cmn = 0;        // common mode noise averaged over all pedestal events
 
-    std::vector<double> corrected_pedestal_data[max_nchan];
-    double pedestal_average[max_nchan];
-    double pedestal_stdev[max_nchan];
+    std::vector<double> corrected_pedestal_data[MAX_NCHAN];
+    double pedestal_average[MAX_NCHAN];
+    double pedestal_stdev[MAX_NCHAN];
 
     if(!valid())
         return;
@@ -215,7 +214,7 @@ void DataFileRoot::load_pedestals(const char* fnam, bool) {
     ifile >> _cmmd[0] >> std::ws;
 
     int i;
-    for(i = 0; i < max_nchan; i++) {
+    for(i = 0; i < MAX_NCHAN; i++) {
         if(ifile.eof())
             break;
 
@@ -227,16 +226,16 @@ void DataFileRoot::load_pedestals(const char* fnam, bool) {
 // This function processes the event, it subtracts pedestals and common mode from data
 // and fills in the signal/noise ratio
 
-void DataFileRoot::process_event(bool do_cmmd) {
-    for(int i : _roi) {
+void DataFileRoot::process_event(bool) {
+    for(auto i : _roi) {
         _signal[i] = (_data.data[i] - _ped[i] - _cmmd_roi) * _polarity;
         _sn[i] = _signal[i] / _noise[i];
     }
 }
 
 void DataFileRoot::calc_common_mode_signal() {
-    int ip, i, n;
-    double mean, st_dev, sig, signal_square, signal_sum, tmp;
+    int ip, n;
+    double mean = 0, st_dev = 0, sig, signal_square, signal_sum, tmp;
     bool use_it;
 
     // Iterate common mode calculation three times to get better result
@@ -244,7 +243,7 @@ void DataFileRoot::calc_common_mode_signal() {
         n = 0;
         signal_square = signal_sum = 0;
         // Use only channels in ROI
-        for(int i : _roi) {
+        for(auto i : _roi) {
             use_it = true;
             sig = _data.data[i] - _ped[i];
             // In first iteration of calculation, mean is not defined -> Use
@@ -301,5 +300,4 @@ DataFileRoot* DataFileRoot::OpenFile(const char* nam, const char* pedfile, const
         return new HDFRoot(nam, pedfile, gainfile);
     else
         return new AsciiRoot(nam, pedfile, gainfile);
-
 }
diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.h b/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.h
index d018a4d9f..267ede406 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.h
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/DataFileRoot.h
@@ -9,6 +9,9 @@
 #include <TH2.h>
 #include <ctime>
 
+// maximum number of channels
+#define MAX_NCHAN 256
+
 /**
  * class DataFileRoot
  *
@@ -21,34 +24,32 @@ public:
     enum RunType { UnknownRun = 0, Calibration = 1, LaserSync, Laser, RadSource, Pedestal, ChargeScan, LastRType };
 
 protected: // This is ugly but comfortable
-    static const int max_nchan = 256;
-
     RunType _type;
     time_t _t0;
     int _nchips;
     int _chip_mask;
     int _firmware;
     ScanType _scantype;
-    int _npoints;
-    int _from;
-    int _to;
-    int _step;
-    int _nevts;
+    unsigned int _npoints;
+    unsigned int _from;
+    unsigned int _to;
+    unsigned int _step;
+    unsigned int _nevts;
     int _charge;
     int _delay;
     int _nchan; // current number of channels
     double _seedcut;
     double _neighcut;
     unsigned short _header[2][16];
-    double _ped[max_nchan];
-    double _noise[max_nchan];
-    double _signal[max_nchan];
-    double _sn[max_nchan];
+    double _ped[MAX_NCHAN];
+    double _noise[MAX_NCHAN];
+    double _signal[MAX_NCHAN];
+    double _sn[MAX_NCHAN];
     double _cmmd[2];
     double _cnoise[2];
-    double _gain[max_nchan];
+    double _gain[MAX_NCHAN];
     double _average_gain;
-    bool _mask[max_nchan];
+    bool _mask[MAX_NCHAN];
     int _version;
     int _polarity;
     double _t1, _t2;
@@ -155,11 +156,11 @@ public:
      */
     virtual int read_data() = 0;
 
-    virtual void check_point(int, const char*){};
-    virtual void new_file(int, const char*) {}
-    virtual void start_of_run(int, const char*) {}
-    virtual void end_of_run(int, const char*) {}
-    virtual void new_data_block(int, const char*){};
+    virtual void check_point(unsigned int, const char*){};
+    virtual void new_file(unsigned int, const char*) {}
+    virtual void start_of_run(unsigned int, const char*) {}
+    virtual void end_of_run(unsigned int, const char*) {}
+    virtual void new_data_block(unsigned int, const char*){};
 
     // The data format version
     int version() const { return _version; }
@@ -180,32 +181,32 @@ public:
     char* date() const { return ctime(&_t0); }
 
     // returns the pedestal value of channel i
-    double ped(int i) const { return _ped[i]; }
+    double ped(unsigned int i) const { return _ped[i]; }
 
     // returns the noise value of channel i
 
-    double noise(int i) const { return _noise[i]; }
+    double noise(unsigned int i) const { return _noise[i]; }
 
     // returns the signal over noise ratio of channel i
-    double sn(int i) const { return _sn[i]; }
+    double sn(unsigned int i) const { return _sn[i]; }
 
     // returns the common mode  of chip i
-    double get_cmmd(int i) const { return _cmmd[i]; }
+    double get_cmmd(unsigned int i) const { return _cmmd[i]; }
 
     // returns the common mode noise of chip i
-    double get_cnoise(int i) const { return _cnoise[i]; }
+    double get_cnoise(unsigned int i) const { return _cnoise[i]; }
 
     /*
      * Event specific information
      */
 
     // returns the raw data of channel i
-    unsigned short data(int i) const { return _data.data[i]; }
+    unsigned short data(unsigned int i) const { return _data.data[i]; }
 
     // returns the signal value of channel i
-    double signal(int i) const { return _signal[i] / _gain[i]; }
+    double signal(unsigned int i) const { return _signal[i] / _gain[i]; }
 
-    double ADC_signal(int i) const { return _signal[i]; }
+    double ADC_signal(unsigned int i) const { return _signal[i]; }
 
     // return the scan value
     double value() const { return _data.value; }
diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.cpp b/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.cpp
index 4383f4d28..76fb3b935 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.cpp
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.cpp
@@ -13,11 +13,11 @@
 #endif
 #endif
 
+#include <ctime>
+#include <hdf5.h>
 #include <iostream>
 #include "HDFRoot.h"
 #include "core/utils/log.h"
-#include <ctime>
-#include <hdf5.h>
 
 struct ScanDef {
     enum ScanTypes { Unknown, Charge, Time, Laser };
@@ -124,7 +124,7 @@ bool HDFRoot::valid() const {
     return priv->fileid != H5I_BADID;
 }
 
-int HDFRoot::nevents() const {
+unsigned int HDFRoot::nevents() const {
     return priv->nevts;
 }
 
@@ -316,7 +316,7 @@ int HDFRoot::read_event() {
         // return rc;
         return 4;
 
-    int ij = 0, nm = 0;
+    int ij = 0;
     for(int ichip = 0; ichip < _nchips; ichip++) {
         for(int ih = 0; ih < 16; ih++, ij++)
             _header[ichip][ih] = priv->data.header[ij];
diff --git a/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.h b/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.h
index 813901f53..552a96767 100644
--- a/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.h
+++ b/src/modules/EventLoaderALiBaVa/ALiBaVa/HDFRoot.h
@@ -23,7 +23,7 @@ public:
     virtual ~HDFRoot();
 
     bool valid() const;
-    int nevents() const;
+    unsigned int nevents() const;
     void open(const char* name);
     void close();
     void rewind();
diff --git a/src/modules/EventLoaderALiBaVa/EventLoaderALiBaVa.cpp b/src/modules/EventLoaderALiBaVa/EventLoaderALiBaVa.cpp
index 7953e7a44..a8b71f304 100644
--- a/src/modules/EventLoaderALiBaVa/EventLoaderALiBaVa.cpp
+++ b/src/modules/EventLoaderALiBaVa/EventLoaderALiBaVa.cpp
@@ -8,12 +8,12 @@
  * Intergovernmental Organization or submit itself to any jurisdiction.
  */
 
+#include "EventLoaderALiBaVa.h"
 #include <TCanvas.h>
 #include <TH1F.h>
 #include <TH2F.h>
 #include <TProfile.h>
 #include <dirent.h>
-#include "EventLoaderALiBaVa.h"
 
 using namespace corryvreckan;
 
-- 
GitLab