@@ -475,10 +475,10 @@ def test_line(self, line: str) -> bool:
475475
476476
477477class TestPdgExplicitCode (TestSpec ):
478- """Detect use of hard-coded PDG codes."""
478+ """Detect hard-coded PDG codes."""
479479
480480 name = "pdg/explicit-code"
481- message = "Avoid using hard-coded PDG codes. Use named values from PDG_t or o2::constants::physics::Pdg instead."
481+ message = "Avoid hard-coded PDG codes. Use named values from PDG_t or o2::constants::physics::Pdg instead."
482482 rationale = "Code comprehensibility, readability, maintainability and safety."
483483 references = [Reference .O2 , Reference .ISO_CPP , Reference .LINTER ]
484484 suffixes = [".h" , ".cxx" , ".C" ]
@@ -497,27 +497,6 @@ def test_line(self, line: str) -> bool:
497497 return True
498498
499499
500- class TestPdgKnownMass (TestSpec ):
501- """Detect unnecessary call of Mass() for a known PDG code."""
502-
503- name = "pdg/known-mass"
504- message = "Use o2::constants::physics::Mass... instead of calling a database method for a known PDG code."
505- rationale = "Performance."
506- references = [Reference .LINTER ]
507- suffixes = [".h" , ".cxx" , ".C" ]
508-
509- def test_line (self , line : str ) -> bool :
510- if is_comment_cpp (line ):
511- return True
512- line = remove_comment_cpp (line )
513- pattern_pdg_code = r"[+-]?(k[A-Z][a-zA-Z0-9]*|[0-9]+)"
514- if re .search (rf"->GetParticle\({ pattern_pdg_code } \)->Mass\(\)" , line ):
515- return False
516- if re .search (rf"->Mass\({ pattern_pdg_code } \)" , line ):
517- return False
518- return True
519-
520-
521500class TestPdgExplicitMass (TestSpec ):
522501 """Detect hard-coded particle masses."""
523502
@@ -563,6 +542,27 @@ def test_line(self, line: str) -> bool:
563542 return True
564543
565544
545+ class TestPdgKnownMass (TestSpec ):
546+ """Detect unnecessary call of Mass() for a known PDG code."""
547+
548+ name = "pdg/known-mass"
549+ message = "Use o2::constants::physics::Mass... instead of calling a database method for a known PDG code."
550+ rationale = "Performance."
551+ references = [Reference .LINTER ]
552+ suffixes = [".h" , ".cxx" , ".C" ]
553+
554+ def test_line (self , line : str ) -> bool :
555+ if is_comment_cpp (line ):
556+ return True
557+ line = remove_comment_cpp (line )
558+ pattern_pdg_code = r"[+-]?(k[A-Z][a-zA-Z0-9]*|[0-9]+)"
559+ if re .search (rf"->GetParticle\({ pattern_pdg_code } \)->Mass\(\)" , line ):
560+ return False
561+ if re .search (rf"->Mass\({ pattern_pdg_code } \)" , line ):
562+ return False
563+ return True
564+
565+
566566class TestLogging (TestSpec ):
567567 """Detect non-O2 logging."""
568568
@@ -588,7 +588,7 @@ class TestConstRefInForLoop(TestSpec):
588588
589589 name = "const-ref-in-for-loop"
590590 message = "Use constant references for non-modified iterators in range-based for loops."
591- rationale = "Peformance , code safety."
591+ rationale = "Performance , code safety."
592592 references = [Reference .O2 , Reference .ISO_CPP , Reference .LLVM ]
593593 suffixes = [".h" , ".cxx" , ".C" ]
594594
@@ -609,7 +609,7 @@ class TestConstRefInSubscription(TestSpec):
609609
610610 name = "const-ref-in-process"
611611 message = "Use constant references for table subscriptions in process functions."
612- rationale = "Peformance , code safety."
612+ rationale = "Performance , code safety."
613613 references = [Reference .O2 , Reference .ISO_CPP , Reference .LINTER ]
614614 suffixes = [".cxx" ]
615615 per_line = False
@@ -1633,8 +1633,8 @@ def main():
16331633 tests .append (TestPiMultipleFraction ())
16341634 tests .append (TestPdgDatabase ())
16351635 tests .append (TestPdgExplicitCode ())
1636- tests .append (TestPdgKnownMass ())
16371636 tests .append (TestPdgExplicitMass ())
1637+ tests .append (TestPdgKnownMass ())
16381638 tests .append (TestLogging ())
16391639 tests .append (TestConstRefInForLoop ())
16401640 tests .append (TestConstRefInSubscription ())
0 commit comments