From 2e7a659ec516b0187b133f0305f65dfffe1dc9dc Mon Sep 17 00:00:00 2001
From: Thomas Owen James <tom.james@cern.ch>
Date: Tue, 15 Aug 2023 14:21:01 +0200
Subject: [PATCH] New updates for hlt processing

---
 etc/scdaq/scdaq.conf               |   7 +-
 src/FRDFileHeader_v2.h             |   1 +
 src/OutputByOrbit.cc               |   7 +-
 src/OutputFile.h                   |   8 +-
 src/OutputFileHandler.cc           | 116 ++++++++++++++++++++---------
 src/OutputFileHandler.h            |  20 ++++-
 src/config.h                       |   2 +
 src/elastico.cc                    |   2 +-
 src/processor.cc                   |  16 ++--
 src/utility.h                      |   4 +-
 test/config/scdaq-calo-cmssw.conf  |   5 +-
 test/config/scdaq-calo.conf        |   5 +-
 test/config/scdaq-gmt-cmssw.conf   |   5 +-
 test/config/scdaq-gmt.conf         |   5 +-
 test/config/scdaq-micron-bril.conf |  12 ++-
 15 files changed, 148 insertions(+), 67 deletions(-)

diff --git a/etc/scdaq/scdaq.conf b/etc/scdaq/scdaq.conf
index 1394cc32..578ac784 100644
--- a/etc/scdaq/scdaq.conf
+++ b/etc/scdaq/scdaq.conf
@@ -121,8 +121,11 @@ nOrbitsPerFile:4096
 # Headers for cmssw support
 cmsswHeaders:no
 
-##  Information necessary to issue a reset request for the board
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
+## Information necessary to issue a reset request for the board
 scone_host:localhost
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:
diff --git a/src/FRDFileHeader_v2.h b/src/FRDFileHeader_v2.h
index 19620a4d..1770e999 100644
--- a/src/FRDFileHeader_v2.h
+++ b/src/FRDFileHeader_v2.h
@@ -18,6 +18,7 @@ class FRDFileHeader_v2 {
     lumiSection_ = lumiSection;
     fileSize_ = fileSize;
   }
+  uint32_t getFileSize() { return fileSize_; }
 
  private:
   std::array<unsigned char, 4> id_;
diff --git a/src/OutputByOrbit.cc b/src/OutputByOrbit.cc
index 89c1c7a2..be31356d 100644
--- a/src/OutputByOrbit.cc
+++ b/src/OutputByOrbit.cc
@@ -19,7 +19,8 @@ OutputByOrbitStream::OutputByOrbitStream(ctrl &c, config &conf_)
       control(c),
       conf(conf_),
       output_file_handler_(conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(),
-                           conf.getNOrbitsPerFile(), conf.getCMSSWHeaders(), conf.getSourceID()),
+                           conf.getHLTConfigPath(), conf.getNOrbitsPerFile(),
+                           conf.getCMSSWHeaders(), conf.getSourceID()),
       min_buffer_queue_size_(1000) {
   LOG(TRACE) << "Created output filter at " << static_cast<void *>(this);
 }
