diff --git a/Application/CMakeLists.txt b/Application/CMakeLists.txt index 17ce6d1..f16be6a 100644 --- a/Application/CMakeLists.txt +++ b/Application/CMakeLists.txt @@ -1,3 +1,5 @@ +#todo sym links not copy headers, use macro to seach for .so files in Usertools and add the libraries to libs list and symlink to libs folder + cmake_minimum_required (VERSION 2.6) project (ToolFrameworkApplicaiton) @@ -10,11 +12,15 @@ set(MYTOOLS_INC "") set(MYTOOLS_LIB_PATH "") set(MYTOOLS_LIBS "") -include_directories (${DATAMODEL_INC} ${MYTOOLS_INC}) -link_directories(${DATAMODEL_LIB_PATH} ${MYTOOLS_LIB_PATH}) +set(TOOLFRAMEWORK_INC "${PROJECT_SOURCE_DIR}/Dependencies/ToolFrameworkCore/include") +set(TOOLFRAMEWORK_LIBS_PATH "${PROJECT_SOURCE_DIR}/Dependencies/ToolFrameworkCore/lib") +set(TOOLFRAMEWORK_LIBS "-lDataModelBase -lLogging -lStore -lToolChain") + +include_directories (${DATAMODEL_INC} ${MYTOOLS_INC} ${TOOLFRAMEWORK_INC}) +link_directories(${DATAMODEL_LIB_PATH} ${MYTOOLS_LIB_PATH} ${TOOLFRAMEWORK_LIBS_PATH}) MACRO(HEADER_DIRECTORIES return_list) - FILE(GLOB_RECURSE new_list ${PROJECT_SOURCE_DIR}/*.h) + FILE(GLOB_RECURSE new_list ${PROJECT_SOURCE_DIR}/src/*.h ${PROJECT_SOURCE_DIR}/DataModel/*.h ${PROJECT_SOURCE_DIR}/UserTools/*.h ) FILE(COPY ${new_list} DESTINATION ${PROJECT_BINARY_DIR}/include) SET(dir_list "") FOREACH(file_path ${new_list}) @@ -30,13 +36,9 @@ FILE(COPY ${PROJECT_SOURCE_DIR}/configfiles DESTINATION ${PROJECT_BINARY_DIR}/) HEADER_DIRECTORIES(header_list) include_directories(${header_list}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) - -file(GLOB_RECURSE STORE_SRC RELATIVE ${CMAKE_SOURCE_DIR} "Dependencies/ToolFrameworkCore/src/Store/*.cpp") -add_library(Store SHARED ${STORE_SRC}) +message(header_list=${header_list}) -file(GLOB_RECURSE LOGGING_SRC RELATIVE ${CMAKE_SOURCE_DIR} "Dependencies/ToolFrameworkCore/src/Logging/*.cpp") -add_library(Logging SHARED ${LOGGING_SRC}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) file(GLOB_RECURSE DATAMODEL_SRC RELATIVE ${CMAKE_SOURCE_DIR} "DataModel/*.cpp") add_library(DataModel SHARED ${DATAMODEL_SRC}) @@ -44,8 +46,5 @@ add_library(DataModel SHARED ${DATAMODEL_SRC}) file(GLOB_RECURSE MYTOOLS_SRC RELATIVE ${CMAKE_SOURCE_DIR} "UserTools/*.cpp") add_library(MyTools SHARED ${MYTOOLS_SRC}) -file(GLOB_RECURSE TOOLCHAIN_SRC RELATIVE ${CMAKE_SOURCE_DIR} "Dependencies/ToolFrameworkCore/src/ToolChain/*.cpp") -add_library(ToolChain SHARED ${TOOLCHAIN_SRC}) - add_executable (main ${PROJECT_SOURCE_DIR}/src/main.cpp) -target_link_libraries (main Store Logging ToolChain MyTools DataModel pthread ${DATAMODEL_LIBS} ${MYTOOLS_LIBS}) +target_link_libraries (main MyTools DataModel pthread ${DATAMODEL_LIBS} ${MYTOOLS_LIBS} ${TOOLFRAMEWORK_LIBS}) diff --git a/Application/Makefile.new b/Application/Makefile.new new file mode 100644 index 0000000..a25855f --- /dev/null +++ b/Application/Makefile.new @@ -0,0 +1,80 @@ +Dependencies=Dependencies +ToolFrameworkCore=$(Dependencies)/ToolFrameworkCore +SOURCEDIR=`pwd` + +CXXFLAGS= -fPIC -O3 -Wpedantic -Wall -std=c++11 -Wno-comment -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef #-Werror -Wold-style-cast + + +ifeq ($(MAKECMDGOALS),debug) +CXXFLAGS+= -O0 -g -lSegFault -rdynamic -DDEBUG +endif + +DataModelInclude = +DataModelLib = + +MyToolsInclude = +MyToolsLib = + +Includes=-I $(ToolFrameworkCore)/include/ -I $(SOURCEDIR)/include/ +ToolLibraries = $(patsubst %, lib/%, $(filter lib%, $(subst /, , $(wildcard UserTools/*/*.so)))) +LIBRARIES=lib/libDataModel.so lib/libMyTools.so $(ToolLibraries) +DataModelHEADERS:=$(patsubst %.h, include/%.h, $(filter %.h, $(subst /, ,$(wildcard DataModel/*.h)))) +MyToolHEADERS:=$(patsubst %.h, include/%.h, $(filter %.h, $(subst /, ,$(wildcard UserTools/*/*.h) $(wildcard UserTools/*.h)))) +ToolLibs = $(patsubst %.so, %, $(patsubst lib%, -l%,$(filter lib%, $(subst /, , $(wildcard UserTools/*/*.so))))) +AlreadyCompiled = $(wildcard UserTools/$(filter-out %.so UserTools , $(subst /, ,$(wildcard UserTools/*/*.so)))/*.cpp) +SOURCEFILES:=$(patsubst %.cpp, %.o, $(filter-out $(AlreadyCompiled), $(wildcard */*.cpp) $(wildcard */*/*.cpp))) +Libs=-L $(SOURCEDIR)/lib/ -lMyTools -lDataModel -L $(ToolFrameworkCore)/lib/ -lStore -lLogging -lToolChain -lDataModelBase -lpthread $(ToolLibs) + + +#.SECONDARY: $(%.o) + +all: $(DataModelHEADERS) $(MyToolHEADERS) $(SOURCEFILES) $(LIBRARIES) main + +debug: all + +main: src/main.o $(LIBRARIES) $(DataModelHEADERS) $(MyToolHEADERS) | $(SOURCEFILES) + @echo -e "\e[38;5;11m\n*************** Making " $@ " ****************\e[0m" + g++ $(CXXFLAGS) $< -o $@ $(Includes) $(Libs) $(DataModelInclude) $(DataModellib) $(MyToolsInclude) $(MyToolslib) + +include/%.h: + @echo -e "\e[38;5;87m\n*************** sym linking headers ****************\e[0m" + ln -s `pwd`/$(filter %$(strip $(patsubst include/%.h, /%.h, $@)), $(wildcard DataModel/*.h) $(wildcard UserTools/*/*.h) $(wildcard UserTools/*.h)) $@ + +src/%.o : src/%.cpp + @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) + +UserTools/Factory/Factory.o : UserTools/Factory/Factory.cpp $(DataModelHEADERS) + @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(DataModelInclude) $(ToolsInclude) + +UserTools/%.o : UserTools/%.cpp $(DataModelHEADERS) UserTools/%.h + @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(DataModelInclude) $(ToolsInclude) + +DataModel/%.o : DataModel/%.cpp DataModel/%.h $(DataModelHEADERS) + @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(DataModelInclude) + +lib/libDataModel.so: $(patsubst %.cpp, %.o , $(wildcard DataModel/*.cpp)) | $(DataModelInclude) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) $(DataModelInclude) + +lib/libMyTools.so: $(patsubst %.cpp, %.o , $(filter-out $(AlreadyCompiled), $(wildcard UserTools/*/*.cpp))) | $(DataModelInclude) $(MyToolsInclude) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) $(DataModelInclude) $(MyToolsInclude) + +lib/%.so: + @echo -e "\e[38;5;87m\n*************** sym linking Tool libs ****************\e[0m" + ln -s `pwd`/$(filter %$(strip $(patsubst lib/%.so, /%.so ,$@)), $(wildcard UserTools/*/*.so)) $@ + +clean: + @echo -e "\e[38;5;201m\n*************** Cleaning up ****************\e[0m" + rm -f */*/*.o + rm -f */*.o + rm -f include/*.h + rm -f lib/*.so + +Docs: + doxygen Doxyfile + diff --git a/Application/Setup.sh b/Application/Setup.sh index bd87c85..916b6c9 100755 --- a/Application/Setup.sh +++ b/Application/Setup.sh @@ -4,6 +4,6 @@ Dependencies=`pwd`/Dependencies -export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=`pwd`/lib:$Dependencies/ToolFrameworkCore/lib:$LD_LIBRARY_PATH export SEGFAULT_SIGNALS="all" diff --git a/CMakeLists.txt b/CMakeLists.txt index 534f1f0..abf7751 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,14 +37,17 @@ add_library(Store SHARED ${STORE_SRC}) file(GLOB_RECURSE LOGGING_SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/Logging/*.cpp") add_library(Logging SHARED ${LOGGING_SRC}) -file(GLOB_RECURSE DATAMODEL_SRC RELATIVE ${CMAKE_SOURCE_DIR} "DataModel/*.cpp") -add_library(DataModel SHARED ${DATAMODEL_SRC}) +file(GLOB_RECURSE DATAMODELBASE_SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/DataModelBase/*.cpp") +add_library(DataModelBase SHARED ${DATAMODELBASE_SRC}) -file(GLOB_RECURSE MYTOOLS_SRC RELATIVE ${CMAKE_SOURCE_DIR} "UserTools/*.cpp") -add_library(MyTools SHARED ${MYTOOLS_SRC}) +file(GLOB_RECURSE TEMPDATAMODEL_SRC RELATIVE ${CMAKE_SOURCE_DIR} "DataModel/*.cpp") +add_library(TempDataModel SHARED ${TEMPDATAMODEL_SRC}) + +file(GLOB_RECURSE TEMPTOOLS_SRC RELATIVE ${CMAKE_SOURCE_DIR} "UserTools/*.cpp") +add_library(TempTools SHARED ${TEMPTOOLS_SRC}) file(GLOB_RECURSE TOOLCHAIN_SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/ToolChain/*.cpp") add_library(ToolChain SHARED ${TOOLCHAIN_SRC}) add_executable (main ${PROJECT_SOURCE_DIR}/src/main.cpp) -target_link_libraries (main Store Logging ToolChain MyTools DataModel pthread ${DATAMODEL_LIBS} ${MYTOOLS_LIBS}) +target_link_libraries (main Store Logging DataModelBase ToolChain TempTools TempDataModel pthread ${DATAMODEL_LIBS} ${MYTOOLS_LIBS}) diff --git a/DataModel/DataModel.cpp b/DataModel/DataModel.cpp index 0726544..adf44b8 100644 --- a/DataModel/DataModel.cpp +++ b/DataModel/DataModel.cpp @@ -1,6 +1,6 @@ #include "DataModel.h" -DataModel::DataModel(){ Log=0;} +DataModel::DataModel():DataModelBase(){} /* TTree* DataModel::GetTTree(std::string name){ diff --git a/DataModel/DataModel.h b/DataModel/DataModel.h index 5fe9682..5059d43 100644 --- a/DataModel/DataModel.h +++ b/DataModel/DataModel.h @@ -11,6 +11,9 @@ #include "Store.h" #include "BStore.h" #include "Logging.h" +#include "DataModelBase.h" + +using namespace ToolFramework; /** * \class DataModel @@ -23,7 +26,7 @@ * */ -class DataModel { +class DataModel: public DataModelBase { public: @@ -33,16 +36,8 @@ class DataModel { //TTree* GetTTree(std::string name); //void AddTTree(std::string name,TTree *tree); //void DeleteTTree(std::string name,TTree *tree); - - Logging *Log; ///< Log class pointer for use in Tools, it can be used to send messages which can have multiple error levels and destination end points - - Store vars; ///< This Store can be used for any variables. It is an inefficent ascii based storage and command line arguments will be placed in here along with ToolChain variables - BStore CStore; ///< This is a more efficent binary Store that can be used to store a dynamic set of inter Tool variables, very useful for constants and and flags hence the name CStore - std::map Stores; ///< This is a map of named BStore pointers which can be deffined to hold a nammed collection of any type of BStore. It is usefull to store data collections that needs subdividing into differnt stores. - - - private: + // private: //std::map m_trees; diff --git a/DataModel/Utilities.h b/DataModel/Utilities.h deleted file mode 100644 index d3244ab..0000000 --- a/DataModel/Utilities.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef UTILITIES_H -#define UTILITIES_H - -#include -#include -#include -#include -#include -#include - -/** - * \struct DataModelThread_args - * - * This is both an base class for any thread argument struct used in the tool threaded Tool templates. -Effectivly this acts as a place to put variable that are specfic to that thread and can be used as a place to transfer variables from the main thread to sub threads. - * - * - * $Author: B.Richards $ - * $Date: 2019/05/26 18:34:00 $ - * - */ - -struct Thread_args{ - - Thread_args(){ ///< Simple constructor - kill=false; - running=false; - } - - virtual ~Thread_args(){ ///< virtual constructor - running =false; - kill=true; - } - - std::string ThreadName; ///< name of thread (deffined at creation) - void (*func)(Thread_args*); ///< function pointer to thread with args - pthread_t thread; ///< Simple constructor underlying thread that interface is built ontop of - bool running; ///< Bool flag to tell the thread to run (if not set thread goes into wait cycle - bool kill; ///< Bool flay used to kill the thread - -}; - - -/** - * \class Utilities - * - * This class can be instansiated in a Tool and provides some helpful threading, dynamic socket descovery and promotion functionality - * - * - * $Author: B.Richards $ - * $Date: 2019/05/26 18:34:00 $ - * - */ - -class Utilities{ - - public: - - Utilities(); ///< Simple constructor - Thread_args* CreateThread(std::string ThreadName, void (*func)(Thread_args*), Thread_args* args); ///< Create a thread with more complicated data exchange definned by arguments - bool KillThread(Thread_args* &args); ///< Kill a thread assosiated to args - bool KillThread(std::string ThreadName); ///< Kill a thread by name - - template bool KillThread(T* pointer){ - - Thread_args* tmp=pointer; - return KillThread(tmp); - - } ///< Kill a thread with args that inheirt form base Thread_args - - - - protected: - - static void* Thread(void *arg); ///< Thread with args - std::map Threads; ///< Map of threads managed by the utilities class. - - -}; - - -#endif diff --git a/Makefile b/Makefile index 368b3b8..df786fd 100644 --- a/Makefile +++ b/Makefile @@ -1,98 +1,113 @@ -CXXFLAGS= -fPIC -O3 -Wpedantic -Wall +SOURCEDIR:=`pwd` + +CXXFLAGS= -fPIC -O3 -Wpedantic -Wall -std=c++11 -Wno-comment -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef #-Werror -Wold-style-cast + ifeq ($(MAKECMDGOALS),debug) CXXFLAGS+= -O0 -g -lSegFault -rdynamic -DDEBUG endif +ifeq ($(MAKECMDGOALS),no_colour) +CXXFLAGS+= -DNO_COLOUR +endif -DataModelInclude = -DataModelLib = - -MyToolsInclude = -MyToolsLib = - +TempDataModelInclude = +TempDataModelLib = -debug: all +TempToolsInclude = +TempToolsLib = -all: lib/libMyTools.so lib/libToolChain.so lib/libStore.so include/Tool.h lib/libDataModel.so lib/libLogging.so main -main: src/main.cpp lib/libStore.so lib/libLogging.so lib/libToolChain.so | lib/libMyTools.so lib/libDataModel.so - @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - g++ $(CXXFLAGS) src/main.cpp -o main -I include -L lib -lStore -lMyTools -lToolChain -lDataModel -lLogging -lpthread $(DataModelInclude) $(MyToolsInclude) $(MyToolsLib) $(DataModelLib) +Includes=-I $(SOURCEDIR)/include/ -I $(SOURCEDIR)/tempinclude/ +Libs=-L $(SOURCEDIR)/lib/ -lToolChain -lTempDataModel -lTempTools -lDataModelBase -lLogging -lStore -lpthread +LIBRARIES=lib/libStore.so lib/libLogging.so lib/libToolChain.so lib/libDataModelBase.so lib/libTempDataModel.so lib/libTempTools.so +HEADERS:=$(patsubst %.h, include/%.h, $(filter %.h, $(subst /, ,$(wildcard src/*/*.h) ))) +TempDataModelHEADERS:=$(patsubst %.h, tempinclude/%.h, $(filter %.h, $(subst /, ,$(wildcard DataModel/*.h)))) +TempMyToolHEADERS:=$(patsubst %.h, tempinclude/%.h, $(filter %.h, $(subst /, ,$(wildcard UserTools/*/*.h) $(wildcard UserTools/*.h)))) +SOURCEFILES:=$(patsubst %.cpp, %.o, $(wildcard */*.cpp) $(wildcard */*/*.cpp)) +#.SECONDARY: $(%.o) -lib/libStore.so: src/Store/* - @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp src/Store/*.h include/ - g++ $(CXXFLAGS) -shared -I include src/Store/*.cpp -o lib/libStore.so +all: $(HEADERS) $(TempDataModelHEADERS) $(TempMyToolHEADERS) $(SOURCEFILES) $(LIBRARIES) main -include/Tool.h: src/Tool/Tool.h +no_colour: all +debug: all - @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp src/Tool/Tool.h include/ +main: src/main.o $(LIBRARIES) $(HEADERS) $(TempDataModelHEADERS) $(TempMyToolHEADERS) | $(SOURCEFILES) + @echo -e "\e[38;5;11m\n*************** Making " $@ " ****************\e[0m" + g++ $(CXXFLAGS) $< -o $@ $(Includes) $(Libs) $(TempDataModelInclude) $(TempDataModellib) $(TempToolsInclude) $(TempToolslib) +include/%.h: + @echo -e "\e[38;5;87m\n*************** sym linking headers ****************\e[0m" + ln -s $(SOURCEDIR)/$(filter %$(strip $(patsubst include/%.h, /%.h, $@)), $(wildcard src/*/*.h) $(wildcard UserTools/*/*.h)) $@ -lib/libToolChain.so: src/ToolChain/* lib/libStore.so include/Tool.h lib/libLogging.so | lib/libDataModel.so lib/libMyTools.so +tempinclude/%.h: + @echo -e "\e[38;5;87m\n*************** sym linking headers ****************\e[0m" + ln -s $(SOURCEDIR)/$(filter %$(strip $(patsubst tempinclude/%.h, /%.h, $@)), $(wildcard DataModel/*.h) $(wildcard UserTools/*/*.h) $(wildcard UserTools/*.h)) $@ +src/%.o : src/%.cpp $(HEADERS) @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp src/ToolChain/ToolChain.h include/ - g++ $(CXXFLAGS) -shared src/ToolChain/ToolChain.cpp -I include -lpthread -L lib -lStore -lDataModel -lMyTools -lLogging -o lib/libToolChain.so $(DataModelInclude) $(MyToolsInclude) $(MyToolsLib) $(DataModelLib) - - -clean: - - @echo -e "\e[38;5;201m\n*************** Cleaning up ****************\e[0m" - rm -f include/*.h - rm -f lib/*.so - rm -f main - rm -f UserTools/*/*.o - rm -f DataModel/*.o - -lib/libDataModel.so: DataModel/* lib/libLogging.so lib/libStore.so $(patsubst DataModel/%.cpp, DataModel/%.o, $(wildcard DataModel/*.cpp)) + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) +UnitTests/%.o : UnitTests/%.cpp $(HEADERS) @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - g++ $(CXXFLAGS) -shared DataModel/*.o -I include -L lib -lStore -lLogging -o lib/libDataModel.so $(DataModelInclude) $(DataModelLib) - - -lib/libMyTools.so: UserTools/*/* UserTools/* lib/libStore.so include/Tool.h lib/libLogging.so UserTools/Factory/Factory.o | lib/libDataModel.so + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) +UserTools/Factory/Factory.o : UserTools/Factory/Factory.cpp $(HEADERS) $(TempDataModelHEADERS) @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - g++ $(CXXFLAGS) -shared UserTools/*/*.o -I include -L lib -lStore -lDataModel -lLogging -o lib/libMyTools.so $(MyToolsInclude) $(DataModelInclude) $(MyToolsLib) $(DataModelLib) + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(TempDataModelInclude) $(TempToolsInclude) - -lib/libLogging.so: src/Logging/* lib/libStore.so +UserTools/%.o : UserTools/%.cpp $(HEADERS) $(TempDataModelHEADERS) UserTools/%.h @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp src/Logging/Logging.h include/ - g++ $(CXXFLAGS) -shared -I include src/Logging/Logging.cpp -o lib/libLogging.so -L lib/ -lStore - + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(TempDataModelInclude) $(TempToolsInclude) -UserTools/Factory/Factory.o: UserTools/Factory/Factory.cpp lib/libStore.so include/Tool.h lib/libLogging.so lib/libDataModel.so $(patsubst UserTools/%.cpp, UserTools/%.o, $(wildcard UserTools/*/*.cpp)) | include/Tool.h +DataModel/%.o : DataModel/%.cpp DataModel/%.h $(HEADERS) $(TempDataModelHEADERS) @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp UserTools/Factory/Factory.h include - cp UserTools/Unity.h include - -g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelLib) + g++ $(CXXFLAGS) -c $< -o $@ $(Includes) $(TempDataModelInclude) +lib/libStore.so: $(patsubst %.cpp, %.o , $(wildcard src/Store/*.cpp)) | $(HEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) -UserTools/%.o: UserTools/%.cpp lib/libStore.so include/Tool.h lib/libLogging.so lib/libDataModel.so | include/Tool.h - @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp $(shell dirname $<)/*.h include - -g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lDataModel -lLogging $(MyToolsInclude) $(MyToolsLib) $(DataModelInclude) $(DataModelLib) +lib/libLogging.so: $(patsubst %.cpp, %.o , $(wildcard src/Logging/*.cpp)) | $(HEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) +lib/libDataModelBase.so: $(patsubst %.cpp, %.o , $(wildcard src/DataModelBase/*.cpp)) | $(HEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) -target: remove $(patsubst %.cpp, %.o, $(wildcard UserTools/$(TOOL)/*.cpp)) +lib/libToolChain.so: $(patsubst %.cpp, %.o , $(wildcard src/ToolChain/*.cpp)) | $(HEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) -remove: - @echo -e "removing" - -rm UserTools/$(TOOL)/*.o - -rm include/$(TOOL).h +lib/libTempDataModel.so: $(patsubst %.cpp, %.o , $(wildcard DataModel/*.cpp)) | $(HEADERS) $(TempDataModelHEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) $(TempDataModelInclude) +lib/libTempTools.so: $(patsubst %.cpp, %.o , $(wildcard UserTools/*/*.cpp)) | $(HEADERS) $(TempDataModelHEADERS) $(TempMyToolHEADERS) + @echo -e "\e[38;5;201m\n*************** Making " $@ "****************\e[0m" + g++ $(CXXFLAGS) --shared $^ -o $@ $(Includes) $(TempDataModelInclude) $(TempToolsInclude) -DataModel/%.o: DataModel/%.cpp lib/libLogging.so lib/libStore.so - @echo -e "\e[38;5;214m\n*************** Making " $@ "****************\e[0m" - cp $(shell dirname $<)/*.h include - -g++ $(CXXFLAGS) -c -o $@ $< -I include -L lib -lStore -lLogging $(DataModelInclude) $(DataModelLib) +clean: + @echo -e "\e[38;5;201m\n*************** Cleaning up ****************\e[0m" + rm -f */*/*.o + rm -f */*.o + rm -f include/*.h + rm -f tempinclude/*.h + rm -f lib/*.so Docs: doxygen Doxyfile + + +test: $(patsubst %.cpp, %.o, $(wildcard */*.cpp) $(wildcard */*/*.cpp)) + echo + echo $(patsubst %.cpp, %.o, $(wildcard */*.cpp) $(wildcard */*/*.cpp)) +# echo $(patsubst %, lib/Lib%.so, $(filter-out %.o %.cpp src, $(subst /, , $(wildcard src/*)))) + +test2: + echo $(patsubst %.h, include/%.h, $(filter %.h, $(subst /, ,$(wildcard src/*/*.h) ))) + echo $(patsubst %.h, include/%.h, $(filter %.h, $(subst /, ,$(patsubst src/%.h, include/%.h, $(wildcard src/*/*.h) )))) diff --git a/UnitTests/StoreTest.cpp b/UnitTests/StoreTest.cpp index 371487b..3fca299 100644 --- a/UnitTests/StoreTest.cpp +++ b/UnitTests/StoreTest.cpp @@ -1,6 +1,8 @@ #include #include +using namespace ToolFramework; + int test_counter=0; template int Test(T &a, T &b, std::string message=""){ @@ -65,20 +67,20 @@ float m2=0; bool n2=false; -pass*=store.Get("a",a2); -pass*=store.Get("b",b2); -pass*=store.Get("c",c2); -pass*=store.Get("d",d2); -pass*=store.Get("e",e2); -pass*=store.Get("f",f2); -pass*=store.Get("g",g2); -pass*=store.Get("h",h2); -pass*=store.Get("i",i2); -const int j2=store.Get("j"); -pass*=store.Get("k",k2); -pass*=store.Get("l",l2); -pass*=store.Get("m",m2); -pass*=store.Get("n",n2); + pass= pass && (store.Get("a",a2)); + pass= pass && (store.Get("b",b2)); + pass= pass && (store.Get("c",c2)); + pass= pass && (store.Get("d",d2)); + pass= pass && (store.Get("e",e2)); + pass= pass && (store.Get("f",f2)); + pass= pass && (store.Get("g",g2)); + pass= pass && (store.Get("h",h2)); + pass= pass && (store.Get("i",i2)); + const int j2=store.Get("j"); + pass= pass && (store.Get("k",k2)); + pass= pass && (store.Get("l",l2)); + pass= pass && (store.Get("m",m2)); + pass= pass && (store.Get("n",n2)); bool tmp=true; diff --git a/UserTools/DummyTool/DummyTool.cpp b/UserTools/DummyTool/DummyTool.cpp index 6385a62..9d41a7b 100644 --- a/UserTools/DummyTool/DummyTool.cpp +++ b/UserTools/DummyTool/DummyTool.cpp @@ -26,8 +26,13 @@ bool DummyTool::Execute(){ // Therefore a message level of 0 is always printed so should be used for high priority messages e.g. errors // and a message level or 9 would be for minor messgaes rarely printed - Log("test 2a"); // defualt log function message level is 0 - *m_log<<"test 2b"< #include "Tool.h" +#include "DataModel.h" /** * \class DummyTool diff --git a/UserTools/template/MyTool.h b/UserTools/template/MyTool.h index 0439927..a2638be 100644 --- a/UserTools/template/MyTool.h +++ b/UserTools/template/MyTool.h @@ -5,7 +5,7 @@ #include #include "Tool.h" - +#include "DataModel.h" /** * \class MyTool diff --git a/UserTools/template/MyToolDynamicMultiThread.h b/UserTools/template/MyToolDynamicMultiThread.h index ece7ac9..a0606ad 100644 --- a/UserTools/template/MyToolDynamicMultiThread.h +++ b/UserTools/template/MyToolDynamicMultiThread.h @@ -5,6 +5,7 @@ #include #include "Tool.h" +#include "DataModel.h" /** * \struct MyToolDynamicMultiThread_args diff --git a/UserTools/template/MyToolMultiThread.h b/UserTools/template/MyToolMultiThread.h index 62c48e0..0c5e16d 100644 --- a/UserTools/template/MyToolMultiThread.h +++ b/UserTools/template/MyToolMultiThread.h @@ -5,6 +5,7 @@ #include #include "Tool.h" +#include "DataModel.h" /** * \struct MyToolMultiThread_args diff --git a/UserTools/template/MyToolThread.h b/UserTools/template/MyToolThread.h index d2a4c91..af9439e 100644 --- a/UserTools/template/MyToolThread.h +++ b/UserTools/template/MyToolThread.h @@ -5,6 +5,7 @@ #include #include "Tool.h" +#include "DataModel.h" /** * \struct MyToolThread_args_args diff --git a/src/DataModelBase/DataModelBase.cpp b/src/DataModelBase/DataModelBase.cpp new file mode 100644 index 0000000..75ad356 --- /dev/null +++ b/src/DataModelBase/DataModelBase.cpp @@ -0,0 +1,7 @@ +#include "DataModelBase.h" + +using namespace ToolFramework; + +DataModelBase::DataModelBase(){ Log=0;} + + diff --git a/src/DataModelBase/DataModelBase.h b/src/DataModelBase/DataModelBase.h new file mode 100644 index 0000000..b68e966 --- /dev/null +++ b/src/DataModelBase/DataModelBase.h @@ -0,0 +1,54 @@ +#ifndef DATAMODELBASE_H +#define DATAMODELBASE_H + +#include +#include +#include +#include "Utilities.h" + +#include "Store.h" +#include "BStore.h" +#include "Logging.h" + +namespace ToolFramework{ + + + /** + * \class DataModelBase + * + * This class Is a transient data model class for your Tools within the ToolChain. If Tools need to comunicate they pass all data objects through the data model. There fore inter tool data objects should be deffined in this class. + * + * + * $Author: B.Richards $ + * $Date: 2019/05/26 18:34:00 $ + * + */ + + class DataModelBase { + + + public: + + DataModelBase(); ///< Simple constructor + + Logging *Log; ///< Log class pointer for use in Tools, it can be used to send messages which can have multiple error levels and destination end points + + Store vars; ///< This Store can be used for any variables. It is an inefficent ascii based storage and command line arguments will be placed in here along with ToolChain variables + BStore CStore; ///< This is a more efficent binary Store that can be used to store a dynamic set of inter Tool variables, very useful for constants and and flags hence the name CStore + std::map Stores; ///< This is a map of named BStore pointers which can be deffined to hold a nammed collection of any type of BStore. It is usefull to store data collections that needs subdividing into differnt stores. + + + + protected: + + + + + + + }; + +} + + +#endif diff --git a/src/DataModelBase/README.md b/src/DataModelBase/README.md new file mode 100644 index 0000000..c91735a --- /dev/null +++ b/src/DataModelBase/README.md @@ -0,0 +1,8 @@ +#Data Model +************************* + +Data Model Class can be defined how ever the User requires. A Store is provided which ineficently maps variables to string lkeys via conversion to stringstream and can be used for debuging or other useful vairables. + +A TTree map with getter and setter functions is provided and can be uncommented if required. + + diff --git a/DataModel/Utilities.cpp b/src/DataModelBase/Utilities.cpp similarity index 97% rename from DataModel/Utilities.cpp rename to src/DataModelBase/Utilities.cpp index 1eb43b6..6c80c6b 100644 --- a/DataModel/Utilities.cpp +++ b/src/DataModelBase/Utilities.cpp @@ -1,5 +1,7 @@ #include +using namespace ToolFramework; + Utilities::Utilities(){ Threads.clear(); } diff --git a/src/DataModelBase/Utilities.h b/src/DataModelBase/Utilities.h new file mode 100644 index 0000000..38fa629 --- /dev/null +++ b/src/DataModelBase/Utilities.h @@ -0,0 +1,85 @@ +#ifndef UTILITIES_H +#define UTILITIES_H + +#include +#include +#include +#include +#include +#include + +namespace ToolFramework{ + + /** + * \struct DataModelThread_args + * + * This is both an base class for any thread argument struct used in the tool threaded Tool templates. + Effectivly this acts as a place to put variable that are specfic to that thread and can be used as a place to transfer variables from the main thread to sub threads. + * + * + * $Author: B.Richards $ + * $Date: 2019/05/26 18:34:00 $ + * + */ + + struct Thread_args{ + + Thread_args(){ ///< Simple constructor + kill=false; + running=false; + } + + virtual ~Thread_args(){ ///< virtual constructor + running =false; + kill=true; + } + + std::string ThreadName; ///< name of thread (deffined at creation) + void (*func)(Thread_args*); ///< function pointer to thread with args + pthread_t thread; ///< Simple constructor underlying thread that interface is built ontop of + bool running; ///< Bool flag to tell the thread to run (if not set thread goes into wait cycle + bool kill; ///< Bool flay used to kill the thread + + }; + + + /** + * \class Utilities + * + * This class can be instansiated in a Tool and provides some helpful threading, dynamic socket descovery and promotion functionality + * + * + * $Author: B.Richards $ + * $Date: 2019/05/26 18:34:00 $ + * + */ + + class Utilities{ + + public: + + Utilities(); ///< Simple constructor + Thread_args* CreateThread(std::string ThreadName, void (*func)(Thread_args*), Thread_args* args); ///< Create a thread with more complicated data exchange definned by arguments + bool KillThread(Thread_args* &args); ///< Kill a thread assosiated to args + bool KillThread(std::string ThreadName); ///< Kill a thread by name + + template bool KillThread(T* pointer){ + + Thread_args* tmp=pointer; + return KillThread(tmp); + + } ///< Kill a thread with args that inheirt form base Thread_args + + + + protected: + + static void* Thread(void *arg); ///< Thread with args + std::map Threads; ///< Map of threads managed by the utilities class. + + + }; + +} + +#endif diff --git a/UserTools/Factory/Factory.h b/src/Factory/Factory.h similarity index 87% rename from UserTools/Factory/Factory.h rename to src/Factory/Factory.h index e322791..32ce6da 100644 --- a/UserTools/Factory/Factory.h +++ b/src/Factory/Factory.h @@ -4,6 +4,8 @@ #include #include "Tool.h" +using namespace ToolFramework; + /** * Global Factory function for creating Tools. @param tool Name of the Tool class to create. diff --git a/src/Logging/Logging.cpp b/src/Logging/Logging.cpp index 6c7ff63..e979656 100644 --- a/src/Logging/Logging.cpp +++ b/src/Logging/Logging.cpp @@ -1,5 +1,6 @@ #include "Logging.h" +using namespace ToolFramework; Logging::TFStreamBuf::~TFStreamBuf(){ @@ -36,6 +37,7 @@ Logging::TFStreamBuf::TFStreamBuf ( bool interactive, bool local, std::string lo m_interactive=interactive; m_error=error; + if(m_error){ m_messagelevel=0; m_verbose=0; @@ -78,7 +80,6 @@ Logging::TFStreamBuf::TFStreamBuf ( bool interactive, bool local, std::string lo int Logging::TFStreamBuf::sync ( ) { - if( (( m_interactive || m_local) && (m_messagelevel <= m_verbose)) && str()!=""){ time_t rawtime; @@ -121,12 +122,14 @@ int Logging::TFStreamBuf::sync ( ) (*output)<<"["; if(m_error) (*output)<<"ERROR"; else (*output)<flush(); } } str(""); + + return 0; } diff --git a/src/Logging/Logging.h b/src/Logging/Logging.h index d12d93c..f290db0 100644 --- a/src/Logging/Logging.h +++ b/src/Logging/Logging.h @@ -10,104 +10,138 @@ #include #include +#include +#include -#define red "\033[38;5;196m" -#define darkred "\033[38;5;88m" -#define green "\033[38;5;46m" -#define darkgreen "\033[38;5;22m" -#define blue "\033[38;5;21m" -#define darkblue "\033[38;5;18m" -#define yellow "\033[38;5;226m" -#define darkyellow "\033[38;5;142m" -#define orange "\033[38;5;208m" -#define darkorange "\033[38;5;130m" -#define pink "\033[38;5;201m" -#define darkpink "\033[38;5;129m" -#define purple "\033[38;5;57m" -#define darkpurple "\033[38;5;54m" -#define cyan "\033[38;5;51m" -#define darkcyan "\033[38;5;39m" -#define white "\033[38;5;255m" -#define gray "\033[38;5;243m" -#define plain "\033[0m" +namespace ToolFramework{ -/** - * \struct MsgL - * - *This struct variables for setting the message level of streamed messages to the logging class - * - * - * $Author: B.Richards $ - * $Date: 2020/12/30 12:50:00 $ - */ + #ifndef NO_COLOUR + const char red[] = "\033[31m"; //"\033[38;5;88m" + const char lightred[] = "\033[91m"; //"\033[38;5;196m" + const char green[] = "\033[32m"; //"\033[38;5;22m" + const char lightgreen[] = "\033[92m"; //"\033[38;5;46m" + const char blue[] = "\033[34m"; //"\033[38;5;18m" + const char lightblue[] = "\033[94m"; //"\033[38;5;21m" + const char yellow[] = "\033[33m"; //"\033[38;5;142m" + const char lightyellow[] = "\033[93m"; //"\033[38;5;226m" + const char orange[] = "\033[38;5;130m"; + const char lightorange[] = "\033[38;5;208m"; + const char pink[] = "\033[35m"; //"\033[38;5;129m" + const char lightpink[] = "\033[95m"; //"\033[38;5;201m" + const char purple[] = "\033[38;5;54m"; + const char lightpurple[] = "\033[38;5;57m"; + const char cyan[] = "\033[36m"; //"\033[38;5;39m" + const char lightcyan[] = "\033[96m"; //"\033[38;5;51m" + const char white[] = "\033[97m"; //"\033[38;5;255m" + const char gray[] = "\033[37m"; //"\033[38;5;243m" + const char plain[] ="\033[39m"; //"\033[0m" -struct MsgL{ + #else - MsgL(int in_messagelevel, int in_verbose){ - messagelevel=in_messagelevel; - verbose=in_verbose; - } - MsgL ML(int in_messagelevel) { - messagelevel=in_messagelevel; - return *this; - } + const char red[] = ""; + const char lightred[] = ""; + const char green[] = ""; + const char lightgreen[] = ""; + const char blue[] = ""; + const char lightblue[] = ""; + const char yellow[] = ""; + const char lightyellow[] = ""; + const char orange[] = ""; + const char lightorange[] = ""; + const char pink[] = ""; + const char lightpink[] = ""; + const char purple[] = ""; + const char lightpurple[] = ""; + const char cyan[] = ""; + const char lightcyan[] = ""; + const char white[] = ""; + const char gray[] = ""; + const char plain[] = ""; - int messagelevel; ///< Message level paramiter - int verbose; ///< Verbosity level pramiter - -}; - - -/** - * \class Logging - * - *This class handels the logging, which can be directed to screen or file or over the via the ToolChain Config file - * - * - * $Author: B.Richards $ - * $Date: 2019/05/27 18:34:00 $ - */ +#endif + + /** + * \struct MsgL + * + *This struct variables for setting the message level of streamed messages to the logging class + * + * + * $Author: B.Richards $ + * $Date: 2020/12/30 12:50:00 $ + */ + + struct MsgL{ + + MsgL(int in_messagelevel, int in_verbose){ + messagelevel=in_messagelevel; + verbose=in_verbose; + } + MsgL ML(int in_messagelevel) { + messagelevel=in_messagelevel; + return *this; + } + + int messagelevel; ///< Message level paramiter + int verbose; ///< Verbosity level pramiter + + }; + + + /** + * \class Logging + * + *This class handels the logging, which can be directed to screen or file or over the via the ToolChain Config file + * + * + * $Author: B.Richards $ + * $Date: 2019/05/27 18:34:00 $ + */ + + + + class Logging: virtual public std::ostream { + + public: + + class TFStreamBuf: virtual public std::stringbuf + { + + public: + + TFStreamBuf(){}; + TFStreamBuf(bool interactive, bool local=false, std::string localpath="./log", bool error=false, std::ostream* filestream=0); + + virtual ~TFStreamBuf(); + + virtual int sync ( ); + + bool ChangeOutFile(std::string localpath); + + int m_messagelevel; + int m_verbose; + + std::ostream* output; + std::ostream* fileoutput; + std::mutex lock1; + std::mutex lock2; -class Logging: virtual public std::ostream { + protected: + + std::ostream* tmp; + + bool m_local; + bool m_interactive; + bool m_error; + + std::ofstream file; + std::streambuf *psbuf, *backup1, *backup2; + + bool no_delete; - public: + }; - class TFStreamBuf: virtual public std::stringbuf - { - - public: - - TFStreamBuf(){}; - TFStreamBuf(bool interactive, bool local=false, std::string localpath="./log", bool error=false, std::ostream* filestream=0); - - virtual ~TFStreamBuf(); - - virtual int sync ( ); - - bool ChangeOutFile(std::string localpath); - - int m_messagelevel; - int m_verbose; - - std::ostream* output; - std::ostream* fileoutput; - - protected: - - std::ostream* tmp; - - bool m_local; - bool m_interactive; - bool m_error; - - std::ofstream file; - std::streambuf *psbuf, *backup1, *backup2; - - bool no_delete; - }; - /** Constructor for Logging class @@ -117,49 +151,58 @@ class Logging: virtual public std::ostream { @param localpath Local path for log output file @param split_output_files if log is directed to disk then whether or nto to use sperate files for standard output and standard error */ - + // Logging(std::ostream& str, std::string mode, std::string localpath=""):std::ostream(&buffer), buffer(str, mode, localpath){}; - + //Logging(std::ostream& str, std::string mode, std::string localpath=""):std::ostream(buffer), buffer(new MyStreamBuf(str, mode, localpath)), errbuffer(new MyStreamBuf(str, mode, localpath)){}; - - Logging(bool interactive, bool local=false, std::string localpath="./log", bool split_output_files=false);//:buffer(new MyStreamBuf(interactive, local, localpath, false)),errbuffer(new MyStreamBuf(interactive, local, localpath, true)){}; - - //:std::ostream(buffer){}; - //, buffer(new MyStreamBuf(interactive, local, "", error)){}; - - Logging(){}; - - virtual ~Logging(); - - /** - Function to create a log messages. - - @param message templated log message text. - @param messagelevel message verbosity level of the message being sent (e.g. if 'messagelevel>= verbose' Then message is sent). - @param verbose verbosity level of the current Tool. - - */ - - template void Log(T message, int messagelevel=1, int verbose=1){ - - - if(messagelevel<=verbose){ - int previous_messagelevel = buffer->m_messagelevel; - int previous_verbosity = buffer->m_verbose; - - buffer->m_messagelevel=messagelevel; - buffer->m_verbose=verbose; - - std::cout.rdbuf(buffer); - std::cout<m_messagelevel=previous_messagelevel; - buffer->m_verbose=previous_verbosity; - } - - } - - + + Logging(bool interactive, bool local=false, std::string localpath="./log", bool split_output_files=false);//:buffer(new MyStreamBuf(interactive, local, localpath, false)),errbuffer(new MyStreamBuf(interactive, local, localpath, true)){}; + + //:std::ostream(buffer){}; + //, buffer(new MyStreamBuf(interactive, local, "", error)){}; + + Logging(){}; + + virtual ~Logging(); + + /** + Function to create a log messages. + + @param message templated log message text. + @param messagelevel message verbosity level of the message being sent (e.g. if 'messagelevel>= verbose' Then message is sent). + @param verbose verbosity level of the current Tool. + + */ + + template void Log(T message, int messagelevel=1, int verbose=1){ + //printf("logmessage\n"); + if(messagelevel<=verbose){ + + buffer->lock1.lock(); + while(!buffer->lock2.try_lock()){ + buffer->lock1.unlock(); + usleep(100); + buffer->lock1.lock(); + } + //printf("locg message locked\n"); + int previous_messagelevel = buffer->m_messagelevel; + int previous_verbosity = buffer->m_verbose; + + buffer->m_messagelevel=messagelevel; + buffer->m_verbose=verbose; + //printf("log about to sync\n"); + std::cout.rdbuf(buffer); + std::cout<m_messagelevel=previous_messagelevel; + buffer->m_verbose=previous_verbosity; + buffer->lock2.unlock(); + buffer->lock1.unlock(); + } + + } + + /** Functionn to change the logs out file if set to a local path. @@ -167,54 +210,82 @@ class Logging: virtual public std::ostream { @return value is bool success of opening new logfile. */ - bool ChangeOutFile(std::string localpath){return buffer->ChangeOutFile(localpath);} - - - - - Logging& operator<<(MsgL a){ - - buffer->m_messagelevel=a.messagelevel; - buffer->m_verbose=a.verbose; - - return *this; - } - - - Logging& operator<<(std::ostream& (*foo)(std::ostream&)) { - - std::cout.rdbuf(buffer); - std::cout< Logging& operator<<(T &a){ - - std::cout.rdbuf(buffer); - std::cout< Logging& operator<<(const T &a){ - - std::cout.rdbuf(buffer); - std::cout<ChangeOutFile(localpath);} + + + + + Logging& operator<<(MsgL a){ + buffer->lock1.lock(); + buffer->lock2.try_lock(); + + buffer->m_messagelevel=a.messagelevel; + buffer->m_verbose=a.verbose; + + buffer->lock2.unlock(); + buffer->lock1.unlock(); + + return *this; + } + + + Logging& operator<<(std::ostream& (*foo)(std::ostream&)) { + //printf("special stream tying to lock\n"); + buffer->lock1.lock(); + buffer->lock2.try_lock(); + + //printf("special stream unlocking and about to sync\n"); + + std::cout.rdbuf(buffer); + std::cout<lock2.unlock(); + buffer->lock1.unlock(); + + return *this; + } + + template Logging& operator<<(T &a){ + //printf("stream locking\n"); + buffer->lock1.lock(); + buffer->lock2.try_lock(); + //printf("stream locked\n"); + + std::cout.rdbuf(buffer); + std::cout<lock1.unlock(); + //printf("stream unlocked\n"); + return *this; + + } + + template Logging& operator<<(const T &a){ + //printf("stream locking\n"); + buffer->lock1.lock(); + buffer->lock2.try_lock(); + //printf("stream locked\n"); + + std::cout.rdbuf(buffer); + std::cout<lock1.unlock(); + //printf("stream unlocked\n"); + + return *this; + + } + + + protected: + + TFStreamBuf* buffer; ///< Stream buffer used to replace std::cout for redirection to coustom output. + TFStreamBuf* errbuffer; + + + }; + +} #endif diff --git a/src/Store/BStore.cpp b/src/Store/BStore.cpp index 4cb7e29..6986117 100644 --- a/src/Store/BStore.cpp +++ b/src/Store/BStore.cpp @@ -1,5 +1,7 @@ #include +using namespace ToolFramework; + //////////////////////// //Notes for Ben /////////////////////////////// diff --git a/src/Store/BStore.h b/src/Store/BStore.h index a8f5a7f..0b973d0 100644 --- a/src/Store/BStore.h +++ b/src/Store/BStore.h @@ -16,239 +16,242 @@ #include #include -enum enum_type {uncompressed, compressed, post_pre_compress, ram}; - - -/** - * \class BStore - * - * This class Is a dynamic data storeage class and can be used to store variables of any type listed by ASCII key. The storage of the varaible is a binarystream. - * - * $Author: B.Richards $ - * $Date: 2022/01/23 10:44:00 $ - */ - - - -class BStore: public SerialisableObject{ - -#define CHUNK 16384 +namespace ToolFramework{ - public: - - BStore(bool header=true, bool type_checking=false); - BStore(const BStore &bs); - ~BStore(); - // void Init(); - // void Init2(); - bool Initnew(std::string filename, enum_type type=post_pre_compress, bool header=true, bool type_checking=false, unsigned int file_end=0); - bool Initnew(BinaryStream& bs, unsigned int position); - bool GetFlags(unsigned int file_end); - bool GetFlags(std::string filename, unsigned int file_end); - bool WriteHeader(); - bool WriteLookup(); - bool WriteFlags(); - bool Save(unsigned int entry=0); - bool GetHeader(); - bool GetEntry(unsigned int entry_request); - bool DeleteEntry(unsigned int entry_request); - unsigned int NumEntries(); - bool Close(); - bool Rollback(); - - std::string GetVersion(); + enum enum_type {uncompressed, compressed, post_pre_compress, ram}; - - std::map m_variables; - std::map m_type_info; - // std::map m_header; - BStore* Header; - std::map m_ptrs; - - - /////////importing - void JsonParser(std::string input); ///< Converts a flat JSON formatted string to Store entries in the form of key value pairs. @param input The input flat JSON string. - bool Print(); - void Print(bool values); ///< Prints the contents of the BoostStore. @param values If true values and keys are printed. If false just keys are printed - void Delete(); ///< Deletes all entries in the BoostStore. - void Remove(std::string key); ///< Removes a single entry from the BoostStore. @param key The key of the entry to remove. - std::string Type(std::string key); ///< Queries the type of an entry if type checking is turned on. @param key The key of the entry to check. @return A string encoding the type info. - bool Has(std::string key); ///< Queries if entry exists in a BoostStore. @param key is the key of the varaible to look up. @return true if varaible is present in the store, false if not. - // BoostStore *Header; ///< Pointer to header BoostStore (only available in multi event BoostStore). This can be used to access and assign header varaibles jsut like a standard non multi event store. - /** - Templated getter function for BoostStore content. Assignment is templated and via reference. - @param name The ASCII key that the variable in the BoostStore is stored with. - @param out The variable to fill with the value. - @return Return value is true if varaible exists in the Store and false if not or wrong type. - */ - template bool Get(std::string name,T &out){ - - if(m_variables.count(name)>0){ - - if(m_type_info[name]==typeid(out).name() || !m_type_checking){ - - m_variables[name].m_pos=0; - return m_variables[name] >> out; - + * \class BStore + * + * This class Is a dynamic data storeage class and can be used to store variables of any type listed by ASCII key. The storage of the varaible is a binarystream. + * + * $Author: B.Richards $ + * $Date: 2022/01/23 10:44:00 $ + */ + + + + class BStore: public SerialisableObject{ + +#define CHUNK 16384 + + public: + + BStore(bool header=true, bool type_checking=false); + BStore(const BStore &bs); + ~BStore(); + // void Init(); + // void Init2(); + bool Initnew(std::string filename, enum_type type=post_pre_compress, bool header=true, bool type_checking=false, unsigned int file_end=0); + bool Initnew(BinaryStream& bs, unsigned int position); + bool GetFlags(unsigned int file_end); + bool GetFlags(std::string filename, unsigned int file_end); + bool WriteHeader(); + bool WriteLookup(); + bool WriteFlags(); + bool Save(unsigned int entry=0); + bool GetHeader(); + bool GetEntry(unsigned int entry_request); + bool DeleteEntry(unsigned int entry_request); + unsigned int NumEntries(); + bool Close(); + bool Rollback(); + + std::string GetVersion(); + + + std::map m_variables; + std::map m_type_info; + // std::map m_header; + BStore* Header; + std::map m_ptrs; + + + /////////importing + + void JsonParser(std::string input); ///< Converts a flat JSON formatted string to Store entries in the form of key value pairs. @param input The input flat JSON string. + bool Print(); + void Print(bool values); ///< Prints the contents of the BoostStore. @param values If true values and keys are printed. If false just keys are printed + void Delete(); ///< Deletes all entries in the BoostStore. + void Remove(std::string key); ///< Removes a single entry from the BoostStore. @param key The key of the entry to remove. + std::string Type(std::string key); ///< Queries the type of an entry if type checking is turned on. @param key The key of the entry to check. @return A string encoding the type info. + bool Has(std::string key); ///< Queries if entry exists in a BoostStore. @param key is the key of the varaible to look up. @return true if varaible is present in the store, false if not. + // BoostStore *Header; ///< Pointer to header BoostStore (only available in multi event BoostStore). This can be used to access and assign header varaibles jsut like a standard non multi event store. + + /** + Templated getter function for BoostStore content. Assignment is templated and via reference. + @param name The ASCII key that the variable in the BoostStore is stored with. + @param out The variable to fill with the value. + @return Return value is true if varaible exists in the Store and false if not or wrong type. + */ + template bool Get(std::string name,T &out){ + + if(m_variables.count(name)>0){ + + if(m_type_info[name]==typeid(out).name() || !m_type_checking){ + + m_variables[name].m_pos=0; + return m_variables[name] >> out; + + } + else return false; } + else return false; + } - else return false; - - } - - /** - Templated getter function for pointer to BoostStore content. Assignment is templated and the object is created on first the heap and a pointer to it assigned. Latter requests will return a pointer to the first object. Bote the pointer is to an indipendant instance of the stored object and so changing its value without using a Setter will not effect the stored value. - @param name The ASCII key that the variable in the BoostStore is stored with. - @param out The pointer to assign. - @return Return value is true if varaible exists in the Store and false if not or wrong type. - */ - template bool Get(std::string name,T* &out){ - - if(m_variables.count(name)>0 || m_ptrs.count(name)>0){ - if((m_type_info[name]==typeid(T).name() || !m_type_checking ) || (m_ptrs.count(name)>0 && m_variables.count(name)==0)){ - - bool ret=true; - if(m_ptrs.count(name)==0){ + /** + Templated getter function for pointer to BoostStore content. Assignment is templated and the object is created on first the heap and a pointer to it assigned. Latter requests will return a pointer to the first object. Bote the pointer is to an indipendant instance of the stored object and so changing its value without using a Setter will not effect the stored value. + @param name The ASCII key that the variable in the BoostStore is stored with. + @param out The pointer to assign. + @return Return value is true if varaible exists in the Store and false if not or wrong type. + */ + template bool Get(std::string name,T* &out){ + + if(m_variables.count(name)>0 || m_ptrs.count(name)>0){ + if((m_type_info[name]==typeid(T).name() || !m_type_checking ) || (m_ptrs.count(name)>0 && m_variables.count(name)==0)){ + + bool ret=true; + if(m_ptrs.count(name)==0){ + + T* tmp=new T; + m_ptrs[name]=new PointerWrapper(tmp); + ret*=Get(name,*tmp); + } + + + PointerWrapper* tmp=static_cast* >(m_ptrs[name]); + out=tmp->pointer; + + return ret; - T* tmp=new T; - m_ptrs[name]=new PointerWrapper(tmp); - ret*=Get(name,*tmp); } - - - PointerWrapper* tmp=static_cast* >(m_ptrs[name]); - out=tmp->pointer; - - return ret; + else return false; } + else return false; - + } - - else return false; - - } - - - /** - Templated setter function to assign vairables in the BoostStore. - @param name The key to be used to store and reference the variable in the BoostStore. - @param in the varaible to be stored. - */ - template bool Set(std::string name,T& in){ - //std::cout<<"in set"<::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ - if (!first) stream<<","; - stream<<"\""<first<<"\":\""<< it->second.buffer<<"\""; - first=false; + + /** + Allows streaming of a flat JASON formatted string of BoostStore contents. + */ + template void operator>>(T& obj){ + + std::stringstream stream; + stream<<"{"; + bool first=true; + for (std::map::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ + if (!first) stream<<","; + stream<<"\""<first<<"\":\""<< it->second.buffer<<"\""; + first=false; + } + stream<<"}"; + + obj=stream.str(); + } - stream<<"}"; - obj=stream.str(); + bool Serialise(BinaryStream &bs); + + // std::map m_lookup; //why is this a map?? should change it when you ahve had more sleep + + std::vector m_lookup; + + BinaryStream output; - } - - bool Serialise(BinaryStream &bs); - - // std::map m_lookup; //why is this a map?? should change it when you ahve had more sleep - - std::vector m_lookup; - - BinaryStream output; - private: - - - - unsigned int m_file_end; - std::string m_file_name; - unsigned int m_open_file_end; - unsigned int m_previous_file_end; - enum_type m_type; - bool m_type_checking; - bool m_has_header; - unsigned int m_header_start; - - unsigned int m_flags_start; - - - unsigned int m_lookup_start; - //unsigned int m_lookup_size; - - // std::map m_lookup; - //unsigned int m_entry; - // unsigned int m_current_loaded_entry; - bool m_update; - - //int m_file_type; //0=gzopen, 1=fopen, 2=stringstream - float m_version; - - -}; + + + + unsigned int m_file_end; + std::string m_file_name; + unsigned int m_open_file_end; + unsigned int m_previous_file_end; + enum_type m_type; + bool m_type_checking; + bool m_has_header; + unsigned int m_header_start; + + unsigned int m_flags_start; + + + unsigned int m_lookup_start; + //unsigned int m_lookup_size; + + // std::map m_lookup; + //unsigned int m_entry; + // unsigned int m_current_loaded_entry; + bool m_update; + + //int m_file_type; //0=gzopen, 1=fopen, 2=stringstream + float m_version; + + + }; +} #endif diff --git a/src/Store/BinaryStream.cpp b/src/Store/BinaryStream.cpp index 62834a8..7d3266b 100644 --- a/src/Store/BinaryStream.cpp +++ b/src/Store/BinaryStream.cpp @@ -1,5 +1,7 @@ #include +using namespace ToolFramework; + BinaryStream::BinaryStream(enum_endpoint endpoint){ m_endpoint=endpoint; diff --git a/src/Store/BinaryStream.h b/src/Store/BinaryStream.h index 1547b4f..dadc156 100644 --- a/src/Store/BinaryStream.h +++ b/src/Store/BinaryStream.h @@ -16,345 +16,348 @@ #endif #include //needed for inflate deflate -#define CHUNK 16384 // dito - -enum enum_endpoint { RAM , UNCOMPRESSED , POST_PRE_COMPRESS, COMPRESSED }; -enum enum_mode { READ , NEW , APPEND, UPDATE, READ_APPEND, NEW_READ }; -class BinaryStream : public SerialisableObject{ +namespace ToolFramework{ + +#define CHUNK 16384 // dito - public: + enum enum_endpoint { RAM , UNCOMPRESSED , POST_PRE_COMPRESS, COMPRESSED }; + enum enum_mode { READ , NEW , APPEND, UPDATE, READ_APPEND, NEW_READ }; - BinaryStream(enum_endpoint endpoint=RAM); - ~BinaryStream(); - bool Bopen(std::string filename, enum_mode method=UPDATE, enum_endpoint endpoint=POST_PRE_COMPRESS); - bool Bclose(bool Ignore_Post_Pre_compress=false); - bool Bwrite(const void* in, unsigned int size); - bool Bread(void* out, unsigned int size); - unsigned long int Btell(); - bool Bseek(unsigned int pos, int whence); - bool Print(); - bool Serialise(BinaryStream &bs); - std::string GetVersion(); - - enum_endpoint m_endpoint; - FILE* pfile; + class BinaryStream : public SerialisableObject{ + + public: + + BinaryStream(enum_endpoint endpoint=RAM); + ~BinaryStream(); + bool Bopen(std::string filename, enum_mode method=UPDATE, enum_endpoint endpoint=POST_PRE_COMPRESS); + bool Bclose(bool Ignore_Post_Pre_compress=false); + bool Bwrite(const void* in, unsigned int size); + bool Bread(void* out, unsigned int size); + unsigned long int Btell(); + bool Bseek(unsigned int pos, int whence); + bool Print(); + bool Serialise(BinaryStream &bs); + std::string GetVersion(); + + enum_endpoint m_endpoint; + FILE* pfile; #ifdef ZLIB - gzFile* gzfile; + gzFile* gzfile; #endif - std::string buffer; - bool m_write; - std::string m_file_name; - unsigned long int m_pos; - - enum_mode m_mode; //0=READ, 1==WRITE, 2==READ/APPEND - // 0=READ, 1==WRITE, 2==APPEND, 3 READ/WRITE, 4 READ/APPEND/ , 5 READ/OVEWRITE - // READ NEW APPEND UPDATE READ/APPEND , NEW/READ - - //gz read r, write w, append a - //fopen read r, write w, append a, read/write r+ (file must exist), read/write w+ (file doesnt exist/overwrite), read/append a+ - - //operator overloads - - bool operator<<(std::string& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.length(); - ret*=(*this) << tmp; - if(tmp) ret*=Bwrite(&(rhs[0]), tmp); - return ret; + std::string buffer; + bool m_write; + std::string m_file_name; + unsigned long int m_pos; + + enum_mode m_mode; //0=READ, 1==WRITE, 2==READ/APPEND + // 0=READ, 1==WRITE, 2==APPEND, 3 READ/WRITE, 4 READ/APPEND/ , 5 READ/OVEWRITE + // READ NEW APPEND UPDATE READ/APPEND , NEW/READ + + //gz read r, write w, append a + //fopen read r, write w, append a, read/write r+ (file must exist), read/write w+ (file doesnt exist/overwrite), read/append a+ + + //operator overloads + + bool operator<<(std::string& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.length(); + ret= ret && ((*this) << tmp); + if(tmp) ret= ret && (Bwrite(&(rhs[0]), tmp)); + return ret; + } + else return false; } - else return false; - } - - bool operator>>(std::string& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - rhs.resize(tmp); - if(tmp) ret*=Bread(&(rhs[0]), tmp); - return ret; + + bool operator>>(std::string& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + rhs.resize(tmp); + if(tmp) ret= ret && (Bread(&(rhs[0]), tmp)); + return ret; + } + else return false; } - else return false; - } - - bool operator&(std::string& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - bool operator<<(const std::string& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.length(); - ret*=(*this) << tmp; - if(tmp) ret*=Bwrite(&(rhs[0]), tmp); - return ret; + + bool operator&(std::string& rhs){ + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; } - else return false; - } - - bool operator&(const std::string& rhs){ - if(m_write) return (*this) << rhs; - return false; - } - - - template bool operator<<(T& rhs){ - if(m_mode!=READ){ - if(check_base::value){ - SerialisableObject* tmp=reinterpret_cast(&rhs); - m_write=true; - return tmp->SerialiseWrapper(*this); + + bool operator<<(const std::string& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.length(); + ret= ret && ((*this) << tmp); + if(tmp) ret= ret && (Bwrite(&(rhs[0]), tmp)); + return ret; } - else return Bwrite(&rhs, sizeof(T)); + else return false; } - else return false; - } - - - template bool operator>>(T& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - if(check_base::value){ - SerialisableObject* tmp=reinterpret_cast(&rhs); - m_write=false; - return tmp->SerialiseWrapper(*this); - } - else return Bread(&rhs, sizeof(T)); + + bool operator&(const std::string& rhs){ + if(m_write) return (*this) << rhs; + return false; } - return false; - } - - - template bool operator&(T& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - template bool operator<<(const T& rhs){ - if(m_mode!=READ){ - if(check_base::value){ - SerialisableObject* tmp=reinterpret_cast(&rhs); - m_write=true; - return tmp->SerialiseWrapper(*this); + + + template bool operator<<(T& rhs){ + if(m_mode!=READ){ + if(check_base::value){ + SerialisableObject* tmp=reinterpret_cast(&rhs); + m_write=true; + return tmp->SerialiseWrapper(*this); + } + else return Bwrite(&rhs, sizeof(T)); } - return Bwrite(&rhs, sizeof(T)); + else return false; } - else return false; - } - - template bool operator&(const T& rhs){ - if(m_write) return (*this) << rhs; - return false; - } - - - template bool operator<<(std::vector& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.size(); - ret*=(*this) << tmp; - if(tmp){ + + template bool operator>>(T& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ if(check_base::value){ - for(typename std::vector::iterator it=rhs.begin(); it!=rhs.end(); it++) ret*=(*this) << (*it); + SerialisableObject* tmp=reinterpret_cast(&rhs); + m_write=false; + return tmp->SerialiseWrapper(*this); } - else ret*=Bwrite(&(rhs[0]), tmp*sizeof(T)); + else return Bread(&rhs, sizeof(T)); } - return ret; + return false; } - else return false; - } - - template bool operator>>(std::vector& rhs){ - - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - rhs.resize(tmp); - if(tmp){ + + + template bool operator&(T& rhs){ + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; + } + + template bool operator<<(const T& rhs){ + if(m_mode!=READ){ if(check_base::value){ - for(typename std::vector::iterator it=rhs.begin(); it!=rhs.end(); it++) ret*=(*this) >> (*it); + SerialisableObject* tmp=reinterpret_cast(&rhs); + m_write=true; + return tmp->SerialiseWrapper(*this); } - else ret*=Bread(&(rhs[0]), tmp*sizeof(T)); + return Bwrite(&rhs, sizeof(T)); } - return ret; + else return false; } - else return false; - } - - template bool operator&(std::vector& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - bool operator<<(std::vector& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.size(); - ret*=(*this) << tmp; - for(unsigned int i=0; i bool operator&(const T& rhs){ + if(m_write) return (*this) << rhs; + return false; + } + + + template bool operator<<(std::vector& rhs){ + + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.size(); + ret= ret && ((*this) << tmp); + if(tmp){ + if(check_base::value){ + for(typename std::vector::iterator it=rhs.begin(); it!=rhs.end(); it++) ret= ret && ((*this) << (*it)); + } + else ret= ret && (Bwrite(&(rhs[0]), tmp*sizeof(T))); + } + return ret; } - return ret; + else return false; } - else return false; - } - - bool operator>>(std::vector& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - rhs.resize(tmp); - for(unsigned int i=0; i> rhs.at(i); + + template bool operator>>(std::vector& rhs){ + + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + rhs.resize(tmp); + if(tmp){ + if(check_base::value){ + for(typename std::vector::iterator it=rhs.begin(); it!=rhs.end(); it++) ret= ret && ((*this) >> (*it)); + } + else ret= ret && (Bread(&(rhs[0]), tmp*sizeof(T))); + } + return ret; } - return ret; + else return false; } - else return false; - } - - bool operator&(std::vector& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - template bool operator<<(std::map& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.size(); - ret*=(*this) << tmp; - for (typename std::map::iterator it=rhs.begin(); it!=rhs.end(); ++it){ - T key=it->first; - U value=it->second; - ret*=(*this) << key; - ret*=(*this) << value; + + template bool operator&(std::vector& rhs){ + + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; + } + + bool operator<<(std::vector& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.size(); + ret= ret && ((*this) << tmp); + for(unsigned int i=0; i bool operator>>(std::map& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - for (unsigned int i=0; i> key; - ret*=(*this) >> value; - rhs[key]=value; + + bool operator>>(std::vector& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + rhs.resize(tmp); + for(unsigned int i=0; i> rhs.at(i)); + } + return ret; } - return ret; + else return false; } - else return false; - } - - template bool operator&(std::map& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - template bool operator<<(std::deque& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.size(); - ret*=(*this) << tmp; - if(tmp){ - if(check_base::value){ - for(typename std::deque::iterator it=rhs.begin(); it!=rhs.end(); it++) ret*=(*this) << (*it); + + bool operator&(std::vector& rhs){ + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; + } + + template bool operator<<(std::map& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.size(); + ret= ret && ((*this) << tmp); + for (typename std::map::iterator it=rhs.begin(); it!=rhs.end(); ++it){ + T key=it->first; + U value=it->second; + ret= ret && ((*this) << key); + ret= ret && ((*this) << value); } - else ret*=Bwrite(&(rhs[0]), tmp*sizeof(T)); + return ret; } - return ret; + else return false; } - else return false; - } - - template bool operator>>(std::deque& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - rhs.resize(tmp); - if(tmp){ - if(check_base::value){ - for(typename std::deque::iterator it=rhs.begin(); it!=rhs.end(); it++) ret*=(*this) >> (*it); + + template bool operator>>(std::map& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + for (unsigned int i=0; i> key); + ret= ret && ((*this) >> value); + rhs[key]=value; } - else ret*=Bread(&(rhs[0]), tmp*sizeof(T)); + return ret; } - return ret; + else return false; } - else return false; - } - - template bool operator&(std::deque& rhs){ - if(m_write) return(*this) << rhs; - else return(*this) >> rhs; - } - - bool operator<<(std::deque& rhs){ - if(m_mode!=READ){ - bool ret=true; - unsigned int tmp=rhs.size(); - ret*=(*this) << tmp; - for(unsigned int i=0; i bool operator&(std::map& rhs){ + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; + } + + template bool operator<<(std::deque& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.size(); + ret= ret && ((*this) << tmp); + if(tmp){ + if(check_base::value){ + for(typename std::deque::iterator it=rhs.begin(); it!=rhs.end(); it++) ret= ret && ((*this) << (*it)); + } + else ret= ret && (Bwrite(&(rhs[0]), tmp*sizeof(T))); + } + return ret; } - return ret; + else return false; } - else return false; - } - - bool operator>>(std::deque& rhs){ - if(m_mode!=NEW && m_mode!=APPEND){ - bool ret=true; - unsigned int tmp=0; - ret*=(*this) >> tmp; - rhs.resize(tmp); - for(unsigned int i=0; i> rhs.at(i); + + template bool operator>>(std::deque& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + rhs.resize(tmp); + if(tmp){ + if(check_base::value){ + for(typename std::deque::iterator it=rhs.begin(); it!=rhs.end(); it++) ret= ret && ((*this) >> (*it)); + } + else ret= ret && (Bread(&(rhs[0]), tmp*sizeof(T))); + } + return ret; } - return ret; + else return false; } - else return false; - } - - bool operator&(std::deque& rhs){ - if(m_write) return (*this) << rhs; - else return (*this) >> rhs; - } - - - private: - - int def(FILE *source, FILE *dest, int level); - int inf(FILE *source, FILE *dest); - void zerr(int ret); - - template struct Host{ - operator B*() const; - operator D*(); + template bool operator&(std::deque& rhs){ + if(m_write) return(*this) << rhs; + else return(*this) >> rhs; + } + + bool operator<<(std::deque& rhs){ + if(m_mode!=READ){ + bool ret=true; + unsigned int tmp=rhs.size(); + ret= ret && ((*this) << tmp); + for(unsigned int i=0; i>(std::deque& rhs){ + if(m_mode!=NEW && m_mode!=APPEND){ + bool ret=true; + unsigned int tmp=0; + ret= ret && ((*this) >> tmp); + rhs.resize(tmp); + for(unsigned int i=0; i> rhs.at(i)); + } + return ret; + } + else return false; + } + + bool operator&(std::deque& rhs){ + if(m_write) return (*this) << rhs; + else return (*this) >> rhs; + } + + + private: + + int def(FILE *source, FILE *dest, int level); + int inf(FILE *source, FILE *dest); + void zerr(int ret); + + template struct Host{ + + operator B*() const; + operator D*(); + + }; + + + template struct check_base { + template + static short check(D*, T); + static char check(B*, int); + + static const bool value = sizeof(check(Host(), int())) == sizeof(short); + }; - }; - - - template struct check_base { - template - static short check(D*, T); - static char check(B*, int); - static const bool value = sizeof(check(Host(), int())) == sizeof(short); - }; - - /* derived: @@ -378,7 +381,8 @@ not derrived: */ -}; + }; +} #endif diff --git a/src/Store/PointerWrapper.h b/src/Store/PointerWrapper.h index afa67f9..f6379b2 100644 --- a/src/Store/PointerWrapper.h +++ b/src/Store/PointerWrapper.h @@ -1,42 +1,45 @@ #ifndef POINTERWRAPPER_H #define POINTERWRAPPER_H +namespace ToolFramework{ -/** - * \class PointerWrapperBase - * - * This class is used to wrap pointers stored in a BoostStore. It gives a generic abstract base class to store pointers under - * - * $Author: B.Richards $ - * $Date: 2019/05/28 10:44:00 $ - */ - -class PointerWrapperBase{ - - public: - - PointerWrapperBase(){} ///< Simple constructor - virtual ~PointerWrapperBase(){} ///< virtual destructor + /** + * \class PointerWrapperBase + * + * This class is used to wrap pointers stored in a BoostStore. It gives a generic abstract base class to store pointers under + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ + */ -}; - -/** - * \class PointerWrapper - * - * Teplated derived class of PointerWrapperBase to provide a plymorphic interface to stored poitner variables. - * - * $Author: B.Richards $ - * $Date: 2019/05/28 10:44:00 $ - */ - -template class PointerWrapper : public PointerWrapperBase { + class PointerWrapperBase{ + + public: + + PointerWrapperBase(){} ///< Simple constructor + virtual ~PointerWrapperBase(){} ///< virtual destructor + + }; - public: + /** + * \class PointerWrapper + * + * Teplated derived class of PointerWrapperBase to provide a plymorphic interface to stored poitner variables. + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ + */ - T* pointer; ///< Pointer to the orignial obkect - PointerWrapper(T* inpointer): pointer(inpointer){} ///< Constructor @param inpointer The pointer to be wrapped. - ~PointerWrapper(){delete pointer; pointer=0;}; ///< Destructor. + template class PointerWrapper : public PointerWrapperBase { + + public: + + T* pointer; ///< Pointer to the orignial obkect + PointerWrapper(T* inpointer): pointer(inpointer){} ///< Constructor @param inpointer The pointer to be wrapped. + ~PointerWrapper(){delete pointer; pointer=0;}; ///< Destructor. + + }; -}; +} #endif diff --git a/src/Store/SerialisableObject.h b/src/Store/SerialisableObject.h index 4df37e8..41b675b 100644 --- a/src/Store/SerialisableObject.h +++ b/src/Store/SerialisableObject.h @@ -3,51 +3,54 @@ #include -/** - * \class SerialisableObject - * - * An abstract base class for sustom calsses to inherit from to ensure version and type information are present, as well as a Print function and some form of sereialisation. -* -* $Author: B.Richards $ -* $Date: 2019/05/28 10:44:00 $ -*/ +namespace ToolFramework{ -//class archive; -class BinaryStream; - -class SerialisableObject{ - - - public: - virtual ~SerialisableObject(){}; - bool SerialiseWrapper(BinaryStream &bs); - virtual bool Serialise(BinaryStream &bs)=0; - virtual std::string GetVersion()=0; - virtual bool Print()=0; ///< Simple virtual Pritn function to ensure inhereted classes have one - // virtual ~SerialisableObject(){}; ///< Destructor - //bool m_serialise; ///< Denotes if the calss should be serialised or not when added to a BoostStore. - //protected: - - //std::string type; ///< String to store type of Tool - // std::string m_version; ///< String to store version of Tool - /** - Simple Boost serialise method to serialise the membervariables of a custom class. This shuld be expanded to include the custom classes variables - @param ar Boost archive. - @param version of the archive. + * \class SerialisableObject + * + * An abstract base class for sustom calsses to inherit from to ensure version and type information are present, as well as a Print function and some form of sereialisation. + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ */ - /* template void serialize(Archive & ar, const unsigned int version){ - if(serialise){ - ar & type; - ar & version; - } - } - */ - - -}; - + //class archive; + class BinaryStream; + + class SerialisableObject{ + + + public: + virtual ~SerialisableObject(){}; + bool SerialiseWrapper(BinaryStream &bs); + virtual bool Serialise(BinaryStream &bs)=0; + virtual std::string GetVersion()=0; + virtual bool Print()=0; ///< Simple virtual Pritn function to ensure inhereted classes have one + // virtual ~SerialisableObject(){}; ///< Destructor + //bool m_serialise; ///< Denotes if the calss should be serialised or not when added to a BoostStore. + //protected: + + //std::string type; ///< String to store type of Tool + // std::string m_version; ///< String to store version of Tool + + /** + Simple Boost serialise method to serialise the membervariables of a custom class. This shuld be expanded to include the custom classes variables + @param ar Boost archive. + @param version of the archive. + */ + /* template void serialize(Archive & ar, const unsigned int version){ + if(serialise){ + ar & type; + ar & version; + } + } + */ + + + + }; + +} #endif diff --git a/src/Store/Store.cpp b/src/Store/Store.cpp index 783f587..fcd692d 100644 --- a/src/Store/Store.cpp +++ b/src/Store/Store.cpp @@ -1,5 +1,6 @@ #include "Store.h" +using namespace ToolFramework; Store::Store(){} diff --git a/src/Store/Store.h b/src/Store/Store.h index 1426b8c..75e5fc7 100644 --- a/src/Store/Store.h +++ b/src/Store/Store.h @@ -8,121 +8,123 @@ #include #include - -/** - * \class Store - * - * This class Is a dynamic data storeage class and can be used to store variables of any type listed by ASCII key. The storage of the varaible is in ASCII, so is inefficent for large numbers of entries. - * - * $Author: B.Richards $ - * $Date: 2019/05/28 10:44:00 $ - */ - -class Store{ - - public: - - Store(); ////< Sinple constructor - - bool Initialise(std::string filename); ///< Initialises Store by reading in entries from an ASCII text file, when each line is a variable and its value in key value pairs. @param filename The filepath and name to the input file. - void JsonParser(std::string input); ///< Converts a flat JSON formatted string to Store entries in the form of key value pairs. @param input The input flat JSON string. - void Print(); ///< Prints the contents of the Store. - void Delete(); ///< Deletes all entries in the Store. - bool Has(std::string key); /// Keys(); //returns a vector of the keys +namespace ToolFramework{ /** - Templated getter function for sore content. Assignment is templated and via reference. - @param name The ASCII key that the variable in the Store is stored with. - @param out The variable to fill with the value. - @return Return value is true if varaible exists in the Store and correctly assigned to out and false if not. - */ - template bool Get(std::string name,T &out){ - - if(m_variables.count(name)>0){ - - std::stringstream stream(m_variables[name]); - stream>>out; - return !stream.fail(); + * \class Store + * + * This class Is a dynamic data storeage class and can be used to store variables of any type listed by ASCII key. The storage of the varaible is in ASCII, so is inefficent for large numbers of entries. + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ + */ + + class Store{ + + public: + + Store(); ////< Sinple constructor + + bool Initialise(std::string filename); ///< Initialises Store by reading in entries from an ASCII text file, when each line is a variable and its value in key value pairs. @param filename The filepath and name to the input file. + void JsonParser(std::string input); ///< Converts a flat JSON formatted string to Store entries in the form of key value pairs. @param input The input flat JSON string. + void Print(); ///< Prints the contents of the Store. + void Delete(); ///< Deletes all entries in the Store. + bool Has(std::string key); /// Keys(); //returns a vector of the keys + + /** + Templated getter function for sore content. Assignment is templated and via reference. + @param name The ASCII key that the variable in the Store is stored with. + @param out The variable to fill with the value. + @return Return value is true if varaible exists in the Store and correctly assigned to out and false if not. + */ + template bool Get(std::string name,T &out){ + + if(m_variables.count(name)>0){ + + std::stringstream stream(m_variables[name]); + stream>>out; + return !stream.fail(); + } + + return false; + } - return false; - - } - -/** - getter function for string content.. - @param name The ASCII key that the variable in the Store is stored with. - @param out The variable to fill with the value. - @return Return value is true if varaible exists in the Store and correctly assigned to out and false if not. - */ - bool Get(std::string name, std::string &out); - - - /** - Templated getter function for sore content. - @param name The ASCII key that the variable in the Store is stored with. - @return Return value is default copiler costructed value if not true (note: no checking exists) - */ - template T Get(std::string name){ - - T tmp; - if(!Get(name,tmp)) std::cout<<"\033[38;5;196mERROR: Store doesnt hold value \""< void Set(std::string name,T in){ - std::stringstream stream; - stream< void operator>>(T& obj){ - - std::stringstream stream; - stream<<"{"; - bool first=true; - for (std::map::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ - if (!first) stream<<","; - stream<<"\""<first<<"\":\""<< it->second<<"\""; - first=false; + /** + getter function for string content.. + @param name The ASCII key that the variable in the Store is stored with. + @param out The variable to fill with the value. + @return Return value is true if varaible exists in the Store and correctly assigned to out and false if not. + */ + bool Get(std::string name, std::string &out); + + + /** + Templated getter function for sore content. + @param name The ASCII key that the variable in the Store is stored with. + @return Return value is default copiler costructed value if not true (note: no checking exists) + */ + template T Get(std::string name){ + + T tmp; + if(!Get(name,tmp)) std::cout<<"\033[38;5;196mERROR: Store doesnt hold value \""<::const_iterator begin() { return m_variables.begin(); } - std::map::const_iterator end() { return m_variables.end(); } - - - private: - + + /** + Templated setter function to assign vairables in the Store. + @param name The key to be used to store and reference the variable in the Store. + @param in the varaible to be stored. + */ + template void Set(std::string name,T in){ + std::stringstream stream; + stream< void operator>>(T& obj){ + + std::stringstream stream; + stream<<"{"; + bool first=true; + for (std::map::iterator it=m_variables.begin(); it!=m_variables.end(); ++it){ + if (!first) stream<<","; + stream<<"\""<first<<"\":\""<< it->second<<"\""; + first=false; + } + stream<<"}"; + + obj=stream.str(); + + } + + std::map::const_iterator begin() { return m_variables.begin(); } + std::map::const_iterator end() { return m_variables.end(); } + + + private: + + + std::map m_variables; + + }; - std::map m_variables; - -}; - +} #endif diff --git a/src/Tool/Tool.h b/src/Tool/Tool.h index 124e659..984d141 100644 --- a/src/Tool/Tool.h +++ b/src/Tool/Tool.h @@ -4,50 +4,55 @@ #include #include "Store.h" -#include "DataModel.h" #include - - -/** - * \class Tool - * - * Abstract base class for Tools to inherit from. This allows a polymphic interface for the factor to use. -* -* $Author: B.Richards $ -* $Date: 2019/05/28 10:44:00 $ -*/ - -class Tool{ - - public: - - Tool(){}; - virtual bool Initialise(std::string configfile,DataModel &data)=0; ///< virtual Initialise function that reads in the assigned config file and optain DataMoodel reference @param configfile Path and name of config file to read in. @param data Reference to DataModel. - virtual bool Execute()=0; ///< Virtual Execute function. - virtual bool Finalise()=0; ///< Virtual Finalise function. - virtual ~Tool(){}; ///< virtual destructor. - std::string Getname() {return m_tool_name;}; - void SetName(std::string name) {m_tool_name=name;}; - - protected: - - std::string m_tool_name; - Store m_variables; ///< Store used to store configuration varaibles - DataModel* m_data; ///< Pointer to transiant DataModel class - Logging* m_log; ///< Pointer to logging class - int m_verbose; ///< verbosity variable for direct logging level - MsgL ML(int messagelevel) {return MsgL(messagelevel,m_verbose);} ///< Function for setting logging level instream @param messagelevel the verboisty level at which to show the message. Checked against internal verbosity level. - void MLC() {*(m_data->Log)< void Log(T message, int messagelevel, int verbosity){m_data->Log->Log(message,messagelevel,verbosity);} - template void Log(T message, int messagelevel=0){m_data->Log->Log(message,messagelevel,m_verbose);} ///< Logging fuction for printouts. @param message Templated message string. @param messagelevel The verbosity level at which to show the message. Checked against internal verbosity level - - - private: - - - - - -}; +#include "Logging.h" + +class DataModel; + +namespace ToolFramework{ + + /** + * \class Tool + * + * Abstract base class for Tools to inherit from. This allows a polymphic interface for the factor to use. + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ + */ + + class Tool{ + + public: + + Tool(){}; + virtual bool Initialise(std::string configfile,DataModel &data)=0; ///< virtual Initialise function that reads in the assigned config file and optain DataMoodel reference @param configfile Path and name of config file to read in. @param data Reference to DataModel. + virtual bool Execute()=0; ///< Virtual Execute function. + virtual bool Finalise()=0; ///< Virtual Finalise function. + virtual ~Tool(){}; ///< virtual destructor. + std::string GetName() {return m_tool_name;}; + void SetName(std::string name) {m_tool_name=name;}; + + protected: + + std::string m_tool_name; + Store m_variables; ///< Store used to store configuration varaibles + DataModel* m_data; ///< Pointer to transiant DataModel class + Logging* m_log; ///< Pointer to logging class + int m_verbose; ///< verbosity variable for direct logging level + MsgL ML(int messagelevel) {return MsgL(messagelevel,m_verbose);} ///< Function for setting logging level instream @param messagelevel the verboisty level at which to show the message. Checked against internal verbosity level. + void MLC() {*(m_log)< void Log(T message, int messagelevel, int verbosity){m_log->Log("-"+GetName()+"-: "+message,messagelevel,verbosity);} + template void Log(T message, int messagelevel=0){m_log->Log("-"+GetName()+"-: "+message,messagelevel,m_verbose);} ///< Logging fuction for printouts. @param message Templated message string. @param messagelevel The verbosity level at which to show the message. Checked against internal verbosity level + + + private: + + + + + + }; + +} #endif diff --git a/src/ToolChain/ToolChain.cpp b/src/ToolChain/ToolChain.cpp index 44ea0fb..a85ee27 100644 --- a/src/ToolChain/ToolChain.cpp +++ b/src/ToolChain/ToolChain.cpp @@ -1,8 +1,10 @@ #include "ToolChain.h" -ToolChain::ToolChain(std::string configfile, int argc, char* argv[]){ +using namespace ToolFramework; + +ToolChain::ToolChain(std::string configfile, DataModel* data_model, int argc, char* argv[]){ - m_data=new DataModel(); + m_data=reinterpret_cast(data_model); if(!m_data->vars.Initialise(configfile)){ std::clog<<"\033[38;5;196m ERROR!!!: No valid config file quitting \033[0m"<(in_data_model); // need to set a flag that you dont own the data model for sue during deletion. (check this for other constructor roo. - Init(); + Init(); //need to check if loging already made incase passing a datamodel for subtoolcahin } @@ -128,7 +130,7 @@ int ToolChain::Initialise(){ try{ #endif - if(m_tools.at(i)->Initialise(m_configfiles.at(i), *m_data)) *m_log<Initialise(m_configfiles.at(i), *(reinterpret_cast(m_data)))) *m_log< #include "Tool.h" -#include "DataModel.h" +#include "DataModelBase.h" #include "Logging.h" #include "Factory.h" #include "Store.h" -/** - * \struct ToolChainargs - * - * Simple struct to pass thread initalisation variables to Interactive ToolChain thread -* -* $Author: B.Richards $ -* $Date: 2019/05/28 10:44:00 $ -*/ +class DataModel; -struct ToolChainargs{ - - ToolChainargs(){}; - - bool *msgflag; ///< Message flag used to indiacte if a new interactive command has been submitted to the interactive thread and needs execution on the main thread. - std::string command; - -}; - -/** - * \class ToolChain - * - * This class holds a dynamic list of Tools which can be Initialised, Executed and Finalised to perform program operation. Large number of options in terms of run modes and setting can be assigned. -* -* $Author: B.Richards $ -* $Date: 2019/05/28 10:44:00 $ -*/ - -class ToolChain{ +namespace ToolFramework{ - public: - - ToolChain(){}; - ToolChain(std::string configfile, int argc=0, char* argv[]=0); ///< Constructor that obtains all of the configuration varaibles from an input file. @param configfile The path and name of the config file to read configuration values from. - /** - Constructor with explicit configuration variables passed as arguments. - @param verbose The verbosity level of the ToolChain. The higher the number the more explicit the print outs. 0 = silent apart from errors. - @param errorlevel The behavior that occurs when the ToolChain encounters an error. 0 = do not exit for both handeled and unhandeled errors, 1 = exit on unhandeled errors only, 2 = exit on handeled and unhandeled errors. - @param log_interactive sets the logging class to use standard output and error to screen - @param log_local sets the logging class to redirect standard output and error to disk -logmode Where log printouts should be forwarded too. "Interactive" = cout, "Remote" = send to a remote logging system, "local" = ouput logs to a file. - @param log_local_path The file path and name of where to store logs if in Local logging mode. - @param log_split_files when loggign to local file whether to split standard output and standard error into differnt files - @param in_data_model option to specify an external data modle for use in ToolChain. + * \struct ToolChainargs + * + * Simple struct to pass thread initalisation variables to Interactive ToolChain thread + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ */ - ToolChain(int verbose, int errorlevel=0, bool log_interactive=true, bool log_local=false, std::string log_local_path="./log", bool log_split_files=false, DataModel* in_data_model=0); - //verbosity: true= print out status messages , false= print only error messages; - //errorlevels: 0= do not exit; error 1= exit if unhandeled error ; exit 2= exit on handeled and unhandeled errors; - virtual ~ToolChain(); - bool Add(std::string name, Tool *tool,std::string configfile=""); ///< Add a Tool to the ToolChain. @param name The name used in logs when reffering to the Tool. @param tool A pointer to the tool to be added to the ToolChain. @param configfile The configuration file path and name to be passed to the Tool. - int Initialise(); ///< Initialise all Tools in the ToolChain sequentially. - int Execute(int repeates=1); ///< Execute all Tools in the ToolChain sequentially. @param repeates How many times to run sequential Execute loop. - int Finalise(); ///< Finalise all Tools in the ToolCahin sequentially. - void Interactive(); ///< Start interactive thread to accept commands and run ToolChain in interactive mode. - bool LoadTools(std::string filename); - DataModel* m_data; ///< Direct access to transient data model class of the Tools in the ToolChain. This allows direct initialisation and copying of variables. - - protected: - - virtual void Init(); - void Inline(); - - static void *InteractiveThread(void* arg); - std::string ExecuteCommand(std::string connand); - - //Tools configs and data - std::vector m_tools; - std::vector m_toolnames; - std::vector m_configfiles; - //conf variables - int m_verbose; - int m_errorlevel; - bool m_log_interactive; - bool m_log_local; - bool m_log_split_files; - std::string m_log_local_path; - bool m_interactive; - int m_inline; - bool m_recover; + struct ToolChainargs{ + + ToolChainargs(){}; + + bool *msgflag; ///< Message flag used to indiacte if a new interactive command has been submitted to the interactive thread and needs execution on the main thread. + std::string command; + + }; - //status variables - bool exeloop; - unsigned long execounter; - bool Initialised; - bool Finalised; - bool paused; - Logging* m_log; - - //socket coms and threading variables - pthread_t thread[1]; - bool msgflag; - -}; + /** + * \class ToolChain + * + * This class holds a dynamic list of Tools which can be Initialised, Executed and Finalised to perform program operation. Large number of options in terms of run modes and setting can be assigned. + * + * $Author: B.Richards $ + * $Date: 2019/05/28 10:44:00 $ + */ + + class ToolChain{ + + public: + + ToolChain(){}; + ToolChain(std::string configfile, DataModel* data_model, int argc=0, char* argv[]=0); ///< Constructor that obtains all of the configuration varaibles from an input file. @param configfile The path and name of the config file to read configuration values from. + + /** + Constructor with explicit configuration variables passed as arguments. + @param verbose The verbosity level of the ToolChain. The higher the number the more explicit the print outs. 0 = silent apart from errors. + @param errorlevel The behavior that occurs when the ToolChain encounters an error. 0 = do not exit for both handeled and unhandeled errors, 1 = exit on unhandeled errors only, 2 = exit on handeled and unhandeled errors. + @param log_interactive sets the logging class to use standard output and error to screen + @param log_local sets the logging class to redirect standard output and error to disk + logmode Where log printouts should be forwarded too. "Interactive" = cout, "Remote" = send to a remote logging system, "local" = ouput logs to a file. + @param log_local_path The file path and name of where to store logs if in Local logging mode. + @param log_split_files when loggign to local file whether to split standard output and standard error into differnt files + @param in_data_model option to specify an external data modle for use in ToolChain. + */ + ToolChain(int verbose, int errorlevel=0, bool log_interactive=true, bool log_local=false, std::string log_local_path="./log", bool log_split_files=false, DataModel* in_data_model=0); + //verbosity: true= print out status messages , false= print only error messages; + //errorlevels: 0= do not exit; error 1= exit if unhandeled error ; exit 2= exit on handeled and unhandeled errors; + virtual ~ToolChain(); + bool Add(std::string name, Tool *tool,std::string configfile=""); ///< Add a Tool to the ToolChain. @param name The name used in logs when reffering to the Tool. @param tool A pointer to the tool to be added to the ToolChain. @param configfile The configuration file path and name to be passed to the Tool. + int Initialise(); ///< Initialise all Tools in the ToolChain sequentially. + int Execute(int repeates=1); ///< Execute all Tools in the ToolChain sequentially. @param repeates How many times to run sequential Execute loop. + int Finalise(); ///< Finalise all Tools in the ToolCahin sequentially. + void Interactive(); ///< Start interactive thread to accept commands and run ToolChain in interactive mode. + bool LoadTools(std::string filename); + DataModelBase* m_data; ///< Direct access to transient data model class of the Tools in the ToolChain. This allows direct initialisation and copying of variables. + + protected: + + virtual void Init(); + void Inline(); + + static void *InteractiveThread(void* arg); + std::string ExecuteCommand(std::string connand); + + //Tools configs and data + std::vector m_tools; + std::vector m_toolnames; + std::vector m_configfiles; + + //conf variables + int m_verbose; + int m_errorlevel; + bool m_log_interactive; + bool m_log_local; + bool m_log_split_files; + std::string m_log_local_path; + bool m_interactive; + int m_inline; + bool m_recover; + + //status variables + bool exeloop; + unsigned long execounter; + bool Initialised; + bool Finalised; + bool paused; + Logging* m_log; + + //socket coms and threading variables + pthread_t thread[1]; + bool msgflag; + + }; + + +} #endif diff --git a/src/main.cpp b/src/main.cpp index 0ab8938..8ac0e76 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,24 @@ #include #include "ToolChain.h" +#include "DataModel.h" //#include "DummyTool.h" +using namespace ToolFramework; + int main(int argc, char* argv[]){ std::string config_file; if (argc==1)config_file="configfiles/Dummy/ToolChainConfig"; else config_file=argv[1]; - ToolChain tools(config_file, argc, argv); - - + DataModel* data_model = new DataModel(); + ToolChain tools(config_file, data_model, argc, argv); + + //DummyTool dummytool; - + //tools.Add("DummyTool",&dummytool,"configfiles/DummyToolConfig"); - + //int portnum=24000; // tools.Remote(portnum); //tools.Interactive(); diff --git a/tempinclude/README.md b/tempinclude/README.md new file mode 100644 index 0000000..28e8dfa --- /dev/null +++ b/tempinclude/README.md @@ -0,0 +1 @@ +# DAQFramework