Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cppcodeandcichecks dec2024 #55

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/softwarecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Software_check
on:
push:
pull_request:
types: [opened]
jobs:
check_compile-job:
runs-on: ubuntu-latest
container:
image: cmscloud/al9-cms:latest
options: --user root
steps:
- name: Checking_out_code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checking_python_3.9
run: |
python3 -V
ls
pwd
python3 -m py_compile src/cmsstyle/cmsstyle.py
ls -lh src/cmsstyle/__pycache__/
- name: Checking_Cpp_compilation
run: |
cd src
echo '{gROOT->LoadMacro("cmsstyle.C++");}' > hola.C

dnf install -y root
echo 'ROOT VERSION='`root-config --version`
root -q hola.C
ls -lh cmsstyle_C.so
#
py2-job:
runs-on: ubuntu-latest
container:
image: cmscloud/cc7-cms:latest
options: --user root
steps:
- name: Checking_python_2.7
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
run: |
python -V
ls
git clone --depth 1 https://github.com/oglez/cmsstyle.git
cd cmsstyle
pwd
python -m py_compile src/cmsstyle/cmsstyle.py
ls -lh src/cmsstyle/cmsstyle.pyc
#
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ __pycache__/

# C extensions
*.so
*.d
*.pcm

# Distribution / packaging
.Python
Expand Down
44 changes: 44 additions & 0 deletions scripts/setup_cmstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# This script, to be run in bash to setup the CMSStyle for ROOT (C++ version)
#
# Called with
# source .../scripts/setup_cmstyle
# using the directory of the actual implementation we want to use of CMSStyle.
#
# Written by O. Gonzalez (2024_11_12)
# 2024_12_01 Changing the used directory for a real one.
#
fich_=${BASH_SOURCE[0]}

if [ ".${fich_::1}" != "./" ] ; then # Relative directory
fich_="$PWD/${fich_}"
fi

# Getting the simplest name of the directory
if [[ ${fich_:(-22):1} == "/" ]] ; then
cd ${fich_::-21} >& /dev/null
else # We are in scripts!
cd .. >& /dev/null
fi
export CMSSTYLE_DIR=`pwd -P`
cd - >& /dev/null

echo "Using CMSStyle located in $CMSSTYLE_DIR"

# Setting up the related variables:

if [[ ! $ROOT_INCLUDE_PATH == *"${CMSSTYLE_DIR}/src"* ]]; then
export ROOT_INCLUDE_PATH=${CMSSTYLE_DIR}/src${ROOT_INCLUDE_PATH:+":$ROOT_INCLUDE_PATH"}
fi

# We also put the same version for python, in case...
if [[ ".${PYTHONPATH}" != *"${CMSSTYLE_DIR}/src"* ]] ; then
export PYTHONPATH=${CMSSTYLE_DIR}/src${PYTHONPATH:+":$PYTHONPATH"}
fi
#
# Note:
# The following command allows to get the location of the CMSStyle that
# it is used/setup already for python:
#
# $ python3 -c "import cmsstyle ; print(cmsstyle.__file__)"
#
100 changes: 100 additions & 0 deletions src/TCmsCanvas.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
///@file
///
/// This code contains the declaration and definition of the class TCmsCanvas
/// that inherits from a normal TCanvas en ROOT but keep track of created
/// objects that are not visible to the user, for its proper deletion as the
/// TCanvas is destroyed.
///
/// <PRE>
/// Written by O. Gonzalez (2024_11_12)
/// </PRE>
///

#ifndef CMSSTYLE_TCMSCANVAS__H_
#define CMSSTYLE_TCMSCANVAS__H_

#include <TCanvas.h>
#include <TASImage.h>

#include <vector>

namespace cmsstyle {


/// This is the class that CMSStyle (in the C++ version) uses to handle the
/// TCanvases that are defined to be plotted, but one has to keep in mind that
/// externally

class TCmsCanvas : public TCanvas {

// Internal variables (pointers to keep track)

TASImage *CMS_logo; ///< CMS Logo when used in the TCanvas.
TPad *pad_logo; ///< TPad containing the CMS logo, when used.

// Internal methods

/// Initialization of the internal variables...
void Initialize (void) {
CMS_logo=nullptr;
pad_logo=nullptr;
}

public:

/// Normal constructor: It just creates the Canvas using the arguments and
/// the corresponding constructor method ot eh TCanvas. It also initializes
/// the values to keep track of when needed.
///
/// Arguments:
/// name: Name of the created object
/// title: Title for the TCanvas
/// wtopx: X position of the top left corner of the canvas in pixels.
/// wtopy: Y position of the top left corner of the canvas in pixels
/// ww: the window size in pixels along X.
/// wh: the window size in pixels along Y.
///
TCmsCanvas (const char *name,
const char *title,
Int_t wtopx,
Int_t wtopy,
Int_t ww,
Int_t wh) : TCanvas(name,title,wtopx,wtopy,ww,wh) {
Initialize();
}

/// Destructor of the class, as the most important object since it handles
/// the deletion of objects defined
~TCmsCanvas () {
if (CMS_logo!=nullptr) delete CMS_logo;
if (pad_logo!=nullptr) delete pad_logo;
}


/// Method to draw the CMS Logo in the defined TCanvas in a TPad set at the indicated location
/// of the currently used TPad.
void AddCmsLogo (Float_t x0, Float_t y0, Float_t x1, Float_t y1, const char *logofile)
{
if (CMS_logo!=nullptr) delete CMS_logo;
CMS_logo = new TASImage(logofile);

auto oldpad = gPad;

if (pad_logo!=nullptr) delete pad_logo;
pad_logo = new TPad("logo", "logo", x0, y0, x1, y1);
pad_logo->Draw();
pad_logo->cd();
CMS_logo->Draw("X");
pad_logo->Modified();

oldpad->cd();
}




};

} // Namespace cmsstyle
#endif
///----------------------------------------------------------------------
Loading
Loading