Skip to content

Commit

Permalink
Refactor data model, cleanup cmake, progress tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Nov 11, 2024
1 parent 7673cb8 commit 95895a1
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 84 deletions.
74 changes: 12 additions & 62 deletions source/tdis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
cmake_policy(SET CMP0144 NEW)


# --------- FETCH DEPENDENCIES --------------
# Fetch CLI11
include(FetchContent)
FetchContent_Declare(
Expand All @@ -23,13 +24,11 @@ FetchContent_Declare(
FetchContent_MakeAvailable(CLI11)



# --------- GENERATE PODIO --------------
find_package(podio REQUIRED)
PODIO_GENERATE_DATAMODEL(podio_model "layout.yaml" DATAMODEL_HEADERS DATAMODEL_SOURCES OUTPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/podio_model")
PODIO_ADD_DATAMODEL_CORE_LIB(podio_model_lib "${DATAMODEL_HEADERS}" "${DATAMODEL_SOURCES}")
PODIO_ADD_ROOT_IO_DICT(podio_model_dict podio_model_lib "${DATAMODEL_HEADERS}" "podio_model/src/selection.xml")
message(STATUS "PODIO MODEL DICT: ${podio_model_dict}")

target_include_directories(podio_model_lib PRIVATE "podio_model")
target_include_directories(podio_model_dict PRIVATE "podio_model")
Expand All @@ -55,11 +54,20 @@ find_package(JANA REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(Boost REQUIRED)

find_package(ROOT COMPONENTS Core RIO Hist Graf Gpad Tree Postscript Matrix Physics MathCore)
find_package(Acts REQUIRED COMPONENTS Core PluginTGeo PluginJson)

target_include_directories(tdis PUBLIC ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/..")
target_link_libraries(tdis ${JANA_LIB} podio::podio podio::podioRootIO podio_model_lib podio_model_dict spdlog::spdlog fmt::fmt CLI11::CLI11 Boost::boost ActsCore ActsPluginTGeo ActsPluginJson)
target_link_libraries(tdis
${JANA_LIB}
ROOT::RIO ROOT::Core
podio::podio podio::podioRootIO podio_model_lib podio_model_dict
spdlog::spdlog
fmt::fmt
CLI11::CLI11
Boost::boost
ActsCore ActsPluginTGeo ActsPluginJson
)

set_target_properties(tdis PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
target_include_directories(tdis PRIVATE "podio_model")
Expand Down Expand Up @@ -103,61 +111,3 @@ if(WITH_TESTS)
message(WARNING "Catch2 not found, unit tests will not be built.")
endif()
endif()

#
#
## Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets
## Setting default includes, libraries and installation paths
#plugin_add(${PLUGIN_NAME})
#
## The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then
## correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds
## headers to the correct installation directory
#plugin_glob_all(${PLUGIN_NAME})
#
## Find dependencies
#
#plugin_add_acts(${PLUGIN_NAME})
#plugin_add_cern_root(${PLUGIN_NAME})
#plugin_add_event_model(${PLUGIN_NAME})
#
#
#
#plugin_sources(${PLUGIN_NAME} ${DATAMODEL_HEADERS} ${DATAMODEL_SOURCES})


#set(PodioExample_SOURCES
# PodioExample.cc
# PodioExampleProcessor.cc
# PodioExampleSource.cc
# ExampleClusterFactory.cc
# ExampleMultifactory.cc
# )
#
#foreach( _conf ${CMAKE_CONFIGURATION_TYPES} )
# string(TOUPPER ${_conf} _conf )
# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
#endforeach()
#
#PODIO_GENERATE_DATAMODEL(datamodel layout.yaml DATAMODEL_HEADERS DATAMODEL_SOURCES IO_BACKEND_HANDLERS ROOT)
#
#PODIO_ADD_DATAMODEL_CORE_LIB(PodioExampleDatamodel "${DATAMODEL_HEADERS}" "${DATAMODEL_SOURCES}")
#
#PODIO_ADD_ROOT_IO_DICT(PodioExampleDatamodelDict PodioExampleDatamodel "${DATAMODEL_HEADERS}" src/selection.xml)
#
#
#
#add_executable(PodioExample ${PodioExample_SOURCES})
#target_include_directories(PodioExample PUBLIC .)
#target_link_libraries(PodioExample jana2 podio::podio PodioExampleDatamodel PodioExampleDatamodelDict podio::podioRootIO)
#set_target_properties(PodioExample PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
#
#install(TARGETS PodioExample DESTINATION bin)
#install(TARGETS PodioExampleDatamodel DESTINATION lib)
#install(TARGETS PodioExampleDatamodelDict DESTINATION lib)




8 changes: 4 additions & 4 deletions source/tdis/io/DigitizedDataEventSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "podio_model/EventInfoCollection.h"
#include "services/LogService.hpp"

namespace tdis::readout {
namespace tdis::io {

/** POD structure for readout hits **/
struct DigitizedReadoutHit {
Expand Down Expand Up @@ -336,8 +336,8 @@ namespace tdis::readout {
EventInfoCollection info;
info.push_back(MutableEventInfo(0, 0, 0)); // event nr, timeslice nr, run nr
event.InsertCollection<EventInfo>(std::move(info), "EventInfo");
event.InsertCollection<DigitizedMtpcMcTrack>(std::move(podioTracks), "McTracks");
event.InsertCollection<DigitizedMtpcMcHit>(std::move(podioHits), "McHits");
event.InsertCollection<DigitizedMtpcMcTrack>(std::move(podioTracks), "DigitizedMtpcMcTrack");
event.InsertCollection<DigitizedMtpcMcHit>(std::move(podioHits), "DigitizedMtpcMcHit");
m_log->info("Event has been emitted at {}", m_event_line_index);
return Result::Success;
}
Expand All @@ -352,7 +352,7 @@ namespace tdis::readout {

// The template specialization needs to be in the global namespace (or at least not inside the tdis namespace)
template <>
inline double JEventSourceGeneratorT<tdis::readout::DigitizedDataEventSource>::CheckOpenable(std::string resource_name) {
inline double JEventSourceGeneratorT<tdis::io::DigitizedDataEventSource>::CheckOpenable(std::string resource_name) {
// CheckOpenable() decides how confident we are that this EventSource can handle this resource.
// 0.0 -> 'Cannot handle'
// (0.0, 1.0] -> 'Cean handle, with this confidence level'
Expand Down
42 changes: 30 additions & 12 deletions source/tdis/io/PodioWriteProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

#include "services/LogService.hpp"

//namespace tdis::readout {
namespace tdis::io {
class PodioWriteProcessor : public JEventProcessor {

public:
Expand All @@ -74,8 +74,8 @@ class PodioWriteProcessor : public JEventProcessor {
"EventInfo",

// Truth record
"McTracks",
"McHits"
"DigitizedMtpcMcTrack",
"DigitizedMtpcMcHit"
};

PodioWriteProcessor(JApplication * app);
Expand Down Expand Up @@ -127,25 +127,36 @@ inline void PodioWriteProcessor::Init() {
"be written (including ones from input file). Don't set this and use "
"PODIO:OUTPUT_EXCLUDE_COLLECTIONS to write everything except a selection.");

m_output_collections = std::set<std::string>(output_collections.begin(), output_collections.end());
m_output_collections
= std::set<std::string>(output_collections.begin(), output_collections.end());

m_app->SetDefaultParameter(
"podio:print_collections",
m_collections_to_print,
"Comma separated list of collection names to print to screen, e.g. for debugging."
);
"podio:print_collections", m_collections_to_print,
"Comma separated list of collection names to print to screen, e.g. for debugging.");

m_writer = std::make_unique<podio::ROOTWriter>(m_output_file);
}


void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
std::lock_guard<std::mutex> lock(m_mutex);

m_log->info("PodioWriteProcessor::Process() All event collections:");
auto event_collections = event->GetAllCollectionNames();
for (const auto& coll_name : event_collections) {
try {
m_log->info(" {}", coll_name);
} catch (std::exception& e) {
// chomp
}
}


// Trigger all collections once to fix the collection IDs
m_collections_to_write.clear();
for (const auto& coll_name : m_output_collections) {
try {
[[maybe_unused]] const auto* coll_ptr = event->GetCollectionBase(coll_name);
m_collections_to_write.push_back(coll_name);
} catch (std::exception& e) {
// chomp
}
Expand Down Expand Up @@ -243,11 +254,18 @@ void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
}
*/
m_writer->writeFrame(*frame, "events", m_collections_to_write);

auto [missing_names, all_names] = m_writer->checkConsistency(m_collections_to_write, "");
m_log->info("PODIO checkConsistency missing_names: {}", missing_names.size());
for (const auto& coll_name : missing_names) {
m_log->info(" {}", coll_name);

}
m_is_first_event = false;
}

void PodioWriteProcessor::Finish() {
inline void PodioWriteProcessor::Finish() {
m_writer->finish();
}

//}
} // namespace tdis:io
6 changes: 3 additions & 3 deletions source/tdis/layout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,22 @@ components:
- std::array<double,16> transform // row-wise 4x4 affine transform [R T; 0 1] with 3x3 rotation matrix R and translation column 3-vector T

datatypes :
EventInfo:
tdis::EventInfo:
Description : "Event info"
Author : "N. Brei"
Members :
- int EventNumber // event number
- int TimesliceNumber // timeslice number
- int RunNumber // run number

TimesliceInfo:
tdis::TimesliceInfo:
Description : "Timeslice info"
Author : "N. Brei"
Members :
- int TimesliceNumber // timeslice number
- int RunNumber // run number

DigitizedMtpcMcTrack:
tdis::DigitizedMtpcMcTrack:
Description: "TDIS MTPC Digitized track"
Author: "Dmitry Romanov"
Members:
Expand Down
2 changes: 1 addition & 1 deletion source/tdis/services/LogService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace tdis::services {
// Set log level for this named logger allowing user to specify as config. parameter
// e.g. EcalEndcapPRecHits:LogLevel
std::string log_level_str = default_level ? LogLevelToString(default_level.value()) : m_log_level_str;
m_application->SetDefaultParameter(name + ":LogLevel", log_level_str, "log_level for " + name + ": trace, debug, info, warn, error, critical, off");
m_application->SetDefaultParameter(name + ":log_level", log_level_str, "log_level for " + name + ": trace, debug, info, warn, error, critical, off");
logger->set_level(ParseLogLevel(log_level_str));
}
return logger;
Expand Down
4 changes: 2 additions & 2 deletions source/tdis/tdis_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ int main(int argc, char* argv[]) {


JApplication app(parameterManager);
app.Add(new JEventSourceGeneratorT<tdis::readout::DigitizedDataEventSource>);
app.Add(new PodioWriteProcessor(&app));
app.Add(new JEventSourceGeneratorT<tdis::io::DigitizedDataEventSource>);
app.Add(new tdis::io::PodioWriteProcessor(&app));
app.ProvideService(std::make_shared<tdis::services::LogService>(&app));
// app.Add(new JEventProcessorPodio);
// app.Add(new JFactoryGeneratorT<ExampleClusterFactory>());
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions source/tdis/tracking/CkfFitFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <JANA/JFactory.h>
#include <JANA/Components/JOmniFactory.h>

namespace tdis::tracking {



struct MyClusterFactory : public JOmniFactory<MyClusterFactory> {

PodioInput<ExampleCluster> m_protoclusters_in {this};
PodioOutput<ExampleCluster> m_clusters_out {this};


void Configure() {
}

void ChangeRun(int32_t /*run_nr*/) {
}

void Execute(int32_t /*run_nr*/, uint64_t /*evt_nr*/) {

auto cs = std::make_unique<ExampleClusterCollection>();

for (auto protocluster : *m_protoclusters_in()) {
auto cluster = MutableExampleCluster(protocluster.energy() + 1000);
cluster.addClusters(protocluster);
cs->push_back(cluster);
}

m_clusters_out() = std::move(cs);
}
};

}

0 comments on commit 95895a1

Please sign in to comment.