Skip to content

Commit 3cf8edd

Browse files
author
Benedikt Volkel
committed
introduce clang-format
* adopt .clang-format from https://github.com/AliceO2Group/AliceO2/blob/d46c55f0b6b09921cd90641c4496721902b5f60d/.clang-format * add basic clang-format github workflow * apply clang-format to current files
1 parent 0838c48 commit 3cf8edd

File tree

11 files changed

+85
-95
lines changed

11 files changed

+85
-95
lines changed

.clang-format

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ CommentPragmas: '^ IWYU pragma:'
1818
ConstructorInitializerAllOnOneLineOrOnePerLine: true
1919
ConstructorInitializerIndentWidth: 2
2020
ContinuationIndentWidth: 2
21-
Cpp11BracedListStyle: false
21+
Cpp11BracedListStyle: true
2222
DerivePointerBinding: false
2323
ExperimentalAutoDetectBinPacking: false
2424
IndentCaseLabels: true
2525
IndentFunctionDeclarationAfterType: true
2626
IndentWidth: 2
2727
# It is broken on windows. Breaks all #include "header.h"
28+
---
2829
Language: Cpp
2930
MaxEmptyLinesToKeep: 1
3031
KeepEmptyLinesAtTheStartOfBlocks: true
@@ -49,3 +50,7 @@ SpacesInParentheses: false
4950
Standard: Cpp11
5051
TabWidth: 2
5152
UseTab: Never
53+
---
54+
# Do not format protobuf files
55+
Language: Proto
56+
DisableFormat: true

.github/workflows/format.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Clang format
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
clang-format:
7+
# We need at least 20.04 to install clang-format-11.
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
ref: ${{ github.event.pull_request.head.sha }}
13+
- name: Install prerequisites
14+
env:
15+
DEBIAN_FRONTEND: noninteractive
16+
run: |
17+
sudo apt update -y
18+
sudo apt install -y clang-format-11
19+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100
20+
sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-11 100
21+
- name: Run clang-foramt on changed files
22+
run: |
23+
set -x
24+
git fetch origin ${{ github.event.pull_request.base.ref }}
25+
git fetch origin pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}
26+
BASE_COMMIT=$(git rev-parse ${{ github.event.pull_request.base.sha }})
27+
COMMIT_FILES=$(git diff --diff-filter=d --name-only ${BASE_COMMIT} | grep -E -- '\.cxx|\.h' | grep -i -v LinkDef) || true ;# avoid failures if nothing is greped
28+
[ "X$COMMIT_FILES" = X ] && { echo "No files to check" ; exit 0; }
29+
RESULT_OUTPUT=$(git-clang-format --commit ${BASE_COMMIT} --diff ${COMMIT_FILES})
30+
if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then
31+
echo "clang-format passed."
32+
exit 0
33+
else
34+
git-clang-format --commit $BASE_COMMIT --diff
35+
echo "$RESULT_OUTPUT"
36+
echo "clang-format failed."
37+
exit 1
38+
fi

.travis.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

include/MCStepLogger/MCAnalysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace mcstepanalysis
3939
// here we will give Step + meta info such as volumename, modulename, pdg
4040
typedef bool (*cut_function_type)(StepInfo const&, std::string const&, std::string const&, int, o2::StepLookups*);
4141

42-
4342
// /class MCAnalysisManager;
4443

4544
class MCAnalysis

include/MCStepLogger/MCAnalysisUtilities.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ void scalePerBin(TH1* histo, const std::vector<float>& scaleVector);
3232
/// for histograms with alphanumeric labels scale bin with name "name" by scaleMap["name"]
3333
void scalePerBin(TH1* histo, const std::unordered_map<std::string, float>& scaleMap);
3434
} // namespace utilities
35-
} // namespace mstepanalysis
36-
} // o2
35+
} // namespace mcstepanalysis
36+
} // namespace o2
3737
#endif /* MCANALYSIS_UTILITIES_H_ */

include/MCStepLogger/MetaInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const std::string defaultMCAnalysisName = "defaultMCAnalysisName";
2929
const std::string defaultLabel = "defaultLabel";
3030
const std::string defaultStepLoggerTTreeName = "StepLoggerTree";
3131

32-
} // end namespace metainfonames
32+
} // namespace defaults
3333

