0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ROOTのマクロをVSCodeで快適に作る

0
Posted at

.vscode/内のファイルを設定することによってROOTマクロを書くための環境構築を行います。

  • .Cファイルがc++ファイルとして扱われるようにする
  • IntelliSenseを設定してマクロファイルで明示的に#includeをしなくても自動的にROOTのヘッダーファイルを読み込むようにする
  • Cmd+Shift+Bで自動的にマクロをターミナルで実行する

.Cファイルがc++ファイルとして扱われるようにする

マクロ(.C)ファイルが通常のc++のファイルとして扱われるようにします。

settings.json
{
    "files.associations": {
        "*.C": "cpp",
    }
}

IntelliSenseを設定する

ヘッダーなどをあらかじめ用意しておいて、それを強制的にマクロの前に読み込ませます。使うヘッダーファイル(ここでは例としてTH1D.hを追加しています)はここに追加してください。

root_setup.hpp
#include <iostream>

using std::cout;

// Add ROOT include files as needed
#include <TH1D.h>

ROOTのインストール方法によって下記の"includePath"が変わるので、ターミナルからroot-config --incdirを実行してインストール場所を調べてください。
forcedIncludeによってヘッダーファイルをマクロの前に入れて読み込んでいます。

c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/homebrew/Cellar/root/*/include/root"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64",
            "forcedInclude": [
                "${workspaceFolder}/.vscode/root_setup.hpp"
            ]
        }
    ],
    "version": 4
}

Cmd+Shift+Bで自動的にマクロをターミナルで実行する

tasks.json設定してマクロの実行を自動化します。

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run ROOT Macro",
            "type": "shell",
            "command": "root",
            "args": [
                "-l",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

必要に応じて適宜コマンドライン引数などは変えてください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?