Skip to content

Commit 9794047

Browse files
authored
Merge pull request #55 from oglez/cppcodeandcichecks_dec2024
Cppcodeandcichecks dec2024
2 parents 211ccb6 + 7dcd864 commit 9794047

File tree

11 files changed

+1522
-5
lines changed

11 files changed

+1522
-5
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Software_check
2+
on:
3+
push:
4+
pull_request:
5+
types: [opened]
6+
jobs:
7+
check_compile-job:
8+
runs-on: ubuntu-latest
9+
container:
10+
image: cmscloud/al9-cms:latest
11+
options: --user root
12+
steps:
13+
- name: Checking_out_code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
- name: Checking_python_3.9
18+
run: |
19+
python3 -V
20+
ls
21+
pwd
22+
python3 -m py_compile src/cmsstyle/cmsstyle.py
23+
ls -lh src/cmsstyle/__pycache__/
24+
- name: Checking_Cpp_compilation
25+
run: |
26+
cd src
27+
echo '{gROOT->LoadMacro("cmsstyle.C++");}' > hola.C
28+
29+
dnf install -y root
30+
echo 'ROOT VERSION='`root-config --version`
31+
root -q hola.C
32+
ls -lh cmsstyle_C.so
33+
#
34+
py2-job:
35+
runs-on: ubuntu-latest
36+
container:
37+
image: cmscloud/cc7-cms:latest
38+
options: --user root
39+
steps:
40+
- name: Checking_python_2.7
41+
# uses: actions/checkout@v4
42+
# with:
43+
# fetch-depth: 0
44+
run: |
45+
python -V
46+
ls
47+
git clone --depth 1 https://github.com/oglez/cmsstyle.git
48+
cd cmsstyle
49+
pwd
50+
python -m py_compile src/cmsstyle/cmsstyle.py
51+
ls -lh src/cmsstyle/cmsstyle.pyc
52+
#

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
*.d
9+
*.pcm
810

911
# Distribution / packaging
1012
.Python

scripts/setup_cmstyle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# This script, to be run in bash to setup the CMSStyle for ROOT (C++ version)
3+
#
4+
# Called with
5+
# source .../scripts/setup_cmstyle
6+
# using the directory of the actual implementation we want to use of CMSStyle.
7+
#
8+
# Written by O. Gonzalez (2024_11_12)
9+
# 2024_12_01 Changing the used directory for a real one.
10+
#
11+
fich_=${BASH_SOURCE[0]}
12+
13+
if [ ".${fich_::1}" != "./" ] ; then # Relative directory
14+
fich_="$PWD/${fich_}"
15+
fi
16+
17+
# Getting the simplest name of the directory
18+
if [[ ${fich_:(-22):1} == "/" ]] ; then
19+
cd ${fich_::-21} >& /dev/null
20+
else # We are in scripts!
21+
cd .. >& /dev/null
22+
fi
23+
export CMSSTYLE_DIR=`pwd -P`
24+
cd - >& /dev/null
25+
26+
echo "Using CMSStyle located in $CMSSTYLE_DIR"
27+
28+
# Setting up the related variables:
29+
30+
if [[ ! $ROOT_INCLUDE_PATH == *"${CMSSTYLE_DIR}/src"* ]]; then
31+
export ROOT_INCLUDE_PATH=${CMSSTYLE_DIR}/src${ROOT_INCLUDE_PATH:+":$ROOT_INCLUDE_PATH"}
32+
fi
33+
34+
# We also put the same version for python, in case...
35+
if [[ ".${PYTHONPATH}" != *"${CMSSTYLE_DIR}/src"* ]] ; then
36+
export PYTHONPATH=${CMSSTYLE_DIR}/src${PYTHONPATH:+":$PYTHONPATH"}
37+
fi
38+
#
39+
# Note:
40+
# The following command allows to get the location of the CMSStyle that
41+
# it is used/setup already for python:
42+
#
43+
# $ python3 -c "import cmsstyle ; print(cmsstyle.__file__)"
44+
#

src/TCmsCanvas.H

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
///@file
2+
///
3+
/// This code contains the declaration and definition of the class TCmsCanvas
4+
/// that inherits from a normal TCanvas en ROOT but keep track of created
5+
/// objects that are not visible to the user, for its proper deletion as the
6+
/// TCanvas is destroyed.
7+
///
8+
/// <PRE>
9+
/// Written by O. Gonzalez (2024_11_12)
10+
/// </PRE>
11+
///
12+
13+
#ifndef CMSSTYLE_TCMSCANVAS__H_
14+
#define CMSSTYLE_TCMSCANVAS__H_
15+
16+
#include <TCanvas.h>
17+
#include <TASImage.h>
18+
19+
#include <vector>
20+
21+
namespace cmsstyle {
22+
23+
24+
/// This is the class that CMSStyle (in the C++ version) uses to handle the
25+
/// TCanvases that are defined to be plotted, but one has to keep in mind that
26+
/// externally
27+
28+
class TCmsCanvas : public TCanvas {
29+
30+
// Internal variables (pointers to keep track)
31+
32+
TASImage *CMS_logo; ///< CMS Logo when used in the TCanvas.
33+
TPad *pad_logo; ///< TPad containing the CMS logo, when used.
34+
35+
// Internal methods
36+
37+
/// Initialization of the internal variables...
38+
void Initialize (void) {
39+
CMS_logo=nullptr;
40+
pad_logo=nullptr;
41+
}
42+
43+
public:
44+
45+
/// Normal constructor: It just creates the Canvas using the arguments and
46+
/// the corresponding constructor method ot eh TCanvas. It also initializes
47+
/// the values to keep track of when needed.
48+
///
49+
/// Arguments:
50+
/// name: Name of the created object
51+
/// title: Title for the TCanvas
52+
/// wtopx: X position of the top left corner of the canvas in pixels.
53+
/// wtopy: Y position of the top left corner of the canvas in pixels
54+
/// ww: the window size in pixels along X.
55+
/// wh: the window size in pixels along Y.
56+
///
57+
TCmsCanvas (const char *name,
58+
const char *title,
59+
Int_t wtopx,
60+
Int_t wtopy,
61+
Int_t ww,
62+
Int_t wh) : TCanvas(name,title,wtopx,wtopy,ww,wh) {
63+
Initialize();
64+
}
65+
66+
/// Destructor of the class, as the most important object since it handles
67+
/// the deletion of objects defined
68+
~TCmsCanvas () {
69+
if (CMS_logo!=nullptr) delete CMS_logo;
70+
if (pad_logo!=nullptr) delete pad_logo;
71+
}
72+
73+
74+
/// Method to draw the CMS Logo in the defined TCanvas in a TPad set at the indicated location
75+
/// of the currently used TPad.
76+
void AddCmsLogo (Float_t x0, Float_t y0, Float_t x1, Float_t y1, const char *logofile)
77+
{
78+
if (CMS_logo!=nullptr) delete CMS_logo;
79+
CMS_logo = new TASImage(logofile);
80+
81+
auto oldpad = gPad;
82+
83+
if (pad_logo!=nullptr) delete pad_logo;
84+
pad_logo = new TPad("logo", "logo", x0, y0, x1, y1);
85+
pad_logo->Draw();
86+
pad_logo->cd();
87+
CMS_logo->Draw("X");
88+
pad_logo->Modified();
89+
90+
oldpad->cd();
91+
}
92+
93+
94+
95+
96+
};
97+
98+
} // Namespace cmsstyle
99+
#endif
100+
///----------------------------------------------------------------------

0 commit comments

Comments
 (0)