diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 78e2f786bea6b334bcd804092d11599d9b665258..b0303648adc56ca4344e72606e1dac5b9ab320fe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ clang-format: image: everybeam_base:${CI_COMMIT_SHORT_SHA} before_script: - apt-get -y install python3-pip - - pip3 install clang-format + - pip3 install clang-format==9.0.0 script: - ./scripts/run-clang-format.sh diff --git a/cpp/coords/itrfconverter.h b/cpp/coords/itrfconverter.h index ee07521b2bd03ed01ec702fcb1b33d6a7ba311a0..364af8f824384730de6a55d8aaa57eb1996ade91 100644 --- a/cpp/coords/itrfconverter.h +++ b/cpp/coords/itrfconverter.h @@ -18,7 +18,8 @@ namespace everybeam { namespace coords { /** * @brief Class providing utilities for coordinate transformations - * to and from ITRF (International Terrestrial Reference Frame) + * to and from ITRF (International Terrestrial Reference Frame). + * NOTE: this class is not thread-safe due to casacore dependencies. * */ class ITRFConverter { diff --git a/cpp/griddedresponse/lofargrid.cc b/cpp/griddedresponse/lofargrid.cc index 51d3700614506f4578ccf8c6e9ad79fff0284ea0..0afee4becd9568d49b7a8c8ca3f9100c44f389e7 100644 --- a/cpp/griddedresponse/lofargrid.cc +++ b/cpp/griddedresponse/lofargrid.cc @@ -33,19 +33,20 @@ void LOFARGrid::CalculateStation(std::complex<float>* buffer, double time, lane_ = &lane; SetITRFVectors(time); - double sb_freq = use_channel_frequency_ ? frequency : subband_frequency_; - // Dummy calculation of gain matrix, needed for multi-threading - inverse_central_gain_.resize(1); - matrix22c_t gain_matrix = lofartelescope.GetStation(station_idx) - ->Response(time, frequency, diff_beam_centre_, - sb_freq, station0_, tile0_); - - inverse_central_gain_[0][0] = gain_matrix[0][0]; - inverse_central_gain_[0][1] = gain_matrix[0][1]; - inverse_central_gain_[0][2] = gain_matrix[1][0]; - inverse_central_gain_[0][3] = gain_matrix[1][1]; - if (!inverse_central_gain_[0].Invert()) { - inverse_central_gain_[0] = aocommon::MC2x2F::Zero(); + + if (lofartelescope.GetOptions().use_differential_beam) { + double sb_freq = use_channel_frequency_ ? frequency : subband_frequency_; + inverse_central_gain_.resize(1); + matrix22c_t gain_matrix = lofartelescope.GetStation(station_idx) + ->Response(time, frequency, diff_beam_centre_, + sb_freq, station0_, tile0_); + inverse_central_gain_[0][0] = gain_matrix[0][0]; + inverse_central_gain_[0][1] = gain_matrix[0][1]; + inverse_central_gain_[0][2] = gain_matrix[1][0]; + inverse_central_gain_[0][3] = gain_matrix[1][1]; + if (!inverse_central_gain_[0].Invert()) { + inverse_central_gain_[0] = aocommon::MC2x2F::Zero(); + } } for (size_t i = 0; i != nthreads_; ++i) { @@ -70,14 +71,12 @@ void LOFARGrid::CalculateAllStations(std::complex<float>* buffer, double time, SetITRFVectors(time); - double sb_freq = use_channel_frequency_ ? frequency : subband_frequency_; - - // Dummy loop, needed for multi-threading - inverse_central_gain_.resize(lofartelescope.GetNrStations()); - for (size_t i = 0; i != lofartelescope.GetNrStations(); ++i) { - matrix22c_t gain_matrix = lofartelescope.GetStation(i)->Response( - time, frequency, diff_beam_centre_, sb_freq, station0_, tile0_); - if (lofartelescope.GetOptions().use_differential_beam) { + if (lofartelescope.GetOptions().use_differential_beam) { + double sb_freq = use_channel_frequency_ ? frequency : subband_frequency_; + inverse_central_gain_.resize(lofartelescope.GetNrStations()); + for (size_t i = 0; i != lofartelescope.GetNrStations(); ++i) { + matrix22c_t gain_matrix = lofartelescope.GetStation(i)->Response( + time, frequency, diff_beam_centre_, sb_freq, station0_, tile0_); inverse_central_gain_[i][0] = gain_matrix[0][0]; inverse_central_gain_[i][1] = gain_matrix[0][1]; inverse_central_gain_[i][2] = gain_matrix[1][0]; diff --git a/cpp/griddedresponse/lofargrid.h b/cpp/griddedresponse/lofargrid.h index a032993475f49d3b27b2c97c26a2814d64cb01e5..28ada8044524046b0312a0a885aa4aabecabcd65 100644 --- a/cpp/griddedresponse/lofargrid.h +++ b/cpp/griddedresponse/lofargrid.h @@ -92,6 +92,12 @@ class LOFARGrid final : public GriddedResponse { }; aocommon::Lane<Job>* lane_; + /** + * @brief Method for computing the ITRF-vectors. + * NOTE: method not thread-safe due to casacore dependencies. + * + * @param time + */ void SetITRFVectors(double time); void CalcThread(std::complex<float>* buffer, double time, double frequency); diff --git a/scripts/run-clang-format.sh b/scripts/run-clang-format.sh index 3fd0419c0f1af1fb78f1dcceae3987d09dc46c0b..48c99ceeb43603d881881ea544e9d8e483ba0f2d 100755 --- a/scripts/run-clang-format.sh +++ b/scripts/run-clang-format.sh @@ -9,6 +9,9 @@ # "./scripts/run-clang-format.sh" to .git/hooks/pre-commit # and make sure pre-commit is an executable shell script. +# Disable globbing +set -e -f + #Script configuration for this repo. Adjust it when copying to a different repo. #The directory that contains the source files, which clang-format should format. @@ -23,10 +26,15 @@ SOURCE_EXT=(*.cc *.h) #End script configuration. -set -e +# Detect run environment. +if [ -n "$CI" ]; then + DRYRUN=" (dry run on CI)" +elif [ -n "$GIT_AUTHOR_DATE" ]; then + DRYRUN=" (dry run in git hook)" +fi # print in bold-face -echo -e "\e[1mRunning clang-format...\e[0m" +echo -e "\e[1mRunning clang-format$DRYRUN...\e[0m" # Convert SOURCE_EXT into "-name ext1 -o -name ext2 -o name ext3 ..." FIND_NAMES="-name ${SOURCE_EXT[0]}" @@ -41,15 +49,23 @@ for e in ${EXCLUDE_DIRS[*]}; do done cd $SOURCE_DIR -find . $FIND_EXCLUDES -type f \( $FIND_NAMES \) \ - -exec clang-format -i -style=file \{\} + +FILES=$(find . $FIND_EXCLUDES -type f \( $FIND_NAMES \) -print) -if git diff --exit-code --quiet; then +if [ -n "$DRYRUN" ]; then + # If the xml has no replacement entries, all files are formatted. + if clang-format -style=file --output-replacements-xml $FILES | + grep -q "<replacement "; then + # Print in bold-face red + echo -e "\e[1m\e[31mAt least one file is not properly formatted!\e[0m" + echo -e "\e[1m\e[31mRun $0 for formatting all files!\e[0m" + exit 1; + else # print in bold-face green - echo -e "\e[1m\e[32mGreat job, git shows no changed files!\e[0m" + echo -e "\e[1m\e[32mGreat job, all files are properly formatted!\e[0m" exit 0; + fi else - # Print in bold-face red - echo -e "\e[1m\e[31mGit shows at least one changed file now!\e[0m" - exit 1; -fi + clang-format -i -style=file $FILES + # print in bold-face + echo -e "\e[1mSuccessfully formatted all files.\e[0m" +fi \ No newline at end of file