Skip to content

Commit

Permalink
style: Implement a C++ style
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoabcoelho committed Oct 6, 2023
1 parent 8d061d5 commit a15fe91
Show file tree
Hide file tree
Showing 35 changed files with 2,119 additions and 2,144 deletions.
192 changes: 192 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: true
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 600
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

13 changes: 13 additions & 0 deletions fix_style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

SEARCHARG=(src inc \
! -name "LinkDef.h" \
\( -name "*.cxx" -o -name "*.h" \))

if [ "$1" == "test" ]; then
find ${SEARCHARG[@]} \
-exec clang-format -n --Werror {} +
else
find ${SEARCHARG[@]} \
-exec clang-format -i --verbose {} +
fi
8 changes: 2 additions & 6 deletions inc/Absorption.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

namespace OscProb {

class Absorption{

class Absorption {
public:

Absorption();
virtual ~Absorption();

Expand All @@ -17,13 +15,11 @@ namespace OscProb {
virtual void SetPath(std::vector<NuPath> paths); ///< Set a path sequence

protected:

std::vector<NuPath> fNuPaths; ///< Vector of neutrino paths

static const double kU; ///< Atomic mass unit

};

}
} // namespace OscProb

#endif
4 changes: 2 additions & 2 deletions inc/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace OscProb {
typedef std::vector<double> vectorD;
typedef std::vector<vectorD> matrixD;

typedef std::complex<double> complexD;
typedef std::complex<double> complexD;
typedef std::vector<complexD> vectorC;
typedef std::vector<vectorC> matrixC;

}
} // namespace OscProb

#endif
45 changes: 28 additions & 17 deletions inc/EarthModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,71 @@
#ifndef EARTHMODELBASE_H
#define EARTHMODELBASE_H

#include "TObject.h"
#include "NuPath.h"
#include "TObject.h"

namespace OscProb {

class EarthModelBase : public TObject {

public:

///
/// Set the coordinates of the detector:
/// radius in km, latitude in degrees, longitude in degrees
///
/// Not implemented in base class.
///
virtual void SetDetPos(double rad, double lat=0, double lon=0) = 0; ///< Set the detector position (rad = radius in km, lat/lon in deg)
virtual void SetDetPos(
double rad, double lat = 0,
double lon = 0) = 0; ///< Set the detector position (rad = radius in
///< km, lat/lon in deg)

///
/// Construct the neutrino path through the Earth having
/// zenith angle defined by cosT and azimuthal angle phi.
///
/// Not implemented in base class.
///
virtual int FillPath(double cosT, double phi) = 0; ///< Fill the path sequence in a vector (phi in degrees)
virtual int FillPath(double cosT,
double phi) = 0; ///< Fill the path sequence in a
///< vector (phi in degrees)

virtual std::vector<NuPath> GetNuPath(); ///< Get the current neutrino path sequence
virtual std::vector<NuPath> GetNuPath(); ///< Get the current neutrino
///< path sequence

virtual std::vector<NuPath> GetMergedPaths(double prec = 0.25); ///< Get merged path sequence in a vector
virtual std::vector<NuPath> GetMergedPaths(
double prec = 0.25); ///< Get merged path sequence in a vector

virtual double GetTotalL(double cosT); ///< Get the total baseline for a given cosTheta
virtual double GetCosT(double L); ///< Get the cosTheta for a given total baseline
virtual double GetTotalL(
double cosT); ///< Get the total baseline for a given cosTheta
virtual double GetCosT(
double L); ///< Get the cosTheta for a given total baseline

virtual void SetRemoveSmallPaths(bool rp = true); ///< Set tag to remove small paths
virtual void SetRemoveSmallPaths(
bool rp = true); ///< Set tag to remove small paths

protected:
virtual void SetDetectorCoordinates(
double rad, double lat,
double lon); ///< Set the coordinates of the detector (rad = radius in
///< km, lat/lon in deg)

virtual void SetDetectorCoordinates(double rad, double lat, double lon); ///< Set the coordinates of the detector (rad = radius in km, lat/lon in deg)

virtual void AddPathSegment(double length, double density, double zoa, int index); ///< Add a path segment to the sequence
virtual void AddPathSegment(
double length, double density, double zoa,
int index); ///< Add a path segment to the sequence

std::vector<NuPath> fNuPath; ///< The current neutrino path sequence

double fRadiusMax; ///< Maximum radius in Earth model (in km)
double fDetRadius; ///< The radius where the detector sits (in km)
double fDetLat; ///< The latitude (in rad) where the detector sits
double fDetLon; ///< The longitude (in rad) where the detector sits
double fDetLat; ///< The latitude (in rad) where the detector sits
double fDetLon; ///< The longitude (in rad) where the detector sits

bool fRemoveSmallPaths; ///< Tag whether to merge small paths

// Required for saving in ROOT files
ClassDef(EarthModelBase, 1);

};

}
} // namespace OscProb

#endif
Loading

0 comments on commit a15fe91

Please sign in to comment.