Advanced Computing Platform for Theoretical Physics

Commit ebdbfbf7 authored by Yu-Chen Ding's avatar Yu-Chen Ding
Browse files

optional ROOT support

parent 5f786ca2
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.1)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
......@@ -7,7 +7,7 @@ endif (POLICY CMP0048)
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Release)
endif()
message(">> CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
......@@ -16,38 +16,49 @@ project(CRDB
LANGUAGES CXX
DESCRIPTION "C++ utility for analysis cosmic ray data")
find_package(ROOT)
if (ROOT_FOUND)
include_directories("${ROOT_INCLUDE_DIRS}")
add_definitions(-DWITH_ROOT)
MESSAGE(">> ROOT found")
if (NOT CMAKE_CXX_STANDARD)
string(REGEX MATCH "-std=(c|gnu)\\+\\+.." ROOT_CXX_STANDARD ${ROOT_CXX_FLAGS})
string(REGEX MATCH "..$" ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 0x 11 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 1y 14 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 1z 17 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 2a 20 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
if (ROOT_CXX_STANDARD)
MESSAGE(">> ROOT_CXX_STANDARD: ${ROOT_CXX_STANDARD}")
set (CMAKE_CXX_STANDARD ${ROOT_CXX_STANDARD} CACHE STRING "")
else(ROOT_CXX_STANDARD)
set (CMAKE_CXX_STANDARD 14)
endif (ROOT_CXX_STANDARD)
endif (NOT CMAKE_CXX_STANDARD)
MESSAGE(">> CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
else (ROOT_FOUND)
MESSAGE(">> ROOT not found")
endif (ROOT_FOUND)
set(WITHOUT_ROOT FALSE CACHE BOOL "disable root library for plotting")
if(WITHOUT_ROOT)
add_definitions(-DWITHOUT_ROOT)
MESSAGE(">> ROOT disabled")
else()
find_package(ROOT)
if(ROOT_FOUND)
include_directories("${ROOT_INCLUDE_DIRS}")
MESSAGE(">> ROOT found")
if(NOT CMAKE_CXX_STANDARD)
string(REGEX MATCH "-std=(c|gnu)\\+\\+.." ROOT_CXX_STANDARD ${ROOT_CXX_FLAGS})
string(REGEX MATCH "..$" ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 0x 11 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 1y 14 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 1z 17 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
string(REPLACE 2a 20 ROOT_CXX_STANDARD ${ROOT_CXX_STANDARD})
if(ROOT_CXX_STANDARD)
MESSAGE(">> ROOT_CXX_STANDARD: ${ROOT_CXX_STANDARD}")
set (CMAKE_CXX_STANDARD ${ROOT_CXX_STANDARD} CACHE STRING "")
else()
set (CMAKE_CXX_STANDARD 14)
endif()
endif(NOT CMAKE_CXX_STANDARD)
MESSAGE(">> CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
else()
add_definitions(-DWITHOUT_ROOT)
MESSAGE(">> ROOT not found")
endif()
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
find_package(CURL REQUIRED)
if (CURL_FOUND)
add_definitions(-DWITH_CURL)
endif (CURL_FOUND)
add_definitions(-DWITHOUT_CURL)
endif()
configure_file(include/crdb.h.in include/crdb.h @ONLY)
include(GNUInstallDirs OPTIONAL)
# set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "install libdir")
# set(CMAKE_INSTALL_INCLUDEDIR include CACHE PATH "install includedir")
add_subdirectory(src)
add_subdirectory(apps)
......@@ -63,4 +74,4 @@ message(">> CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# Requirements: Copy the uninstall.cmake file to the appropriate CMAKE_MODULE_PATH.
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake"
)
)
......@@ -318,7 +318,7 @@ class argument {
o->value = "0";
o->valid = true;
continue;
} else if (o = find_flag(a.substr(2))) {
} else if ((o = find_flag(a.substr(2)))) {
// set flag
o->value = "1";
o->valid = true;
......@@ -339,7 +339,7 @@ class argument {
o->valid = true;
continue;
}
} else if (o = find_option(a.substr(2, eqpos - 2))) {
} else if ((o = find_option(a.substr(2, eqpos - 2)))) {
// joined long argument
o->value = a.substr(eqpos + 1);
o->valid = true;
......@@ -355,11 +355,11 @@ class argument {
} else if (a.length() > 1 && a[0] == '-') {
// short arguments
for (size_t j = 1; j < a.length(); ++j) {
if (o = find_flag(a[j])) {
if ((o = find_flag(a[j]))) {
o->value = "1";
o->valid = true;
continue;
} else if (o = find_option(a[j])) {
} else if ((o = find_option(a[j]))) {
if (++j == a.length()) {
// end of string, read next argument
if (++i == argc) {
......@@ -405,9 +405,10 @@ class argument {
if (opt.short_name % 32 == 0) {
name = "--" + opt.long_name;
} else if (opt.long_name.empty()) {
name = '-' + opt.short_name;
name = std::string("-") + opt.short_name;
} else {
name = '-' + opt.short_name + "/--" + opt.long_name;
name = std::string("-") + opt.short_name + "/--" +
opt.long_name;
}
std::cerr << _position[0] << ": require option '" << name
<< "'" << std::endl;
......
......@@ -7,7 +7,13 @@
#include <valarray>
#include <vector>
#ifndef _WITHOUT_ROOT
#ifndef WITHOUT_ROOT
#if @WITHOUT_ROOT@
#define WIHTOUT_ROOT
#endif
#endif
#ifndef WITHOUT_ROOT
#include <TCanvas.h>
#endif
......@@ -197,8 +203,8 @@ class CRPlot {
const std::array<size_t, 4>& columns = {0});
void DropBand(const std::string& label = "");
#ifndef WITHOUT_ROOT
public:
#ifndef _WITHOUT_ROOT
std::shared_ptr<TCanvas> Plot(void) const;
#endif
};
......
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.1)
file(GLOB CRDB_SOURCES *.cc)
file(GLOB CRDB_HEADERS ${PROJECT_SOURCE_DIR}/include/crdb.h)
file(GLOB CRDB_HEADERS ${PROJECT_BINARY_DIR}/include/crdb.h)
if (${CMAKE_CXX_STANDARD} LESS 17)
set_source_files_properties(${CRDB_SOURCE_DIR}/src/crrequest.cc PROPERTIES
COMPILE_FLAGS "-std=c++1z") # using 1z since the compiler is probably old enough
set_source_files_properties(${CRDB_SOURCE_DIR}/src/crinfo.cc PROPERTIES
COMPILE_FLAGS "-std=c++1z") # using 1z since the compiler is probably old enough
endif()
add_library(crdb SHARED ${CRDB_SOURCES})
target_include_directories(crdb PUBLIC ${CRDB_SOURCE_DIR}/include)
target_include_directories(crdb PUBLIC ${CRDB_BINARY_DIR}/include)
target_link_libraries(crdb
PRIVATE ${CURL_LIBRARIES}
PRIVATE ${ROOT_LIBRRIES}
......
#define WITHOUT_ROOT
#include "crinfo.hh"
#include "crdb.h"
......
#include "crutil.hh"
#include "loginterp"
#include <crdb.h>
#include <iostream>
......@@ -8,18 +9,17 @@
#include <sstream>
#include <vector>
#ifndef WITHOUT_ROOT
#include <TColor.h>
#include <TError.h>
#include <TFile.h>
#include <TGaxis.h>
#include <TGraphAsymmErrors.h>
#include <TH1D.h>
#include <TLegend.h>
#include <TPad.h>
#include <TError.h>
#include "loginterp"
int gErrorIgnoreLevel = kWarning;
#endif
namespace _CRPLOT {
template <size_t N>
......@@ -86,8 +86,7 @@ CRPlot::CRPlot(const std::string& title, int canv_w, int canv_h)
ratio_min(NAN), ratio_max(NAN), //
canvas_width(canv_w), //
canvas_height(canv_h), //
divide_ratio(0.3) {
}
divide_ratio(0.3) {}
using Style = CRPlot::Style;
void CRPlot::AddData(const CRData& data, const Style& style,
......@@ -206,6 +205,7 @@ double AdjustYMax(const CRPlot& plot) {
return y;
}
#ifndef WITHOUT_ROOT
std::shared_ptr<TCanvas> CRPlot::Plot(void) const {
const bool with_ratio = !ratio_ref.empty();
double x_min_plot = std::isnan(x_min) ? AdjustXMin(*this) : x_min;
......@@ -496,22 +496,18 @@ std::shared_ptr<TCanvas> CRPlot::Plot(void) const {
switch (legend_phase) {
case 1:
// l = pad_plot->BuildLegend(0.6, 0.9 - nLedgend * .03, 0.9, 0.9);
leg->SetX1(0.6);
leg->SetY1(leg->GetY2() - n_entry * 0.03);
break;
case 2:
// l = pad_plot->BuildLegend(0.1, 0.9 - nLedgend * .03, 0.4, 0.9);
leg->SetX2(0.4);
leg->SetY1(leg->GetY2() - n_entry * 0.03);
break;
case 3:
// l = pad_plot->BuildLegend(0.1, 0.1, 0.4, 0.1 + nLedgend * .03);
leg->SetX2(0.4);
leg->SetY2(leg->GetY1() + n_entry * 0.03);
break;
case 4:
// l = pad_plot->BuildLegend(0.6, 0.1, 0.9, 0.1 + nLedgend * .03);
leg->SetX1(0.6);
leg->SetY2(leg->GetY1() + n_entry * 0.03);
break;
......@@ -532,5 +528,5 @@ std::shared_ptr<TCanvas> CRPlot::Plot(void) const {
// for (auto p : graphs) {
// delete p;
// }
// XXX According to ROOT community,
}
#endif
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.1)
file(GLOB Test_DATA data)
......@@ -11,6 +11,7 @@ add_test(
NAME test:read_usine
COMMAND bash -c "$<TARGET_FILE:test_read> <(cat ${Test_DATA}/*.usine)")
if(NOT WITHOUT_ROOT)
add_executable(test_plot "test_plot.cc")
target_link_libraries(test_plot crdb ${ROOT_LIBRARIES})
add_test(
......@@ -22,7 +23,9 @@ target_link_libraries(test_plot_with_ratio crdb ${ROOT_LIBRARIES})
add_test(
NAME test:plot_with_ratio
COMMAND test_plot_with_ratio "${Test_DATA}/BC_EKN.usine" "${Test_DATA}/fitted_BC.tsv" "${Test_DATA}/fitted_BC_band.tsv")
endif()
if(NOT WITHOUT_CURL)
add_executable(test_fetch "test_fetch.cc")
target_link_libraries(test_fetch crdb ${ROOT_LIBRARIES})
add_test(NAME test:fetch_B_C
......@@ -31,3 +34,4 @@ add_test(NAME test:fetch_p_pe
COMMAND test_fetch "e+" "e-+e+")
add_test(NAME test:fetch_cached
COMMAND test_fetch "e+" "e-+e+")
endif()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment