diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index 2835a91cb1c3f309d72ae30dfda2d132e72e5f34..975c450b49f64f7ecb37e2ad738e0b38c49b1ead 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -23,6 +23,7 @@ list(APPEND headers ${DDSegmentation_INCLUDE_DIRS}/DDSegmentation/Segmentation.h list(REMOVE_ITEM headers ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/DetFactoryHelper.h ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Factories.h ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/Plugins.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/DD4hep/IoStreams.h ) root_generate_dictionary( G__DD4hep ${headers} ${internal_headers} LINKDEF include/ROOT/LinkDef.h) list(APPEND sources G__DD4hep.cxx) diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h index f6fb8e344b73fa676ceb823e0f5082532c2e71c6..a5d85ac53433fd3e8fe3c6dc401e156d88db978c 100644 --- a/DDCore/include/DD4hep/Dictionary.h +++ b/DDCore/include/DD4hep/Dictionary.h @@ -197,51 +197,66 @@ template vector<pair<string, int> >::iterator; // Shapes.h +#pragma link C++ class DD4hep::Geometry::Handle<TGeoShape>+; +#pragma link C++ class DD4hep::Geometry::Solid_type<TGeoShape>+; + #pragma link C++ class DD4hep::Geometry::Polycone+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoPcon>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoPcon>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoPcon>+; #pragma link C++ class DD4hep::Geometry::ConeSegment+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoConeSeg>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoConeSeg>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoConeSeg>+; #pragma link C++ class DD4hep::Geometry::Box+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoBBox>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoBBox>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoBBox>+; #pragma link C++ class DD4hep::Geometry::Torus+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTorus>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTorus>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoTorus>+; #pragma link C++ class DD4hep::Geometry::Cone+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoCone>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoCone>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoCone>+; #pragma link C++ class DD4hep::Geometry::Tube+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTubeSeg>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTubeSeg>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoTubeSeg>+; #pragma link C++ class DD4hep::Geometry::Trap+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTrap>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTrap>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoTrap>+; #pragma link C++ class DD4hep::Geometry::Trapezoid+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoTrd2>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoTrd2>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoTrd2>+; #pragma link C++ class DD4hep::Geometry::Sphere+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoSphere>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoSphere>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoSphere>+; #pragma link C++ class DD4hep::Geometry::Paraboloid+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoParaboloid>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoParaboloid>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoParaboloid>+; #pragma link C++ class DD4hep::Geometry::PolyhedraRegular+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoPgon>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoPgon>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoPgon>+; #pragma link C++ class DD4hep::Geometry::BooleanSolid+; +#pragma link C++ class DD4hep::Geometry::Handle<TGeoCompositeShape>+; #pragma link C++ class DD4hep::Geometry::Solid_type<TGeoCompositeShape>+; #pragma link C++ class DD4hep::Geometry::Handle<TGeoCompositeShape>+; diff --git a/DDCore/include/DD4hep/IoStreams.h b/DDCore/include/DD4hep/IoStreams.h new file mode 100644 index 0000000000000000000000000000000000000000..7d3e243e3a667d7bca969df4cae5cc878daa435b --- /dev/null +++ b/DDCore/include/DD4hep/IoStreams.h @@ -0,0 +1,224 @@ +// $Id: Primitives.h 603 2013-06-13 21:15:14Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_DD4HEP_IOSTREAMS_H +#define DD4HEP_DD4HEP_IOSTREAMS_H + +// C/C++ include files +#include <string> + +// booost iostreams include files +#include <boost/iostreams/categories.hpp> +#include <boost/iostreams/detail/ios.hpp> +#include <boost/iostreams/detail/path.hpp> +#include <boost/iostreams/positioning.hpp> + +class TFile; + +namespace DD4hep { + + // Forward declarations + template <typename T> class dd4hep_file_source; + template <typename T> class dd4hep_file_sink; + + enum dd4hep_file_flags { + never_close_handle = 0, + close_handle = 3 + }; + + /// DD4hep file handling extension to boost::iostreams + /** + * Basic file handling for data sources and data sinks. + * Please see boost::iostreams for details. + * This got inspired by boost::iostreams::device::file_descriptor + * + * The final aim is to hide all this behind a TFile object, + * so that we get the entire network file handling for free! + * + * Note: + * Credits go to a large extend to the authors of boost::iostreams. + * Without their work I could not have done this! + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + * \see http://www.boost.org/libs/iostreams for further documentation. + */ + template <typename T> class dd4hep_file { + public: + friend class dd4hep_file_source<T>; + friend class dd4hep_file_sink<T>; + typedef T handle_type; + typedef char char_type; + typedef boost::iostreams::stream_offset stream_offset; + typedef boost::iostreams::detail::path detail_path; + struct category : boost::iostreams::seekable_device_tag, boost::iostreams::closable_tag { }; + + // Default constructor + dd4hep_file() : m_handle(0) { } + // Constructors taking file desciptors + dd4hep_file(handle_type fd, dd4hep_file_flags); + // Constructors taking file desciptors + dd4hep_file(const char* fname, BOOST_IOS::openmode mode); + + // open overloads taking file descriptors + void open(handle_type fd, dd4hep_file_flags flags); + + // open overload taking C-style string + void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::in | BOOST_IOS::out ); + + bool is_open() const { return m_handle != 0; } + void close(); + std::streamsize read(char_type* s, std::streamsize n); + std::streamsize write(const char_type* s, std::streamsize n); + std::streampos seek(stream_offset off, BOOST_IOS::seekdir way); + handle_type handle() const { return m_handle; } + private: + handle_type m_handle; + dd4hep_file_flags m_flag; + }; + + + /// DD4hep file source extension to boost::iostreams + /** + * Basic data sources implementation. + * Please see boost::iostreams for details. + * This got inspired by boost::iostreams::device::file_descriptor + * + * The final aim is to hide all this behind a TFile object, + * so that we get the entire network file handling for free! + * + * Note: + * Credits go to a large extend to the authors of boost::iostreams. + * Without their work I could not have done this! + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + * \see http://www.boost.org/libs/iostreams for further documentation. + */ + template <typename T=int> struct dd4hep_file_source : private dd4hep_file<T> { + typedef dd4hep_file<T> descriptor; + struct category : boost::iostreams::input_seekable, + boost::iostreams::device_tag, + boost::iostreams::closable_tag { }; + typedef typename descriptor::handle_type handle_type; + typedef typename descriptor::char_type char_type; + using descriptor::is_open; + using descriptor::close; + using descriptor::read; + using descriptor::seek; + using descriptor::handle; + + /// Default Constructor + dd4hep_file_source() : descriptor() { } + + /// Copy constructor + dd4hep_file_source(const dd4hep_file_source<T>& other) + : descriptor(other) { } + + /// Constructors taking file desciptors + explicit dd4hep_file_source(handle_type h, dd4hep_file_flags flags) + : descriptor(h,flags) { } + + /// Constructors taking file desciptors + explicit dd4hep_file_source(const char* name, BOOST_IOS::openmode mode = BOOST_IOS::in) + : descriptor(name,mode) { } + + /// open overload taking file desciptors + void open(handle_type h, dd4hep_file_flags flags) + { this->descriptor::open(h, flags); } + + /// open overload taking C-style string + void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::in) + { this->descriptor::open(path,mode); } + + /// open overload taking a std::string + void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::in) + { open(path.c_str(), mode); } + + /// open overload taking a Boost.Filesystem path + template<typename Path> void open(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::in) + { open(detail_path(path), mode); } + }; + + /// DD4hep file sink extension to boost::iostreams + /** + * Basic data sink implementation. + * Please see boost::iostreams for details. + * This got inspired by boost::iostreams::device::file_descriptor + * + * The final aim is to hide all this behind a TFile object, + * so that we get the entire network file handling for free! + * + * Note: + * Credits go to a large extend to the authors of boost::iostreams. + * Without their work I could not have done this! + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP + * \see http://www.boost.org/libs/iostreams for further documentation. + */ + template <typename T> + class dd4hep_file_sink : private dd4hep_file<T> { + public: + typedef dd4hep_file<T> descriptor; + struct category : boost::iostreams::output_seekable, + boost::iostreams::device_tag, + boost::iostreams::closable_tag { }; + typedef typename descriptor::handle_type handle_type; + typedef typename descriptor::char_type char_type; + using descriptor::is_open; + using descriptor::close; + using descriptor::write; + using descriptor::seek; + using descriptor::handle; + + /// Default constructor + dd4hep_file_sink() { } + + /// Copy constructor + dd4hep_file_sink(const dd4hep_file_sink<T>& other) + : descriptor(other) { } + + /// Constructors taking file desciptors + explicit dd4hep_file_sink(handle_type fd, dd4hep_file_flags flags) + : descriptor(fd, flags) { } + + /// Constructor taking a std::string + explicit dd4hep_file_sink(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::out) + : descriptor(path.c_str(), mode) { } + + /// Constructor taking a C-style string + explicit dd4hep_file_sink(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::out ) + : descriptor(path, mode) { } + + /// Constructor taking a Boost.Filesystem path + template<typename Path> + explicit dd4hep_file_sink(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::out ) + : descriptor(detail_path(path), mode) { } + + /// open overloads taking file descriptors + void open(handle_type fd, dd4hep_file_flags flags) + { this->descriptor::open(fd,flags); } + + /// open overload taking a std::string + void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::out ) + { open(path.c_str(),mode); } + + /// open overload taking C-style string + void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::out ) + { this->descriptor::open(path, mode); } + + /// open overload taking a Boost.Filesystem path + template<typename Path> void open(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::out ) + { open(detail_path(path), mode); } + }; +} // End namespace boost +#endif // DD4HEP_DD4HEP_IOSTREAMs_H diff --git a/DDCore/include/DD4hep/Plugins.h b/DDCore/include/DD4hep/Plugins.h index b0e88c70a5cf15d01e71c0b08bebaabc1d7b0939..24b01e9e505bb7d215e2f8190f32ad3573767834 100644 --- a/DDCore/include/DD4hep/Plugins.h +++ b/DDCore/include/DD4hep/Plugins.h @@ -12,7 +12,6 @@ // ROOT include files #ifndef __CINT__ #include "Reflex/PluginService.h" -#endif /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -39,4 +38,6 @@ namespace DD4hep { }; } /* End namespace DD4hep */ +#endif + #endif /* DD4HEP_PLUGINS_H */ diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index b03cdba1653fe6245ab77bcdbcd167f4632388a1..04a922af25ddb2780fc50bec384d63d097322f15 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -131,7 +131,7 @@ const TGeoHMatrix& DetElementObject::worldTransformation() { PlacementPath nodes; flag |= HAVE_WORLD_TRAFO; DetectorTools::placementPath(this, nodes); - DetectorTools::placementTrafo(nodes,true,worldTrafo); + DetectorTools::placementTrafo(nodes,false,worldTrafo); } return worldTrafo; } @@ -142,7 +142,7 @@ const TGeoHMatrix& DetElementObject::parentTransformation() { PlacementPath nodes; flag |= HAVE_PARENT_TRAFO; DetectorTools::placementPath(DetElement(parent), this, nodes); - DetectorTools::placementTrafo(nodes,true,parentTrafo); + DetectorTools::placementTrafo(nodes,false,parentTrafo); } return parentTrafo; } @@ -158,12 +158,12 @@ const TGeoHMatrix& DetElementObject::referenceTransformation() { else if ( DetectorTools::isParentElement(ref,self) ) { PlacementPath nodes; DetectorTools::placementPath(ref,self,nodes); - DetectorTools::placementTrafo(nodes,true,referenceTrafo); + DetectorTools::placementTrafo(nodes,false,referenceTrafo); } else if ( DetectorTools::isParentElement(self,ref) ) { PlacementPath nodes; DetectorTools::placementPath(self,ref,nodes); - DetectorTools::placementTrafo(nodes,true,referenceTrafo); + DetectorTools::placementTrafo(nodes,false,referenceTrafo); } else { throw runtime_error("DD4hep: referenceTransformation: No path from " + string(self.name()) + @@ -199,7 +199,7 @@ void DetElementObject::revalidate(TGeoHMatrix* parent_world_trafo) { if ( have_world_tr && print ) worldTrafo.Print(); if ( (flag&HAVE_PARENT_TRAFO) ) { - DetectorTools::placementTrafo(par_path,true,parentTrafo); + DetectorTools::placementTrafo(par_path,false,parentTrafo); } /// Compute world transformations @@ -213,7 +213,7 @@ void DetElementObject::revalidate(TGeoHMatrix* parent_world_trafo) { // Else re-compute the transformation to the world. PlacementPath world_nodes; DetectorTools::placementPath(this, world_nodes); - DetectorTools::placementTrafo(world_nodes,true,worldTrafo); + DetectorTools::placementTrafo(world_nodes,false,worldTrafo); flag |= HAVE_WORLD_TRAFO; } diff --git a/DDCore/src/IoStreams.cpp b/DDCore/src/IoStreams.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fcb90d19240d1ec6fd9ca1b7db84081195db8daa --- /dev/null +++ b/DDCore/src/IoStreams.cpp @@ -0,0 +1,124 @@ +// $Id: Primitives.h 603 2013-06-13 21:15:14Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +// Framework includes +#include "DD4hep/IoStreams.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <cstdio> +#include "TFile.h" + +using namespace DD4hep; + +namespace { + /// Anonymous cast class to get access to protected members of TFile ;-) + class MyTFile : public TFile { + private: + /// Destructor (unused!) + virtual ~MyTFile() {} + public: + /// Basic write call + virtual Int_t SysWrite(Int_t fd, const void* buf, Int_t len) { return TFile::SysWrite(fd, buf, len); } + /// Basic read call + virtual Int_t SysRead(Int_t fd, void* buf, Int_t len) { return TFile::SysRead(fd,buf,len); } + /// Basic seek call + virtual Long64_t SysSeek(Int_t fd, Long64_t off, Int_t way) { return TFile::SysSeek(fd, off, way); } + }; +} + +namespace DD4hep { + + /// Specialization for standard file descriptor files according to the posix standard + template<> void dd4hep_file<int>::open(const char* path, BOOST_IOS::openmode mode) { + if ( m_handle ) ::close(m_handle); + m_handle = ::open(path,mode); + } + + /// Specialization for standard file descriptor files according to the posix standard + template<> dd4hep_file<int>::dd4hep_file(handle_type fd, dd4hep_file_flags flags) + : m_handle(fd), m_flag(flags) { } + + /// Specialization for standard file descriptor files according to the posix standard + template<> dd4hep_file<int>::dd4hep_file(const char* fn, BOOST_IOS::openmode mode) + : m_handle(0), m_flag(close_handle) {open(fn,mode); } + + /// Specialization for standard file descriptor files according to the posix standard + template<> std::streamsize dd4hep_file<int>::read(char_type* s, std::streamsize n) + { return ::read(m_handle,s,n); } + + /// Specialization for standard file descriptor files according to the posix standard + template<> std::streamsize dd4hep_file<int>::write(const char_type* s, std::streamsize n) + { return ::write(m_handle,s,n); } + + /// Specialization for standard file descriptor files according to the posix standard + template<> std::streampos dd4hep_file<int>::seek(stream_offset off, BOOST_IOS::seekdir way) + { return ::lseek(m_handle,off,way); } + + /// Specialization for standard file descriptor files according to the posix standard + template<> void dd4hep_file<int>::close() { + if ( m_handle ) ::close(m_handle); + m_handle = 0; + } + + /// Specialization for the usage of TFile structures + template<> void dd4hep_file<TFile*>::open(const char* path, BOOST_IOS::openmode mode) { + if ( m_handle ) { + m_handle->Close(); + delete m_handle; + } + std::string p = path; + p += "?filetype=raw"; + if ( mode&BOOST_IOS::out ) + m_handle = TFile::Open(p.c_str(),"RECREATE","ROOT"); + else + m_handle = TFile::Open(p.c_str()); + if ( m_handle->IsZombie() ) { + delete m_handle; + m_handle = 0; + throw 1; + } + } +#define _p(x) ((MyTFile*)x) + + /// Specialization for the usage of TFile structures + template<> dd4hep_file<TFile*>::dd4hep_file(handle_type fd, dd4hep_file_flags flags) + : m_handle(fd), m_flag(flags) { } + + /// Specialization for the usage of TFile structures + template<> dd4hep_file<TFile*>::dd4hep_file(const char* fname, BOOST_IOS::openmode mode) + : m_handle(0), m_flag(close_handle) { open(fname,mode); } + + /// Specialization for the usage of TFile structures + template<> std::streamsize dd4hep_file<TFile*>::read(char_type* s, std::streamsize n) { + if ( m_handle ) { + Long64_t nb1 = m_handle->GetBytesRead(); + Bool_t res = _p(m_handle)->ReadBuffer(s,nb1,n); + if ( res ) { + Long64_t nb2 = m_handle->GetBytesRead(); + return nb2-nb1; + } + } + return -1; + } + + /// Specialization for the usage of TFile structures + template<> std::streamsize dd4hep_file<TFile*>::write(const char_type* s, std::streamsize n) + { return m_handle ? _p(m_handle)->SysWrite(m_handle->GetFd(),s,n) : -1; } + + /// Specialization for the usage of TFile structures + template<> std::streampos dd4hep_file<TFile*>::seek(stream_offset off, BOOST_IOS::seekdir way) + { return m_handle ? _p(m_handle)->SysSeek(m_handle->GetFd(),off,way) : -1; } + + /// Specialization for the usage of TFile structures + template<> void dd4hep_file<TFile*>::close() + { if ( m_handle ) { m_handle->Close(); delete m_handle; m_handle=0; } } + +}