3434
struct MCAnalysisMetaInfo {
3535
MCAnalysisMetaInfo()

include/MCStepLogger/SimpleStepAnalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class SimpleStepAnalysis : public MCAnalysis
8585
TH2D* histXY;
8686

8787
// keep steps (under cutting for instance)
88-
TTree *steptree;
89-
TFile *stepfile;
88+
TTree* steptree;
89+
TFile* stepfile;
9090

9191
// pointing to a user cut function
9292
cut_function_type* mUserCutFunction = nullptr; //!

include/MCStepLogger/StepInfo.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ struct StepLookups {
5757
std::vector<std::string*> volidtovolname;
5858
std::vector<std::string*> volidtomodule;
5959
std::vector<std::string*> volidtomedium;
60-
std::vector<bool> volidtoissensitive; // keep track of which volume is sensitive
60+
std::vector<bool> volidtoissensitive; // keep track of which volume is sensitive
6161
std::vector<int> tracktopdg;
6262
std::vector<int> tracktoparent; // when parent is -1 we mean primary
6363
std::vector<int> stepcounterpertrack;
6464

65-
std::vector<int> trackorigin; // the volumeID where the track originates
66-
std::vector<float> tracktoenergy; // mapping of trackID to the track energy
67-
std::vector<bool> crossedboundary; // if track every crossed a geometry boundary
65+
std::vector<int> trackorigin; // the volumeID where the track originates
66+
std::vector<float> tracktoenergy; // mapping of trackID to the track energy
67+
std::vector<bool> crossedboundary; // if track every crossed a geometry boundary
6868
std::vector<bool> producedsecondary; // if track ever produced a secondary
6969

7070
void insertVolName(int index, std::string const& s) { insertValueAt(index, s, volidtovolname); }
@@ -89,34 +89,38 @@ struct StepLookups {
8989
tracktopdg[trackindex] = pdg;
9090
}
9191

92-
void incStepCount(int trackindex) {
92+
void incStepCount(int trackindex)
93+
{
9394
if (trackindex >= stepcounterpertrack.size()) {
9495
stepcounterpertrack.resize(trackindex + 1, 0);
9596
}
9697
stepcounterpertrack[trackindex]++;
9798
}
9899

99-
void setProducedSecondary(int trackindex, bool b) {
100+
void setProducedSecondary(int trackindex, bool b)
101+
{
100102
if (trackindex >= producedsecondary.size()) {
101103
producedsecondary.resize(trackindex + 1, false);
102104
}
103-
producedsecondary[trackindex]=b;
105+
producedsecondary[trackindex] = b;
104106
}
105107

106-
void setCrossedBoundary(int trackindex, bool b) {
108+
void setCrossedBoundary(int trackindex, bool b)
109+
{
107110
if (trackindex >= crossedboundary.size()) {
108111
crossedboundary.resize(trackindex + 1, false);
109112
}
110-
crossedboundary[trackindex]=b;
113+
crossedboundary[trackindex] = b;
111114
}
112115

113-
void setTrackEnergy(int trackindex, float e) {
116+
void setTrackEnergy(int trackindex, float e)
117+
{
114118
if (trackindex >= tracktoenergy.size()) {
115119
tracktoenergy.resize(trackindex + 1, -1.);
116120
}
117121
// only take the starting energy
118-
if (tracktoenergy[trackindex]==-1.) {
119-
tracktoenergy[trackindex]=e;
122+
if (tracktoenergy[trackindex] == -1.) {
123+
tracktoenergy[trackindex] = e;
120124
}
121125
}
122126

@@ -143,7 +147,8 @@ struct StepLookups {
143147
tracktoparent[trackindex] = parent;
144148
}
145149

146-
void clearTrackLookups() {
150+
void clearTrackLookups()
151+
{
147152
tracktoparent.clear();
148153
producedsecondary.clear();
149154
crossedboundary.clear();
@@ -192,13 +197,13 @@ struct StepInfo {
192197
float step = 0.;
193198
float maxstep = 0.;
194199
int nsecondaries = 0;
195-
int prodprocess = -1; // prod process of current track
196-
int nprocessesactive = 0; // number of active processes
197-
bool stopped = false; // if track was stopped during last step
198-
bool entered = false; // if track entered volume during last step
199-
bool exited = false; // if track exited volume during last step
200-
bool newtrack = false; // if track is new
201-
bool insensitiveRegion = false; // whether step done in sensitive region
200+
int prodprocess = -1; // prod process of current track
201+
int nprocessesactive = 0; // number of active processes
202+
bool stopped = false; // if track was stopped during last step
203+
bool entered = false; // if track entered volume during last step
204+
bool exited = false; // if track exited volume during last step
205+
bool newtrack = false; // if track is new
206+
bool insensitiveRegion = false; // whether step done in sensitive region
202207

203208
const char* getProdProcessAsString() const;
204209

@@ -227,5 +232,5 @@ struct MagCallInfo {
227232
static int stepcounter;
228233
ClassDefNV(MagCallInfo, 1);
229234
};
230-
}
235+
} // namespace o2
231236
#endif

src/MCStepLoggerAnalysisLinkDef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
1312
#ifdef __CLING__
1413
#pragma link off all globals;
1514
#pragma link off all classes;

src/MCStepLoggerCoreLinkDef.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
1312
#ifdef __CLING__
1413
#pragma link off all globals;
1514
#pragma link off all classes;
1615
#pragma link off all functions;
1716

18-
#pragma link C++ class o2::StepInfo+;
19-
#pragma link C++ class o2::MagCallInfo+;
20-
#pragma link C++ class std::vector<o2::StepInfo>+;
21-
#pragma link C++ class std::vector<o2::MagCallInfo>+;
22-
#pragma link C++ class std::vector<o2::StepInfo*>+;
23-
#pragma link C++ class std::vector<o2::MagCallInfo*>+;
24-
#pragma link C++ class std::vector<TGeoVolume const *>+;
25-
#pragma link C++ class std::vector<std::vector<TGeoVolume const *> *>+;
26-
#pragma link C++ class o2::VolInfoContainer+;
27-
#pragma link C++ class o2::StepLookups+;
17+
#pragma link C++ class o2::StepInfo + ;
18+
#pragma link C++ class o2::MagCallInfo + ;
19+
#pragma link C++ class std::vector < o2::StepInfo> + ;
20+
#pragma link C++ class std::vector < o2::MagCallInfo> + ;
21+
#pragma link C++ class std::vector < o2::StepInfo*> + ;
22+
#pragma link C++ class std::vector < o2::MagCallInfo*> + ;
23+
#pragma link C++ class std::vector < TGeoVolume const*> + ;
24+
#pragma link C++ class std::vector < std::vector < TGeoVolume const*>*> + ;
25+
#pragma link C++ class o2::VolInfoContainer + ;
26+
#pragma link C++ class o2::StepLookups + ;
2827

2928
#endif

0 commit comments

Comments
 (0)