Skip to content

Commit 95895a1

Browse files
committed
Refactor data model, cleanup cmake, progress tracking
1 parent 7673cb8 commit 95895a1

File tree

8 files changed

+88
-84
lines changed

8 files changed

+88
-84
lines changed

source/tdis/CMakeLists.txt

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1313
cmake_policy(SET CMP0144 NEW)
1414

1515

16+
# --------- FETCH DEPENDENCIES --------------
1617
# Fetch CLI11
1718
include(FetchContent)
1819
FetchContent_Declare(
@@ -23,13 +24,11 @@ FetchContent_Declare(
2324
FetchContent_MakeAvailable(CLI11)
2425

2526

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

3433
target_include_directories(podio_model_lib PRIVATE "podio_model")
3534
target_include_directories(podio_model_dict PRIVATE "podio_model")
@@ -55,11 +54,20 @@ find_package(JANA REQUIRED)
5554
find_package(fmt REQUIRED)
5655
find_package(spdlog REQUIRED)
5756
find_package(Boost REQUIRED)
58-
57+
find_package(ROOT COMPONENTS Core RIO Hist Graf Gpad Tree Postscript Matrix Physics MathCore)
5958
find_package(Acts REQUIRED COMPONENTS Core PluginTGeo PluginJson)
6059

6160
target_include_directories(tdis PUBLIC ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/..")
62-
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)
61+
target_link_libraries(tdis
62+
${JANA_LIB}
63+
ROOT::RIO ROOT::Core
64+
podio::podio podio::podioRootIO podio_model_lib podio_model_dict
65+
spdlog::spdlog
66+
fmt::fmt
67+
CLI11::CLI11
68+
Boost::boost
69+
ActsCore ActsPluginTGeo ActsPluginJson
70+
)
6371

6472
set_target_properties(tdis PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
6573
target_include_directories(tdis PRIVATE "podio_model")
@@ -103,61 +111,3 @@ if(WITH_TESTS)
103111
message(WARNING "Catch2 not found, unit tests will not be built.")
104112
endif()
105113
endif()
106-
107-
#
108-
#
109-
## Function creates ${PLUGIN_NAME}_plugin and ${PLUGIN_NAME}_library targets
110-
## Setting default includes, libraries and installation paths
111-
#plugin_add(${PLUGIN_NAME})
112-
#
113-
## The macro grabs sources as *.cc *.cpp *.c and headers as *.h *.hh *.hpp Then
114-
## correctly sets sources for ${_name}_plugin and ${_name}_library targets Adds
115-
## headers to the correct installation directory
116-
#plugin_glob_all(${PLUGIN_NAME})
117-
#
118-
## Find dependencies
119-
#
120-
#plugin_add_acts(${PLUGIN_NAME})
121-
#plugin_add_cern_root(${PLUGIN_NAME})
122-
#plugin_add_event_model(${PLUGIN_NAME})
123-
#
124-
#
125-
#
126-
#plugin_sources(${PLUGIN_NAME} ${DATAMODEL_HEADERS} ${DATAMODEL_SOURCES})
127-
128-
129-
#set(PodioExample_SOURCES
130-
# PodioExample.cc
131-
# PodioExampleProcessor.cc
132-
# PodioExampleSource.cc
133-
# ExampleClusterFactory.cc
134-
# ExampleMultifactory.cc
135-
# )
136-
#
137-
#foreach( _conf ${CMAKE_CONFIGURATION_TYPES} )
138-
# string(TOUPPER ${_conf} _conf )
139-
# set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
140-
# set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
141-
# set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${_conf} ${CMAKE_CURRENT_BINARY_DIR} )
142-
#endforeach()
143-
#
144-
#PODIO_GENERATE_DATAMODEL(datamodel layout.yaml DATAMODEL_HEADERS DATAMODEL_SOURCES IO_BACKEND_HANDLERS ROOT)
145-
#
146-
#PODIO_ADD_DATAMODEL_CORE_LIB(PodioExampleDatamodel "${DATAMODEL_HEADERS}" "${DATAMODEL_SOURCES}")
147-
#
148-
#PODIO_ADD_ROOT_IO_DICT(PodioExampleDatamodelDict PodioExampleDatamodel "${DATAMODEL_HEADERS}" src/selection.xml)
149-
#
150-
#
151-
#
152-
#add_executable(PodioExample ${PodioExample_SOURCES})
153-
#target_include_directories(PodioExample PUBLIC .)
154-
#target_link_libraries(PodioExample jana2 podio::podio PodioExampleDatamodel PodioExampleDatamodelDict podio::podioRootIO)
155-
#set_target_properties(PodioExample PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
156-
#
157-
#install(TARGETS PodioExample DESTINATION bin)
158-
#install(TARGETS PodioExampleDatamodel DESTINATION lib)
159-
#install(TARGETS PodioExampleDatamodelDict DESTINATION lib)
160-
161-
162-
163-

source/tdis/io/DigitizedDataEventSource.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#include "podio_model/EventInfoCollection.h"
5656
#include "services/LogService.hpp"
5757

58-
namespace tdis::readout {
58+
namespace tdis::io {
5959

6060
/** POD structure for readout hits **/
6161
struct DigitizedReadoutHit {
@@ -336,8 +336,8 @@ namespace tdis::readout {
336336
EventInfoCollection info;
337337
info.push_back(MutableEventInfo(0, 0, 0)); // event nr, timeslice nr, run nr
338338
event.InsertCollection<EventInfo>(std::move(info), "EventInfo");
339-
event.InsertCollection<DigitizedMtpcMcTrack>(std::move(podioTracks), "McTracks");
340-
event.InsertCollection<DigitizedMtpcMcHit>(std::move(podioHits), "McHits");
339+
event.InsertCollection<DigitizedMtpcMcTrack>(std::move(podioTracks), "DigitizedMtpcMcTrack");
340+
event.InsertCollection<DigitizedMtpcMcHit>(std::move(podioHits), "DigitizedMtpcMcHit");
341341
m_log->info("Event has been emitted at {}", m_event_line_index);
342342
return Result::Success;
343343
}
@@ -352,7 +352,7 @@ namespace tdis::readout {
352352

353353
// The template specialization needs to be in the global namespace (or at least not inside the tdis namespace)
354354
template <>
355-
inline double JEventSourceGeneratorT<tdis::readout::DigitizedDataEventSource>::CheckOpenable(std::string resource_name) {
355+
inline double JEventSourceGeneratorT<tdis::io::DigitizedDataEventSource>::CheckOpenable(std::string resource_name) {
356356
// CheckOpenable() decides how confident we are that this EventSource can handle this resource.
357357
// 0.0 -> 'Cannot handle'
358358
// (0.0, 1.0] -> 'Cean handle, with this confidence level'

source/tdis/io/PodioWriteProcessor.hpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
#include "services/LogService.hpp"
6666

67-
//namespace tdis::readout {
67+
namespace tdis::io {
6868
class PodioWriteProcessor : public JEventProcessor {
6969

7070
public:
@@ -74,8 +74,8 @@ class PodioWriteProcessor : public JEventProcessor {
7474
"EventInfo",
7575

7676
// Truth record
77-
"McTracks",
78-
"McHits"
77+
"DigitizedMtpcMcTrack",
78+
"DigitizedMtpcMcHit"
7979
};
8080

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

130-
m_output_collections = std::set<std::string>(output_collections.begin(), output_collections.end());
130+
m_output_collections
131+
= std::set<std::string>(output_collections.begin(), output_collections.end());
131132

132133
m_app->SetDefaultParameter(
133-
"podio:print_collections",
134-
m_collections_to_print,
135-
"Comma separated list of collection names to print to screen, e.g. for debugging."
136-
);
134+
"podio:print_collections", m_collections_to_print,
135+
"Comma separated list of collection names to print to screen, e.g. for debugging.");
137136

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

141-
142-
void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
140+
inline void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
143141
std::lock_guard<std::mutex> lock(m_mutex);
144142

143+
m_log->info("PodioWriteProcessor::Process() All event collections:");
144+
auto event_collections = event->GetAllCollectionNames();
145+
for (const auto& coll_name : event_collections) {
146+
try {
147+
m_log->info(" {}", coll_name);
148+
} catch (std::exception& e) {
149+
// chomp
150+
}
151+
}
152+
153+
145154
// Trigger all collections once to fix the collection IDs
155+
m_collections_to_write.clear();
146156
for (const auto& coll_name : m_output_collections) {
147157
try {
148158
[[maybe_unused]] const auto* coll_ptr = event->GetCollectionBase(coll_name);
159+
m_collections_to_write.push_back(coll_name);
149160
} catch (std::exception& e) {
150161
// chomp
151162
}
@@ -243,11 +254,18 @@ void PodioWriteProcessor::Process(const std::shared_ptr<const JEvent>& event) {
243254
}
244255
*/
245256
m_writer->writeFrame(*frame, "events", m_collections_to_write);
257+
258+
auto [missing_names, all_names] = m_writer->checkConsistency(m_collections_to_write, "");
259+
m_log->info("PODIO checkConsistency missing_names: {}", missing_names.size());
260+
for (const auto& coll_name : missing_names) {
261+
m_log->info(" {}", coll_name);
262+
263+
}
246264
m_is_first_event = false;
247265
}
248266

249-
void PodioWriteProcessor::Finish() {
267+
inline void PodioWriteProcessor::Finish() {
250268
m_writer->finish();
251269
}
252270

253-
//}
271+
} // namespace tdis:io

source/tdis/layout.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,22 @@ components:
252252
- 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
253253

254254
datatypes :
255-
EventInfo:
255+
tdis::EventInfo:
256256
Description : "Event info"
257257
Author : "N. Brei"
258258
Members :
259259
- int EventNumber // event number
260260
- int TimesliceNumber // timeslice number
261261
- int RunNumber // run number
262262

263-
TimesliceInfo:
263+
tdis::TimesliceInfo:
264264
Description : "Timeslice info"
265265
Author : "N. Brei"
266266
Members :
267267
- int TimesliceNumber // timeslice number
268268
- int RunNumber // run number
269269

270-
DigitizedMtpcMcTrack:
270+
tdis::DigitizedMtpcMcTrack:
271271
Description: "TDIS MTPC Digitized track"
272272
Author: "Dmitry Romanov"
273273
Members:

source/tdis/services/LogService.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace tdis::services {
111111
// Set log level for this named logger allowing user to specify as config. parameter
112112
// e.g. EcalEndcapPRecHits:LogLevel
113113
std::string log_level_str = default_level ? LogLevelToString(default_level.value()) : m_log_level_str;
114-
m_application->SetDefaultParameter(name + ":LogLevel", log_level_str, "log_level for " + name + ": trace, debug, info, warn, error, critical, off");
114+
m_application->SetDefaultParameter(name + ":log_level", log_level_str, "log_level for " + name + ": trace, debug, info, warn, error, critical, off");
115115
logger->set_level(ParseLogLevel(log_level_str));
116116
}
117117
return logger;

source/tdis/tdis_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ int main(int argc, char* argv[]) {
109109

110110

111111
JApplication app(parameterManager);
112-
app.Add(new JEventSourceGeneratorT<tdis::readout::DigitizedDataEventSource>);
113-
app.Add(new PodioWriteProcessor(&app));
112+
app.Add(new JEventSourceGeneratorT<tdis::io::DigitizedDataEventSource>);
113+
app.Add(new tdis::io::PodioWriteProcessor(&app));
114114
app.ProvideService(std::make_shared<tdis::services::LogService>(&app));
115115
// app.Add(new JEventProcessorPodio);
116116
// app.Add(new JFactoryGeneratorT<ExampleClusterFactory>());

source/tdis/tracking/CkfFitFactory.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <JANA/JFactory.h>
4+
#include <JANA/Components/JOmniFactory.h>
5+
6+
namespace tdis::tracking {
7+
8+
9+
10+
struct MyClusterFactory : public JOmniFactory<MyClusterFactory> {
11+
12+
PodioInput<ExampleCluster> m_protoclusters_in {this};
13+
PodioOutput<ExampleCluster> m_clusters_out {this};
14+
15+
16+
void Configure() {
17+
}
18+
19+
void ChangeRun(int32_t /*run_nr*/) {
20+
}
21+
22+
void Execute(int32_t /*run_nr*/, uint64_t /*evt_nr*/) {
23+
24+
auto cs = std::make_unique<ExampleClusterCollection>();
25+
26+
for (auto protocluster : *m_protoclusters_in()) {
27+
auto cluster = MutableExampleCluster(protocluster.energy() + 1000);
28+
cluster.addClusters(protocluster);
29+
cs->push_back(cluster);
30+
}
31+
32+
m_clusters_out() = std::move(cs);
33+
}
34+
};
35+
36+
}

0 commit comments

Comments
 (0)