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

[ci] add clang-format check #9

Merged
merged 3 commits into from
Mar 1, 2022
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
92 changes: 92 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
JavaScriptQuotes: Leave
...
24 changes: 24 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: clang-format-check

on: [push, pull_request]

jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: cvmfs-contrib/github-action-cvmfs@v2
- name: Start container
run: |
docker run \
-it --name k4MW_CI \
-v ${{ github.workspace }}:/k4MW \
-v /cvmfs:/cvmfs:shared \
-d ghcr.io/aidasoft/centos7:latest /bin/bash

- name: Check Format
run: |
docker exec k4MW_CI /bin/bash -c 'source /cvmfs/sft.cern.ch/lcg/releases/clang/13.0.0-7985e/x86_64-centos7/setup.sh;\
clang-format -Werror --verbose --dry-run --style=file $(find ./k4ProjectTemplate/ -name "*.cpp" -o -name "*.h" );\
exit $?;\
'
19 changes: 8 additions & 11 deletions k4ProjectTemplate/src/components/CreateExampleEventData.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "CreateExampleEventData.h"


// datamodel
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"


DECLARE_COMPONENT(CreateExampleEventData)

CreateExampleEventData::CreateExampleEventData(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {
CreateExampleEventData::CreateExampleEventData(const std::string& aName, ISvcLocator* aSvcLoc)
: GaudiAlgorithm(aName, aSvcLoc) {
declareProperty("mcparticles", m_mcParticleHandle, "Dummy Particle collection (output)");
declareProperty("trackhits", m_simTrackerHitHandle, "Dummy Hit collection (output)");
}
Expand All @@ -23,28 +22,26 @@ StatusCode CreateExampleEventData::initialize() {
}

StatusCode CreateExampleEventData::execute() {

m_singleIntHandle.put(new int(12345));

std::vector<float>* floatVector = m_vectorFloatHandle.createAndPut();
floatVector->emplace_back( 125.);
floatVector->emplace_back( 25.);
floatVector->emplace_back(125.);
floatVector->emplace_back(25.);

edm4hep::MCParticleCollection* particles = m_mcParticleHandle.createAndPut();

auto particle = particles->create();

auto& p4 = particle.momentum();
p4.x = m_magicNumberOffset + 5;
p4.y = m_magicNumberOffset + 6;
p4.z = m_magicNumberOffset + 7;
p4.x = m_magicNumberOffset + 5;
p4.y = m_magicNumberOffset + 6;
p4.z = m_magicNumberOffset + 7;
particle.setMass(m_magicNumberOffset + 8);

auto* hits = m_simTrackerHitHandle.createAndPut();
auto hit = hits->create();
auto hit = hits->create();
hit.setPosition({3, 4, 5});


return StatusCode::SUCCESS;
}

Expand Down
21 changes: 10 additions & 11 deletions k4ProjectTemplate/src/components/CreateExampleEventData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
#include "GaudiAlg/GaudiAlgorithm.h"

// edm4hep
#include "k4FWCore/DataHandle.h"
#include "TTree.h"
#include "k4FWCore/DataHandle.h"



// datamodel
// datamodel
namespace edm4hep {
class MCParticleCollection;
class SimTrackerHitCollection;
class SimCaloHit;
}
class MCParticleCollection;
class SimTrackerHitCollection;
class SimCaloHit;
} // namespace edm4hep

/** @class CreateExampleEventData
* Lightweight producer for edm data for tests that do not depend on the actual
Expand Down Expand Up @@ -43,14 +41,15 @@ class CreateExampleEventData : public GaudiAlgorithm {

private:
/// integer to add to the dummy values written to the edm
Gaudi::Property<int> m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"};
Gaudi::Property<int> m_magicNumberOffset{this, "magicNumberOffset", 0,
"Integer to add to the dummy values written to the edm"};
/// Handle for the genparticles to be written
DataHandle<edm4hep::MCParticleCollection> m_mcParticleHandle{"MCParticles", Gaudi::DataHandle::Writer, this};
/// Handle for the genvertices to be written
DataHandle<edm4hep::SimTrackerHitCollection> m_simTrackerHitHandle{"SimTrackerHit", Gaudi::DataHandle::Writer, this};

DataHandle<float> m_singleFloatHandle{"SingleFloat", Gaudi::DataHandle::Writer, this};
DataHandle<float> m_singleFloatHandle{"SingleFloat", Gaudi::DataHandle::Writer, this};
DataHandle<std::vector<float>> m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Writer, this};
DataHandle<int> m_singleIntHandle{"SingleInt", Gaudi::DataHandle::Writer, this};
DataHandle<int> m_singleIntHandle{"SingleInt", Gaudi::DataHandle::Writer, this};
};
#endif /* TESTFWCORE_CREATEEXAMPLEEVENTDATA */
15 changes: 4 additions & 11 deletions k4ProjectTemplate/src/components/EmptyAlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

DECLARE_COMPONENT(EmptyAlg)

EmptyAlg::EmptyAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {
}
EmptyAlg::EmptyAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {}

EmptyAlg::~EmptyAlg() {}

StatusCode EmptyAlg::initialize() {
return StatusCode::SUCCESS;
}
StatusCode EmptyAlg::initialize() { return StatusCode::SUCCESS; }

StatusCode EmptyAlg::execute() {
return StatusCode::SUCCESS;
}
StatusCode EmptyAlg::execute() { return StatusCode::SUCCESS; }

StatusCode EmptyAlg::finalize() {
return StatusCode::SUCCESS;
}
StatusCode EmptyAlg::finalize() { return StatusCode::SUCCESS; }
9 changes: 4 additions & 5 deletions k4ProjectTemplate/src/components/EmptyAlg.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once
#pragma once

// GAUDI
#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Property.h"

#include "GaudiAlg/GaudiAlgorithm.h"

class EmptyAlg : public GaudiAlgorithm {
public:
Expand All @@ -23,6 +22,6 @@ class EmptyAlg : public GaudiAlgorithm {
virtual StatusCode finalize() final;

private:
// member variable
int m_member = 0;
// member variable
int m_member = 0;
};
8 changes: 3 additions & 5 deletions k4ProjectTemplate/src/components/HelloWorldAlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

DECLARE_COMPONENT(HelloWorldAlg)

HelloWorldAlg::HelloWorldAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) { }
HelloWorldAlg::HelloWorldAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {}

HelloWorldAlg::~HelloWorldAlg() {}

Expand All @@ -17,12 +17,10 @@ StatusCode HelloWorldAlg::initialize() {
StatusCode HelloWorldAlg::execute() {
info() << endmsg;
info() << endmsg;
info() << theMessage << endmsg;
info() << theMessage << endmsg;
info() << endmsg;
info() << endmsg;
return StatusCode::SUCCESS;
}

StatusCode HelloWorldAlg::finalize() {
return GaudiAlgorithm::finalize();
}
StatusCode HelloWorldAlg::finalize() { return GaudiAlgorithm::finalize(); }
10 changes: 5 additions & 5 deletions k4ProjectTemplate/src/components/HelloWorldAlg.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef TESTFWCORE_HELLOWORLDALG
#define TESTFWCORE_HELLOWORLDALG

#pragma once
#pragma once

// GAUDI
#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Property.h"

#include "GaudiAlg/GaudiAlgorithm.h"

class HelloWorldAlg : public GaudiAlgorithm {
public:
Expand All @@ -26,8 +25,9 @@ class HelloWorldAlg : public GaudiAlgorithm {
virtual StatusCode finalize() final;

private:
// member variable
Gaudi::Property<std::string> theMessage{this, "PerEventPrintMessage", "Hello ", "The message to printed for each Event"};
// member variable
Gaudi::Property<std::string> theMessage{this, "PerEventPrintMessage", "Hello ",
"The message to printed for each Event"};
};

#endif /* TESTFWCORE_HELLOWORLDALG */