Skip to content

Commit e38f721

Browse files
add logs; improve CMake
1 parent d264d9e commit e38f721

12 files changed

Lines changed: 110 additions & 148 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(AnalysisTreeQA_BUNDLED_AT_VERSION "v2.2.6" CACHE STRING "Bundled AnalysisTre
1717
set(AnalysisTreeQA_BUNDLED_CUTS ON CACHE BOOL "Get and build AnalysisTreeCuts")
1818
set(AnalysisTreeQA_BUNDLED_CUTS_VERSION "v0.0.1" CACHE STRING "Bundled AnalysisTreeCuts version")
1919

20+
option(yaml-cpp_BUNDLED "Build bundled yaml-cpp" OFF)
21+
2022
# by default build optimized code
2123
if(NOT DEFINED CMAKE_BUILD_TYPE)
2224
set(CMAKE_BUILD_TYPE RELEASE)
@@ -48,7 +50,9 @@ list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
4850
list(APPEND CMAKE_PREFIX_PATH ${ROOTSYS})
4951

5052
find_package(ROOT REQUIRED RIO)
51-
find_package(yaml-cpp REQUIRED)
53+
54+
include(cmake_modules/YamlCpp.cmake)
55+
include(cmake_modules/AnalysisTree.cmake)
5256

5357
message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>")
5458
include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIR} ${ROOT_INCLUDE_DIRS})

cmake_modules/YamlCpp.cmake

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
if (TRUE)
2-
message("-- Building bundled yaml-cpp")
3-
include(FetchContent)
1+
if (yaml-cpp_BUNDLED)
2+
message("-- Building bundled yaml-cpp package...")
3+
include(ExternalProject)
44

