From 264d08ba6e3003cabbea60c9092956efb9a39853 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Tue, 12 Dec 2023 21:40:51 +0100
Subject: [PATCH] QA: mcbm_qa.C -> new regular expressions for the CI test

---
 core/qa/CbmQaIO.cxx                           |  1 +
 core/qa/CbmQaManager.h                        | 10 +++
 core/qa/CbmQaTask.cxx                         |  2 +-
 macro/mcbm/CMakeLists.txt                     |  3 +-
 macro/mcbm/mcbm_qa.C                          |  4 +-
 macro/qa/configs/CMakeLists.txt               |  2 +
 ...sks_config_mcbm_beam_2021_07_surveyed.yaml | 49 +++++++++++++
 ...ks_config_mcbm_beam_2022_05_23_nickel.yaml | 72 +++++++++++++++++++
 8 files changed, 139 insertions(+), 4 deletions(-)
 create mode 100644 macro/qa/configs/qa_tasks_config_mcbm_beam_2021_07_surveyed.yaml
 create mode 100644 macro/qa/configs/qa_tasks_config_mcbm_beam_2022_05_23_nickel.yaml

diff --git a/core/qa/CbmQaIO.cxx b/core/qa/CbmQaIO.cxx
index 12ed180c22..8c3b84699a 100644
--- a/core/qa/CbmQaIO.cxx
+++ b/core/qa/CbmQaIO.cxx
@@ -113,6 +113,7 @@ void CbmQaIO::WriteToFile(TFile* pOutFile) const
 {
   pOutFile->cd();
   for (auto& [pObject, sPath] : (*fpvObjList)) {
+    //LOG(info) << "Writing object " << pObject->GetName() << " -- " << sPath;
     if (!pOutFile->GetDirectory(sPath)) {
       pOutFile->mkdir(sPath);
     }
diff --git a/core/qa/CbmQaManager.h b/core/qa/CbmQaManager.h
index 96c0ac0ca5..7919ad76db 100644
--- a/core/qa/CbmQaManager.h
+++ b/core/qa/CbmQaManager.h
@@ -12,6 +12,8 @@
 #include "FairTask.h"
 #include "TString.h"
 
+#include <TFile.h>
+
 #include <map>
 #include <string>
 
@@ -62,7 +64,15 @@ class CbmQaManager : public FairTask {
   /// \brief Sets YAML config name
   void SetConfigName(const TString& name) { fsConfigName = name; }
 
+  /// \brief Open cross-check file
+  /// \param path  Path to the cross-check file
+  ///
+  /// Opens the cross-check ROOT-file with the QA-chain output, obtained under the default code base.
+  //void OpenCrossCheckFile(const TString& path);
+
  private:
   bool fStatus         = true;  ///< Status of QA: true - all tasks passed, false - at least one of the task failed
   TString fsConfigName = "";    ///< Name of the configuration YAML file (passed to underlying QA tasks)
+
+  //std::shared_ptr<TFile> fpCrossCheckFile = nullptr;  ///< A file with default histograms to carry out a cross-check
 };
diff --git a/core/qa/CbmQaTask.cxx b/core/qa/CbmQaTask.cxx
index f545fc93e9..df38af48b2 100644
--- a/core/qa/CbmQaTask.cxx
+++ b/core/qa/CbmQaTask.cxx
@@ -193,7 +193,7 @@ void CbmQaTask::ReadCheckListFromConfig()
       if (static_cast<int>(configEntry.find_last_of("%d")) != -1) {
         vbConfigKeyUsed.push_back(true);
         bool bCheckStatus = it->second.as<bool>();  // use-flag, stored in the configuration
-        std::regex keyRex = std::regex(std::regex_replace(configEntry, rexInt, "([0-9*])"));
+        std::regex keyRex = std::regex(std::regex_replace(configEntry, rexInt, "([0-9]+)"));
         int iCheckEntry   = 0;
         for (auto& [checkEntry, checkFlags] : fmCheckList) {
           if (!vbCheckKeyProcessed[iCheckEntry] && std::regex_match(checkEntry, keyRex)) {
diff --git a/macro/mcbm/CMakeLists.txt b/macro/mcbm/CMakeLists.txt
index 041afb1adc..c44bc0fe3c 100644
--- a/macro/mcbm/CMakeLists.txt
+++ b/macro/mcbm/CMakeLists.txt
@@ -111,9 +111,10 @@ ForEach(setup IN LISTS cbm_setup)
   Add_Test(${testname} ${CBMROOT_BINARY_DIR}/macro/mcbm/mcbm_qa.sh ${NumEvents} \"data/${setup}_test\" \"${setup}\")
   Set_Tests_Properties(${testname} PROPERTIES
           TIMEOUT "300"
-          PASS_REGULAR_EXPRESSION "Test Passed;All ok"
+          PASS_REGULAR_EXPRESSION "QA checks passed;Test Passed;All ok"
           FAIL_REGULAR_EXPRESSION "ERROR"
           FAIL_REGULAR_EXPRESSION "FATAL"
+          FAIL_REGULAR_EXPRESSION "QA checks failed"
           FIXTURES_REQUIRED ${fixture_mcbm_digi_tb}
           FIXTURES_SETUP ${fixture_mcbm_qa_event_mc}
   )
diff --git a/macro/mcbm/mcbm_qa.C b/macro/mcbm/mcbm_qa.C
index 7601e16f3f..1a4723b9f0 100644
--- a/macro/mcbm/mcbm_qa.C
+++ b/macro/mcbm/mcbm_qa.C
@@ -52,7 +52,7 @@ void mcbm_qa(Int_t nEvents = 0, TString dataset = "data/mcbm_beam_2020_03_test",
   int verbose    = 6;                              // verbose level
   TString myName = "mcbm_qa";                      // this macro's name for screen output
   TString srcDir = gSystem->Getenv("VMCWORKDIR");  // top source directory
-  TString qaConfig = (config.Length() ? config : srcDir + "/macro/qa/configs/qa_tasks_config_mcbm.yaml");
+  TString qaConfig = (config.Length() ? config : srcDir + "/macro/qa/configs/qa_tasks_config_" + setupName + ".yaml");
   // NOTE: SZh 28.07.2024: config can depend from the setup
   // ------------------------------------------------------------------------
 
@@ -309,7 +309,7 @@ void mcbm_qa(Int_t nEvents = 0, TString dataset = "data/mcbm_beam_2020_03_test",
   std::cout << "Parameter file is " << parFile << std::endl;
   std::cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << std::endl;
   std::cout << std::endl;
-  std::cout << " QA checks " << (qaManager->GetStatus() ? "\e[1;32mpassed" : "\e[1;31mfailed") << "\e[0m\n";
+  std::cout << " QA checks " << (qaManager->GetStatus() ? "passed" : "failed") << std::endl;
   std::cout << " Test passed" << std::endl;
   std::cout << " All ok " << std::endl;
   // ------------------------------------------------------------------------
diff --git a/macro/qa/configs/CMakeLists.txt b/macro/qa/configs/CMakeLists.txt
index bb215f639a..32d6e46c09 100644
--- a/macro/qa/configs/CMakeLists.txt
+++ b/macro/qa/configs/CMakeLists.txt
@@ -1,4 +1,6 @@
 Install(FILES objects.yaml
               qa_tasks_config_mcbm.yaml
+              qa_tasks_config_mcbm_beam_2021_07_surveyed.yaml
+              qa_tasks_config_mcbm_beam_2022_05_23_nickel.yaml
               DESTINATION share/cbmroot/macro/qa/configs
        )
diff --git a/macro/qa/configs/qa_tasks_config_mcbm_beam_2021_07_surveyed.yaml b/macro/qa/configs/qa_tasks_config_mcbm_beam_2021_07_surveyed.yaml
new file mode 100644
index 0000000000..e12dd8c0e4
--- /dev/null
+++ b/macro/qa/configs/qa_tasks_config_mcbm_beam_2021_07_surveyed.yaml
@@ -0,0 +1,49 @@
+#  Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+#  SPDX-License-Identifier: GPL-3.0-only
+#  Authors: Sergei Zharko [committer] 
+# 
+## @file   qa_task_config_mcbm.yaml
+## @brief  Configuration file for QA-tasks in mCBM
+## @since  27.07.2023
+## @author Sergei Zharko <s.zharko@gsi.de>
+
+qa:
+  CbmCaInputQaMvd:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+      pull_station_%_pull_x: false
+  CbmCaInputQaSts:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: true
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+      pull_u_%d_digis: false
+      pull_v_%d_digis: false
+  CbmCaInputQaTrd:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      hit_efficiency_station_0: false
+      hit_efficiency_station_1: false
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: false
+  CbmCaInputQaTof:
+    check_list:
+      station_position_ordering: false
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+
+...
diff --git a/macro/qa/configs/qa_tasks_config_mcbm_beam_2022_05_23_nickel.yaml b/macro/qa/configs/qa_tasks_config_mcbm_beam_2022_05_23_nickel.yaml
new file mode 100644
index 0000000000..50f9dc7093
--- /dev/null
+++ b/macro/qa/configs/qa_tasks_config_mcbm_beam_2022_05_23_nickel.yaml
@@ -0,0 +1,72 @@
+#  Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+#  SPDX-License-Identifier: GPL-3.0-only
+#  Authors: Sergei Zharko [committer] 
+# 
+## @file   qa_task_config_mcbm.yaml
+## @brief  Configuration file for QA-tasks in mCBM
+## @since  27.07.2023
+## @author Sergei Zharko <s.zharko@gsi.de>
+
+qa:
+  CbmCaInputQaMvd:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+      pull_station_%_pull_x: false
+  CbmCaInputQaSts:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+      pull_u_%d_digis: true
+      pull_v_%d_digis: true
+  CbmCaInputQaMuch:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: true
+      hit_efficiency_station_%d: true
+      pull_x_station_2: false   
+      pull_x_station_3: false
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+      pull_t_station_1: false
+      pull_t_station_3: false
+  CbmCaInputQaTrd:
+    histograms:
+      #xy_station0: 
+      #  x: { nbins: 500, min: -20., max: 20. }
+      #  y: { nbins: 500, min: -20., max: 20. }
+      #xy_station1: 
+      #  x: { nbins: 500, min: -100., max: 100. } 
+      #  y: { nbins: 500, min: -100., max: 100. }
+      #xy_station2: 
+      #  x: { nbins: 500, min: -100., max: 100. } 
+      #  y: { nbins: 500, min: -100., max: 100. }
+    profiles: none
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: true
+      hit_efficiency_station_%d: true
+      pull_t_station_0: false
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: true
+  CbmCaInputQaTof:
+    check_list:
+      station_position_ordering: true
+      station_position_hit_delta_z: false
+      hit_efficiency_station_%d: true
+      pull_x_station_%d: true
+      pull_y_station_%d: true
+      pull_t_station_%d: false
+      pull_t_station_3: false
+
+...
-- 
GitLab