diff --git a/Simulation/G4Sim/FADS/FadsPackageLoader/CMakeLists.txt b/Simulation/G4Sim/FADS/FadsPackageLoader/CMakeLists.txt index 02e5f286f2c276eec25e9f8ea1ee20ebd7dfc4fb..95887e00d38948f795b3f75f3f7dde68a83019d3 100644 --- a/Simulation/G4Sim/FADS/FadsPackageLoader/CMakeLists.txt +++ b/Simulation/G4Sim/FADS/FadsPackageLoader/CMakeLists.txt @@ -5,13 +5,12 @@ # Declare the package name: atlas_subdir( FadsPackageLoader ) -# Declare the package's dependencies: -atlas_depends_on_subdirs( PRIVATE - Simulation/G4Sim/FADS/FadsUtilities ) +find_package( Boost COMPONENTS filesystem thread system ) # Component(s) in the package: atlas_add_library( FadsPackageLoader src/*.cxx + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} PUBLIC_HEADERS FadsPackageLoader - PRIVATE_LINK_LIBRARIES FadsUtilities ) + LINK_LIBRARIES dl ) diff --git a/Simulation/G4Sim/FADS/FadsPackageLoader/cmt/requirements b/Simulation/G4Sim/FADS/FadsPackageLoader/cmt/requirements index f2dedf57f52ab3fb74262c5cb1f248aec14252f1..bf537ef4e5c08641eaa4ec231d66953774286df5 100755 --- a/Simulation/G4Sim/FADS/FadsPackageLoader/cmt/requirements +++ b/Simulation/G4Sim/FADS/FadsPackageLoader/cmt/requirements @@ -5,22 +5,15 @@ author ADA use AtlasPolicy AtlasPolicy-* private -use FadsUtilities FadsUtilities-* Simulation/G4Sim/FADS +use AtlasBoost AtlasBoost-* External end_private +# Add required system libraries for cmake (transparent to CMT) +apply_pattern cmake_add_libraries target=FadsPackageLoader libraries=dl + include_dirs "$(FadsPackageLoader_root)" "$(FadsPackageLoader_root)/FadsPackageLoader" library FadsPackageLoader ../src/*.cxx apply_pattern installed_library -#======================================================= -#private -# -#macro_remove cppflags "-O3 " -#macro_remove cppflags "-O " -#macro_remove cppflags "-Wall " -# -#macro_remove CLHEP_pp_cppflags "-DCLHEP_SQR_DEFINED " -#macro_remove CLHEP_pp_cppflags "-DCLHEP_MAX_MIN_DEFINED " - diff --git a/Simulation/G4Sim/FADS/FadsPackageLoader/src/PackageLoader.cxx b/Simulation/G4Sim/FADS/FadsPackageLoader/src/PackageLoader.cxx index 9563e9a59411b1ec840d01cb98ddf7fe7b7ce29b..847162e7eb5b84c2f78db462f48829730b404d22 100755 --- a/Simulation/G4Sim/FADS/FadsPackageLoader/src/PackageLoader.cxx +++ b/Simulation/G4Sim/FADS/FadsPackageLoader/src/PackageLoader.cxx @@ -2,15 +2,18 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include<iostream> -#include <string> -#include <cstdio> -#include <dlfcn.h> - -#include "FadsUtilities/Tokenizer.h" - +// This package header #include "FadsPackageLoader/PackageLoader.h" +// For the string handling +#include <boost/foreach.hpp> +#include <boost/tokenizer.hpp> + +// standard library +#include <iostream> +#include <string> +#include <cstdio> +#include <dlfcn.h> #include <cstdlib> namespace FADS { @@ -78,36 +81,35 @@ bool PackageLoader::operator()(const std::string & packlist, const std::string& if (packlist.empty()) return true; Dict & localLoaded = loaded(); bool ok = true; - std::string semicolon(":"); - FADS::Tokenizer packs(semicolon,packlist); - // load - typedef std::vector<std::string>::const_iterator Itr; - for (Itr p=packs.begin(); p!=packs.end(); p++) { - CDI ol = localLoaded.find(*p); + // load + boost::char_separator<char> sep(":"); + boost::tokenizer<boost::char_separator<char>> packs(packlist,sep); + BOOST_FOREACH(std::string p, packs){ + CDI ol = localLoaded.find(p); if (ol==localLoaded.end()) { // new package - std::cout << "loading package " << *p + std::cout << "loading package " << p << " version " << version << std::endl; std::string fLibPath("lib"); - fLibPath+=*p; fLibPath+=".so"; + fLibPath+=p; fLibPath+=".so"; void * handle=dlopen(fLibPath.c_str(),RTLD_LAZY|RTLD_GLOBAL); if (handle==0) { - std::cerr << "error in loading shared library: " << dlerror() << std::endl; - ok = false; + std::cerr << "error in loading shared library: " << dlerror() << std::endl; + ok = false; } - CDI nl = localLoaded.find(*p); - if (nl!=localLoaded.end()) std::cout << "package " << *p << ": loading confirmed" << std::endl; - localLoaded[*p] = Elem(version,handle); + CDI nl = localLoaded.find(p); + if (nl!=localLoaded.end()) std::cout << "package " << p << ": loading confirmed" << std::endl; + localLoaded[p] = Elem(version,handle); } else { // package already loaded - std::cerr << "asked to load package " << *p << " version \"" << version << "\"" << std::endl; + std::cerr << "asked to load package " << p << " version \"" << version << "\"" << std::endl; if ((*ol).second.first==version) std::cerr << "Warning: package already loaded" << std::endl; else if ((*ol).second.first=="Unknown") std::cerr << "Warning: package already loaded with unknown version" << std::endl; else { - std::cerr << "ERROR: package already loaded with version" << (*ol).second.first << std::endl; - ok = false; + std::cerr << "ERROR: package already loaded with version" << (*ol).second.first << std::endl; + ok = false; } } @@ -120,24 +122,23 @@ bool PackageLoader::unload(const std::string & packlist) { if (packlist.empty()) return true; Dict & localLoaded = loaded(); bool ok = true; - std::string semicolon(":"); - FADS::Tokenizer packs(semicolon,packlist); // load - typedef std::vector<std::string>::const_iterator Itr; - for (Itr p=packs.begin(); p!=packs.end(); p++) { - DI ol = localLoaded.find(*p); + boost::char_separator<char> sep(":"); + boost::tokenizer<boost::char_separator<char>> packs(packlist,sep); + BOOST_FOREACH(std::string p, packs){ + DI ol = localLoaded.find(p); if (ol==localLoaded.end()) { - std::cerr<< "cannot unload not registered package " << *p <<std::endl; + std::cerr<< "cannot unload not registered package " << p <<std::endl; ok=false; } else if((*ol).second.second==0) { - std::cerr << "cannot unload package " << *p + std::cerr << "cannot unload package " << p << " handle is 0" << std::endl; ok=false; } else { dlclose((*ol).second.second); - std::cout << "unloading package " << *p + std::cout << "unloading package " << p << " version " << (*ol).second.first << std::endl; localLoaded.erase(ol); }