Skip to content
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

fix: working installation for JugDigi CalorimeterHitDigi and CalorimeterBirksCorr #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Installed in source as prefix
/include/
/lib/
/bin/

# Compiled Object files
*.slo
*.lo
Expand Down
42 changes: 37 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

cmake_minimum_required(VERSION 3.19)

# CMP0074: find_package() uses <PackageName>_ROOT variables
cmake_policy(SET CMP0074 NEW)

project(Juggler VERSION 4.3.0)
project(algorithms VERSION 0.0.1)

set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
if(NOT CMAKE_CXX_STANDARD MATCHES "17|20")
Expand Down Expand Up @@ -49,6 +46,9 @@ if(NOT CMAKE_BUILD_TYPE MATCHES Release)
add_compile_options(-Wall -Wextra -Werror)
endif()

# Use GNU install dirs
include(GNUInstallDirs)

find_package(Microsoft.GSL CONFIG)

find_package(EICD REQUIRED)
Expand Down Expand Up @@ -76,9 +76,41 @@ add_definitions("-DActs_VERSION_PATCH=${Acts_VERSION_PATCH}")
find_library(genfit2 genfit2 /usr/local/lib REQUIRED)
find_path(genfit2_INCLUDE_DIR NAMES GFGbl.h PATHS /usr/local/include ${genfit2}/../include REQUIRED)

#add_subdirectory(JugBase)
add_subdirectory(JugBase)
add_subdirectory(JugDigi)
#add_subdirectory(JugFast)
#add_subdirectory(JugPID)
#add_subdirectory(JugReco)
#add_subdirectory(JugTrack)


# -------------------------
# install library config
include(CMakePackageConfigHelpers)

# Install and export targets
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/${PROJECT_NAME}
)

set(TARGETS_INSTALL_PATH lib/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake)

configure_package_config_file(
cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/${PROJECT_NAME}
PATH_VARS TARGETS_INSTALL_PATH
)

write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION lib/${PROJECT_NAME}
)
78 changes: 16 additions & 62 deletions JugBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,29 @@
# Package: JugBase
################################################################################

file(GLOB JugBase_sources CONFIGURE_DEPENDS src/*.cpp)
file(GLOB JugBase_plugins CONFIGURE_DEPENDS src/Plugins/*.cpp)
file(GLOB JugBase_utilities CONFIGURE_DEPENDS src/Utilities/*.cpp)
gaudi_add_library(JugBase
SOURCES
${JugBase_sources}
${JugBase_plugins}
${JugBase_utilities}
LINK
Gaudi::GaudiKernel Gaudi::GaudiAlgLib
podio::podioRootIO
ROOT::Core ROOT::RIO ROOT::Tree
DD4hep::DDG4IO DD4hep::DDRec
ActsCore ActsPluginDD4hep
${genfit2}
)

target_include_directories(JugBase PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${genfit2_INCLUDE_DIR}
)

target_compile_options(JugBase PRIVATE -Wno-suggest-override)

file(GLOB JugBasePlugins_sources CONFIGURE_DEPENDS src/components/*.cpp)
gaudi_add_module(JugBasePlugins
SOURCES
${JugBasePlugins_sources}
LINK
Gaudi::GaudiKernel Gaudi::GaudiAlgLib
ROOT::Core ROOT::RIO ROOT::Tree
JugBase
set(JugBasePlugins_sources
src/components/Algorithm.cpp
)
file(GLOB JugBasePlugins_headers CONFIGURE_DEPENDS JugBase/*.h)
add_library(JugBasePlugins SHARED "${JugBasePlugins_sources}")
set_target_properties(JugBasePlugins
PROPERTIES PUBLIC_HEADER "${JugBasePlugins_headers}")
target_link_libraries(JugBasePlugins
EDM4HEP::edm4hep
DD4hep::DDRec
ActsCore ActsPluginDD4hep ActsPluginJson
EICD::eicd
${genfit2}
)

target_include_directories(JugBasePlugins PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/JugBase>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${genfit2_INCLUDE_DIR}
)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_compile_options(JugBasePlugins PRIVATE -Wno-suggest-override)

install(TARGETS JugBase JugBasePlugins
EXPORT JugBaseTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
COMPONENT dev)

if(BUILD_TESTING)
enable_testing()
endif()

#add_test(NAME ProduceForReadTest
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# COMMAND ${CMAKE_BINARY_DIR}/run ${PROJECT_SOURCE_DIR}/JugBase/scripts/gaudirun tests/options/simple_producer.py)
#add_test(NAME ReadTest
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# COMMAND ${CMAKE_BINARY_DIR}/run ${PROJECT_SOURCE_DIR}/JugBase/scripts/gaudirun tests/options/simple_reader.py)
#add_test(NAME ReadGeoTest
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# COMMAND ${CMAKE_BINARY_DIR}/run ${PROJECT_SOURCE_DIR}/JugBase/scripts/gaudirun tests/options/reader_with_geosvc.py)
#add_test(NAME CheckReadCollectionSize
# ENVIRONMENT PYTHONPATH+=${PODIO_PYTHON_DIR}
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
# COMMAND python JugBase/tests/scripts/check_coll_after_read.py
# DEPENDS ReadTest)
install(TARGETS JugBasePlugins
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/JugBase
)
2 changes: 2 additions & 0 deletions JugBase/JugAlg/JugAlgorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "Jug/Algorithm.h"
1 change: 1 addition & 0 deletions JugBase/JugAlg/JugTool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
2 changes: 2 additions & 0 deletions JugBase/JugAlg/Producer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "Jug/Algorithm.h"
2 changes: 2 additions & 0 deletions JugBase/JugAlg/Transformer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "Jug/Algorithm.h"
70 changes: 62 additions & 8 deletions JugBase/JugBase/Algorithm.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,82 @@
namespace Jug {
#pragma once

class Algorithm {
#include <functional>
#include <string>

namespace algorithms {

class PropertyBase;
class ServiceBase;

class StatusCode {
public:
enum Value : uint {
SUCCESS,
FAILURE
};
StatusCode() = default;
constexpr StatusCode(Value value): m_value(value) { };
constexpr operator Value() const { return m_value; }
explicit operator bool() const = delete;
constexpr bool operator==(StatusCode a) const { return m_value == a.m_value; }
constexpr bool operator!=(StatusCode a) const { return m_value != a.m_value; }
constexpr bool isFailure() const { return m_value == FAILURE; }
private:
Value m_value;
};

class AlgorithmBase {
private:
std::vector<std::pair<std::string, PropertyBase*>> m_properties;
std::vector<std::pair<std::string, ServiceBase*>> m_services;
public:
AlgorithmBase() = default;
void registerProperty(PropertyBase* property, const std::string& name) {
m_properties.push_back(std::make_pair(name, property));
}
void registerService(ServiceBase* service, const std::string& name) {
m_services.push_back(std::make_pair(name, service));
}

};

template<typename Out, typename In>
class JugAlgorithm : public AlgorithmBase {
private:
std::string m_name;

static std::function<std::ostream&()> m_debug;
static std::function<std::ostream&()> m_info;
static std::function<std::ostream&()> m_warning;
static std::function<std::ostream&()> m_error;
static std::function<std::ostream&()> m_endmsg;

static void SetInfo(std::function<std::ostream&()> info) {
static void SetLoggers(
std::function<std::ostream&()> debug,
std::function<std::ostream&()> info,
std::function<std::ostream&()> warning,
std::function<std::ostream&()> error
) {
m_debug = debug;
m_info = info;
}
static void SetError(std::function<std::ostream&()> error) {
m_warning = warning;
m_error = error;
}

public:
Algorithm(const std::string& name)
: m_name ( name ) {
JugAlgorithm(const std::string& name = "")
: m_name(name) {
}

virtual Out operator()(const In&) const = 0;

protected:
static std::ostream& debug() { return m_debug(); };
static std::ostream& info() { return m_info(); };
static std::ostream& warning() { return m_warning(); };
static std::ostream& error() { return m_error(); };
static std::ostream& endmsg() { return m_endmsg(); };

};

} // namespace Jug
} // namespace algorithms
41 changes: 2 additions & 39 deletions JugBase/JugBase/IParticleSvc.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Whitney Armstrong
#pragma once

#ifndef IParticleSvc_H
#define IParticleSvc_H

#include <GaudiKernel/IService.h>
#include <unordered_map>

namespace Jug::Base {

/** Simple particle data.
*
*/
struct ParticleData {
int pdgCode;
int charge;
double mass; //std::string name;
};
} // namespace Jug::Base

