Skip to content

Commit

Permalink
Persist ldmx-sw version and sha in run header (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvami authored Jan 28, 2025
1 parent 6172a9a commit e5d00d3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,33 @@ find_package(ROOT 6.16 CONFIG REQUIRED)
# to generate the dictionary.
include("${ROOT_DIR}/RootMacros.cmake")

# Execute the command to extract the SHA1 hash of the current git tag. The
# variable GIT_SHA1 will be set to contain the hash.
execute_process(COMMAND git rev-parse HEAD OUTPUT_VARIABLE GIT_SHA1)

# Remove the newline character
string(REGEX REPLACE "\n$" "" GIT_SHA1 "${GIT_SHA1}")
# Execute the command to extract the SHA1 hash of the current git tag.
# 'git' is removed from within the container to discourage opening a shell
# in the container, so we need to go to some lengths in order to avoid using 'git'
# The variable GIT_SHA1 will be set to contain the hash.
set(git_dir "${PROJECT_SOURCE_DIR}/../.git")
if (NOT IS_DIRECTORY "${git_dir}")
# we are a submodule of another project
file(READ "${git_dir}" git_dir)
string(REGEX REPLACE "^gitdir: " "" git_dir ${git_dir})
string(REGEX REPLACE "\n$" "" git_dir ${git_dir})
endif()
file(READ "${git_dir}/HEAD" current_ref)
string(REGEX REPLACE "\n$" "" current_ref ${current_ref})
if (current_ref MATCHES "^ref:.*$")
# on a branch
string(REGEX REPLACE "^ref: " "" current_ref "${current_ref}")
file(READ "${git_dir}/${current_ref}" GIT_SHA1)
string(REGEX REPLACE "\n$" "" GIT_SHA1 ${GIT_SHA1})
else()
# in detached head state (probably on a tag)
set(GIT_SHA1 ${current_ref})
endif()
message(STATUS "Deduced git SHA: ${GIT_SHA1}")

# Include ldmx-sw version in the Run Header
file(READ ${PROJECT_SOURCE_DIR}/../.github/actions/validate/gold_label LDMXSW_VERSION)
string(STRIP "${LDMXSW_VERSION}" LDMXSW_VERSION)

# Copies the file 'Version.h.in', substitutes the value of GIT_SHA1 and writes
# it out to Version.h.
Expand Down
15 changes: 14 additions & 1 deletion Framework/include/Framework/RunHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace ldmx {
* the user somehow gets into the situation of reading a v4 RunHeader with v3
* software, the numTries_ member is quietly ignored, maintaining the format of
* the v3 RunHeader in the resulting output file.
*
* ## v5
* Include a member to track the ldmx-sw version
*/
class RunHeader {
public:
Expand Down Expand Up @@ -85,6 +88,11 @@ class RunHeader {
*/
const std::string &getSoftwareTag() const { return softwareTag_; }

/**
* @return The ldmx-sw version used to generate this file
*/
const std::string &getLdmxswVersion() const { return ldmxsw_version_; }

/** @return A short description of the run. */
const std::string &getDescription() const { return description_; }

Expand Down Expand Up @@ -281,6 +289,11 @@ class RunHeader {
*/
std::string softwareTag_{GIT_SHA1};

/**
* ldmx-sw software version
*/
std::string ldmxsw_version_{LDMXSW_VERSION};

/** Map of int parameters. */
std::map<std::string, int> intParameters_;

Expand All @@ -290,7 +303,7 @@ class RunHeader {
/** Map of string parameters. */
std::map<std::string, std::string> stringParameters_;

ClassDef(RunHeader, 4);
ClassDef(RunHeader, 5);

}; // RunHeader

Expand Down
6 changes: 6 additions & 0 deletions Framework/include/Framework/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* software related constants e.g. git SHA-1.
* @author Omar Moreno, SLAC National Accelerator Laboratory
* @author Tom Eichlersmith, University of Minnesota
* @author Tamas Almos Vami (UCSB), added LDMXSW_VERSION
*/

#ifndef _EVENT_VERSION_H_
Expand All @@ -21,6 +22,11 @@ namespace ldmx {
*/
#define GIT_SHA1 "${GIT_SHA1}"

/**
* ldmx-sw version
*/
#define LDMXSW_VERSION "${LDMXSW_VERSION}"

}

#endif // _EVENT_VERSION_H_
1 change: 1 addition & 0 deletions SimCore/src/SimCore/Simulator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void Simulator::beforeNewRun(ldmx::RunHeader& header) {
"G4 Version string.";
}

header.setStringParameter("ldmx-sw version", LDMXSW_VERSION);
header.setStringParameter("ldmx-sw revision", GIT_SHA1);
}

Expand Down

0 comments on commit e5d00d3

Please sign in to comment.