@@ -28,6 +29,9 @@ void OutputByOrbitStream::OutputFixedOrbits(Slice &out) {
   uint32_t orbitN = out.get_firstOrbitN();
   uint32_t index = uint32_t(orbitN / conf.getNOrbitsPerFile());
   size_t n = 0;
+  if (index == 0) {
+    LOG(DEBUG) << "index is 0";
+  }
   if (out.get_counts() == 0) {
     LOG(TRACE) << "got an empty slice ";
   }
@@ -37,6 +41,7 @@ void OutputByOrbitStream::OutputFixedOrbits(Slice &out) {
       n = fwrite(out.begin(), 1, out.size(),
                  output_file_handler_.getFile(control.run_number, index).getFilePtr());
       output_file_handler_.upFileSize(n);
+      output_file_handler_.upNOrbits(conf.getNOrbitsPerDMAPacket());
     } else if (output_file_handler_.hasFile()) {
       // the run has been stopped so drop but first check if there is a last
       // file to close
diff --git a/src/OutputFile.h b/src/OutputFile.h
index a0236b4d..f8e0288c 100644
--- a/src/OutputFile.h
+++ b/src/OutputFile.h
@@ -17,17 +17,18 @@
 class OutputFile {
  public:
   OutputFile(FILE* filePtr, std::string fileName, FRDFileHeader_v2 fileHeader, uint32_t lumisection,
-             uint32_t index)
+             uint32_t index, std::string rundir)
       : filePtr_(filePtr),
         fileName_(fileName),
         fileHeader_(fileHeader),
         lumisection_(lumisection),
-        index_(index) {}
+        index_(index),
+        rundir_(rundir) {}
   OutputFile() : filePtr_(NULL), fileName_(""), fileHeader_(0, 0, 0, 0, 0, 0) {}
   std::string getFileName() { return fileName_; }
   FILE* getFilePtr() { return filePtr_; }
   FRDFileHeader_v2 getFileHeader() { return fileHeader_; }
-
+  std::string getRunDir() { return rundir_; }
   bool writeFileHeader() {
     fseek(filePtr_, 0, SEEK_SET);
     size_t written = fwrite(&fileHeader_, 1, sizeof(fileHeader_), filePtr_);
@@ -62,6 +63,7 @@ class OutputFile {
   FRDFileHeader_v2 fileHeader_;
   uint32_t lumisection_;
   uint32_t index_;
+  std::string rundir_;
 };
 
 #endif
diff --git a/src/OutputFileHandler.cc b/src/OutputFileHandler.cc
index 0ab911b5..97b86ebe 100644
--- a/src/OutputFileHandler.cc
+++ b/src/OutputFileHandler.cc
@@ -25,31 +25,47 @@ void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() {
       outputFile_.writeFileHeader();
     }
     ls_file_size_ += file_size_;
-    files_to_close_.push(outputFile_);
+    ls_NOrbits_ += NOrbits_;
+    if (outputFile_.getFileHeader().getFileSize() > 32) {
+      files_to_close_.push(outputFile_);
+      LOG(TRACE) << "queued " << outputFile_.getFileName() << " queue size now "
+                 << files_to_close_.size();
+    } else {
+      fclose(outputFile_.getFilePtr());
+    }
+    // resetting for next file
+    NOrbits_ = 0;
     if (this->OutputFileHandler::getCMSSWHeaders() == true) {
       file_size_ = sizeof(FRDFileHeader_v2);
     } else {
       file_size_ = 0;
     }
     outputFile_.nullify();
-    LOG(TRACE) << "queued " << outputFile_.getFileName() << " queue size now "
-               << files_to_close_.size();
   }
 }
 
 OutputFile OutputFileHandler::getFile(uint32_t run, uint32_t index) {
-  if (current_run_number_ != run) {
+  if (current_run_number_ != run && getCMSSWHeaders()) {
     OutputFileHandler::write_EoR_file(
         1 + static_cast<uint32_t>((current_index_ * nOrbitsPerFile) /
                                   constants::N_orbits_per_lumisection),
         current_index_);
   }
+
   if (current_run_number_ != run || current_index_ != index) {
     enqueue_current_file_for_close_and_move_maybe();
     LOG(TRACE) << "new index: " << index << "'.";
     LOG(TRACE) << "currentindex: " << current_index_ << "'.";
-    current_run_number_ = run;
     current_index_ = index;
+    if (current_run_number_ != run) {
+      run_NOrbits_ = 0;
+    }
+    current_run_number_ = run;
+    std::stringstream path_ss;
+    path_ss << base_path_ << "/run" << std::setfill('0') << std::setw(6) << current_run_number_;
+    run_dir_ = path_ss.str();
+    path_ss << "/" << working_dir_;
+    working_files_base_path_ = path_ss.str();
     open_new_file();
   }
   return outputFile_;
@@ -58,14 +74,14 @@ OutputFile OutputFileHandler::getFile(uint32_t run, uint32_t index) {
 FRDFileHeader_v2 OutputFileHandler::createFileHeader(uint32_t ls) {  // file header for CMSSW input
   uint16_t headerSize = sizeof(FRDFileHeader_v2);
   uint16_t dataType = static_cast<uint16_t>(sourceID);
-  uint32_t eventCount = nOrbitsPerFile;
+  uint32_t eventCount = NOrbits_;
   uint32_t runNumber = current_run_number_;
   uint64_t fileSize = file_size_;
   FRDFileHeader_v2 fileHeader(headerSize, dataType, eventCount, runNumber, ls, fileSize);
   return fileHeader;
 }
 
-void OutputFileHandler::create_output_directory_maybe(std::string &output_directory) {
+void OutputFileHandler::create_output_directory_maybe(std::string& output_directory) {
   struct stat sb;
   LOG(TRACE) << "checking if working directory " << output_directory << " exists ";
   /* check if path exists and is a directory */
@@ -86,6 +102,33 @@ void OutputFileHandler::create_output_directory_maybe(std::string &output_direct
     throw std::runtime_error(err);
   }
   LOG(TRACE) << "Created output directory: " << output_directory << "'.";
+
+  if (getCMSSWHeaders()) {
+    create_hlt_conf_symlinks("hlt");
+    create_hlt_conf_symlinks("jsd");
+  }
+}
+
+void OutputFileHandler::create_hlt_conf_symlinks(const std::string subdir) {
+  // create symlinks - would be simpler in c++ 17 but this is c++ 11 compatible
+  const size_t symlink_len_from = (run_dir_ + "/" + subdir).length();
+  const size_t symlink_len_to = (hlt_config_path_ + "/" + subdir).length();
+
+  char* symlink_from = new char[symlink_len_from + 1];
+  char* symlink_to = new char[symlink_len_to + 1];
+
+  strcpy(symlink_from, (run_dir_ + "/" + subdir).c_str());
+  strcpy(symlink_to, (hlt_config_path_ + "/" + subdir).c_str());
+
+  if (symlink(symlink_to, symlink_from) != 0) {
+    std::string err = tools::strerror("ERROR when creating the " + subdir + " simlink '" +
+                                      hlt_config_path_ + "/" + subdir + "'");
+    LOG(ERROR) << err;
+    throw std::runtime_error(err);
+  }
+  delete[] symlink_from;
+  delete[] symlink_to;
+  LOG(TRACE) << "Symlinked " + subdir + " hlt config directory: " << hlt_config_path_ << "'.";
 }
 
 void OutputFileHandler::open_new_file() {
@@ -96,7 +139,7 @@ void OutputFileHandler::open_new_file() {
   std::string full_filename = working_files_base_path_ + "/" + filename;
   LOG(TRACE) << "opening file with index " << current_index_ << ", in lumisection " << ls;
   OutputFile outputFile(fopen(full_filename.c_str(), "wbx"), filename, createFileHeader(ls), ls,
-                        current_index_ % (max_index_per_ls_ + 1));
+                        current_index_ % (max_index_per_ls_ + 1), run_dir_);
   if (!outputFile.exists()) {
     std::string err =
         tools::strerror("ERROR when creating file '" + outputFile.getFileName() + "'");
@@ -117,7 +160,7 @@ std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t ind
   if (this->OutputFileHandler::getCMSSWHeaders() == true) {
     ofilename << "run" << std::setfill('0') << std::setw(6) << run_number << "_ls"
               << std::setfill('0') << std::setw(4) << ls << "_index" << std::setfill('0')
-              << std::setw(6) << index % max_index_per_ls_ << ".raw";
+              << std::setw(6) << index % (max_index_per_ls_ + 1) << ".raw";
 
   } else {
     ofilename << filename_prefix_ << "_" << std::setfill('0') << std::setw(6) << run_number << "_"
@@ -132,7 +175,7 @@ void OutputFileHandler::close_and_rename::operator()() const {
     LOG(TRACE) << "try pop now. queue size now " << files_to_close_.size();
     try {
       files_to_close_.pop(outputFile);
-    } catch (tbb::user_abort &e) {
+    } catch (tbb::user_abort& e) {
       break;
     }
     LOG(TRACE) << "popping file: " << outputFile.getFileName() << " for closing, queue size now "
@@ -140,13 +183,15 @@ void OutputFileHandler::close_and_rename::operator()() const {
     if (fclose(outputFile.getFilePtr()) != 0) {
       LOG(ERROR) << tools::strerror("File close failed");
     }
-    std::string from = base_path_ + "/" + working_dir_ + "/" + outputFile.getFileName();
-    std::string to = base_path_ + "/" + outputFile.getFileName();
+    std::string from =
+        outputfilehandler_->working_files_base_path_ + "/" + outputFile.getFileName();
+    std::string to = outputFile.getRunDir() + "/" + outputFile.getFileName();
     if (rename(from.c_str(), to.c_str()) != 0) {
-      LOG(ERROR) << tools::strerror("File rename failed");
+      LOG(ERROR) << tools::strerror("File rename of " + outputFile.getFileName() + " failed");
     }
 
-    if (outputFile.Index() == outputfilehandler_->max_index_per_ls_) {  // end of lumisection
+    if (outputFile.Index() == outputfilehandler_->max_index_per_ls_ &&
+        outputfilehandler_->getCMSSWHeaders() == true) {  // end of lumisection
       outputfilehandler_->write_EoLS_file(outputFile.Lumisection());
     }
   }
@@ -157,51 +202,48 @@ void OutputFileHandler::close_and_rename::operator()() const {
 void OutputFileHandler::write_EoLS_file(uint32_t ls) {
   std::stringstream EoLS_filename_stringstream;
   EoLS_filename_stringstream << "run" << std::setfill('0') << std::setw(6) << current_run_number_
-                             << "_ls" << std::setfill('0') << std::setw(4) << ls << "_EoLS.jsd";
+                             << "_ls" << std::setfill('0') << std::setw(4) << ls << "_EoLS.jsn";
   std::string EoLS_filename = EoLS_filename_stringstream.str();
-  std::string path = working_files_base_path_ + "/jsd/";
-  create_output_directory_maybe(path);
-  std::string full_filename = working_files_base_path_ + "/jsd/" + EoLS_filename;
+  std::string full_filename = run_dir_ + "/" + EoLS_filename;
   std::stringstream EoLS_file_string_stream;
   std::fstream EoLS_file;
   LOG(TRACE) << "writing EoLS file " << EoLS_filename;
   EoLS_file.open(full_filename.c_str(), std::ios_base::out);
 
-  EoLS_file_string_stream
-      << "{\n  \"data\":[\""
-      << constants::N_orbits_per_lumisection  // always 2^18 orbits per lumisection
-      << "\",\"" << 1 + max_index_per_ls_ << "\",\"" << constants::N_orbits_per_lumisection
-      << "\",\"0\",\"" << ls_file_size_ << "\"],\n  \"definition\":\"" << working_files_base_path_
-      << "/" << current_run_number_ << "/jsd/EoLS.jsd\",\n  \"source\":\"l1scout\"\n}";
+  EoLS_file_string_stream << "{\n  \"data\":[\"" << ls_NOrbits_ << "\",\""         // NEvents
+                          << 1 + max_index_per_ls_ << "\",\""                      // NFiles
+                          << constants::N_orbits_per_lumisection << "\",\"0\",\""  // Total Events
+                          << constants::N_orbits_per_lumisection - ls_NOrbits_
+                          << "\",\"0\",\""                                         // NLost Events
+                          << ls_file_size_ << "\"],\n  \"definition\":\""          // NBytes
+                          << "/fff/ramdisk/run" << std::setfill('0') << std::setw(6)
+                          << current_run_number_ << "/jsd/EoLS.jsd\",\n  \"source\":\"l1scout\"\n}";
 
   ls_file_size_ = 0;
+  run_NOrbits_ += ls_NOrbits_;
+  ls_NOrbits_ = 0;
   std::string EoLS_file_string = EoLS_file_string_stream.str();
   EoLS_file << EoLS_file_string_stream.str();
   EoLS_file.close();
-
-  // move up directories
-  std::string from = full_filename.c_str();
-  std::string to = base_path_ + "/jsd/" + EoLS_filename;
-  if (rename(from.c_str(), to.c_str()) != 0) {
-    LOG(ERROR) << tools::strerror("File rename failed");
-  }
 }
 
 void OutputFileHandler::write_EoR_file(uint32_t ls, uint32_t index) {
   std::stringstream EoR_filename;
-  EoR_filename << working_files_base_path_ << "/"
+  EoR_filename << run_dir_ << "/"
                << "run" << std::setfill('0') << std::setw(6) << current_run_number_
                << "_ls0000_EoR.jsn";
   std::fstream EoR_file;
   LOG(TRACE) << "writing EoR file " << EoR_filename;
   EoR_file.open(EoR_filename.str().c_str(), std::ios_base::out);
   std::stringstream EoR_file_string_stream;
-  EoR_file_string_stream << "{\n  \"data\":[\"" << constants::N_orbits_per_lumisection * ls
+  EoR_file_string_stream << "{\n  \"data\":[\"" << run_NOrbits_  // NEvents
                          << "\",\""
-                         << static_cast<int>((ls * max_index_per_ls_) + nOrbitsPerFile * index)
-                         << "\",\"" << ls << "\",\"" << ls << "\"],\n  \"definition\":\""
-                         << working_files_base_path_
-                         << "/jsd/EoR.jsd\",\n  \"source\":\"l1scout\"\n}";
+                         << static_cast<int>((ls * (max_index_per_ls_ + 1)) +
+                                             nOrbitsPerFile * index)  // NFiles
+                         << "\",\"" << ls << "\",\""                  // NLumis
+                         << ls << "\"],\n  \"definition\":\""         // LastLumi
+                         << "/fff/ramdisk/run" << std::setfill('0') << std::setw(6)
+                         << current_run_number_ << "/jsd/EoR.jsd\",\n  \"source\":\"l1scout\"\n}";
   std::string EoR_file_string = EoR_file_string_stream.str();
   EoR_file << EoR_file_string_stream.str();
   EoR_file.close();
diff --git a/src/OutputFileHandler.h b/src/OutputFileHandler.h
index 94ec76f1..8843ed5f 100644
--- a/src/OutputFileHandler.h
+++ b/src/OutputFileHandler.h
@@ -16,10 +16,13 @@
 class OutputFileHandler {
  public:
   OutputFileHandler(const std::string &base_path, const std::string &filename_prefix,
-                    int nOrbitsPerFile_, const bool cmsswHeaders_, uint32_t sourceID_)
+                    const std::string &hlt_config_path, int nOrbitsPerFile_,
+                    const bool cmsswHeaders_, uint32_t sourceID_)
       : base_path_(base_path),
+        run_dir_(base_path + "/run000000"),
         filename_prefix_(filename_prefix),
         working_files_base_path_(base_path_ + "/" + working_dir_),
+        hlt_config_path_(hlt_config_path),
         current_run_number_(0),
         current_index_(0),
         close_and_rename_(base_path_, nOrbitsPerFile_),
@@ -27,11 +30,14 @@ class OutputFileHandler {
         cmsswHeaders(cmsswHeaders_),
         sourceID(sourceID_),
         t{},
-        max_index_per_ls_(static_cast<int>(constants::N_orbits_per_lumisection / nOrbitsPerFile_)) {
+        max_index_per_ls_(static_cast<int>(constants::N_orbits_per_lumisection / nOrbitsPerFile_) -
+                          1) {
     close_and_rename_.SetOutputFileHandlerObj(*this);
-    create_output_directory_maybe(working_files_base_path_);
     t = std::thread(close_and_rename_);
     file_size_ = 0;
+    NOrbits_ = 0;
+    ls_NOrbits_ = 0;
+    run_NOrbits_ = 0;
     if (cmsswHeaders_) {
       file_size_ = sizeof(FRDFileHeader_v2);  // accounting for cmssw header size
       ls_file_size_ = 0;
@@ -53,6 +59,7 @@ class OutputFileHandler {
 
   FRDFileHeader_v2 createFileHeader(uint32_t ls);
   void upFileSize(size_t n) { file_size_ += n; }
+  void upNOrbits(uint32_t n) { NOrbits_ += n; }
 
   void write_EoLS_file(uint32_t ls);
   void write_EoR_file(uint32_t ls, uint32_t index);
@@ -79,6 +86,8 @@ class OutputFileHandler {
  private:
   void create_output_directory_maybe(std::string &output_directory);
 
+  void create_hlt_conf_symlinks(const std::string subdir);
+
   void open_new_file();
 
   std::string format_filename(uint32_t run_number, uint32_t index, uint32_t ls);
@@ -101,8 +110,10 @@ class OutputFileHandler {
   static std::atomic<bool> file_handler_running_;
 
   std::string base_path_;
+  std::string run_dir_;
   std::string filename_prefix_;
   std::string working_files_base_path_;
+  std::string hlt_config_path_;
   OutputFile outputFile_;
   uint32_t current_run_number_;
   uint32_t current_index_;
@@ -114,6 +125,9 @@ class OutputFileHandler {
   const uint32_t max_index_per_ls_;
   size_t ls_file_size_;
   size_t file_size_;
+  uint32_t NOrbits_;
+  uint32_t ls_NOrbits_;
+  uint32_t run_NOrbits_;
 };
 
 #endif
diff --git a/src/config.h b/src/config.h
index fb2d35bb..2de83aa9 100644
--- a/src/config.h
+++ b/src/config.h
@@ -114,6 +114,8 @@ class config {
 
   const std::string &getOutputFilenameBase() const { return vmap.at("output_filename_base"); }
 
+  const std::string &getHLTConfigPath() const { return vmap.at("hlt_config_path"); }
+
   uint64_t getOutputMaxFileSize() const {
     std::string v = vmap.at("max_file_size");
     return boost::lexical_cast<uint64_t>(v.c_str());
diff --git a/src/elastico.cc b/src/elastico.cc
index 0c3caa45..d2943efe 100644
--- a/src/elastico.cc
+++ b/src/elastico.cc
@@ -89,7 +89,7 @@ void ElasticProcessor::makeCreateIndexRequest(unsigned int run) {
 
   curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
   curl_easy_setopt(handle, CURLOPT_URL, c_request_url.c_str());
-  curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */
+  curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PUT");                  /* !!! */
 
   curl_easy_setopt(handle, CURLOPT_POSTFIELDS, index_setting_run.c_str()); /* data goes here */
 
diff --git a/src/processor.cc b/src/processor.cc
index be372020..bd619e9b 100644
--- a/src/processor.cc
+++ b/src/processor.cc
@@ -130,9 +130,9 @@ StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitCalo(orbit_trailer
   uint32_t bx = 3554;  // We start at 3554 here, because we increment by 1
                        // immediately after starting the loops.
   size_t word = 111;
-  size_t bit = 1;  // Will be incremented immediately after starting the loop
+  size_t bit = 1;      // Will be incremented immediately after starting the loop
   for (size_t pseudo_bx = 0; pseudo_bx < 3564;
-       ++pseudo_bx) {                       // Looping over at most an entire orbit here.
+       ++pseudo_bx) {  // Looping over at most an entire orbit here.
     if (word == 14 * 8 - 1 && bit == 11) {  // Bit 11 in word 111 is the last valid BX (3564), so we
                                             // roll over afterwards. (== 11 because that's the one
                                             // we worked on in the previous loop iteration)
@@ -283,9 +283,9 @@ StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitMuon(orbit_trailer
   uint32_t bx = 3554;  // We start at 3554 here, because we increment by 1
                        // immediately after starting the loops.
   size_t word = 111;
-  size_t bit = 1;  // Will be incremented immediately after starting the loop
+  size_t bit = 1;      // Will be incremented immediately after starting the loop
   for (size_t pseudo_bx = 0; pseudo_bx < 3564;
-       ++pseudo_bx) {                       // Looping over at most an entire orbit here.
+       ++pseudo_bx) {  // Looping over at most an entire orbit here.
     if (word == 14 * 8 - 1 && bit == 11) {  // Bit 11 in word 111 is the last valid BX (3564), so we
                                             // roll over afterwards. (== 11 because that's the one
                                             // we worked on in the previous loop iteration)
@@ -308,7 +308,7 @@ StreamProcessor::fillOrbitMetadata StreamProcessor::FillOrbitMuon(orbit_trailer
     blockMuon *bl = reinterpret_cast<blockMuon *>(rd_ptr);
     if (bl->orbit[0] == constants::beefdead) {
       break;
-    }  // orbit trailer has been reached, end of orbit data
+    }                    // orbit trailer has been reached, end of orbit data
     assert(wr_ptr + (3 + 2 * 8 * 3) * 4 - 1 <=
            wr_end_ptr);  // Assuming the maximum size a decoded muon block can use.
     int mAcount = 0;
@@ -442,7 +442,10 @@ void StreamProcessor::process(Slice &input, Slice &out) {
       meta = FillOrbitMuon(trailer, rd_ptr, wr_ptr, rd_end_ptr, wr_end_ptr);
       orbitCount = meta.counts;
       ++orbit_per_packet_count;
-
+      if (orbit_per_packet_count > nOrbitsPerDMAPacket) {
+        stats.excess_orbits_per_packet_count++;
+        return;
+      }
       // 12 bytes for each muon/count then 12 bytes for each bx header
       int orbit_size_bytes = meta.counts * 12 + 12 * meta.filled_bxs;
 
@@ -498,7 +501,6 @@ void StreamProcessor::process(Slice &input, Slice &out) {
                        << orbit_per_packet_count << ", > expected, (" << nOrbitsPerDMAPacket
                        << ") skipping packet.";
         }
-        stats.excess_orbits_per_packet_count++;
         if (stats.excess_orbits_per_packet_count % 10000 == 0) {
           LOG(WARNING) << "count of packets with excess # orbits "
                        << stats.excess_orbits_per_packet_count;
diff --git a/src/utility.h b/src/utility.h
index a9d30167..113c941b 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -367,8 +367,8 @@ int step_function_power2_ladder(int previous, double nsteps) {
   // The actual step is 1 until the value is twice as big as nsteps
   if (previous < 2 * steps) return previous + 1;
   // calculate the previous power of 2
-  int prev_power2 = previous / 2;  // start with half the given value
-  int rshift = 1;                  // and with the shift of 1;
+  int prev_power2 = previous / 2;      // start with half the given value
+  int rshift = 1;                      // and with the shift of 1;
   while (int shifted =
              prev_power2 >> rshift) {  // shift the value right; while the result is non-zero,
     prev_power2 |= shifted;            //   add the bits set in 'shifted';
diff --git a/test/config/scdaq-calo-cmssw.conf b/test/config/scdaq-calo-cmssw.conf
index ad596e8b..4c22f123 100644
--- a/test/config/scdaq-calo-cmssw.conf
+++ b/test/config/scdaq-calo-cmssw.conf
@@ -121,8 +121,11 @@ nOrbitsPerFile:256
 # Headers for cmssw support
 cmsswHeaders:yes
 
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
 ##  Information necessary to issue a reset request for the board
 scone_host:scoutdaq-s1d12-39-01
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:kcu1500_demux
diff --git a/test/config/scdaq-calo.conf b/test/config/scdaq-calo.conf
index cd5d043f..d4ec1000 100644
--- a/test/config/scdaq-calo.conf
+++ b/test/config/scdaq-calo.conf
@@ -121,8 +121,11 @@ nOrbitsPerFile:4096
 # Headers for cmssw support
 cmsswHeaders:no
 
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
 ##  Information necessary to issue a reset request for the board
 scone_host:scoutdaq-s1d12-39-01
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:kcu1500_demux
diff --git a/test/config/scdaq-gmt-cmssw.conf b/test/config/scdaq-gmt-cmssw.conf
index 4844377b..84161df1 100644
--- a/test/config/scdaq-gmt-cmssw.conf
+++ b/test/config/scdaq-gmt-cmssw.conf
@@ -121,8 +121,11 @@ nOrbitsPerFile:256
 # Headers for cmssw support
 cmsswHeaders:yes
 
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
 ##  Information necessary to issue a reset request for the board
 scone_host:scoutdaq-s1d12-34-01
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:kcu1500_ugmt
diff --git a/test/config/scdaq-gmt.conf b/test/config/scdaq-gmt.conf
index b833c7db..1d582dd6 100644
--- a/test/config/scdaq-gmt.conf
+++ b/test/config/scdaq-gmt.conf
@@ -121,8 +121,11 @@ nOrbitsPerFile:4096
 # Headers for cmssw support
 cmsswHeaders:no
 
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
 ##  Information necessary to issue a reset request for the board
 scone_host:scoutdaq-s1d12-34-01
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:kcu1500_ugmt
diff --git a/test/config/scdaq-micron-bril.conf b/test/config/scdaq-micron-bril.conf
index a9fd91ae..2573bf53 100644
--- a/test/config/scdaq-micron-bril.conf
+++ b/test/config/scdaq-micron-bril.conf
@@ -122,13 +122,11 @@ nOrbitsPerFile:4096
 # Headers for cmssw support
 cmsswHeaders:no
 
-##  Information necessary to issue a reset request for the board
-scone_host:scoutdaq-s1d12-34-01
-scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
-scone_board:kcu1500_ugmt
-##  Information necessary to issue a reset request for the board
+# HLT config and jsd path
+hlt_config_path:/nfshome0/matteomi/scDaqConf/HLT
+
+## Information necessary to issue a reset request for the board
 scone_host:scoutdaq-s1d12-32-01
 scone_port:8080
-# Currently can be one of kcu1500_ugmt and kcu1500_demux
+# e.g kcu1500_ugmt, kcu1500_demux, sb852_bril
 scone_board:sb852_bril
-- 
GitLab