Skip to content

Storage of job execution environment in output files [2/4] #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • need to include the GIT extraction macros from sbnobj

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ project(sbncode VERSION 09.92.00 LANGUAGES CXX)

message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================")


include(CetCMakeEnv)
cet_cmake_env()

Expand Down Expand Up @@ -82,6 +81,7 @@ find_package( Boost COMPONENTS system filesystem REQUIRED )
include(ArtDictionary)
include(ArtMake)
include(BuildPlugins)
include(SBNutils)

add_subdirectory(sbncode)
add_subdirectory(fcl)
Expand Down
1 change: 1 addition & 0 deletions fcl/CMakeLists.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • added a new job configuration and new directory

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(gen)
add_subdirectory(g4)
add_subdirectory(caf)
add_subdirectory(util)
install_fhicl()

1 change: 1 addition & 0 deletions fcl/util/CMakeLists.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • added a new job configuration and new directory

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install_fhicl()
41 changes: 41 additions & 0 deletions fcl/util/dump_sbnjobmetadata.fcl
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • a new job configuration for dumping the SBN metadata

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# File: dump_sbnjobmetadata.fcl
# Purpose: Prints on screen all the job SBN metadata stored in an input file.
# Author: Gianluca Petrillo (petrillo@slac.stanford.edu)
# Date: January 20, 2025
#
# Reads and prints on screen the SBN job environment information from the input
# file.
#
# Changes
# --------
#
# [20250120] (petrillo@slac.stanford.edu)
# original version
#

#include "messages_icarus.fcl"

process_name: JobMeta

# use `icarus_message_services_interactive` to see dump on screen
services.message: @local::icarus_message_services_prod

services.message.destinations.MetadataLog: {
type: file
filename: "JobEnvironment.log"
append: false
threshold: INFO
categories: {
DumpJobEnvironment: { limit: -1 }
default: { limit: 0 }
}
}

outputs.metadataDumper: {
module_type: "DumpJobEnvironment"
}

physics: {
streams: [ metadataDumper ]
}
45 changes: 45 additions & 0 deletions sbncode/Metadata/CMakeLists.txt
Copy link
Member Author

@PetrilloAtWork PetrilloAtWork Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • metadata "framework":
    • added algorithm to extract SBN metadata
    • added output plugin to write the metadata into art output
    • added the output module to dump that metadata from files to screen
  • package metadata:
    • added macros for extraction of the version of this repository
    • added plugin for reporting versions of sbncode and sbnobj

Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
cet_enable_asserts()

GenerateRepoVersionSource(${CMAKE_PROJECT_NAME})

message(DEBUG "Generated source file '${${CMAKE_PROJECT_NAME}_GIT_REPO_VERSION_SOURCE}.h'")

art_make_library(
LIBRARIES
sbnobj::Common_Metadata
larcorealg::headers
art::Persistency_Provenance
art::Utilities
canvas::canvas
messagefacility::MF_MessageLogger
fhiclcpp::fhiclcpp
)


