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

Script to compile only the tools you need #325

Open
wants to merge 5 commits into
base: Application
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ DataModel/DataModel_Linkdef.hh
# These are imported as part of ToolPack
UserTools/ImportedTools
UserTools/InactiveTools
build_*/

165 changes: 165 additions & 0 deletions script/ToolAnalysisMyTools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/bin/bash
# Dummy test by M. Ascencio, Dec-2024
# [email protected]

##########################################################################
# chmod +x ToolAnalysisMyTools.sh
# Description: The script creates a build_{configfileName} directory in ./ToolAnalysis. It copies
# the necessary default files and directories to build_{configfileName} in addition to the toolchains
# used in your configfileName. You will need to `source Setup.sh` in the build_{configfileName} directory
# and compile with `make clean` and `make`. WARNING, do not use `make -jN` where N is the number of cores.
# For some reason `make -jN` will compile fine but the Total events for example will be random.
#
# USE:
# ./ToolAnalysisMyTools.sh configfileName
#
# If its more than one configfileName you need to use a "," without space as follows:
# ./ToolAnalysisMyTools.sh "configfileName1,configfileName2,..."
#
# You can clean the built directory with:
# ./ToolAnalysisMyTools.sh configfileName clean
# ./ToolAnalysisMyTools.sh "configfileName1,configfileName2,..." clean
##########################################################################

setBuild(){

# Copy the main tools, scripts, etc
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo -e "\t ####################################################"
echo -e "\t ############# Preparing $(echo "$1" | tr ',' '_') "
echo -e "\t ####################################################"
echo -e "\t ####### Making the $(echo "$1" | tr ',' '_') dir"
cd ../ # Because I am script dir now
DIR_NAME="build_$(echo "$1" | tr ',' '_')"
IFS=',' read -r -a tools <<< "$1"

if [ -d $DIR_NAME ]; then
echo -e "\t Ha! Directory '$DIR_NAME' exists. Removing it..."
rm -rf $DIR_NAME
echo -e "\t Directory '$DIR_NAME' removed."
fi

mkdir -p $DIR_NAME/UserTools
mkdir -p $DIR_NAME/configfiles

echo -e "\t ####### Copying Makefile, DataModel, lib, src, include, linkdef* and Setup.sh to $DIR_NAME"
cp Setup.sh $DIR_NAME/
cp Makefile $DIR_NAME/
cp -r DataModel $DIR_NAME/
cp -r lib $DIR_NAME/
cp -r src $DIR_NAME/
cp -r include $DIR_NAME/
cp linkdef* $DIR_NAME/

darray=("recoANNIE" "PlotWaveforms" "Factory" "Examples")
echo -e "\t ####### Copying the default Tools"
for element in "${darray[@]}"; do
echo -e "\t\t @@@@@@@@ Copying $element"
cp -r UserTools/$element $DIR_NAME/UserTools
done

for tool in "${tools[@]}"; do
echo -e "\t ####### Copying configfile/$tool"
done
cp -r configfiles/LoadGeometry $DIR_NAME/configfiles

array=()
for tool in "${tools[@]}"; do
cp -r configfiles/$tool $DIR_NAME/configfiles
toolschain="configfiles/$tool/ToolsConfig"
array+=($(grep -v '^#' $toolschain | awk '{print $2}'))
done
echo -e "\t ####################################################"
echo -e "\t \t Extracted tools : "
for element in "${array[@]}"; do
echo -e "\t \t \t \t tool ----> " $element
done
echo -e "\t ####################################################"
echo -e "\t ####### Copying the extracted Tools"
for element in "${array[@]}"; do
cp -r UserTools/$element $DIR_NAME/UserTools
done

cd $DIR_NAME

echo -e "\t ####### Making the symbolic links"
for tool in "${tools[@]}"; do
ln -s configfiles/$tool/ToolChainConfig $tool
done
ln -s /ToolAnalysis/ToolDAQ ToolDAQ

# Making the Unity.h
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo -e "\t ####### Making Unity.h"
uarray=("Unity_recoANNIE" "PlotWaveforms" "Factory")
farray=("PlotWaveforms")

# Spe. tools
#echo -e "\t #include DummyTool.h"
echo "#include \"DummyTool.h\"" >> UserTools/Unity.h

for element in "${uarray[@]}"; do
#echo -e "\t #include $element.h"
echo "#include \"$element.h\"" >> UserTools/Unity.h
done

# My tools
for element in "${array[@]}"; do
#echo -e "\t #include $element.h"
echo "#include \"$element.h\"" >> UserTools/Unity.h
done

# making Factory.cpp
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rm UserTools/Factory/Factory.cpp
echo -e "\t ####### Making Factory/Factory.cpp"
echo "#include \"Factory.h\"" >> UserTools/Factory/Factory.cpp
echo "Tool* Factory(std::string tool) {" >> UserTools/Factory/Factory.cpp
echo " Tool* ret = 0;" >> UserTools/Factory/Factory.cpp
echo " if (tool==\"DummyTool\") ret=new DummyTool;" >> UserTools/Factory/Factory.cpp

# Loop through the array and add the conditional checks
for element in "${farray[@]}"; do
echo " if (tool==\"$element\") ret=new $element;" >> UserTools/Factory/Factory.cpp
done

# Loop through the array and add the conditional checks
for element in "${array[@]}"; do
echo " if (tool==\"$element\") ret=new $element;" >> UserTools/Factory/Factory.cpp
done
echo "return ret;" >> UserTools/Factory/Factory.cpp
echo "}" >> UserTools/Factory/Factory.cpp

echo -e "\t DONE!"
echo -e "\t Now go to ../$DIR_NAME, execute the container and compile it. Use cd ../$DIR_NAME; source Setup.sh; make clean; make"
}
# Check the arguments
if [ $# -eq 0 ]; then
echo "###################################################################################################"
echo "# No arguments provided. Please provide at least one argument. "
echo "# Usage: '$0 [configfileName]' or"
echo "# '$0 \"configfileName1,configfileName2,...\"' or"
echo "# '$0 [configfileName] clean' or "
echo "# '$0 \"configfileName1,configfileName2\" clean' "
echo "###################################################################################################"
exit 1
fi

DIR_NAME="build_$(echo "$1" | tr ',' '_')"
CONFIG_DIR="../configfiles/"
IFS=',' read -r -a tools <<< "$1"

if [ $# -eq 1 ]; then
for tool in "${tools[@]}"; do
if [ ! -d "$CONFIG_DIR/$tool" ]; then
echo "ERROR: Directory 'configfiles/$tool' does not exist."
exit 1
fi
done
setBuild $1
elif [ $# -eq 2 ] && [ "$2" == "clean" ]; then
rm -rf ../$DIR_NAME
else
echo "Invalid argument. Usage: '$0 [configfileName]' or '$0 \"configfileName1,configfileName2,...\" or '$0 [configfileName] clean'"
exit 1
fi
Loading