/** Particle interface.
*
* \ingroup base
*/
class GAUDI_API IParticleSvc : virtual public IService {
public:
using Particle = Jug::Base::ParticleData;
using ParticleMap = std::map<int, Particle>;

public:
/// InterfaceID
DeclareInterfaceID(IParticleSvc, 1, 0);
virtual ~IParticleSvc() {}

virtual ParticleMap particleMap() const = 0;
virtual Particle particle(int pdg) const = 0;
};

#endif // IParticleSvc_H
#include "Jug/Particle.h"
13 changes: 13 additions & 0 deletions JugBase/JugBase/Particle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

namespace algorithms::base {

/** Simple particle data.
*
*/
struct Particle {
int pdgCode;
int charge;
double mass; //std::string name;
};
} // namespace algorithms::base
44 changes: 27 additions & 17 deletions JugBase/JugBase/Property.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
namespace Jug {
#pragma once

template <class TYPE>
class Property {
public:
using StorageType = TYPE;
using ValueType = typename std::remove_reference<StorageType>::type;
#include <string>

private:
StorageType m_value;
namespace algorithms {

public:
template <class OWNER>
Property(OWNER* /* owner */, std::string /* name */, TYPE&& value)
: m_value( std::forward<TYPE>( value ) ) {
}
class PropertyBase {
public:
PropertyBase() = default;
};

template <class TYPE> class Property : public PropertyBase {
public:
using StorageType = TYPE;
using ValueType = typename std::remove_reference<StorageType>::type;

const ValueType& value() const { return *this; }
ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
private:
std::string m_name;
StorageType m_value;

public:
template <class OWNER>
Property(OWNER* owner, const std::string& name, TYPE&& value) : m_name(name), m_value(std::forward<TYPE>(value)) {
if (owner != nullptr) {
owner->registerProperty(this, m_name);
}
}

};
const ValueType& value() const { return this->m_value; }
ValueType& value() { return const_cast<ValueType&>((const ValueType&)*this); }
};

} // namespace Jug
} // namespace algorithms
22 changes: 22 additions & 0 deletions JugBase/JugBase/Service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <functional>
#include <string>

#include "JugBase/Algorithm.h"

namespace algorithms {

template <class FUNCTIONAL> class Service : public std::function<FUNCTIONAL> {
private:
std::string m_name;

public:
template <class OWNER> Service(OWNER* /*owner*/, const std::string& name) : m_name(name) {
if (this != nullptr) {
//owner->registerService(this, name);
}
}
};

} // namespace algorithms
Loading