Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
added content
Browse files Browse the repository at this point in the history
  • Loading branch information
grasph committed May 30, 2024
1 parent cf037d2 commit 5d5fdeb
Show file tree
Hide file tree
Showing 48 changed files with 17,573 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "ROOT2"
uuid = "b0506e13-49c2-4ce6-b48c-bb2bc691fb3e"
version = "0.0.1"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"

[extras]
UnROOT = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
CxxWrap = "0.14"

[targets]
test = ["Test", "UnROOT"]
181 changes: 181 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# ROOT2

## Introduction

ROOT2 is a Julia interface to the C++ [ROOT Data analysis framework](https://root.cern/) used in the high energy physics community.

It is a work-in-progress package covering a limited set of ROOT classes. It targets persons used to the ROOT framework and wishing to access it from Julia.

Function documentation for the Julia help command is not yet available. Please refer to the [C++ ROOT reference guide](https://root.cern/doc/master/) for API documentation.

ROOT2 uses [CxxWrap](https://github.com/JuliaInterop/CxxWrap.jl) to interface to the C++ libraries and the wrappers were generated using [WrapIt!](https://github.com/grasph/wrapit).

## Installation

```
import Pkg
Pkg.add("ROOT2")
```

⚠️ Installation or first import may take a while due to code compilation.

## ROOT version

Current ROOT2 version uses ROOT release 6.30.04. If a ROOT installation is found in the default binary search paths (PATH environment variable) with this version then it will be used. Otherwise, ROOT will be installed using [Conda](https://github.com/JuliaPy/Conda.jl) into `$HOME/.julia/Conda/3`.

## C++ / Julia mapping and symbol export

C++ classes are mapped to Julia struct with the same name. Non-static class methods are mapped to julia methods, with the same name, taking the class instance as first argument followed by the arguments of the C++ methods. The double column `::` used for C++ namespace and for static fields in C++ is mapped to the ! symbol: static function `f` of class `A`, `A::f()` becomes `A!f()` in Julia.

Non-static methods of C++ classes are exported, the other symbols (classes, global functions, etc) are not.

## Use Example

### Short demo

```julia
import ROOT2

ROOT2.demo()
```

### Simple example

```julia

#Import the module.
# The iROOT module is required for interactive graphic display
# Loading the package trigger a loop that process ROOT graphic events.
using ROOT2

# An alias for ROOT2
const R = ROOT2

# Create a ROOT histogram, fill it with random events, and fit it.
h = R.TH1D("h", "Normal distribution", 100, -5., 5.)
R.FillRandom(h, "gaus")

#Draw the histogram on screen
c = R.TCanvas()
R.Draw(h)

#Fit the histogram wih a normal distribution
R.Fit(h, "gaus")

#Save the Canvas in an image file
R.SaveAs(c, "demo_ROOT.png")

#Save the histogram and the graphic canvas in the demo_ROOT_out.root file.
f = R.TFile!Open("demo_ROOT_out.root", "RECREATE")
R.Write(h)
R.Write(c)
Close(f)
```

### More examples

More examples can be found in the `examples` directory.

## Supported ROOT classes

### Principal supported ROOT classes:

- `TSystem`
- `TROOT`
- `TTree`
- `TBranch`
- `TCanvas`
- `TH1`
- `TRandom`
- `TAxis`
- `TGraph`
- `TF1`
- `TApplication`
- `TFile`, `TDirectoryFile`
- `TTreeReader`, `TTreeReaderValue`, `TTreeReaderArray`
- `TVectorD`, `TVectorF`
- `TObject`, `TNamed`

### Complete list of suppported ROOT class and types

- CpuInfo_t
- FileStat_t
- Foption_t
- _IO_FILE
- MemInfo_t
- ProcInfo_t
- RedirectHandle_t
- ROOT::Internal::GetFunctorType
- ROOT::Internal::TF1Builder
- ROOT::Internal::TParBranchProcessingRAII
- ROOT::Internal::TStringView
- ROOT::Internal::TTreeReaderArrayBase
- ROOT::Internal::TTreeReaderValueBase
- ROOT::TIOFeatures
- SysInfo_t
- TApplication
- TApplicationImp
- TArrayC
- TArrayD
- TAxis
- TBranch
- TBranchPtr
- TBuffer
- TCanvas
- TClass
- TCollection
- TDataType
- TDatime
- TDictionary
- TDirectory
- TDirectoryFile
- TEntryList
- TF1
- TF1Parameters
- TF1::TF1FunctorPointer
- TFile
- TFileHandler
- TFileOpenHandle
- TFitResultPtr
- TFormula
- TGraph
- TH1
- TH1C
- TH1D
- TH1F
- TH1I
- TH1S
- TInetAddress
- TInterpreter
- TIterator
- TLeaf
- TList
- TMethodCall
- TNamed
- TObjArray
- TObject
- TObjLink
- TPad
- TProcessEventTimer
- TRandom
- TROOT
- TSeqCollection
- TSignalHandler
- TStdExceptionHandler
- TStreamerInfo
- TString
- TSystem
- TTime
- TTimer
- TTreeFriendLeafIter
- TTreeReader
- TTreeReaderArray
- TTreeReader::Iterator_t
- TTreeReaderValue
- TTree, TTree::TClusterIterator
- TUrl
- TVectorT
- TVirtualMutex
- TVirtualPad
- TVirtualTreePlayer
- UserGroup_t
110 changes: 110 additions & 0 deletions deps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# This makefile is meant to be called from the companion build.jl Julia script.
# and requires the CXXWRAP_PREFIX and JL_SHARE to be set.
#
# make CXXWRAP_PREFIX=... JL_SHARE=...
#
BUILD_DIR = build
ROOT_CONFIG = root-config

ROOT_LIBS = $(shell $(ROOT_CONFIG) --libs)
ROOT_INC_DIR = $(shell $(ROOT_CONFIG) --incdir)

CPPFLAGS = -MMD -I. -I $(CXXWRAP_PREFIX)/include
CXXFLAGS = $(patsubst -std=gnu%,,$(shell $(JL_SHARE)/julia-config.jl --cflags))
CXXFLAGS += $(shell $(ROOT_CONFIG) --cflags)
CXXFLAGS += -O2
CXXFLAGS += -Wno-c++20-extensions
#CXXFLAGS += -DVERBOSE_IMPORT #To enable the verbose mode of the libray loading
#CXXFLAGS += -Wall -O0 -g #To compile with debugger infomation
LDFLAGS = $(shell $(JL_SHARE)/julia-config.jl --ldflags)
LDLIBS = $(shell $(JL_SHARE)/julia-config.jl --ldlibs) -L$(CXXWRAP_PREFIX)/lib -lcxxwrap_julia -lcxxwrap_julia_stl
JULIA = julia

CXX_IS_CLANG = $(shell $(CXX) -dM -E - < /dev/null | grep -c __clang__)

ifeq ($(UNAME),Darwin)
SO_SUFFIX = .dylib
else
SO_SUFFIX = .so
endif

ifneq ($(CXX_IS_CLANG), 0)
CXXFLAGS += -ferror-limit=3
else #assuming gcc
CXXFLAGS += -fmax-errors=3
endif


LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)

.PHONY: all clean distclean run_demo run_demo2 check_root make_lib_from_objs

PRODUCTS = libjlROOT2$(SO_SUFFIX)

#Define WRAPPER_CXX
#WRAPPER_CXX: = $(file < src/generated_cxx) Extra.cxx #does not work on MacOS
include generated_cxx.make

OBJS = $(addprefix $(BUILD_DIR)/, $(patsubst %.cxx,%.o, $(WRAPPER_CXX)))
DEPS = $(patsubst %.o,%.d, $(OBJS))

all: $(PRODUCTS)

clean:
-$(RM) -r build

distclean:
-$(RM) -r build build.log
-$(RM) $(PRODUCTS)


$(BUILD_DIR):
@mkdir $(BUILD_DIR)
@echo 'all:\n\n%:\n\t$$(MAKE) -C .. $$@\nclean:\n\t$$(MAKE) -C .. clean build\n' > $(BUILD_DIR)/Makefile

$(BUILD_DIR)/ROOT2-generated.wit: ROOT2.wit $(BUILD_DIR)
$(MAKE) check_root
$(shell echo "#\n# Warning: file generated automatically from $<\n#" > $@)
$(shell sed "s@%ROOT_INC_DIR%@$(ROOT_INC_DIR)@" $< >> $@ || rm $@)

check_root:
ifeq ($(ROOT_LIBS),)
$(error ERROR: "Command root-config not found. ROOT (http:://root.cern.ch) environment needs to be set")
endif

run_demo: all
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) JULIA_LOAD_PATH=.:@:@v#.#:@stdlib "$(JULIA)" -i demo_ROOT.jl

run_demo2: all
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) JULIA_LOAD_PATH=.:@:@v#.#:@stdlib "$(JULIA)" -i demo_TGraph.jl

test: all
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) \
JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. demo_ROOT2.jl
cmp demo_ROOT.png demo_ROOT-ref.png
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) \
JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. demo_TGraph.jl
cmp demo_TGraph.png demo_TGraph-ref.png
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) \
JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. TTree_examples/write_tree1.jl \
&& JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. TTree_examples/read_tree1.jl
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) \
JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. TTree_examples/write_tree2.jl \
&& JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. -e 'import Pkg; Pkg.activate(;temp=true); Pkg.add("UnROOT"); include("TTree_examples/read_tree2.jl")'
LD_LIBRARY_PATH=$(shell $(ROOT_CONFIG) --libdir) \
JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. TTree_examples/write_tree3.jl \
&& JULIA_LOAD_PATH=`pwd`/build/ROOT2/src:$(JULIA_LOAD_PATH): "$(JULIA)" --project=.. TTree_examples/read_tree3.jl

$(BUILD_DIR)/%.o: src/%.cxx $(BUILD_DIR)
[ -d $(BUILD_DIR)/libROOT2/build ] || mkdir -p $(BUILD_DIR)/libROOT2/build
$(COMPILE.cc) $(CPPFLAGS) -o $@ $<

libjlROOT2$(SO_SUFFIX): $(OBJS)
$(MAKE) check_root
$(LINK.o) -o $@ --shared -fPIC $(OBJS) $(ROOT_LIBS) $(LDLIBS)


echo_%:
@echo "$* = $(subst ",\",$($*))"

-include $(DEPS)
Loading

0 comments on commit 5d5fdeb

Please sign in to comment.