5-
FetchContent_Declare(
6-
YamlCpp
5+
ExternalProject_Add(
6+
yaml-cpp_Ext
77
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
8-
GIT_TAG "yaml-cpp-0.7.0"
8+
GIT_TAG yaml-cpp-0.6.3
99
GIT_SHALLOW ON
10+
CMAKE_ARGS
11+
-DYAML_BUILD_SHARED_LIBS=ON
12+
-DCMAKE_BUILD_TYPE=Release
13+
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/external/yaml-cpp
14+
PREFIX ${CMAKE_BINARY_DIR}/external/yaml-cpp
1015
)
11-
FetchContent_MakeAvailable(YamlCpp)
16+
17+
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
18+
19+
add_library(yaml-cpp SHARED IMPORTED GLOBAL)
20+
set_target_properties(yaml-cpp PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/external/yaml-cpp/lib/libyaml-cpp.so)
21+
target_include_directories(yaml-cpp INTERFACE ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
22+
add_dependencies(yaml-cpp yaml-cpp_Ext yaml-cpp.include)
23+
24+
set(yaml-cpp_FOUND TRUE)
25+
set(yaml-cpp_INCLUDE_DIR ${CMAKE_BINARY_DIR}/external/yaml-cpp/include)
1226
else()
13-
list(APPEND CMAKE_PREFIX_PATH ${ANALYSISTREE_HOME})
14-
list(APPEND CMAKE_PREFIX_PATH $ENV{ANALYSISTREE_HOME})
15-
find_package(AnalysisTree REQUIRED)
16-
list(APPEND PROJECT_INCLUDE_DIRECTORIES ${YAML_CPP_INCLUDE_DIR})
17-
endif()
27+
find_package(yaml-cpp REQUIRED)
28+
endif ()

examples/CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include(AnalysisTree)
2-
31
if(Boost_FOUND)
42
include_directories(${PROJECT_INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIR})
53
link_directories(${PROJECT_LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})
@@ -17,9 +15,8 @@ add_executable(example example.cpp)
1715
add_dependencies(example AnalysisTreeQA)
1816
target_link_libraries(example ${ROOT_LIBRARIES} AnalysisTreeQA AnalysisTreeBase AnalysisTreeInfra)
1917

20-
add_executable(test_yaml test_yaml.cpp)
21-
add_dependencies(test_yaml AnalysisTreeQA)
22-
target_link_libraries(test_yaml ${ROOT_LIBRARIES} AnalysisTreeQA AnalysisTreeBase AnalysisTreeInfra ${YAML_CPP_LIBRARIES})
23-
18+
add_executable(example_yaml example_yaml.cpp)
19+
add_dependencies(example_yaml AnalysisTreeQA)
20+
target_link_libraries(example_yaml ${ROOT_LIBRARIES} AnalysisTreeQA AnalysisTreeBase AnalysisTreeInfra ${YAML_CPP_LIBRARIES})
2421

2522
install (TARGETS example RUNTIME DESTINATION bin)

src/Axis.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "Axis.hpp"
2+
3+
namespace AnalysisTree {
4+
namespace QA {
5+
6+
using std::cout;
7+
using std::endl;
8+
using std::setw;
9+
10+
void Axis::Print() const {
11+
cout << setw(25) << this->name_ << " ";
12+
if (this->IsVariableBinSize()) {
13+
cout << setw(4) << this->GetNbins() << setw(6) << this->GetXmin() << " .. " << setw(2) << this->GetXmax();
14+
} else {
15+
cout << setw(4) << this->GetNbins() << setw(6) << this->GetXmin() << setw(6) << this->GetXmax();
16+
}
17+
}
18+
19+
}
20+
}

src/Axis.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef ANALYSISTREEQA_AXIS_HPP
2+
#define ANALYSISTREEQA_AXIS_HPP
3+
4+
#include "TAxis.h"
5+
#include "AnalysisTree/Variable.hpp"
6+
7+
namespace AnalysisTree {
8+
namespace QA {
9+
10+
class Axis : public Variable, public TAxis {
11+
public:
12+
Axis() = default;
13+
Axis(const std::string& title, const Variable& var, const TAxis& a) : Variable(var), TAxis(a) {
14+
this->SetTitle(title.c_str());
15+
if(this->GetFields().size() == 1 && this->GetFields().at(0).GetName() == "ones"){
16+
this->lambda_ = [](const std::vector<double>& ){ return 1; };
17+
this->name_ = "Ones";
18+
}
19+
}
20+
const char* GetName() const override { return Variable::GetName().c_str(); }
21+
void Print() const override ;
22+
23+
protected:
24+
ClassDefOverride(Axis, 1);
25+
};
26+
}
27+
}
28+
#endif//ANALYSISTREEQA_AXIS_HPP

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
include(AnalysisTree)
2-
#include(YamlCpp)
32

43
set(SOURCES
54
EntryConfig.cpp
65
Task.cpp
7-
YamlReader.cpp)
6+
YamlReader.cpp Axis.cpp Axis.hpp)
87

98
string(REPLACE ".cpp" ".hpp" HEADERS "${SOURCES}")
109
list(APPEND HEADERS "BasicQA.hpp")
@@ -30,12 +29,13 @@ target_link_libraries(AnalysisTreeQA
3029
PUBLIC
3130
AnalysisTreeBase
3231
AnalysisTreeInfra
33-
# ${YAML_CPP_LIBRARIES}
32+
yaml-cpp
3433
)
3534
target_include_directories(AnalysisTreeQA
3635
PUBLIC
3736
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
3837
${YAML_CPP_INCLUDE_DIR}
38+
${yaml-cpp_INCLUDE_DIR}
3939
)
4040

4141
install(TARGETS AnalysisTreeQA EXPORT AnalysisTreeQATargets

src/EntryConfig.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ EntryConfig::EntryConfig(const Axis& axis, Cuts* cuts, bool is_integral, const s
3434
name_ += "_integral";
3535
}
3636
InitPlot();
37+
Print();
3738
}
3839

3940
EntryConfig::EntryConfig(const Axis& x, const Axis& y, Cuts* cuts, bool is_profile, const std::string& name)
@@ -43,6 +44,7 @@ EntryConfig::EntryConfig(const Axis& x, const Axis& y, Cuts* cuts, bool is_profi
4344
{
4445
name_ = name.empty() ? Construct2DName() : name;
4546
InitPlot();
47+
Print();
4648
}
4749

4850
EntryConfig::EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_y, const std::string& name)
@@ -52,6 +54,7 @@ EntryConfig::EntryConfig(const Axis& x, Cuts* cuts_x, const Axis& y, Cuts* cuts_
5254
{
5355
name_ = name.empty() ? Construct2DName() : name;
5456
InitPlot();
57+
Print();
5558
}
5659

5760
TH1* EntryConfig::CreateHisto1D() const {
@@ -158,5 +161,26 @@ std::string EntryConfig::GetDirectoryName() const {
158161
return name;
159162
}
160163

164+
void EntryConfig::Print() const {
165+
using std::cout;
166+
using std::endl;
167+
using std::setw;
168+
169+
switch (type_) {
170+
case PlotType::kHisto1D : cout << setw(12) << "1D histo"; break;
171+
case PlotType::kHisto2D : cout << setw(12) << "2D histo"; break;
172+
case PlotType::kProfile : cout << setw(12) << "Profile"; break;
173+
case PlotType::kIntegral1D : cout << setw(12) << "Integral"; break;
174+
case PlotType::kIntegral2D : cout << setw(12) << "2D integral"; break;
175+
}
176+
for(const auto& axis : axes_){
177+
axis.Print();
178+
}
179+
if(entry_cuts_){
180+
cout << setw(15) << entry_cuts_->GetName();
181+
}
182+
cout << endl;
183+
}
184+
161185
}// namespace QA
162186
}// namespace AnalysisTree

src/EntryConfig.hpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,18 @@
44
#include <string>
55
#include <vector>
66

7-
#include <TAxis.h>
8-
97
#include "AnalysisTree/Cuts.hpp"
108
#include "AnalysisTree/Utils.hpp"
119

10+
#include <Axis.hpp>
11+
1212
class TH1;
1313
class TH2;
1414
class TProfile;
1515

1616
namespace AnalysisTree {
1717
namespace QA {
1818

19-
class Axis : public Variable, public TAxis {
20-
public:
21-
Axis() = default;
22-
Axis(const std::string& title, const Variable& var, const TAxis& a) : Variable(var), TAxis(a) {
23-
this->SetTitle(title.c_str());
24-
if(this->GetFields().size() == 1 && this->GetFields().at(0).GetName() == "ones"){
25-
this->lambda_ = [](const std::vector<double>& ){ return 1; };
26-
this->name_ = "Ones";
27-
}
28-
}
29-
const char* GetName() const override { return Variable::GetName().c_str(); }
30-
31-
protected:
32-
ClassDefOverride(Axis, 1);
33-
};
34-
3519
class EntryConfig {
3620

3721
using PlotPointer = ANALYSISTREE_UTILS_VARIANT<TH1*, TH2*, TProfile*>;
@@ -84,6 +68,8 @@ class EntryConfig {
8468

8569
PlotPointer GetPlot() { return plot_; }
8670

71+
void Print() const;
72+
8773
protected:
8874
void InitPlot();
8975
ANALYSISTREE_ATTR_NODISCARD TH1* CreateHisto1D() const;

tasks/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)