Skip to content

Commit 33be63b

Browse files
authored
Enable AT tasks running from examples directory (HeavyIonAnalysis#137)
* make error msg of Branch checks more clear * tidy up examples
1 parent cdd3507 commit 33be63b

6 files changed

+88
-47
lines changed

examples/CMakeLists.txt

+37-39
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
set(EXECUTABLES
2+
example
3+
run_read_task
4+
run_write_task
5+
)
6+
17
set(SOURCES
28
UserTaskWrite.cpp
39
UserTaskRead.cpp
@@ -28,47 +34,39 @@ target_link_libraries(AnalysisTreeUser
2834
include(${ROOT_USE_FILE})
2935
include_directories(${ROOT_INCLUDE_DIR} ${ROOT_INCLUDE_DIRS} ${AnalysisTree_INCLUDE_DIR})
3036

31-
add_executable(example example.cpp)
32-
target_link_libraries(example AnalysisTreeBase AnalysisTreeInfra AnalysisTreeUser ${ROOT_LIBRARIES} EG)
33-
34-
add_executable(run_read_task run_read_task.cpp)
35-
target_link_libraries(run_read_task AnalysisTreeBase AnalysisTreeInfra AnalysisTreeUser ${ROOT_LIBRARIES} EG)
36-
37+
install(TARGETS AnalysisTreeUser EXPORT AnalysisTreeTargets
38+
LIBRARY DESTINATION lib
39+
ARCHIVE DESTINATION lib
40+
RUNTIME DESTINATION bin
41+
INCLUDES DESTINATION include/AnalysisTree
42+
)
3743

44+
install(FILES
45+
${HEADERS}
46+
DESTINATION
47+
include/AnalysisTree
48+
COMPONENT
49+
Devel
50+
)
3851

52+
set(PCM_FILE_NAME libAnalysisTreeUser)
3953

54+
install(FILES
55+
"${CMAKE_CURRENT_BINARY_DIR}/${PCM_FILE_NAME}_rdict.pcm"
56+
DESTINATION
57+
lib
58+
OPTIONAL
59+
)
4060

61+
install(FILES
62+
"${CMAKE_CURRENT_BINARY_DIR}/${PCM_FILE_NAME}.rootmap"
63+
DESTINATION
64+
lib
65+
OPTIONAL
66+
)
4167

42-
#cmake_minimum_required(VERSION 3.5)
43-
#project(AnalysisTreeTask CXX)
44-
#set(PROJECT_VERSION 1.0)
45-
#
46-
#if(NOT DEFINED CMAKE_BUILD_TYPE)
47-
# set(CMAKE_BUILD_TYPE RELEASE)
48-
#endif()
49-
#
50-
#if(NOT DEFINED CMAKE_CXX_STANDARD)
51-
# set(CMAKE_CXX_STANDARD 17)
52-
#endif()
53-
#
54-
## in DEBUG mode make verbose Makefile
55-
#if (CMAKE_BUILD_TYPE MATCHES DEBUG)
56-
# set(CMAKE_VERBOSE_MAKEFILE ON)
57-
#endif ()
58-
#
59-
#if(CMAKE_CXX_STANDARD LESS 17)
60-
# find_package(Boost)
61-
#endif()
62-
#
63-
#if(Boost_FOUND)
64-
# message(STATUS "Boost version ${Boost_VERSION_STRING} is found!")
65-
# message(STATUS "Boost include dir: ${Boost_INCLUDE_DIRS}")
66-
# add_definitions(-DUSEBOOST)
67-
#endif()
68-
#
69-
#find_package(ROOT REQUIRED)
70-
#list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
71-
#find_package(AnalysisTree REQUIRED)
72-
#
73-
#message(STATUS "${ROOT_INCLUDE_DIRS} ${AnalysisTree_INCLUDE_DIR}")
74-
#message(STATUS "${ROOT_LIBRARIES} ${AnalysisTree_INCLUDE_DIR}")
68+
foreach(EXE ${EXECUTABLES})
69+
add_executable(${EXE} ${EXE}.cpp)
70+
target_link_libraries(${EXE} AnalysisTreeBase AnalysisTreeInfra AnalysisTreeUser ${ROOT_LIBRARIES} EG)
71+
install (TARGETS ${EXE} RUNTIME DESTINATION bin)
72+
endforeach()

examples/UserTaskRead.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ void UserTaskRead::Init() {
1111
AddInputBranch("SimParticles");
1212
AddInputBranch("VtxTracks");
1313

14-
particles_ = chain->GetBranch("SimParticles");
15-
tracks_ = chain->GetBranch("VtxTracks");
14+
particles_ = chain->GetBranchObject("SimParticles");
15+
tracks_ = chain->GetBranchObject("VtxTracks");
1616
match_ = chain->GetMatching("VtxTracks", "SimParticles");
1717
}
1818

examples/UserTaskWrite.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void UserTaskWrite::Init() {
99
auto chain = man->GetChain();
1010

1111
AddInputBranch("SimParticles");
12-
particles_ = chain->GetBranch("SimParticles");
12+
particles_ = chain->GetBranchObject("SimParticles");
1313

1414
auto br_conf = chain->GetConfiguration()->GetBranchConfig("SimParticles");
1515
auto new_conf = br_conf.Clone("NewParticles", DetType::kParticle);
@@ -18,6 +18,7 @@ void UserTaskWrite::Init() {
1818

1919
new_particles_ = Branch(new_conf);
2020
new_particles_.SetMutable();
21+
particles_.Freeze();
2122
man->AddBranch(&new_particles_);
2223
}
2324

examples/run_read_task.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char* argv[]) {
1313

1414
if (argc < 3) {
1515
std::cout << "Error! Please use " << std::endl;
16-
std::cout << " ./example filelist treename" << std::endl;
16+
std::cout << " ./run_read_task filelist treename" << std::endl;
1717
exit(EXIT_FAILURE);
1818
}
1919

examples/run_write_task.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Copyright (C) 2025 GSI, Heidelberg University
2+
SPDX-License-Identifier: GPL-3.0-only
3+
Authors: Oleksii Lubynets, Ilya Selyuzhenkov */
4+
#include "UserTaskWrite.hpp"
5+
#include <TaskManager.hpp>
6+
7+
using namespace AnalysisTree;
8+
9+
void run_write_task(const std::string& filelist, const std::string& treename);
10+
11+
int main(int argc, char* argv[]) {
12+
if (argc < 3) {
13+
std::cout << "Error! Please use " << std::endl;
14+
std::cout << " ./run_write_task filelist treename" << std::endl;
15+
exit(EXIT_FAILURE);
16+
}
17+
18+
const std::string filelist = argv[1];
19+
const std::string treename = argv[2];
20+
run_write_task(filelist, treename);
21+
22+
return 0;
23+
}
24+
25+
void run_write_task(const std::string& filelist, const std::string& treename) {
26+
auto* man = TaskManager::GetInstance();
27+
man->SetOutputName("UTW_output.root", "aTree");
28+
man->SetWriteMode(eBranchWriteMode::kCopyTree);
29+
30+
auto* task = new UserTaskWrite();
31+
man->AddTask(task);
32+
33+
man->Init({filelist}, {treename});
34+
man->Run(2);
35+
man->Finish();
36+
}

infra/Branch.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@ class Branch {
102102

103103
/* Checks are used very often */
104104
inline void CheckFrozen(bool expected = true) const {
105-
if (is_frozen_ != expected)
106-
throw std::runtime_error("Branch is frozen");
105+
if (is_frozen_ != expected) {
106+
const std::string prefix = expected ? "un" : "";
107+
const std::string message = "Branch " + config_.GetName() + " is " + prefix + "frozen while the opposite was expected";
108+
throw std::runtime_error(message);
109+
}
107110
}
108111
inline void CheckMutable(bool expected = true) const {
109-
if (is_mutable_ != expected)
110-
throw std::runtime_error("Branch is not mutable");
112+
if (is_mutable_ != expected) {
113+
const std::string prefix = expected ? "im" : "";
114+
const std::string message = "Branch " + config_.GetName() + " is " + prefix + "mutable while the opposite was expected";
115+
throw std::runtime_error(message);
116+
}
111117
}
112118
/**
113119
* @brief Gets variables according to variable names specified in the arguments.

0 commit comments

Comments
 (0)