set( sbn_meta_lib_list art::Framework_Core
art::Framework_Principal
art::Framework_Services_Registry
Expand All @@ -21,6 +37,35 @@ cet_build_plugin( MetadataSBN art::service
art::Framework_IO_detail
)

cet_build_plugin(SaveJobEnvironment art::ResultsProducer
LIBRARIES
sbncode::Metadata
sbnobj::Common_Metadata
art_root_io::TFileService_service
art_root_io::tfile_support
art::Framework_Services_Registry
)

# cet_build_plugin(DumpJobEnvironment art::ResultsProducer
# LIBRARIES
# sbnobj::Common_Metadata
# )

cet_build_plugin(DumpJobEnvironment art::Output
LIBRARIES
sbnobj::Common_Metadata
)

cet_build_plugin(sbncodeRepositoryVersion art::tool
LIBRARIES
sbncode::Metadata
sbnobj::Metadata
sbnobj::Common_Metadata
)


install_headers(LIST "${CMAKE_CURRENT_BINARY_DIR}/${${CMAKE_PROJECT_NAME}_GIT_REPO_VERSION_SOURCE}.h")
install_source(LIST "${CMAKE_CURRENT_BINARY_DIR}/${${CMAKE_PROJECT_NAME}_GIT_REPO_VERSION_SOURCE}.cxx")
install_headers()
install_fhicl()
install_source()
176 changes: 176 additions & 0 deletions sbncode/Metadata/DumpJobEnvironment_module.cc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • output module dumping SBN metadata from an input file to screen

Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
* @file sbncode/Metadata/DumpJobEnvironment_module.cc
* @brief Producer module writing job environment information into output.
* @author Gianluca Petrillo (petrillo@slac.stanford.edu)
* @date January 16, 2025
*/

// local libraries
#include "sbnobj/Common/Metadata/JobEnvironmentInfo.h"

// framework libraries
#include "art/Framework/Core/ModuleMacros.h"
#include "art/Framework/Core/OutputModule.h"
#include "art/Framework/Principal/ResultsPrincipal.h"
#include "art/Framework/Principal/Results.h"
#include "art/Framework/Principal/Provenance.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Persistency/Provenance/ModuleContext.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "fhiclcpp/types/ConfigurationTable.h" // fhicl::WrappedTable
#include "fhiclcpp/types/TableFragment.h"
#include "fhiclcpp/types/Atom.h"

// C++ standard libraries
#include <string>
#include <vector>


// -----------------------------------------------------------------------------
namespace sbn { class DumpJobEnvironment; }
/**
* @brief Output module dumping input versions to screen.
*
* The output module can be added to any of the end paths of an _art_ job to
* get a complete dump of the SBN job environment metadata stored into the input
* file.
*
* For example:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* process_name: JobMeta
*
* services.message.destinations.MetadataLog: {
* type: file
* filename: "JobEnvironment.log"
* append: false
* threshold: INFO
* categories: {
* DumpJobEnvironment: { limit: -1 }
* default: { limit: 0 }
* }
* }
*
* outputs.metadataDumper: { module_type: "DumpJobEnvironment" }
*
* physics.streams: [ metadataDumper ]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* will dump the metadata into a text file named `JobEnvironment.log`.
*
*/
class sbn::DumpJobEnvironment: public art::OutputModule {
public:

/// Module configuration.
struct Config {

using Name = fhicl::Name;
using Comment = fhicl::Comment;

fhicl::TableFragment<art::OutputModule::Config> OutputModuleConfig;

fhicl::Atom<std::string> LogCategory {
Name{ "LogCategory" },
Comment{ "name of the messagefacility output category to be used" },
"DumpJobEnvironment"
};

}; // Config

using Parameters
= fhicl::WrappedTable<Config, art::OutputModule::Config::KeysToIgnore>;

explicit DumpJobEnvironment(Parameters const& params);

private:

// --- BEGIN --- Configuration -----------------------------------------------

std::string const fLogCategory; ///< Messagefacility category for the output.

// --- END ----- Configuration -----------------------------------------------


/// Dumps the information from an handle into the output stream.
template <typename Stream>
void dumpInformation(
Stream& out,
art::Handle<std::vector<sbn::JobEnvironmentInfo>> const& infoHandle
) const;



void write(art::EventPrincipal&) override {}
void writeRun(art::RunPrincipal&) override {}
void writeSubRun(art::SubRunPrincipal&) override {}

/// Reads and prints all the metadata data products.
void readResults(art::ResultsPrincipal const& results) override;

}; // sbn::DumpJobEnvironment


// -----------------------------------------------------------------------------
// --- Implementation
// -----------------------------------------------------------------------------
sbn::DumpJobEnvironment::DumpJobEnvironment(Parameters const& params)
: OutputModule{ params().OutputModuleConfig }
, fLogCategory{ params().LogCategory() }
{}


// -----------------------------------------------------------------------------
void sbn::DumpJobEnvironment::readResults
(art::ResultsPrincipal const& principal)
{
if (!principal.size()) return;

art::ModuleContext const moduleContext{ moduleDescription() };
art::Results const& results = principal.makeResults(moduleContext);

std::vector<art::Handle<std::vector<sbn::JobEnvironmentInfo>>> infoHandles
= results.getMany<std::vector<sbn::JobEnvironmentInfo>>();

mf::LogInfo out{ fLogCategory };
out << "Found " << infoHandles.size() << " job information entries in input.";

for (art::Handle<std::vector<sbn::JobEnvironmentInfo>> const& infoHandle
: infoHandles
) {
out << '\n' << std::string(80, '*') << '\n';
dumpInformation(out, infoHandle);
}

} // sbn::DumpJobEnvironment::readResults()


// -----------------------------------------------------------------------------
template <typename Stream>
void sbn::DumpJobEnvironment::dumpInformation(
Stream& out,
art::Handle<std::vector<sbn::JobEnvironmentInfo>> const& infoHandle
) const {

art::Provenance const* provenance = infoHandle.provenance();
if (provenance) {
out << "Information from '" << provenance->inputTag().encode() << "'";
}
else {
out << "Information with unknown provenance";
}

if (infoHandle.isValid()) {
out << " from " << infoHandle->size() << " sources\n";
for (sbn::JobEnvironmentInfo const& info: *infoHandle) {
out << std::string(80, '=') << '\n' << info;
}
}
else out << "\n[information not available]\n";

} // sbn::DumpJobEnvironment::dumpInformation()


// -----------------------------------------------------------------------------
DEFINE_ART_MODULE(sbn::DumpJobEnvironment)


// -----------------------------------------------------------------------------
16 changes: 16 additions & 0 deletions sbncode/Metadata/GITrepoVersion.cxx.in
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • template source for sbncode repository version library

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file ${gitRepoVersionSourceStem}.cxx
* @brief GIT version for repository `${gitRepoName}`.
* @author automatically generated;
* template: Gianluca Petrillo (petrillo@slac.stanford.edu)
* @date January 18, 2025
* @see ${gitRepoVersionSourceStem}.h
*/

#include "${gitRepoVersionSourceStem}.h"

// -----------------------------------------------------------------------------
const char RepositoryVersion_${gitRepoName}[] = "${gitRepoVersion}";


// -----------------------------------------------------------------------------
18 changes: 18 additions & 0 deletions sbncode/Metadata/GITrepoVersion.h.in
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • template interface for sbncode repository version library

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file ${gitRepoVersionSourceStem}.h
* @brief GIT version for repository `${gitRepoName}`.
* @author automatically generated;
* template: Gianluca Petrillo (petrillo@slac.stanford.edu)
* @date January 18, 2025
* @see ${gitRepoVersionSourceStem}.cxx
*/

#ifndef ${gitRepoName}_${gitRepoVersionSourceStem}_H
#define ${gitRepoName}_${gitRepoVersionSourceStem}_H


/// Repository version for ${gitRepoName}.
extern const char RepositoryVersion_${gitRepoName}[];


#endif // ${gitRepoName}_${gitRepoVersionSourceStem}_H
Loading
Loading