Skip to content

Commit

Permalink
Add Formatting (#101)
Browse files Browse the repository at this point in the history
Add clang-format check
  • Loading branch information
beomki-yeo authored Sep 23, 2021
1 parent 0413d92 commit 77cd30e
Show file tree
Hide file tree
Showing 179 changed files with 7,366 additions and 7,504 deletions.
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
BasedOnStyle: Google
IndentWidth: 4
Language: Cpp
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
PointerAlignment: Left
ColumnLimit: 80
AccessModifierOffset: 0
KeepEmptyLinesAtTheStartOfBlocks: true
46 changes: 46 additions & 0 deletions .github/check_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
#
# check that all code complies w/ the clang-format specification
#
# if all is well, returns w/o errors and does not print anything.
# otherwise, return an error and print offending changes

set -e # abort on error

INCLUDE_DIRS=("apps core display plugins tests")

if [ $# -ne 1 ]; then
echo "wrong number of arguments"
echo ""
echo "usage: check_format <DIR>"
exit 1
fi

_binary=${CLANG_FORMAT_BINARY:-clang-format}

$_binary --version

cd $1
$_binary -i -style=file $(find ${INCLUDE_DIRS} \( -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' -or -iname '*.inl' -or -iname '*.cu' -or -iname '*.cuh' -or -iname '*.hip' -or -iname '*.sycl' \))

if ! [ -z $CI ] || ! [ -z $GITHUB_ACTIONS ]; then
mkdir changed
for f in $(git diff --name-only -- ${INCLUDE_DIRS[@]/#/:/}); do
cp --parents $f changed
done
fi

echo "clang-format done"

set +e
git diff --exit-code --stat -- ${INCLUDE_DIRS[@]/#/:/}
result=$?

if [ "$result" -eq "128" ]; then
echo "Format was successfully applied"
echo "Could not create summary of affected files"
echo "Are you in a submodule?"

fi

exit $result
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- main
- 'release/**'

jobs:
ubuntu:
runs-on: ubuntu-latest
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Checks

on:
push:
pull_request:
branches:
- main

jobs:
format:
runs-on: ubuntu-latest
container: ghcr.io/acts-project/format10:v11
steps:
- uses: actions/checkout@v2
- name: Check
run: .github/check_format.sh .
- uses: actions/upload-artifact@v1
if: failure()
with:
name: changed
path: changed
176 changes: 90 additions & 86 deletions apps/common/include/apps/common/display_bin_association.inl
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
/** Detray library, part of the ACTS project (R&D line)
*
*
* (c) 2021 CERN for the benefit of the ACTS project
*
*
* Mozilla Public License Version 2.0
*/
#pragma once

#include <matplot/matplot.h>

#include <climits>
#include <fstream>
#include <iostream>

#include "core/detector.hpp"
#include "core/transform_store.hpp"
#include "io/csv_io.hpp"
#include "grids/associator.hpp"
#include "io/csv_io.hpp"
#include "style/styles.hpp"
#include "utils/enumerate.hpp"
#include "utils/generators.hpp"
#include "view/draw.hpp"
#include "view/views.hpp"
#include "style/styles.hpp"

#include <fstream>
#include <iostream>
#include <climits>
#include <matplot/matplot.h>

int main(int argc, char **argv)
{
int main(int argc, char **argv) {
using point2 = __plugin::point2;
using namespace detray;
using namespace matplot;

if (argc > 1)
{
if (argc > 1) {
std::string first_arg = argv[1];
if (first_arg == "-h" or first_arg == "--help")
{
std::cout << "[detray] Usage: 'display_bin_association detector_name <surface_file> <grid_file> <volume_file>'" << std::endl;
if (first_arg == "-h" or first_arg == "--help") {
std::cout
<< "[detray] Usage: 'display_bin_association detector_name "
"<surface_file> <grid_file> <volume_file>'"
<< std::endl;
return 1;
}
else if (argc > 7)
{
} else if (argc > 7) {

// Create a sub plot
auto ax = matplot::subplot({0.1, 0.1, 0.65, 0.8});
Expand All @@ -47,8 +46,9 @@ int main(int argc, char **argv)
std::string volumes_file = argv[3];
std::string grids_file = argv[4];
std::string grid_entries_file = argv[5];

auto d = detector_from_csv<>(name, surfaces_file, volumes_file, grids_file, grid_entries_file);

auto d = detector_from_csv<>(name, surfaces_file, volumes_file,
grids_file, grid_entries_file);
std::cout << "[detray] Detector read successfully." << std::endl;

global_xy_view xy_view;
Expand Down Expand Up @@ -89,24 +89,25 @@ int main(int argc, char **argv)
// Grid drawing sections styles and addons
// - styles and addons are on faint grid, cell, assoc
std::vector<style> gstyles = {grid_style, cell_style, assoc_style};
std::vector<std::array<scalar, 4>> gadds = {grid_adds, cell_adds, assoc_adds};
std::vector<std::array<scalar, 4>> gadds = {grid_adds, cell_adds,
assoc_adds};

decltype(d)::transform_store::context s_context;

// Surface finders, volume, bounds
auto surfaces_finders = d.surfaces_finders();
const auto &lvolume = d.indexed_volume(lvol);
const auto &bounds = lvolume.bounds();
bool is_cylinder = std::abs(bounds[1] - bounds[0]) < std::abs(bounds[3] - bounds[2]);
const auto &sf_range = lvolume. template range<>();
bool is_cylinder = std::abs(bounds[1] - bounds[0]) <
std::abs(bounds[3] - bounds[2]);
const auto &sf_range = lvolume.template range<>();

dindex finder_entry = lvolume.surfaces_finder_entry();
const auto &surfaces = d.surfaces();
const auto &surface_transforms = d.transforms(sf_range, s_context);
const auto &surface_masks = d.masks();

if (not is_cylinder)
{
if (not is_cylinder) {

const auto &disk_grid = surfaces_finders[finder_entry];
auto r_borders = disk_grid.axis_p0().borders(bin_0);
Expand All @@ -118,16 +119,15 @@ int main(int argc, char **argv)
scalar phi_max = phi_borders[1];

const auto &bin_entry = disk_grid.bin(bin_0, bin_1);
std::cout << "Disk grid - bin (" << bin_0 << ", " << bin_1 << ") = ";
for (auto b_e : bin_entry)
{
std::cout << "Disk grid - bin (" << bin_0 << ", " << bin_1
<< ") = ";
for (auto b_e : bin_entry) {
std::cout << b_e << ", ";
}
std::cout << std::endl;

// Loop over the surfaces within a volume
for (dindex sfi = sf_range[0]; sfi < sf_range[1]; sfi++)
{
for (dindex sfi = sf_range[0]; sfi < sf_range[1]; sfi++) {
const auto &s = surfaces[sfi];
dvector<point3> vertices = {};
const auto &mask_link = s.mask();
Expand All @@ -139,25 +139,30 @@ int main(int argc, char **argv)
const auto &mask_context = std::get<0>(mask_link);
const auto &mask_range = std::get<1>(mask_link);

auto vertices_per_masks = unroll_masks_for_vertices(surface_masks, mask_range, mask_context,
std::make_integer_sequence<dindex, std::tuple_size_v<decltype(d)::surface_mask_container>>{});

for (auto &vertices : vertices_per_masks)
{
if (not vertices.empty())
{
style draw_style = (std::find(bin_entry.begin(), bin_entry.end(), static_cast<dindex>(sfi - sf_range[0])) != bin_entry.end())
? selected_surface_style
: surface_style;

draw_vertices(vertices, transform, draw_style, xy_view);
auto vertices_per_masks = unroll_masks_for_vertices(
surface_masks, mask_range, mask_context,
std::make_integer_sequence<
dindex, std::tuple_size_v<decltype(
d)::surface_mask_container>>{});

for (auto &vertices : vertices_per_masks) {
if (not vertices.empty()) {
style draw_style =
(std::find(
bin_entry.begin(), bin_entry.end(),
static_cast<dindex>(sfi - sf_range[0])) !=
bin_entry.end())
? selected_surface_style
: surface_style;

draw_vertices(vertices, transform, draw_style,
xy_view);
}
}
}

// Grid drawing section
for (auto [i, st] : enumerate(gstyles))
{
for (auto [i, st] : enumerate(gstyles)) {

// Arc parameters
scalar arc_r_min = r_min - gadds[i][0];
Expand All @@ -177,20 +182,14 @@ int main(int argc, char **argv)
scalar cos_phi_max = std::cos(rad_phi_max);
scalar sin_phi_max = std::sin(rad_phi_max);

draw_line(rad_r_min * cos_phi_max,
rad_r_min * sin_phi_max,
rad_r_max * cos_phi_max,
rad_r_max * sin_phi_max,
draw_line(rad_r_min * cos_phi_max, rad_r_min * sin_phi_max,
rad_r_max * cos_phi_max, rad_r_max * sin_phi_max,
st);
draw_line(rad_r_min * cos_phi_min,
rad_r_min * sin_phi_min,
rad_r_max * cos_phi_min,
rad_r_max * sin_phi_min,
draw_line(rad_r_min * cos_phi_min, rad_r_min * sin_phi_min,
rad_r_max * cos_phi_min, rad_r_max * sin_phi_min,
st);
}
}
else
{
} else {
const auto &cylinder_grid = surfaces_finders[finder_entry + 2];
auto z_borders = cylinder_grid.axis_p0().borders(bin_0);
auto phi_borders = cylinder_grid.axis_p1().borders(bin_1);
Expand All @@ -201,16 +200,15 @@ int main(int argc, char **argv)
scalar phi_max = phi_borders[1];

const auto &bin_entry = cylinder_grid.bin(bin_0, bin_1);
std::cout << "Cylinder grid - bin (" << bin_0 << ", " << bin_1 << ") = ";
for (auto b_e : bin_entry)
{
std::cout << "Cylinder grid - bin (" << bin_0 << ", " << bin_1
<< ") = ";
for (auto b_e : bin_entry) {
std::cout << b_e << ", ";
}
std::cout << std::endl;

// Loop over the surfaces within a volume
for (dindex sfi = sf_range[0]; sfi < sf_range[1]; sfi++)
{
for (dindex sfi = sf_range[0]; sfi < sf_range[1]; sfi++) {
const auto &s = surfaces[sfi];
dvector<point3> vertices = {};
const auto &mask_link = s.mask();
Expand All @@ -222,34 +220,42 @@ int main(int argc, char **argv)
const auto &mask_context = std::get<0>(mask_link);
const auto &mask_range = std::get<1>(mask_link);

auto vertices_per_masks = unroll_masks_for_vertices(surface_masks, mask_range, mask_context,
std::make_integer_sequence<dindex, std::tuple_size_v<decltype(d)::surface_mask_container>>{});
auto vertices_per_masks = unroll_masks_for_vertices(
surface_masks, mask_range, mask_context,
std::make_integer_sequence<
dindex, std::tuple_size_v<decltype(
d)::surface_mask_container>>{});

for (auto &vertices : vertices_per_masks)
{
for (auto &vertices : vertices_per_masks) {

if (not vertices.empty())
{
if (not vertices.empty()) {

// Check the association (with potential splits)
style draw_style = (std::find(bin_entry.begin(), bin_entry.end(), static_cast<dindex>(sfi - sf_range[0])) != bin_entry.end())
? selected_surface_style
: surface_style;

draw_vertices(vertices, transform, draw_style, zphi_view, true);
style draw_style =
(std::find(
bin_entry.begin(), bin_entry.end(),
static_cast<dindex>(sfi - sf_range[0])) !=
bin_entry.end())
? selected_surface_style
: surface_style;

draw_vertices(vertices, transform, draw_style,
zphi_view, true);
}
}
}

// Grid drawing section
for (auto [i, st] : enumerate(gstyles))
{
if (i > 0)
{
point2 p0 = {z_min - gadds[i][0], phi_min - gadds[i][1]};
point2 p1 = {z_min - gadds[i][0], phi_max + gadds[i][1]};
point2 p2 = {z_max + gadds[i][0], phi_max + gadds[i][1]};
point2 p3 = {z_max + gadds[i][0], phi_min - gadds[i][1]};
for (auto [i, st] : enumerate(gstyles)) {
if (i > 0) {
point2 p0 = {z_min - gadds[i][0],
phi_min - gadds[i][1]};
point2 p1 = {z_min - gadds[i][0],
phi_max + gadds[i][1]};
point2 p2 = {z_max + gadds[i][0],
phi_max + gadds[i][1]};
point2 p3 = {z_max + gadds[i][0],
phi_min - gadds[i][1]};

draw_polygon({p0, p1, p2, p3}, st);
}
Expand All @@ -263,13 +269,10 @@ int main(int argc, char **argv)
vol_lay_name += "_";
vol_lay_name += std::to_string(bin_1);
vol_lay_name += ".png";
if (is_cylinder)
{
if (is_cylinder) {
ax->xlabel("z [mm]");
ax->ylabel("phi [rad]");
}
else
{
} else {
ax->xlabel("x [mm]");
ax->ylabel("y [mm]");
matplot::axis(equal);
Expand All @@ -284,6 +287,7 @@ int main(int argc, char **argv)
}
}

std::cout << "[detray] Not enough arguments given, run with -h for help. " << std::endl;
std::cout << "[detray] Not enough arguments given, run with -h for help. "
<< std::endl;
return 0;
}
Loading

0 comments on commit 77cd30e

Please sign in to comment.