switch to git no-history version

This commit is contained in:
AndreaRigoni
2018-04-17 15:39:10 +02:00
commit b14311ce09
274 changed files with 27340 additions and 0 deletions

92
src/Core/Archives.cpp Normal file
View File

@@ -0,0 +1,92 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Core/Archives.h"
//#define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/archive_serializer_map.hpp>
// explicitly instantiate for this type of xml stream
#include <boost/archive/impl/archive_serializer_map.ipp>
#include <boost/archive/impl/basic_xml_oarchive.ipp>
#include <boost/archive/impl/xml_oarchive_impl.ipp>
#include <boost/archive/impl/basic_xml_iarchive.ipp>
#include <boost/archive/impl/xml_iarchive_impl.ipp>
#include <boost/archive/impl/basic_text_oarchive.ipp>
#include <boost/archive/impl/text_oarchive_impl.ipp>
#include <boost/archive/impl/basic_text_iarchive.ipp>
#include <boost/archive/impl/text_iarchive_impl.ipp>
#include <boost/archive/polymorphic_xml_oarchive.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
namespace boost {
namespace archive {
template class detail::archive_serializer_map <uLib::Archive::xml_oarchive> ;
template class basic_xml_oarchive <uLib::Archive::xml_oarchive> ;
template class xml_oarchive_impl <uLib::Archive::xml_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::xml_iarchive> ;
template class basic_xml_iarchive <uLib::Archive::xml_iarchive> ;
template class xml_iarchive_impl <uLib::Archive::xml_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::text_oarchive> ;
template class basic_text_oarchive <uLib::Archive::text_oarchive> ;
template class text_oarchive_impl <uLib::Archive::text_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::text_iarchive> ;
template class basic_text_iarchive <uLib::Archive::text_iarchive> ;
template class text_iarchive_impl <uLib::Archive::text_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::hrt_oarchive> ;
template class basic_text_oarchive <uLib::Archive::hrt_oarchive> ;
template class text_oarchive_impl <uLib::Archive::hrt_oarchive> ;
template class detail::archive_serializer_map <uLib::Archive::hrt_iarchive> ;
template class basic_text_iarchive <uLib::Archive::hrt_iarchive> ;
template class text_iarchive_impl <uLib::Archive::hrt_iarchive> ;
template class detail::archive_serializer_map <uLib::Archive::log_archive> ;
template class basic_xml_oarchive <uLib::Archive::log_archive> ;
template class xml_oarchive_impl <uLib::Archive::log_archive> ;
} // namespace archive
} // namespace boost

781
src/Core/Archives.h Normal file
View File

@@ -0,0 +1,781 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARCHIVES_H
#define U_CORE_ARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include "StringReader.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES //
namespace uLib {
namespace Archive {
class xml_iarchive;
class xml_oarchive;
class text_iarchive;
class text_oarchive;
class log_archive;
}
}
namespace boost {
namespace archive {
namespace detail {
template<class ArchiveImplementation> class polymorphic_oarchive_route;
template<class ArchiveImplementation> class polymorphic_iarchive_route;
}
}
}
namespace boost {
namespace serialization {
template <typename T> struct hrp;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION //
namespace uLib {
namespace Archive {
namespace detail {
struct adl_tag {};
}
}
}
namespace boost {
namespace archive {
namespace detail {
// This function gets called, but its only purpose is to participate
// in overload resolution with the functions declared by
// BOOST_SERIALIZATION_REGISTER_ARCHIVE, below.
template <class Serializable>
void instantiate_ptr_serialization(Serializable*, int, uLib::Archive::detail::adl_tag ) {}
}
}
}
// The function declaration generated by this macro never actually
// gets called, but its return type gets instantiated, and that's
// enough to cause registration of serialization functions between
// Archive and any exported Serializable type. See also:
// boost/serialization/export.hpp
# define ULIB_SERIALIZATION_REGISTER_ARCHIVE(_Archive) \
namespace boost { namespace archive { namespace detail { \
\
template <class Serializable> \
BOOST_DEDUCED_TYPENAME _ptr_serialization_support<_Archive, Serializable>::type \
instantiate_ptr_serialization( Serializable*, _Archive*, uLib::Archive::detail::adl_tag ); }}}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES //
namespace boost {
namespace archive {
namespace detail {
/**
* Custom implementation of boost interface_iarchive to add new operators
*/
template<class Archive>
class uLib_interface_iarchive
{
protected:
uLib_interface_iarchive(){};
public:
/////////////////////////////////////////////////////////
// archive public interface
typedef mpl::bool_<true> is_loading;
typedef mpl::bool_<false> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
template<class T>
const basic_pointer_iserializer *
register_type(T * = NULL){
const basic_pointer_iserializer & bpis =
boost::serialization::singleton<
pointer_iserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpis.get_basic_serializer());
return & bpis;
}
template<class T>
Archive & operator>>(T & t){
this->This()->load_override(t, 0);
return * this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
return *(this->This()) >> t;
}
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return * this->This();
}
};
/**
* Custom implementation of boost interface_oarchive to add new operators
*/
template <class Archive>
class uLib_interface_oarchive {
protected:
uLib_interface_oarchive(){};
public:
/////////////////////////////////////////////////////////
// archive public interface
typedef mpl::bool_<false> is_loading;
typedef mpl::bool_<true> is_saving;
// return a pointer to the most derived class
Archive * This(){
return static_cast<Archive *>(this);
}
template<class T>
const basic_pointer_oserializer *
register_type(const T * = NULL){
const basic_pointer_oserializer & bpos =
boost::serialization::singleton<
pointer_oserializer<Archive, T>
>::get_const_instance();
this->This()->register_basic_serializer(bpos.get_basic_serializer());
return & bpos;
}
template<class T>
Archive & operator<<(T & t){
// to get access you must redefine save_override by typing
// "using save_override" in archive impl
this->This()->save_override(t, 0);
return * this->This();
}
// the & operator
template<class T>
Archive & operator&(T & t){
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
return * this->This() << const_cast<const T &>(t);
#else
return * this->This() << t;
#endif
}
// the == operator
template <class T>
Archive & operator == (T & t) {
return this->operator &(t);
}
// the != operator for human readable access
template <class T>
Archive & operator != (T & t) {
std::cerr << std::flush << "cauch string: " << t << "\n"; // REMOVE THIS !
return * this->This();
}
};
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own
// extended interface //
template <>
class interface_iarchive <uLib::Archive::xml_iarchive> : public
uLib_interface_iarchive <uLib::Archive::xml_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::xml_oarchive> : public
uLib_interface_oarchive <uLib::Archive::xml_oarchive> {};
template <>
class interface_iarchive <uLib::Archive::text_iarchive> : public
uLib_interface_iarchive <uLib::Archive::text_iarchive> {};
template <>
class interface_oarchive <uLib::Archive::text_oarchive> : public
uLib_interface_oarchive <uLib::Archive::text_oarchive> {};
template <>
class interface_oarchive <uLib::Archive::log_archive> : public
uLib_interface_oarchive <uLib::Archive::log_archive> {};
//// Veritical repetition macro // FINIRE !!!!!!!!!!!!!!!!!!!!!!!!!
//#define _DECL_INTERFACE_ARCHIVE_V(vz,vn,vdata) \
// template <class TypeSeq> \
// struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
// BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
// {};
//// Multiple size declaration //
//BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
//#undef _INERIT_NOFOLD_H
//#undef _INERIT_NOFOLD_V
} // detail
} // archive
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES DEFINITIONS //
namespace boost {
namespace archive {
//template<class Archive>
//inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
// typex::invoke(ar, t);
//}
//template<class Archive, class T>
//inline void load(Archive & ar, T &t){
// // if this assertion trips. It means we're trying to load a
// // const object with a compiler that doesn't have correct
// // funtion template ordering. On other compilers, this is
// // handled below.
// // detail::check_const_loading< T >();
// typedef
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
// mpl::identity<detail::load_pointer_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
// mpl::identity<detail::load_array_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
// mpl::identity<detail::load_enum_type<Archive> >
// ,//else
// mpl::identity<detail::load_non_pointer_type<Archive> >
// >
// >
// >::type typex;
// typex::invoke(ar, t);
//}
}
}
namespace uLib {
namespace Archive {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// POLYMORPHIC //
//class polymorphic_iarchive :
// public boost::archive::polymorphic_iarchive {
//public:
// void load_override(const char *t, BOOST_PFTO int)
// {
// boost::archive::load_const_override(* this->This(), const_cast<char*>(t));
// }
//};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML //
class xml_iarchive :
public boost::archive::xml_iarchive_impl<xml_iarchive>
{
typedef xml_iarchive Archive;
typedef boost::archive::xml_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_xml_iarchive<Archive>;
friend class boost::archive::load_access;
public:
xml_iarchive(std::istream & is, unsigned int flags = 0) :
xml_iarchive_impl<xml_iarchive>(is, flags)
{}
using basic_xml_iarchive::load_override;
// Anything not an attribute should be a name value pair as nvp or hrp
typedef boost::archive::detail::common_iarchive<Archive> detail_common_iarchive;
template<class T>
void load_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
boost::serialization::hrp< T > & t,
int v
){
this->This()->load_start(t.name());
this->detail_common_iarchive::load_override(t.value(), 0);
// t.stov();
this->This()->load_end(t.name());
}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
// StringReader sr(basic_text_iprimitive::is);
// sr >> str;
}
~xml_iarchive(){};
};
//typedef boost::archive::detail::polymorphic_iarchive_route<
//boost::archive::xml_iarchive_impl<xml_iarchive>
//> polymorphic_xml_iarchive;
template <class ArchiveImpl>
struct polymorphic_iarchive_route :
boost::archive::detail::polymorphic_iarchive_route<ArchiveImpl>
{
virtual void load(const char * t){
ArchiveImpl::load(t);
}
};
class polymorphic_xml_iarchive :
public polymorphic_iarchive_route< boost::archive::xml_iarchive_impl<xml_iarchive> >
{
// give serialization implementation access to this class
// friend class boost::archive::detail::interface_iarchive<Archive>;
// friend class boost::archive::basic_xml_iarchive<Archive>;
// friend class boost::archive::load_access;
public:
virtual void load_override(const char *str, int v) {
;
}
};
class xml_oarchive :
public boost::archive::xml_oarchive_impl<xml_oarchive>
{
typedef xml_oarchive Archive;
typedef boost::archive::xml_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_xml_oarchive<Archive>;
friend class boost::archive::save_access;
public:
xml_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<xml_oarchive>(os, flags)
{}
// example of implementing save_override for const char* //
// void save_override(const char *t, int) {
// std::cout << "found char: " << t << "\n";
// }
using basic_xml_oarchive::save_override;
// special treatment for name-value pairs.
typedef boost::archive::detail::common_oarchive<Archive> detail_common_oarchive;
template<class T>
void save_override(
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
::boost::serialization::hrp< T > & t,
int v
){
this->This()->save_start(t.name());
// t.vtos();
// this->detail_common_oarchive::save_override(t.const_value(), 0);
this->This()->save_end(t.name());
}
void save_override(const char *str, int v) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
~xml_oarchive(){}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::xml_oarchive_impl<xml_oarchive>
//> polymorphic_xml_oarchive;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TEXT //
class text_iarchive :
public boost::archive::text_iarchive_impl<text_iarchive>
{
typedef text_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
text_iarchive(std::istream & is, unsigned int flags = 0) :
text_iarchive_impl<Archive>(is, flags)
{}
using basic_text_iarchive::load_override;
void load_override(boost::archive::object_id_type & t, int) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
~text_iarchive() {};
};
typedef text_iarchive naked_text_iarchive;
//typedef boost::archive::detail::polymorphic_iarchive_route<
//naked_text_iarchive
//> polymorphic_text_iarchive;
class text_oarchive :
public boost::archive::text_oarchive_impl<text_oarchive>
{
typedef text_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
text_oarchive(std::ostream & os, unsigned int flags = 0) :
boost::archive::text_oarchive_impl<Archive>(os, flags)
{}
using basic_text_oarchive::save_override;
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
~text_oarchive(){}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::text_oarchive_impl<text_oarchive>
//> polymorphic_text_oarchive;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SIMPLE HUMAN READABLE TEXT //
class hrt_iarchive :
public boost::archive::text_iarchive_impl<hrt_iarchive>
{
typedef hrt_iarchive Archive;
typedef boost::archive::text_iarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_iarchive<Archive>;
friend class boost::archive::basic_text_iarchive<Archive>;
friend class boost::archive::load_access;
public:
hrt_iarchive(std::istream & is, unsigned int flags = 0) :
base(is, flags | boost::archive::no_header )
{}
using basic_text_iarchive::load_override;
// hide all archive props //
void load_override( boost::archive::object_id_type & t, int) {}
void load_override( boost::archive::object_reference_type & t, int) {}
void load_override( boost::archive::version_type & t, int) {}
void load_override( boost::archive::class_id_type & t, int) {}
void load_override( boost::archive::class_id_optional_type & t, int) {}
void load_override( boost::archive::class_id_reference_type & t, int){}
void load_override( boost::archive::class_name_type & t, int) {}
void load_override( boost::archive::tracking_type & t, int) {}
// class_name_type can't be handled here as it depends upon the
// char type used by the stream. So require the derived implementation.
// derived in this case is xml_iarchive_impl or base ..
using base::load_override;
void load_override(const char *str, int v) {
StringReader sr(basic_text_iprimitive::is);
sr >> str;
}
~hrt_iarchive() {};
};
class hrt_oarchive :
public boost::archive::text_oarchive_impl<hrt_oarchive>
{
typedef hrt_oarchive Archive;
typedef boost::archive::text_oarchive_impl<Archive> base;
// give serialization implementation access to this class
friend class boost::archive::detail::interface_oarchive<Archive>;
friend class boost::archive::basic_text_oarchive<Archive>;
friend class boost::archive::save_access;
public:
hrt_oarchive(std::ostream & os, unsigned int flags = 0) :
base(os, flags | boost::archive::no_header )
{}
using basic_text_oarchive::save_override;
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
void save_override(const char *str, int v) {
basic_text_oprimitive::save(str);
}
~hrt_oarchive(){}
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML FOR LOG OUTPUT PURPOUSE //
/////////////////////////////////////////////////////////////////////////
// log data to an output stream. This illustrates a simpler implemenation
// of text output which is useful for getting a formatted display of
// any serializable class. Intended to be useful as a debugging aid.
class log_archive :
/* protected ? */
public boost::archive::xml_oarchive_impl<log_archive>
{
typedef boost::archive::xml_oarchive_impl<log_archive> base;
typedef log_archive Archive;
// give serialization implementation access to this clas
friend class boost::archive::detail::interface_oarchive<log_archive>;
friend class boost::archive::basic_xml_oarchive<log_archive>;
friend class boost::archive::save_access;
public:
void save_override(const char *str, int v) {
// Do not save any human decoration string //
// basic_text_oprimitive::save(str);
}
template<class T>
void save_override(T & t, BOOST_PFTO int){
base::save_override(boost::serialization::make_nvp(NULL, t), 0);
}
// activate this if you want to trap non nvp objects //
// template<class T>
// void save_override(T & t, BOOST_PFTO int)
// {
// BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // this->detail_common_oarchive::save_override(t, 0);
// }
template<class T>
void save_override(const boost::serialization::nvp<T> & t, int){
base::save_override(t, 0);
}
// specific overrides for attributes - not name value pairs so we
// want to trap them before the above "fall through"
// since we don't want to see these in the output - make them no-ops.
void save_override(const boost::archive::object_id_type & t, int) {}
void save_override(const boost::archive::object_reference_type & t, int) {}
void save_override(const boost::archive::version_type & t, int) {}
void save_override(const boost::archive::class_id_type & t, int) {}
void save_override(const boost::archive::class_id_optional_type & t, int) {}
void save_override(const boost::archive::class_id_reference_type & t, int){}
void save_override(const boost::archive::class_name_type & t, int) {}
void save_override(const boost::archive::tracking_type & t, int) {}
public:
log_archive(std::ostream & os, unsigned int flags = 0) :
boost::archive::xml_oarchive_impl<log_archive>(
os,
flags | boost::archive::no_header
)
{}
};
//typedef boost::archive::detail::polymorphic_oarchive_route<
//boost::archive::xml_oarchive_impl<log_archive>
//> polymorphic_log_archive;
} // Archive
} // uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::xml_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::text_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_iarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::hrt_oarchive)
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::log_archive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_iarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_xml_oarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_iarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_text_oarchive)
//ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::polymorphic_log_archive)
#endif // U_CORE_ARCHIVES_H

72
src/Core/Array.h Normal file
View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_ARRAY_H
#define U_CORE_ARRAY_H
#include <array> // std::array
#include "Types.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//// ERROR NOT WORKING CLASS, USE VECTOR INSTEAD //////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
template< typename T, Size_t size >
class Array : public std::array<T,size> {
};
template< typename T, Size_t size >
class SmartArray : public SmartPointer< Array<T,size> > {
typedef SmartPointer< Array<T,size> > ptr;
public:
SmartArray() : ptr(new Array<T,size>()) { }
SmartArray( const SmartArray &copy) : ptr(copy) { }
virtual ~SmartArray() {}
T& operator[](unsigned int p) {
return ptr::get()->at(p);
}
};
}
#endif // ARRAY_H

46
src/Core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,46 @@
set(HEADERS
Archives.h
Array.h
Collection.h
Debug.h
Export.h
Function.h
Macros.h
Mpl.h
Object.h
ObjectProps.h
Options.h
Serializable.h
Signal.h
Singleton.h
SmartPointer.h
StaticInterface.h
StringReader.h
Types.h
Uuid.h
Vector.h
CommaInitializer.h
Timer.h
)
SET(SOURCES
Archives.cpp
Object.cpp
Options.cpp
Serializable.cpp
Signal.cpp
Uuid.cpp
)
set(LIBRARIES
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
)
uLib_add_shared_library(${uLib-module})
add_subdirectory(testing)

100
src/Core/Collection.h Normal file
View File

@@ -0,0 +1,100 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_COLLECTION_H
#define U_CORE_COLLECTION_H
#include <iostream>
#include <vector>
#include "SmartPointer.h"
#include "Vector.h"
////////////////////////////////////////////////////////////////////////////////
/////// COLLECTION TEMPLATE //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Implements concept of unordered collection of elements
namespace uLib {
namespace Abstract {
template <typename T>
class Collection {
public:
virtual ~Collection() {}
virtual void AddItem(T obj) =0;
virtual void RemoveItem(int i) =0;
virtual int GetNumberOfItems() =0;
virtual T& At(unsigned int i) =0;
virtual void PrintSelf(std::ostream &o) =0;
};
}
template <typename T>
class Collection : public Abstract::Collection<T> {
public:
Collection() : data() {}
Collection(int size) : data(size) {}
~Collection() {}
inline void AddItem(T obj) { data->push_back(obj); }
inline void RemoveItem(int i) { data.remove_element(i); }
inline int GetNumberOfItems() { return data->size(); }
inline T& At(unsigned int i) { return data->at(i); }
inline T& operator[] (unsigned int i) { return data->at(i); }
inline void PrintSelf(std::ostream &o);
private:
SmartVector<T> data;
};
template<typename T>
void Collection<T>::PrintSelf(std::ostream &o)
{
o << " *** uLib Collection *** \n";
o << " n. of items = " << this->GetNumberOfItems() << "\n";
}
}
#endif // COLLECTION_H

View File

@@ -0,0 +1,89 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_COMMAINITIALIZER_H
#define U_CORE_COMMAINITIALIZER_H
namespace uLib {
// Comma Initializer template ...
// ContentT should provide operator[] and resize() methods.
// Waiting for Static interface check
template < typename ContainerT, typename ContentT >
struct CommaInitializer
{
inline explicit CommaInitializer(ContainerT *container, ContentT s)
: container(container)
{
this->index = 0;
container->resize(1);
this->container->operator[](0) = s;
}
inline CommaInitializer & operator, (ContentT s) {
this->index++;
container->resize(index + 1);
this->container->operator[](this->index) = s;
return *this;
}
ContainerT *container;
unsigned int index;
};
// Comma Initializer template for fixed array...
// ContentT should provide operator[] and size() methods.
// Waiting for Static interface check
template < typename ContainerT, typename ContentT >
struct CommaInitializerFixed
{
inline explicit CommaInitializerFixed(ContainerT *container, ContentT s)
: container(container)
{
this->index = 0;
this->container->operator[](0) = s;
}
inline CommaInitializerFixed & operator, (ContentT s) {
this->index++;
this->container->operator[](this->index) = s;
return *this;
}
ContainerT *container;
unsigned int index;
};
} // uLib
#endif // COMMAINITIALIZER_H

31
src/Core/Debug.cpp Normal file
View File

@@ -0,0 +1,31 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Debug.h"

148
src/Core/Debug.h Normal file
View File

@@ -0,0 +1,148 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_DEBUG_H
#define U_CORE_DEBUG_H
#include "ltk/ltkdebug.h"
#include "Macros.h"
#include "Types.h"
#include "Mpl.h"
#include "Vector.h"
#include <boost/any.hpp>
#include <TObject.h>
namespace uLib {
namespace detail {
struct DebugAdapterInterface {
virtual ~DebugAdapterInterface() {}
virtual void operator()(char val) {}
virtual void operator()(unsigned char val) {}
virtual void operator()(short val) {}
virtual void operator()(unsigned short val) {}
virtual void operator()(int val) {}
virtual void operator()(unsigned int val) {}
virtual void operator()(long val) {}
virtual void operator()(unsigned long val) {}
virtual void operator()(float val) {}
virtual void operator()(double val) {}
virtual void operator()(std::string val) {}
};
struct DebugAdapter {
struct AnyCastAdapterBase {
virtual ~AnyCastAdapterBase(){}
virtual void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) {}
};
template < typename T >
struct AnyCastAdapter : AnyCastAdapterBase {
void operator()(SmartPointer<DebugAdapterInterface> &ad, boost::any &val) { ad->operator()(boost::any_cast<T>(val)); }
};
struct DItem {
DItem(){}
template <typename T> DItem(std::string str, T &t) :
m_adapter(new AnyCastAdapter<T>()),
m_name(str),
m_value(t) { }
SmartPointer<AnyCastAdapterBase> m_adapter;
std::string m_name;
boost::any m_value;
};
};
} // detail
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// text ADAPTER
class DebugAdapterText : public detail::DebugAdapterInterface {
std::ostream &m_out;
public:
DebugAdapterText(std::ostream &o) : m_out(o) {}
void operator()(int val) { m_out << "debug: " << val << "\n"; }
void operator()(std::string val) { m_out << "debug: " << val << "\n"; }
};
class Debug {
typedef detail::DebugAdapterInterface AdapterInterface;
typedef SmartPointer<detail::DebugAdapterInterface> Adapter;
typedef detail::DebugAdapter::DItem DItem;
public:
template <typename T> void operator() (std::string str, T &t) { m_v.push_back(DItem(str,t)); }
void AddAdapter(AdapterInterface &ad) { m_a.push_back(Adapter(ad)); }
void Update() {
foreach(Adapter &ad, m_a) {
foreach(DItem &item, m_v) {
item.m_adapter->operator()(ad, item.m_value);
}
}
}
private:
Vector<DItem> m_v;
Vector<Adapter> m_a;
};
} // uLib
#endif // DEBUG_H

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <TTree.h>
#include "DebugArchives.h"
namespace uLib {
namespace Archive {
namespace detail {
basic_Root_Ttree_oprimitive::basic_Root_Ttree_oprimitive(const char *tree_name)
{
m_tree = new TTree(tree_name,tree_name);
}
basic_Root_Ttree_oprimitive::~basic_Root_Ttree_oprimitive()
{
m_tree->Write();
m_tree->ResetBranchAddresses();
m_tree->Delete();
}
} // detail
} // Archive
} // uLib

289
src/Core/DebugArchives.h Normal file
View File

@@ -0,0 +1,289 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_DEBUGARCHIVES_H
#define U_CORE_DEBUGARCHIVES_H
#include <boost/archive/detail/basic_pointer_iserializer.hpp>
#include <boost/archive/detail/basic_pointer_oserializer.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/polymorphic_iarchive.hpp>
#include <boost/archive/polymorphic_oarchive.hpp>
#include <boost/archive/detail/polymorphic_iarchive_route.hpp>
#include <boost/archive/detail/polymorphic_oarchive_route.hpp>
#include <boost/archive/polymorphic_text_oarchive.hpp>
#include "Archives.h"
#include "StringReader.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// FWD DECLARATIONS OF ARCHIVES //
namespace uLib {
namespace Archive {
class Root_debug_archive;
}
}
namespace boost {
namespace archive {
namespace detail {
template<class ArchiveImplementation> class polymorphic_oarchive_route;
template<class ArchiveImplementation> class polymorphic_iarchive_route;
}
}
}
namespace boost {
namespace serialization {
template <typename T> struct hrp;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES REGISTRATION //
// in Archives.h
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES IO INTERFACES //
namespace boost {
namespace archive {
namespace detail {
// DECLARE INTERFACE SPECIALIZATIONS ///////////////////////////////////////////
// With this declarations all uLib archive Implementation will use their own
// extended interface //
template <>
class interface_iarchive <uLib::Archive::Root_debug_archive> : public
uLib_interface_iarchive <uLib::Archive::Root_debug_archive> {};
} // detail
} // archive
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ARCHIVES DEFINITIONS //
namespace boost {
namespace archive {
//template<class Archive>
//inline void load_const_override(Archive & ar, const char *t ){
// typedef typename mpl::identity<detail::load_non_pointer_type<Archive> >::type typex;
// typex::invoke(ar, t);
//}
//template<class Archive, class T>
//inline void load(Archive & ar, T &t){
// // if this assertion trips. It means we're trying to load a
// // const object with a compiler that doesn't have correct
// // funtion template ordering. On other compilers, this is
// // handled below.
// // detail::check_const_loading< T >();
// typedef
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer< T >,
// mpl::identity<detail::load_pointer_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array< T >,
// mpl::identity<detail::load_array_type<Archive> >
// ,//else
// BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum< T >,
// mpl::identity<detail::load_enum_type<Archive> >
// ,//else
// mpl::identity<detail::load_non_pointer_type<Archive> >
// >
// >
// >::type typex;
// typex::invoke(ar, t);
//}
}
}
// ROOT FWD
class TTree;
///////////
namespace uLib {
namespace Archive {
namespace detail {
class basic_Root_Ttree_oprimitive
{
TTree *m_tree;
public:
basic_Root_Ttree_oprimitive(const char *tree_name);
~basic_Root_Ttree_oprimitive();
};
} // detail
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// XML FOR LOG OUTPUT PURPOUSE //
///////////////////////////////////////////////////////////////////////////
//// log data to an output stream. This illustrates a simpler implemenation
//// of text output which is useful for getting a formatted display of
//// any serializable class. Intended to be useful as a debugging aid.
class Root_debug_archive :
/* protected ? */
public boost::archive::detail::common_oarchive<Archive>
{
typedef boost::archive::detail::common_oarchive<Root_debug_archive> base;
typedef Root_debug_archive Archive;
// give serialization implementation access to this clas
friend class boost::archive::detail::interface_oarchive<Root_debug_archive>;
friend class boost::archive::save_access;
public:
// void save_override(const char *str, int v) {
// // Do not save any human decoration string //
// // basic_text_oprimitive::save(str);
// }
// template<class T>
// void save_override(T & t, BOOST_PFTO int){
// base::save_override(boost::serialization::make_nvp(NULL, t), 0);
// }
// // activate this if you want to trap non nvp objects //
// // template<class T>
// // void save_override(T & t, BOOST_PFTO int)
// // {
// // BOOST_MPL_ASSERT((boost::serialization::is_wrapper< T >));
// // // this->detail_common_oarchive::save_override(t, 0);
// // }
// template<class T>
// void save_override(const boost::serialization::nvp<T> & t, int){
// base::save_override(t, 0);
// }
// // specific overrides for attributes - not name value pairs so we
// // want to trap them before the above "fall through"
// // since we don't want to see these in the output - make them no-ops.
// void save_override(const boost::archive::object_id_type & t, int) {}
// void save_override(const boost::archive::object_reference_type & t, int) {}
// void save_override(const boost::archive::version_type & t, int) {}
// void save_override(const boost::archive::class_id_type & t, int) {}
// void save_override(const boost::archive::class_id_optional_type & t, int) {}
// void save_override(const boost::archive::class_id_reference_type & t, int){}
// void save_override(const boost::archive::class_name_type & t, int) {}
// void save_override(const boost::archive::tracking_type & t, int) {}
//public:
// Root_debug_archive(std::ostream & os, unsigned int flags = 0) :
// boost::archive::xml_oarchive_impl<log_archive>(
// os,
// flags | boost::archive::no_header
// )
// {}
};
} // Archive
} // uLib
ULIB_SERIALIZATION_REGISTER_ARCHIVE(uLib::Archive::Root_debug_archive)
#endif // U_CORE_DEBUGARCHIVES_H

117
src/Core/Export.h Normal file
View File

@@ -0,0 +1,117 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_EXPORT_H
#define U_CORE_EXPORT_H
#include <utility>
#include <cstddef> // NULL
#include <iostream>
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/serialization/extended_type_info.hpp> // for guid_defined only
#include <boost/serialization/static_warning.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/force_include.hpp>
#include <boost/serialization/singleton.hpp>
#include <boost/archive/detail/register_archive.hpp>
#include "Core/Archives.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
namespace Archive {
namespace detail {
namespace extra_detail {
template<class T>
struct guid_initializer
{
void export_guid(mpl::false_) const {
// generates the statically-initialized objects whose constructors
// register the information allowing serialization of T objects
// through pointers to their base classes.
boost::archive::detail::
instantiate_ptr_serialization((T*)0, 0,
uLib::Archive::detail::adl_tag());
}
void export_guid(mpl::true_) const {
}
guid_initializer const & export_guid() const {
BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
// note: exporting an abstract base class will have no effect
// and cannot be used to instantitiate serialization code
// (one might be using this in a DLL to instantiate code)
//BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
export_guid(boost::serialization::is_abstract< T >());
return *this;
}
};
template<typename T>
struct init_guid;
} // anonymous
} // namespace detail
} // namespace Archive
} // namespace uLib
#define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
namespace uLib { \
namespace Archive { \
namespace detail { \
namespace extra_detail { \
template<> \
struct init_guid< T > { \
static guid_initializer< T > const & g; \
}; \
guid_initializer< T > const & init_guid< T >::g = \
::boost::serialization::singleton< \
guid_initializer< T > \
>::get_mutable_instance().export_guid(); \
}}}} \
/**/
#endif // EXPORT_H

54
src/Core/Flags.h Normal file
View File

@@ -0,0 +1,54 @@
#ifndef FLAGS_H
#define FLAGS_H
#include <Core/Types.h>
namespace uLib {
template<typename Enum>
class Flags
{
int i;
public:
typedef Enum enum_type;
CONSTEXPR inline Flags(const Flags &f) : i(f.i) {}
CONSTEXPR inline Flags(Enum f) : i(f) {}
CONSTEXPR inline Flags() : i(0) {}
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
inline Flags &operator&=(int mask) { i &= mask; return *this; }
inline Flags &operator&=(uint mask) { i &= mask; return *this; }
inline Flags &operator|=(Flags f) { i |= f.i; return *this; }
inline Flags &operator|=(Enum f) { i |= f; return *this; }
inline Flags &operator^=(Flags f) { i ^= f.i; return *this; }
inline Flags &operator^=(Enum f) { i ^= f; return *this; }
CONSTEXPR inline operator int() const { return i; }
CONSTEXPR inline Flags operator|(Flags f) const { return Flags(Enum(i | f.i)); }
CONSTEXPR inline Flags operator|(Enum f) const { return Flags(Enum(i | f)); }
CONSTEXPR inline Flags operator^(Flags f) const { return Flags(Enum(i ^ f.i)); }
CONSTEXPR inline Flags operator^(Enum f) const { return Flags(Enum(i ^ f)); }
CONSTEXPR inline Flags operator&(int mask) const { return Flags(Enum(i & mask)); }
CONSTEXPR inline Flags operator&(uint mask) const { return Flags(Enum(i & mask)); }
CONSTEXPR inline Flags operator&(Enum f) const { return Flags(Enum(i & f)); }
CONSTEXPR inline Flags operator~() const { return Flags(Enum(~i)); }
CONSTEXPR inline bool operator!() const { return !i; }
inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
};
#define ULIB_OPERATORS_FOR_FLAGS(Flags) \
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
{ return f2 | f1; }
} // uLib
#endif // FLAGS_H

155
src/Core/Function.h Normal file
View File

@@ -0,0 +1,155 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_FUNCTION_H
#define U_CORE_FUNCTION_H
#include <typeinfo>
#include <boost/type_traits.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/function_types/function_type.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/function_arity.hpp>
//#include <boost/typeof/std/utility.hpp>
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
// type synthesize ( please read: boost implementation synthesize.hpp ) //
////////////////////////////////////////////////////////////////////////////////
// TODO: change this to boost implementation //
// return a reference to function ... as the boost signal signature wants
template <typename FuncT>
struct FunctionTypes {};
template <typename R, class O>
struct FunctionTypes< R(O::*)() > {
typedef R ref();
typedef R (ptr)();
typedef O obj;
};
template <typename R, class O, typename T0>
struct FunctionTypes< R(O::*)(T0) > {
typedef R ref(T0);
typedef R (ptr)(T0);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1>
struct FunctionTypes< R(O::*)(T0,T1) > {
typedef R ref(T0,T1);
typedef R (ptr)(T0,T1);
typedef O obj;
};
template <typename R, class O, typename T0, typename T1, typename T2>
struct FunctionTypes< R(O::*)(T0,T1,T2) > {
typedef R ref(T0,T1,T2);
typedef R (ptr)(T0,T1,T2);
typedef O obj;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function pointers //
template<typename Func>
struct FunctionPointer {
typedef typename boost::function_types::function_type<Func>::type Signature;
typedef typename FunctionTypes<Func>::ref SignalSignature;
enum {
arity = boost::function_types::function_arity<Func>::value,
ismfp = boost::is_member_function_pointer<Func>::value
};
typedef boost::mpl::bool_< ismfp > HasObjectType;
typedef typename FunctionTypes<Func>::obj Object;
typedef boost::function_traits< Signature > Traits;
virtual void PrintSelf( std::ostream &o ) {
o << "[fp: " << typeid(Signature).name()
<< " arity: " << arity << "]\n"; }
};
//////// generic mfp container object /////////////////////////////////////////
class GenericMFPtr {
typedef void (GenericMFPtr::*_MFPtrStub_t)();
public:
typedef _MFPtrStub_t Type;
GenericMFPtr() {}
template <typename T>
GenericMFPtr(T in) {
m_ptr = reinterpret_cast<_MFPtrStub_t>(in);
}
template <typename T>
inline bool operator == (T in) {
return m_ptr == reinterpret_cast<_MFPtrStub_t>(in);
}
inline bool operator == (const GenericMFPtr &in) {
return m_ptr == in.m_ptr;
}
Type operator()() { return m_ptr; }
_MFPtrStub_t m_ptr;
private:
};
} // uLib
#endif // FUNCTION_H

133
src/Core/Macros.h Normal file
View File

@@ -0,0 +1,133 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_MACROS_H
#define U_CORE_MACROS_H
//#ifndef HAVE_CONFIG_H
// #include "config.h"
//#endif
#include <assert.h>
#define uLibAssert(condition) assert(condition)
// Symbols visibility attribute, see: http://gcc.gnu.org/wiki/Visibility //
// http://stackoverflow.com/questions/5116333/dynamic-cast-failed-when-hidding-symbol //
#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllexport))
#else
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
#endif
#else
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((dllimport))
#else
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
#endif
#endif
#define DLL_LOCAL
#else
#if __GNUC__ >= 4
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define DLL_PUBLIC
#define DLL_LOCAL
#endif
#endif
// foreach Qt style
#ifndef foreach
#include "boost/foreach.hpp"
#define foreach(ref, list) BOOST_FOREACH(ref,list)
#endif
#define uLibVGetMacro(name,type) \
virtual inline const type Get##name() const = 0;
#define uLibVSetMacro(name,type) \
virtual inline void Set##name(const type name) = 0;
#define uLibVGetSetMacro(name,type) \
uLibVGet(name,type); \
uLibVSet(name,type);
#define uLibVRefMacro(name,type) \
virtual inline type & name() = 0;
#define uLibGetMacro(name,type) \
inline type Get##name() const { return this->m_##name; }
#define uLibConstRefMacro(name,type) \
inline const type & name() const { return this->m_##name; }
// verificare necessita' di typecast //
#define uLibSetMacro(name,type) \
inline void Set##name(type name) { this->m_##name = name; }
#define uLibGetSetMacro(name,type) \
inline type Get##name() const { return this->m_##name; } \
uLibSetMacro(name,type);
#define uLibRefMacro(name,type) \
inline type & name() { return this->m_##name; }
/* Following macros override usual branch prediction of compiler
* These are to be used in conditional statement whose result might
* be Bayesian biased:
*
* // previous_line
* if (likely(a>1)) { // block_1 }
* else { block_2 }
*
* will write the block_1 code right after previous line, without using
* compiler branch prediction for results. Otherwise
*
* // previous_line
* if (unlikely(a>1)) { // block_1 }
* else { block_2 }
*
* will write block_2 after previous_line, leaving block_1 after
* (usually after the end of the whole function! Use with care!)
*/
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#define likely(expr) __builtin_expect(!!(expr), 1)
#endif // MACROS_H

41
src/Core/Makefile.am Normal file
View File

@@ -0,0 +1,41 @@
SUBDIRS = .
include $(top_srcdir)/Common.am
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Core
library_include_HEADERS = \
Archives.h \
Array.h \
Collection.h \
Debug.h \
Export.h \
Function.h \
Macros.h \
Mpl.h \
Object.h \
ObjectProps.h \
Options.h \
Serializable.h \
Signal.h \
Singleton.h \
SmartPointer.h \
StaticInterface.h \
StringReader.h \
Types.h \
Uuid.h \
Vector.h
_CORE_SOURCES = \
Archives.cpp \
Debug.cpp \
Object.cpp \
Options.cpp \
Serializable.cpp \
Signal.cpp \
Uuid.cpp
noinst_LTLIBRARIES = libmutomcore.la
libmutomcore_la_SOURCES = ${_CORE_SOURCES}

139
src/Core/Mpl.h Normal file
View File

@@ -0,0 +1,139 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MPL_H
#define U_MPL_H
#include <boost/preprocessor.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector/vector0.hpp>
#include <boost/mpl/vector/vector10.hpp>
#include <boost/mpl/vector/vector20.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/mpl/filter_view.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/utility/enable_if.hpp>
/**
* Max size of nofold inerited capability
*/
#ifndef ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE
# define ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE 10
#endif
namespace uLib {
namespace mpl {
using namespace boost::mpl;
using namespace boost::mpl::placeholders;
//using boost::enable_if;
namespace detail {
/**
* Inerit nofold implementation, set ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE to
* desired max derivation size keeping in mind that total size accounts all
* mutiple inherited classes.
*/
template <class TypeSeq, unsigned int size>
struct inherit_nofold {};
// Horizontal repetition macro //
#define _INERIT_NOFOLD_H(hz,hn,hdata) \
BOOST_PP_COMMA_IF(hn) \
mpl::at<TypeSeq,mpl::int_<hn> >::type
// Veritical repetition macro //
#define _INERIT_NOFOLD_V(vz,vn,vdata) \
template <class TypeSeq> \
struct inherit_nofold<TypeSeq,BOOST_PP_INC(vn)> : \
BOOST_PP_REPEAT(BOOST_PP_INC(vn),_INERIT_NOFOLD_H,~) \
{};
// Multiple size declaration //
BOOST_PP_REPEAT(ULIB_CFG_MPL_INERIT_NOFOLD_MAXSIZE,_INERIT_NOFOLD_V,~)
#undef _INERIT_NOFOLD_H
#undef _INERIT_NOFOLD_V
} // detail
/**
* Build a derivation tuple from mpl type sequence.
* The same behavior can be obtained by inherit_linearly but folding derivation
* results in a hard to read debugging
*/
template <class TypeSeq>
struct inherit_nofold {
typedef detail::inherit_nofold< TypeSeq, mpl::size<TypeSeq>::type::value > type;
};
/** INHERIT LINEARLY standard utility macro */
#define ULIB_MPL_INHERIT_SEQ(_TypeList) \
uLib::mpl::inherit_linearly< _TypeList, mpl::inherit< mpl::_1, mpl::_2 > >::type
/** INHERIT NOFOLD utility macro (see struct inherit_nofold template) */
#define ULIB_MPL_INHERIT_NOFOLD_SEQ(_TypeList) \
uLib::mpl::inherit_nofold< _TypeList >::type
template< class T>
struct type {
};
template <const char *N, class T>
struct nvp {
nvp() : name(N) {}
const char *name;
typedef T type;
};
} // mpl
} // uLib
#endif // MPL_H

227
src/Core/Object.cpp Normal file
View File

@@ -0,0 +1,227 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "config.h"
#include "Object.h"
#include "Vector.h"
#include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/archive/polymorphic_binary_oarchive.hpp"
#include "boost/archive/polymorphic_binary_iarchive.hpp"
namespace uLib {
const char *Version::PackageName = PACKAGE_NAME;
const char *Version::VersionNumber = PACKAGE_VERSION;
const char *Version::Release = "x"; //SVN_REVISION;
////////////////////////////////////////////////////////////////////////////////
// Object Private //
class ObjectPrivate {
public:
struct Signal {
GenericMFPtr sigptr;
std::string sigstr;
SignalBase *signal;
};
struct Slot {
GenericMFPtr sloptr;
std::string slostr;
};
Vector<Signal> sigv;
Vector<Slot> slov;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT IMPLEMENTATION
Object::Object() :
d(new ObjectPrivate)
{}
Object::Object(const Object &copy) :
ObjectPropable(copy),
d(new ObjectPrivate(*copy.d))
{}
Object::~Object() {
delete d;
}
void Object::DeepCopy(const Object &copy)
{
// should lock to be tread safe //
memcpy(d,copy.d,sizeof(ObjectPrivate));
// ERROR! does not copy parameters ... <<<< FIXXXXX
}
void Object::SaveXml(std::ostream &os, Object &ob)
{
Archive::xml_oarchive ar(os);
ar << boost::serialization::make_nvp("Object",ob);
}
void Object::LoadXml(std::istream &is, Object &ob)
{
Archive::xml_iarchive ar(is);
ar >> boost::serialization::make_nvp("Object",ob);
}
// FINIRE
void Object::SaveConfig(std::ostream &os, int version)
{
Archive::xml_oarchive ar(os);
ObjectPropable::serialize(ar,0);
}
void Object::LoadConfig(std::istream &is, int version)
{
if(!props()) this->init_properties();
Archive::xml_iarchive ar(is);
ObjectPropable::serialize(ar,0);
}
void Object::PrintSelf(std::ostream &o) const
{
o << "OBJECT signals: ------------------\n";
Vector<ObjectPrivate::Signal>::Iterator itr;
for(itr = d->sigv.begin(); itr<d->sigv.end(); itr++)
{
o << " signal:[ " << itr->sigstr << " ]\n";
}
o << "--------------------------------------\n\n";
}
bool Object::addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name)
{
ObjectPrivate::Signal s = {fptr,std::string(name),sig};
d->sigv.push_back(s);
}
bool Object::addSlotImpl(GenericMFPtr fptr, const char *name)
{
ObjectPrivate::Slot s = {fptr,std::string(name)};
d->slov.push_back(s);
}
SignalBase *Object::findSignalImpl(const GenericMFPtr &fptr) const
{
for(int i=0; i<d->sigv.size(); ++i)
{
if(d->sigv[i].sigptr == fptr)
return d->sigv[i].signal;
}
return NULL;
}
SignalBase *Object::findSignalImpl(const char *name) const
{
std::string in(name);
for(int i=0; i<d->sigv.size(); ++i)
{
if(d->sigv[i].sigstr == in)
return d->sigv[i].signal;
}
return NULL;
}
GenericMFPtr *Object::findSlotImpl(const char *name) const
{
std::string in(name);
for(int i=0; i<d->slov.size(); ++i)
{
if(d->slov[i].slostr == in)
return &d->slov[i].sloptr;
}
return NULL;
}
// std::ostream &
// operator << (std::ostream &os, uLib::Object &ob)
// {
// uLib::Object *op = &ob;
// uLib::Archive::hrt_oarchive (os) << op;
// return os;
// }
// std::ostream &
// operator << (std::ostream &os, uLib::Object *ob)
// {
// uLib::Archive::hrt_oarchive(os) << ob;
// return os;
// }
// std::istream &
// operator >> (std::istream &is, uLib::Object &ob)
// {
// // uLib::Object *op = &ob;
// uLib::Archive::hrt_iarchive(is) >> ob;
// return is;
// }
} // uLib

222
src/Core/Object.h Normal file
View File

@@ -0,0 +1,222 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OBJECT_H
#define U_CORE_OBJECT_H
#include <iostream>
// WARNING: COPILE ERROR if this goes after mpl/vector //
//#include "Core/Vector.h"
#include "Core/Types.h"
#include "Core/Debug.h"
#include "Core/Function.h"
#include "Core/Signal.h"
#include "Core/Mpl.h"
#include "Core/Serializable.h"
#include "Core/ObjectProps.h"
#include "Core/Uuid.h"
namespace boost {
namespace archive {
class polymorphic_iarchive;
class polymorphic_oarchive;
} // archive
} // boost
namespace uLib {
class Version {
public:
static const char *PackageName;
static const char *VersionNumber;
static const char *Release;
};
////////////////////////////////////////////////////////////////////////////////
//// OBJECT ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* @brief Object class is the object base implementation for uLib Framework.
*/
class Object : public ObjectPropable
{
public:
// std::string name;
// void PrintName() { std::cout << "Ob name: " << name << "\n"; }
Object();
Object(const Object &copy);
~Object();
////////////////////////////////////////////////////////////////////////////
// PARAMETERS //
// FIXX !!!
virtual void DeepCopy(const Object &copy);
////////////////////////////////////////////////////////////////////////////
// SERIALIZATION //
template <class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
ObjectPropable::serialize(ar,version);
}
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version) {}
void SaveConfig(std::ostream &os, int version = 0);
void LoadConfig(std::istream &is, int version = 0);
static void SaveXml(std::ostream &os, Object &ob);
static void LoadXml(std::istream &is, Object &ob);
////////////////////////////////////////////////////////////////////////////
// SIGNALS //
// Qt4 style connector //
static bool connect(const Object *ob1, const char *signal_name, const Object *receiver, const char *slot_name) {
// // NOT WORKING YET //
// 1) find slot pointer from name
// SignalBase *sig = ob1->findSignal(signal_name);
// GenericMFPtr *slo = receiver->findSlot(slot_name);
// if(sig && slo)
// return Object::connect(sig,slo->operator ()(),receiver);
// else return false;
}
// Qt5 style connector //
template <typename Func1, typename Func2>
static bool connect( typename FunctionPointer<Func1>::Object *sender, Func1 sigf,
typename FunctionPointer<Func2>::Object *receiver, Func2 slof)
{
SignalBase *sigb = sender->findOrAddSignal(sigf);
typedef boost::signals2::signal<typename FunctionPointer<Func2>::SignalSignature> SigT;
ConnectSignal(sigb,slof,receiver);
}
template <typename FuncT>
static inline bool connect(SignalBase *sigb, FuncT slof, Object *receiver) {
ConnectSignal(sigb,slof,receiver);
}
template< typename FuncT >
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
addSignal(FuncT fun, const char *name) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
SignalBase *sig = NewSignal(fun);
addSignalImpl(sig,fun,name);
return (SigT *)sig;
}
template< typename FuncT>
inline bool addSlot(FuncT fun, const char *name) {
this->addSlotImpl(GenericMFPtr(fun),name);
}
template < typename FuncT >
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
findSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
return (SigT *)findSignalImpl(GenericMFPtr(fptr));
}
template < typename FuncT >
inline typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type *
findOrAddSignal(FuncT fptr)
{
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
SignalBase *sig = findSignalImpl(GenericMFPtr(fptr));
if(!sig) {
sig = NewSignal(fptr);
addSignalImpl(sig,fptr,"signal_name_to_be_implemented");
}
return (SigT *)sig;
}
inline SignalBase *
findSignal(const char *name) const
{
return findSignalImpl(name);
}
inline GenericMFPtr *
findSlot(const char *name) const
{
return findSlotImpl(name);
}
void PrintSelf(std::ostream &o) const;
inline const Object& operator = (const Object &copy)
{ this->DeepCopy(copy); return *this; }
private:
bool addSignalImpl(SignalBase *sig, GenericMFPtr fptr, const char *name);
bool addSlotImpl(GenericMFPtr fptr, const char *name);
SignalBase *findSignalImpl(const GenericMFPtr &fptr) const;
SignalBase *findSignalImpl(const char *name) const;
GenericMFPtr *findSlotImpl(const char *name) const;
friend class boost::serialization::access;
friend class ObjectPrivate;
class ObjectPrivate *d;
};
} // uLib
////////////////////////////////////////////////////////////////////////////////
//std::ostream & operator << (std::ostream &os, uLib::Object &ob);
//std::ostream & operator << (std::ostream &os, uLib::Object *ob);
//std::istream & operator >> (std::istream &is, uLib::Object &ob);
#endif // U_OBJECT_H

278
src/Core/ObjectProps.h Normal file
View File

@@ -0,0 +1,278 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_OBJECTPROPS_H
#define U_OBJECTPROPS_H
#include <boost/algorithm/string/replace.hpp>
#include <Core/Mpl.h>
#include <Core/Types.h>
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MACROS //
#define ULIB_props() \
public: struct ObjectProps; \
virtual void init_properties(); \
inline struct ObjectProps &p() { /* static const unsigned int offset = props_offset(this); */ \
/* NON FUNZIA! return * (struct ObjectProps *)(reinterpret_cast<char*>(props())+offset); */ \
return *props()->ptr<ObjectProps>(); } \
typedef uLib::mpl::bool_<true>::type propable_trait; \
public: struct DLL_PUBLIC ObjectProps
#define properties() ULIB_props()
#define default(vlaue)
#define $$ p()
#define $(_name) props_ref<_name>()
#define $_init() \
if(props(this)) return; \
props_new(this); \
uLib::detail::ObjectProps::initializer::init_object_baselist(this);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace serialization {
class access;
}
}
namespace uLib {
namespace detail {
struct ObjectProps {
/** Define a trait has_member to find if an Object is Propable*/
BOOST_MPL_HAS_XXX_TRAIT_DEF(propable_trait)
/** IsA ProbapleObject Implementation Template */
template <class T>
struct IsA : has_propable_trait<T> {};
/** Lambda to get Props member type */
template <class T>
struct props_type {
typedef typename T::ObjectProps type;
};
template <typename T>
struct get_props {
/** CFList has result but this method check for has BaseList */
typedef typename detail::TypeIntrospection::child_first<T>::type CFTypeList;
/** Filter List items that have not Propable feature */
typedef typename mpl::filter_view< CFTypeList, IsA<mpl::_> >::type FilteredCFTypeList;
/** Get Props from each Parent in Seq */
typedef typename mpl::transform_view< FilteredCFTypeList, props_type<mpl::_> >::type type;
// qui sotto ho un problema che ho temporaneamente tamponato //
// ovvero ho usato child_first_impl per ottenere la lista delle basi //
// vorrei farlo facendo un pop_back ma non va forse perche il tipo //
// non e' corretto. //
/** Get Parent list from CFTypeList */
typedef typename detail::TypeIntrospection::child_first_impl<T>::Childs CFBaseList;
/** Filter Parents that have not Propable feature */
typedef typename mpl::filter_view< CFBaseList, IsA<mpl::_> >::type FilteredCFBaseList;
};
// TODO: convert to pp const value,
// (non so se sia possibile con il dinamic casting intanto funziona cosi' )
template <typename T1, typename T2>
static unsigned int measure_offset(T1 base, T2 derived) {
return reinterpret_cast<char*>(derived) - reinterpret_cast<char*>(base);
}
struct initializer {
template <class _ObjectT>
struct lambda_init_object {
_ObjectT *o;
lambda_init_object(_ObjectT *o) : o(o) {}
template<class T> void operator()(T) {
o->T::init_properties();
}
};
/**
* This calls the internal init_properties() virtual function for each
* object parent defined in BaseList only if it is propable
*/
template <class T>
static void init_object_baselist(T *o) {
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFBaseList CFBaseList;
mpl::for_each<CFBaseList>(lambda_init_object<T>(o));
}
/**
* This calls the internal init_properties() virtual function only if
* object is propable ( implementation if not propable )
*/
template <class T>
static
typename boost::enable_if<mpl::not_<IsA<T> >,void>::type
init_object(T *o) {
; // do nothing //
}
/**
* This calls the internal init_properties() virtual function only if
* object is propable ( implementation if propable )
*/
template <class T>
static
typename boost::enable_if<IsA<T>,void>::type
init_object(T *o) {
o->init_properties();
}
};
template <class ThisClass, class Archive>
struct serialize_baselist {
ThisClass & m_object;
Archive & m_ar;
serialize_baselist(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
// T is taken fron get_props<BaseList>::FilteredPList types to get
// type_info_name that is the type name defined by Type macro
typedef typename props_type<T>::type PType;
std::string name(TypeIntrospection::access<T>::type_info::name);
boost::algorithm::replace_all(name,"::","_");
m_ar & boost::serialization::make_nvp(
name.c_str() ,
boost::serialization::base_object<PType>(m_object));
}
};
};
} // detail
struct ObjectPropsBase {
virtual ~ObjectPropsBase() {}
virtual ObjectPropsBase *copy() = 0;
template <class T> inline T *ptr() { return dynamic_cast<T*>(this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {}
};
template <class T>
struct ObjectPropsImpl :
ObjectPropsBase,
ULIB_MPL_INHERIT_NOFOLD_SEQ(typename uLib::detail::ObjectProps::get_props<T>::type)
{
typedef ObjectPropsImpl<T> ThisClass;
typedef typename uLib::detail::ObjectProps::get_props<T>::type CFList;
typedef typename uLib::detail::ObjectProps::get_props<T>::FilteredCFTypeList FilteredCFTypeList;
ObjectPropsBase *copy() { return new ThisClass(*this); }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
boost::serialization::void_cast_register<ThisClass,ObjectPropsBase>();
mpl::for_each<FilteredCFTypeList>(detail::ObjectProps::serialize_baselist<ThisClass,ArchiveT>(*this,ar));
}
};
class ObjectPropable {
ObjectPropsBase *m_props;
friend class uLib::detail::ObjectProps;
friend class boost::serialization::access;
public:
ObjectPropable() : m_props(NULL) {}
ObjectPropable(const ObjectPropable &c) { if(c.m_props) m_props = c.m_props->copy(); else m_props = NULL; }
~ObjectPropable() { if(m_props) delete m_props; }
template <class T> inline typename T::ObjectProps& props_ref() const { if(m_props) return *m_props->ptr<typename T::ObjectProps>(); else exit(1); }
template <class T> inline typename T::ObjectProps* props(T *ptr = NULL) const { if(m_props) return m_props->ptr<typename T::ObjectProps>(); else return NULL; }
protected:
ObjectPropsBase *props() const { return m_props; }
template <class T> inline void props_new(T* ptr = NULL) { if(!m_props) m_props = new ObjectPropsImpl<T>; }
/** NOT working dynamic cache casting */
template <class T> inline unsigned int props_offset(T *ptr) const
{ if(m_props) return detail::ObjectProps::measure_offset(m_props,m_props->ptr<T>()); else return -1; }
template<class ArchiveT> void serialize(ArchiveT &ar, const unsigned int version) {
if(m_props) ar & boost::serialization::make_nvp("properties",m_props);
}
public:
/**
* ObjectPropable is not directly propable itself to prevent Basclass
* duplication in inherit_nofold. And for the same reason ANY VIRTUAL BASE
* SHOULD NOT BE PROPABLE
*/
virtual void init_properties() {}
};
} // uLib
#endif // U_OBJECTPROPS_H

87
src/Core/Options.cpp Normal file
View File

@@ -0,0 +1,87 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Options.h"
#include <boost/program_options.hpp>
//class boost::program_options::error_with_option_name;
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>();
//template<> boost::program_options::typed_value<int> boost::program_options::value<int>(int *);
namespace uLib {
Options::Options(const char *str) :
m_global(str),
m_configuration("Configuration")
{}
void Options::parse_command_line(int argc, char *argv[]) {
boost::program_options::store(boost::program_options::parse_command_line(argc,argv,m_global),m_vm);
boost::program_options::notify(m_vm);
if(m_vm.count("help")) {
std::cout << "\n" << m_global << "\n";
if(m_configuration.options().size()) {
std::cout << "\n" << m_configuration << "\n\n";
}
exit(1);
}
}
void Options::parse_config_file(std::string &str)
{
this->parse_config_file(str.c_str());
}
void Options::parse_config_file(const char *fname)
{
std::ifstream is;
is.open(fname);
boost::program_options::options_description fileopt;
fileopt.add(m_global).add(m_configuration);
if(is.is_open()) {
boost::program_options::store(boost::program_options::parse_config_file(is,fileopt,true),m_vm);
boost::program_options::notify(m_vm);
}
}
bool Options::count(const char *str) const
{
return (m_vm.count(str));
}
} // uLib

179
src/Core/Options.h Normal file
View File

@@ -0,0 +1,179 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_OPTIONS_H
#define U_CORE_OPTIONS_H
#include <boost/program_options.hpp>
namespace uLib {
namespace detail {
struct Options {
/**
* Wrapper for boost program_options easy init syntax
*/
class options_description_easy_init {
typedef boost::program_options::options_description_easy_init InitClass;
InitClass m_init;
public:
options_description_easy_init(InitClass init) :
m_init(init) {}
options_description_easy_init&
operator()(const char* name,
const char* description)
{
m_init(name,description);
return *this;
}
options_description_easy_init&
operator()(const char* name,
const boost::program_options::value_semantic* s)
{
m_init(name,s);
return *this;
}
options_description_easy_init&
operator()(const char* name,
const boost::program_options::value_semantic* s,
const char* description)
{
m_init(name,s,description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const T default_value,
const char* description)
{
m_init(name,
boost::program_options::value<T>(value)->default_value(default_value),
description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const char* description)
{
assert(value);
m_init(name,
boost::program_options::value<T>(value)->default_value(*value),
description);
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value,
const T default_value)
{
m_init(name,
boost::program_options::value<T>(value)->default_value(default_value));
return *this;
}
template <typename T>
options_description_easy_init&
operator()(const char* name,
T * value)
{
assert(value);
m_init(name,
boost::program_options::value<T>(value)->default_value(*value));
return *this;
}
};
}; // Options
} // detail
class Options {
boost::program_options::options_description m_global;
boost::program_options::options_description m_configuration;
boost::program_options::positional_options_description m_posdesc;
boost::program_options::variables_map m_vm;
public:
typedef detail::Options::options_description_easy_init initType;
Options(const char *str = "Program options");
initType add_options() {
return initType(m_global.add_options());
}
initType add_config_options() {
return initType(m_configuration.add_options());
}
void add_positional_option(const char *name, int max_count) {
// TODO:
// m_posdesc(name,max_count);
}
void parse_command_line(int argc, char *argv[]);
void parse_config_file(std::string &str);
void parse_config_file(const char *fname);
template <typename T>
static inline boost::program_options::typed_value<T>* value(T *v, T dvalue) {
boost::program_options::typed_value<T> *r = boost::program_options::value<T>(v);
r->default_value(dvalue);
return r;
}
bool count(const char *str) const;
};
} // uLib
#endif // U_CORE_OPTIONS_H

95
src/Core/Serializable.cpp Normal file
View File

@@ -0,0 +1,95 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "boost/archive/polymorphic_xml_iarchive.hpp"
#include "boost/archive/polymorphic_text_oarchive.hpp"
#include "boost/archive/polymorphic_text_iarchive.hpp"
#include "boost/archive/polymorphic_binary_oarchive.hpp"
#include "boost/archive/polymorphic_binary_iarchive.hpp"
#include "Serializable.h"
using namespace uLib;
//void Serializable::SaveXml(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_xml_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadXml(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_xml_iarchive(is);
// this->Load(*xia,this);
// delete xia;
//}
//void Serializable::SaveText(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_text_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadText(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_text_iarchive(is);
// this->Load(*xia,this);
// delete xia;
//}
//void Serializable::SaveBin(std::ostream &os, const char *name)
//{
// boost::archive::polymorphic_oarchive *xoa = new boost::archive::polymorphic_binary_oarchive(os);
// this->Save(*xoa);
// delete xoa;
//}
//void Serializable::LoadBin(std::istream &is, const char *name)
//{
// boost::archive::polymorphic_iarchive *xia = new boost::archive::polymorphic_binary_iarchive(is);
// Serializable::Load(*xia,this);
// delete xia;
//}
//void Serializable::Save(boost::archive::polymorphic_oarchive &ar, Serializable *ob)
//{
// ar << boost::serialization::make_nvp("Object",ob);
//}
//void Serializable::Load(boost::archive::polymorphic_iarchive &ar, Serializable *ob)
//{
// ar >> boost::serialization::make_nvp("Object",ob);
//}

412
src/Core/Serializable.h Normal file
View File

@@ -0,0 +1,412 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_SERIALIZABLE_H
#define U_SERIALIZABLE_H
/* Serialization:
TODO:
* Problema nella serializzazione delle properties in test_archive
* implementare human readable make_hrp ... non riesco..
*/
#include <boost/serialization/access.hpp>
#include <boost/serialization/export.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/remove_if.hpp>
#include <boost/serialization/nvp.hpp>
//#include <boost/archive/xml_iarchive.hpp>
//#include <boost/archive/xml_oarchive.hpp>
//#include <boost/archive/text_iarchive.hpp>
//#include <boost/archive/text_oarchive.hpp>
//#include "boost/archive/polymorphic_iarchive.hpp"
//#include "boost/archive/polymorphic_oarchive.hpp"
#include <boost/preprocessor/comma_if.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/inc.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/tuple/to_seq.hpp>
#include "Core/Mpl.h"
#include "Core/ObjectProps.h"
#include "Core/Archives.h"
#include "Core/Export.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// BOOST SERIALIZATION ADD-ON
namespace boost {
namespace serialization {
// ACCESS 2 //
template <class T> struct access2 {};
// NON FUNZIONA ... SISTEMARE !!!! // ------------------------------------------
template<class T>
class hrp :
public wrapper_traits<const hrp< T > >
{
const char *m_name;
T *m_value;
std::string *m_str;
public:
explicit hrp(const char * name_, T &t) :
m_str(new std::string),
m_name(name_), m_value(&t) {}
const char * name() const {
return this->m_name;
}
template<class Archivex>
void save( Archivex & ar, const unsigned int /* file_version */) const {
//// ar.operator<<(const_value());
// std::stringstream ss;
// uLib::Archive::hrt_oarchive har(ss);
// har << make_nvp(m_name,*m_value);
// // (*m_str) = ss.str();
//// ar.operator << (make_nvp(m_name, ss.str());
}
template<class Archivex>
void load( Archivex & ar, const unsigned int /* file_version */) {
// ar.operator>>(value());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
template<class T>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
hrp< T > make_hrp(const char * name, T & t){
return hrp< T >(name, t);
}
#define HRP(name) \
boost::serialization::make_hrp(BOOST_PP_STRINGIZE(name), name)
} // serialization
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ULIB SERIALIZATION
namespace uLib {
#define _AR_OP(r,data,elem) data&BOOST_SERIALIZATION_BASE_OBJECT_NVP(elem);
#define NVP(data) BOOST_SERIALIZATION_NVP(data)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SERIALIZTION MACROS //
// !!! WARNING !!! INTRUSIVE SERIALIZATION IS ACTUALLY NOT WORKING FEATURE
// SO LEAVE ULIB_CFG_INTRUSIVE_SERIALIZATION NOT DEFINED
#ifdef ULIB_CFG_INTRUSIVE_SERIALIZATION_OBJECT
# define ULIB_SERIALIZABLE_OBJECT _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
# define _AR_(_name) _ULIB_DETAIL_INTRUSIVE_AR_(_name)
#else
# define ULIB_SERIALIZABLE(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
ULIB_CLASS_EXPORT_KEY(_Ob)
# define ULIB_SERIALIZE(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob)
# define ULIB_SERIALIZE_DERIVED(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZABLE_OBJECT(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
ULIB_CLASS_EXPORT_OBJECT_KEY(_Ob)
# define ULIB_SERIALIZE_OBJECT(_Ob,...) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,__VA_ARGS__)
# define ULIB_SERIALIZE_OBJECT_PROPS(_Ob) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob)
# define AR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
# define HR(_name) _ULIB_DETAIL_UNINTRUSIVE_AR_(_name)
#endif
#define ULIB_SERIALIZE_ACCESS \
friend class boost::serialization::access; \
template <class T> friend class boost::serialization::access2;
#define ULIB_CLASS_EXPORT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass)
#define ULIB_CLASS_EXPORT_OBJECT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass) \
BOOST_CLASS_EXPORT_KEY(_FullNamespaceClass::ObjectProps) \
BOOST_CLASS_EXPORT_KEY(uLib::ObjectPropsImpl<_FullNamespaceClass>)
#define _SERIALIZE_IMPL_SEQ \
(uLib::Archive::text_iarchive) \
(uLib::Archive::text_oarchive) \
(uLib::Archive::hrt_iarchive) \
(uLib::Archive::hrt_oarchive) \
(uLib::Archive::xml_iarchive) \
(uLib::Archive::xml_oarchive) \
(uLib::Archive::log_archive)
/** Solving virtual class check problem */
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(_Base,_Derived) namespace boost{ template<> struct is_virtual_base_of<_Base,_Derived>: public boost::mpl::true_ {}; }
#define _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP(r,data,elem) _ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE(elem,data)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// INTRUSIVE SERIALIZATION ( NOT WORKING YET !! ) //
#define _ULIB_DETAIL_INTRUSIVE_AR_(name) ar & BOOST_SERIALIZATION_NVP(name);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
template void Class::serialize(Archive &ar,const unsigned int);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC(data,elem);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZABLE_OBJECT \
typedef boost::mpl::bool_<true> serializable; \
typedef boost::mpl::remove_if< TypeList, IsUnSerializable >::type SerilizableTypeList; \
void PrintSerializableListId() { boost::mpl::for_each<SerilizableTypeList>(PrintTypeId()); } \
template <class ArchiveT> void serialize(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void serialize_parents(ArchiveT &ar,const unsigned int version); \
template <class ArchiveT> void save_override(ArchiveT &ar,const unsigned int version);
#define _ULIB_DETAIL_INTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
template <class ArchiveT> void _Ob::serialize(ArchiveT &ar, const unsigned int version) { \
boost::serialization::void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); \
_Ob::serialize_parents(ar,version); \
_Ob::save_override(ar,version); }\
template <class ArchiveT> void _Ob::serialize_parents(ArchiveT &ar, const unsigned int v) { \
BOOST_PP_SEQ_FOR_EACH(_AR_OP,ar,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); } \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_INTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
namespace boost { \
namespace serialization { \
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *o, const unsigned int file_version) \
{ ::new(o)_Ob(); o->init_parameters(); } }}\
template <class ArchiveT> void _Ob::save_override(ArchiveT &ar, const unsigned int version)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// UNINTRUSIVE SERIALIZATION
#define _UNAR_OP(r,data,elem) ar&boost::serialization::make_nvp(BOOST_PP_STRINGIZE(elem),boost::serialization::base_object<elem>(ob));
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(Class,Archive) \
template void boost::serialization::serialize(Archive &ar, Class &ob, const unsigned int i);
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP(r,data,elem) _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC(data,elem)
// NOTE: becouse of BOOST_PP_VARIADIC_SIZE issue of some boost macro has two
// different implementation
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; }}
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) {} \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override(ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_DERIVED(_Ob,...) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
BOOST_PP_IF(BOOST_PP_VARIADIC_SIZE((__VA_ARGS__)),BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__)));,) } \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override (ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZABLE_OBJECT(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <class ArchiveT> void serialize_parents (ArchiveT &ar, _Ob &ob, const unsigned int version); \
template <> struct access2< _Ob > { template <class ArchiveT> static void save_override (ArchiveT &ar, _Ob &ob, const unsigned int version); }; \
template <class ArchiveT> void serialize (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); \
template <class ArchiveT> void save_override (ArchiveT &ar, class _Ob::ObjectProps &ob, const unsigned int version); }}
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_OBJECT(_Ob,...) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize_parents(ArchiveT &ar, _Ob &ob, const unsigned int v) { \
/* PP serialize */ BOOST_PP_SEQ_FOR_EACH(_UNAR_OP,ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))); \
/* MPL serialize */ /*uLib::mpl::for_each<_Ob::BaseList>(uLib::detail::Serializable::serialize_baseobject<_Ob,ArchiveT>(ob,ar) );*/ } \
template<class ArchiveT> inline void load_construct_data(ArchiveT & ar, _Ob *ob, const unsigned int file_version) { \
::new(ob)_Ob(); uLib::detail::ObjectProps::initializer::init_object(ob); } \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob &ob, const unsigned int version) { \
void_cast_register<_Ob,_Ob::BaseClass>(static_cast<_Ob *>(NULL),static_cast<_Ob::BaseClass *>(NULL)); /*fix*/ \
serialize_parents(ar,ob,version); \
access2< _Ob >::save_override (ar,ob,version); } }}\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_SPECIALIZE_IS_VIRTUAL_BASE_OP,_Ob,BOOST_PP_TUPLE_TO_SEQ((__VA_ARGS__))) \
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob,_SERIALIZE_IMPL_SEQ)\
template <class ArchiveT> void boost::serialization::access2< _Ob >::save_override(ArchiveT &ar, _Ob &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_PROPS(_Ob) \
namespace boost { namespace serialization { \
template <class ArchiveT> void serialize (ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version) { \
save_override (ar,ob,version); } }}\
BOOST_PP_SEQ_FOR_EACH(_ULIB_DETAIL_UNINTRUSIVE_SERIALIZE_FUNC_OP,_Ob::ObjectProps,_SERIALIZE_IMPL_SEQ)\
ULIB_CLASS_EXPORT_IMPLEMENT(_Ob::ObjectProps) \
ULIB_CLASS_EXPORT_IMPLEMENT(uLib::ObjectPropsImpl<_Ob>) \
template <class ArchiveT> void boost::serialization::save_override(ArchiveT &ar, _Ob::ObjectProps &ob, const unsigned int version)
#define _ULIB_DETAIL_UNINTRUSIVE_AR_(name) boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name),ob.name)
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
namespace detail {
struct Serializable {
/**
* Serializable trait to check if an object type is serializable.
* This only works if UNINTRUSIVE SERIALIZATION is applyed; in intrusive
* cases a has_serialize trait should be implemented
*/
template <class T>
struct serializable_trait : mpl::bool_<false> {};
/**
* IsA Serializable Implementation Template
*/
template <class T>
struct IsA : serializable_trait<T> {};
template <class ThisClass, class Archive>
struct serialize_baseobject {
ThisClass & m_object;
Archive & m_ar;
serialize_baseobject(ThisClass &o, Archive &ar) : m_object(o), m_ar(ar) {}
template <class T> void operator()(T &o) {
m_ar & boost::serialization::make_nvp(
typeid(T).name() ,
boost::serialization::base_object<T>(m_object));
}
};
};
} // detail
struct Serializable {
friend class boost::serialization::access;
template <class T> friend class boost::serialization::access2;
virtual ~Serializable() {}
protected:
};
} // uLib
#endif // U_SERIALIZABLE_H

28
src/Core/Signal.cpp Normal file
View File

@@ -0,0 +1,28 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/

168
src/Core/Signal.h Normal file
View File

@@ -0,0 +1,168 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SIGNAL_H
#define U_CORE_SIGNAL_H
#include <boost/typeof/typeof.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/signals2/slot.hpp>
#include <boost/signals2/signal_type.hpp>
#include "Function.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Signals macro //
#define default(vlaue)
#define slots
#define signals /*virtual void init_signals();*/ public
#define emit
#define SLOT(a) BOOST_STRINGIZE(a)
#define SIGNAL(a) BOOST_STRINGIZE(a)
#define _ULIB_DETAIL_SIGNAL_EMIT(_name,...) \
static BOOST_AUTO(sig,this->findOrAddSignal(&_name)); \
sig->operator()(__VA_ARGS__);
/**
* Utility macro to implement signal emission implementa una delle seguenti:
*
* // metodo standard con cast //
* SignalBase * sig = this->findSignal((void (Ob1::*)(void))&Ob1::V0);
* typedef Signal<void()>::type SigT;
* if(sig) reinterpret_cast<SigT*>(sig)->operator()();
*
* // cast automatico //
* static BOOST_AUTO(sig,this->findOrAddSignal(&Ob1::V0));
* sig->operator()();
*/
#define ULIB_SIGNAL_EMIT(_name,...) _ULIB_DETAIL_SIGNAL_EMIT(_name,__VA_ARGS__)
namespace uLib {
// A boost::signal wrapper structure ///////////////////////////////////////////
// TODO ...
typedef boost::signals2::signal_base SignalBase;
template <typename T>
struct Signal {
typedef boost::signals2::signal<T> type;
};
////////////////////////////////////////////////////////////////////////////////
namespace detail {
template <typename FuncT, int arity>
struct ConnectSignal {};
template <typename FuncT>
struct ConnectSignal< FuncT, 0 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(slof);
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 1 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 2 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 3 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 4 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3));
}
};
template <typename FuncT>
struct ConnectSignal< FuncT, 5 > {
static void connect(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver) {
typedef typename Signal<typename FunctionPointer<FuncT>::SignalSignature>::type SigT;
reinterpret_cast<SigT*>(sigb)->connect(boost::bind(slof,receiver,_1,_2,_3,_4));
}
};
} // detail
template <typename FuncT>
SignalBase *NewSignal(FuncT f) {
// seems to work wow !
return new Signal<void()>::type;
}
template <typename FuncT>
void ConnectSignal(SignalBase *sigb, FuncT slof, typename FunctionPointer<FuncT>::Object *receiver)
{
detail::ConnectSignal< FuncT, FunctionPointer<FuncT>::arity >::connect(sigb,slof,receiver);
}
} // uLib
#endif // SIGNAL_H

46
src/Core/Singleton.h Normal file
View File

@@ -0,0 +1,46 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SINGLETON_H
#define U_CORE_SINGLETON_H
#include <boost/serialization/singleton.hpp>
namespace uLib {
template <typename T>
struct Singleton : boost::serialization::singleton<T> {
};
}
#endif // SINGLETON_H

111
src/Core/SmartPointer.h Normal file
View File

@@ -0,0 +1,111 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_SMARTPOINTER_H
#define U_CORE_SMARTPOINTER_H
namespace uLib {
template <typename T>
class SmartPointer {
typedef T element_type;
public:
explicit
SmartPointer(T* ptr = NULL) : m_counter(0) {
if(!ptr) ptr = new T;
if (ptr) m_counter = new ReferenceCounter(ptr);
}
// TakeReference //
SmartPointer(T &ref) : m_counter(new ReferenceCounter(&ref,0)) { }
SmartPointer(const SmartPointer& copy) throw () {
acquire(copy.m_counter);
}
SmartPointer(SmartPointer * copy) throw () {
acquire(copy->m_counter);
}
virtual ~SmartPointer() { release(); }
SmartPointer & operator=(const SmartPointer& copy) {
if (this != &copy)
{
release();
acquire(copy.m_counter);
}
return *this;
}
T & operator*() const throw () { return *m_counter->ptr; }
T * operator->() const throw () { return m_counter->ptr; }
T * get() const throw () {
return m_counter ? m_counter->ptr : 0; }
bool unique() const throw () {
return (m_counter ? m_counter->count == 1 : true); }
private:
struct ReferenceCounter
{
ReferenceCounter(T* ptr = 0, unsigned c = 1) : ptr(ptr), count(c) { }
T* ptr;
unsigned count;
} * m_counter;
// increment the count
void acquire(ReferenceCounter* c) throw ()
{
m_counter = c;
if (c && c->count>0) ++c->count;
}
// decrement the count, delete if it is 0
void release() {
if (m_counter) {
if (--m_counter->count == 0) {
delete m_counter->ptr;
}
if (m_counter->count <= 0) {
delete m_counter;
m_counter = NULL;
}
}
}
};
}
#endif // SMARTPOINTER_H

View File

@@ -0,0 +1,77 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_STATICINTERFACE_H
#define U_CORE_STATICINTERFACE_H
namespace uLib {
#define MAKE_TRAITS ; // TODO
#define uLibCheckFunction(class_name,name,out, ... ) \
{ out (class_name::*x)(__VA_ARGS__) = &class_name::name; (void) x; }
#define uLibCheckConstFunction(class_name,name,out,...) \
{ out (class_name::*x)(__VA_ARGS__) const = &class_name::name; (void) x; }
#define uLibCheckMember(class_name,name,type) \
{ class_name x; type *y = &x.name; (void) y; }
namespace Interface {
// EXAMPLE :
//template <class T> struct Voxel {
// MAKE_TRAITS;
// template<class Self> void check_structural() {
// { float & (Self::*x)() = &Self::Density; (void) x; }
// { int & (Self::*x)() = &Self::TrackCount; (void) x; }
// }
//protected:
// ~Voxel() {}
//};
template <class T, class SI>
static inline void IsA() {
(void) ((void (SI::*)()) &SI::template check_structural<T>);
}
// not working
//template <class T, class SI>
//struct StaticIsA {
// void test() {
// static const void (SI::*x)() = SI::template check_structural<T>;
// }
//};
}
}
#endif // STATICINTERFACE_H

94
src/Core/StringReader.h Normal file
View File

@@ -0,0 +1,94 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_STRINGREADER_H
#define U_CORE_STRINGREADER_H
#include <istream>
#include <algorithm>
#include "Core/Vector.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
// RIPENSARE COMPLETAMENTE !!!
namespace uLib {
struct StringReader {
std::istream & m_is;
StringReader(std::istream &is) : m_is(is) {}
void ReadString(const char *str) {
// // clean compared string //
// char chars[] = " \t\n";
// for (unsigned int i = 0; i < strlen(chars); ++i)
// { cmps.erase (std::remove(str.begin(), str.end(), chars[i]), str.end()); }
// SISTEMARE !!!
int pos = 0;
char c;
while( pos < strlen(str) ) {
while( IsEscape(str[pos])) pos++;
if ( pos >= strlen(str) ) break;
while( IsEscape(c = m_is.get()) );
if (c == str[pos] ) pos++;
else pos = 0;
}
}
static inline bool IsEscape(char c){
const char *escapes = " \r\n\t";
for ( int i = 0 ; i < 4 ; ++i) {
if(c == escapes[i]) return true;
}
return false;
}
};
template <typename T>
inline StringReader & operator >> (StringReader &isr, T &t) {
isr.m_is >> t;
return isr;
}
inline StringReader & operator >> (StringReader &isr, const char *str) {
isr.ReadString(str);
return isr;
}
} // uLib
#endif // STRINGREADER_H

28
src/Core/Timer.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef TIMER_H
#define TIMER_H
#include <sys/time.h>
////////////////////////////////////////////////////////////////////////////////
// Timer /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Timer
{
public:
void Start() { gettimeofday(&m_start, NULL); }
double StopWatch() {
gettimeofday(&m_end, NULL);
double timeSec = m_end.tv_sec - m_start.tv_sec +
(m_end.tv_usec - m_start.tv_usec)*1E-6;
return timeSec;
}
private:
struct timeval m_start, m_end;
};
#endif // TIMER_H

276
src/Core/Types.h Normal file
View File

@@ -0,0 +1,276 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_TYPES_H
#define U_CORE_TYPES_H
#include <iostream>
#include <typeinfo>
#include <boost/preprocessor.hpp>
#include <ltk/ltktypes.h>
#include "Core/Macros.h"
#include "Core/Mpl.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
namespace detail {
struct TypeIntrospection {
// BOOST IMPL //
BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
// SFINAE IMPL //
/*
template <typename T>
struct has_type_info {
typedef char yes[1];
typedef char no[2];
template <typename U> static yes& test(typename U::type_info::BaseList*);
template <typename > static no& test(...);
// struct apply {
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
typedef boost::mpl::bool_<value> type;
// };
};
*/
/** IsA Introspectable Object Implementation Template */
template <class T>
struct IsIntrospectable : has_type_info<T> {};
template <typename T> struct access {
typedef typename T::type_info type_info;
};
template <typename T>
struct child_first_impl {
template <class T1, bool cond>
struct lambda_CFList_f {
typedef mpl::vector<T1> type;
};
template <class T1>
struct lambda_CFList_f<T1,true> {
// typedef typename T1::type_info::CFList type;
typedef typename access<T1>::type_info::CFList type;
};
template <class T1>
struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
/** Transforms all Base Type into proper CFList */
typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
, lambda_CFList<mpl::_>
>::type CFListSeq;
/** Folds each CFList into a new sequence */
typedef typename mpl::fold< CFListSeq
, mpl::vector<>
, mpl::copy< mpl::_1
, mpl::back_inserter<mpl::_2>
>
>::type Childs;
/** Add This Class to final CFList sequence */
typedef typename mpl::copy< Childs
, mpl::back_inserter< mpl::vector<T> >
>::type type;
};
/**
* Tests if T has a member called type_info then compile type CFList
*/
template <typename T>
struct child_first : mpl::if_< has_type_info<T>
, child_first_impl<T>
, mpl::vector<>
>::type {};
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE ADAPTERS // FINIRE !!!
//#define _REPETITION_V(vz,vn,vdata)
//template < class TypeList >
//class TypeAdapterInputInterface {
// virtual ~TypeAdapterInputInterface() {}
//public:
// virtual void operator()(int val) {}
// virtual void operator()(std::string val) {}
//};
} // detail ////////////////////////////////////////////////////////////////////
#define CONSTEXPR BOOST_CONSTEXPR
typedef ltk::Real_t Real_t;
typedef ltk::Id_t Id_t;
//typedef ltk::Size_t Size_t;
typedef ltk::Pointer_t Pointer_t;
typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
//--- bit manipulation ---------------------------------------------------------
#ifndef BIT
#define BIT(n) (1ULL << (n))
#endif
#ifndef SETBIT
#define SETBIT(n,i) ((n) |= BIT(i))
#endif
#ifndef CLRBIT
#define CLRBIT(n,i) ((n) &= ~BIT(i))
#endif
#ifndef TESTBIT
#define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
#endif
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE INTROSPECTION FOR OBJECTS //
#define uLibTypeMacro(thisClass,...) \
\
/* Friendship detail for accessing introspection */ \
template <typename> friend class uLib::detail::TypeIntrospection::access; \
\
/* type info structure*/ public: \
/* in GCC 4.8 must be public or dynamic_cast wont work */ \
struct type_info { \
/*WARNING: -std=c++0x required for this! */ \
constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \
typedef thisClass ThisClass; \
typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \
typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
}; \
\
public: \
typedef type_info::BaseClass BaseClass; \
virtual const char *type_name() const { return type_info::name; } \
/* Object Props fwd declaration*/ \
struct ObjectProps; \
/**/
/**
* TypeList inheritance introspection
*/
struct TypeIntrospection {
template <typename T>
struct child_first : detail::TypeIntrospection::child_first<T> {};
};
// SISTEMARE //
struct PrintTypeId {
template <class T>
void operator()(T) const
{ std::cout << typeid(T).name() << std::endl; }
template <typename SeqT>
static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
template <typename Class>
static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
};
} // uLib
#endif // U_CORE_TYPES_H

45
src/Core/Uuid.cpp Normal file
View File

@@ -0,0 +1,45 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Uuid.h"
#include "Singleton.h"
using namespace uLib;
uLib::uuid_t uLib::uLib_dns_uuid;
TypeRegister* TypeRegister::s_Instance = new TypeRegister();
TypeRegister::TypeRegister() :
BaseClass(uLib_dns_uuid)
{}
TypeRegister * TypeRegister::Controller() {
return TypeRegister::s_Instance;
}

163
src/Core/Uuid.h Normal file
View File

@@ -0,0 +1,163 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_UUID_H
#define U_CORE_UUID_H
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/name_generator.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "Core/Mpl.h"
#include "Core/Vector.h"
#include "Core/Object.h"
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Object Registration //
typedef boost::uuids::uuid uuid_t;
extern uuid_t uLib_dns_uuid;
template < typename T >
class type_id : public boost::uuids::uuid {
public:
type_id() :
m_size(sizeof(T)),
uuid(boost::uuids::name_generator(uLib_dns_uuid)(typeid(T).name()))
{
std::cout << "Request for register new type\n" <<
"name: " << typeid(T).name() << "\n" <<
"uuid: " << to_string(*this) << "\n";
}
explicit type_id(boost::uuids::uuid const& u)
: boost::uuids::uuid(u) {}
operator boost::uuids::uuid() {
return static_cast<boost::uuids::uuid&>(*this);
}
operator boost::uuids::uuid() const {
return static_cast<boost::uuids::uuid const&>(*this);
}
unsigned int size() const { return m_size; }
private:
unsigned int m_size;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TYPE REGISTER //
namespace detail {
class TypeRegister {
typedef boost::uuids::name_generator IDGen_t;
public:
struct RegisterEntry {
uuid_t id;
int size;
};
TypeRegister(uuid_t const &dns) :
gen(dns) {}
template< typename T >
RegisterEntry * AddType(T *t = NULL) {
RegisterEntry en = { gen(typeid(T).name()), sizeof(T) };
for(int i=0; i < m_registry.size(); ++i)
if(en.id == m_registry[i].id) return &(m_registry[i]);
m_registry.push_back(en);
return &m_registry.back();
}
void PrintSelf(std::ostream &o) {
std::cout << "RegisterController: \n";
for (int i=0; i<m_registry.size(); ++i)
o << "type [" << i << "]: "
<< to_string(m_registry[i].id) << " "
<< m_registry[i].size << "\n";
o << "\n";
}
private:
IDGen_t gen;
Vector<RegisterEntry> m_registry;
};
} // detail
class TypeRegister : public detail::TypeRegister {
public:
typedef detail::TypeRegister BaseClass;
typedef detail::TypeRegister::RegisterEntry Entry;
static TypeRegister* Controller();
private:
TypeRegister(); // Blocks constructor
static TypeRegister *s_Instance; // Singleton instance
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT REGISTER //
} // uLib
#endif // UUID_H

178
src/Core/Vector.h Normal file
View File

@@ -0,0 +1,178 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_VECTOR_H
#define U_CORE_VECTOR_H
#include <vector>
#include <iostream>
#include <Core/StaticInterface.h>
#include <Core/SmartPointer.h>
#include <Core/CommaInitializer.h>
namespace uLib {
// Vector Implemetation ... wraps std::vector
template <typename T>
class Vector : public std::vector<T, std::allocator<T> >
{
typedef std::vector< T,std::allocator<T> > BaseClass;
typedef std::allocator<T> Allocator;
public:
typedef T TypeData;
typedef __gnu_cxx::__normal_iterator<T*, BaseClass > Iterator;
typedef __gnu_cxx::__normal_iterator<const T*, BaseClass> ConstIterator;
typedef CommaInitializer< Vector<T> , T > VectorCommaInit;
Vector(unsigned int size) : BaseClass(size) {}
Vector(unsigned int size, T &value) : BaseClass(size,value) {}
Vector() : BaseClass(0) {}
inline VectorCommaInit operator <<(T scalar) {
return VectorCommaInit(this, scalar);
}
inline void PrintSelf(std::ostream &o);
void remove_element(unsigned int index) {
std::swap(this->at(index),this->back());
this->pop_back();
}
void remove_element(T &t) {
std::swap(t, this->back());
this->pop_back();
}
};
template<typename T>
void Vector<T>::PrintSelf(std::ostream &o)
{
o << " *** uLib Vector *** \n";
o << " n. of items = " << this->size() << "\n";
for(int i=0; i< this->size(); ++i)
o << (T)this->at(i) << " ";
o << "\n";
}
template <typename T>
std::ostream & operator << (std::ostream &o, const Vector<T> &v) {
for(int i=0; i< v.size(); ++i)
o << (T)v.at(i) << " ";
o << "\n";
return o;
}
template <typename T>
std::ofstream & operator << (std::ofstream &o, const Vector<T> &v) {
for(int i=0; i< v.size(); ++i)
o << (T)v.at(i) << " ";
return o;
}
template < typename T >
std::istream & operator >> (std::istream &is, Vector<T> &v) {
T value;
while( is >> value ) {
if(is.fail()) v.push_back(0);
else v.push_back( value );
}
return is;
}
// Smart pointer Vector Implementation //
template <typename T>
class SmartVector : public SmartPointer< Vector<T> > {
typedef SmartPointer< Vector<T> > Base;
public:
SmartVector() : Base(new Vector<T>()) { }
SmartVector( const SmartVector &copy) : Base(copy) { }
SmartVector(unsigned int size) : Base(new Vector<T>((int)size)) { }
virtual ~SmartVector() {}
T& operator[](int p) {
return Base::get()->at(p);
}
void swap_elements(unsigned int first, unsigned int second) {
std::swap(Base::get()->at(first),Base::get()->at(second));
}
void remove_element(unsigned int index) {
std::swap(Base::get()->at(index),Base::get()->back());
Base::get()->pop_back();
}
void remove_element(T &t) {
std::swap(t, Base::get()->back());
Base::get()->pop_back();
}
};
// ------ Utils ------------------------------------------------------------- //
// RIFARE con iteratore !
template <typename _Tp, class _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
_Tp it = _it;
_Tp end = _end-1;
for(it; it != end;)
{
if (_comp(*it,value)) ++it;
else if(_comp(*end,value)) std::swap(*it,*end--);
else --end;
}
return it - _it;
}
} // uLib
#endif // VECTOR_H

View File

@@ -0,0 +1,88 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Core/Object.h>
#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include "testing-prototype.h"
using namespace boost::accumulators;
using namespace boost;
using namespace boost::accumulators;
typedef accumulator_set<double, features<tag::density> > acc;
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
template <typename T>
class data_filler
{
public:
data_filler(){}
T operator()() { return rand()/(T)RAND_MAX; }
};
int main(int argc, char** argv)
{
//create some random data
std::vector<double> data(100);
std::generate(data.begin(), data.end(), data_filler<double>());
int c = data.size();//cache size for histogramm.
//create an accumulator
acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);
//fill accumulator
for (int j = 0; j < c; ++j)
{
myAccumulator(data[j]);
}
histogram_type hist = density(myAccumulator);
double total = 0.0;
for( int i = 0; i < hist.size(); i++ )
{
std::cout << "Bin lower bound: " << hist[i].first << ", Value: " << hist[i].second << std::endl;
total += hist[i].second;
}
std::cout << "Total: " << total << std::endl; //should be 1 (and it is)
return 0;
}

View File

@@ -0,0 +1,64 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Options.h"
#include "Core/Singleton.h"
#include "testing-prototype.h"
using namespace uLib;
struct A : Object {
A() : a(0) {}
int a;
};
int main(int argc, char **argv)
{
BEGIN_TESTING(Boost Mock);
A &a = Singleton<A>::get_mutable_instance();
a.a = 5552368;
const A &aa = Singleton<A>::get_const_instance();
std::cout << a.a << "\n";
std::cout << aa.a << "\n";
TEST1( a.a == 5552368 );
TEST1( aa.a == 5552368 );
END_TESTING;
}

View File

@@ -0,0 +1,33 @@
# TESTS
set( TESTS
SmartVectorTest
VectorTest
ObjectFlagsTest
ObjectParametersTest
ObjectCopyTest
StaticInterfaceTest
CommaInitTest
DebugTTreeDumpTest
BoostTest
BoostAccumulatorTest
PropertiesTest
SignalTest
SerializeTest
SerializeDreadDiamondTest
DreadDiamondParameters
ObjectPropableTest
UuidTest
TypeIntrospectionTraversal
OptionsTest
)
set(LIBRARIES
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${ROOT_LIBRARIES}
)
uLib_add_tests(${uLib-module})

View File

@@ -0,0 +1,57 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include<stdio.h>
#define test_print(file,str,...) \
printf(str,__VA_ARGS__)
using namespace uLib;
int main()
{
BEGIN_TESTING( Comma Init );
Vector<int> test;
test << 1,2,3,4,5;
test.PrintSelf(std::cout);
test_print(stdout,"ciao %d \n",5);
printf("ciao\n");
END_TESTING;
}

View File

@@ -0,0 +1,118 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Debug.h"
#include <boost/any.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/container.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/include/push_back.hpp>
#include <Rtypes.h>
#include <TFile.h>
#include <TObject.h>
#include <TTree.h>
#include <TApplication.h>
#include <TBrowser.h>
using namespace uLib;
class DebugAdapterTTree : public detail::DebugAdapterInterface {
TTree *m_tree;
public:
DebugAdapterTTree(const char *name) : m_tree(new TTree(name,name)) {}
~DebugAdapterTTree() { delete m_tree; }
void operator()(int val) {
std::cout << "debugger 2 prints: " << val << "\n";
}
};
int main(int argc, char **argv)
{
{
Debug debug;
DebugAdapterText adapter(std::cout);
DebugAdapterTTree treead("test");
debug.AddAdapter(adapter);
debug.AddAdapter(treead);
int a = 5552368;
debug("a",a);
std::string str = "ciao";
debug("str",str);
debug.Update();
}
// TestTObject *test = new TestTObject;
TFile *file = new TFile("test_file.root","RECREATE");
file->cd();
TTree *tree = new TTree;
// tree->Branch("test",&test);
// for(int i=0;i<10;++i) {
// test->a = i;
// test->b = -i;
// tree->Fill();
// }
tree->Write();
gApplication = new TApplication("My ROOT Application", &argc, argv);
TBrowser *tbr = new TBrowser("test");
tbr->Show();
gApplication->Run();
return 0;
}

View File

@@ -0,0 +1,80 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include "testing-prototype.h"
#include "Core/Object.h"
#include "Math/Dense.h"
#include "Core/Mpl.h"
using namespace uLib;
//////////////////////////////////////////////////////////////////////////////
int main() {
}

76
src/Core/testing/Flags.h Normal file
View File

@@ -0,0 +1,76 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CORE_FLAGS_H
#define U_CORE_FLAGS_H
namespace uLib {
template<typename T> class Flags
{
T i;
public:
typedef T EnumT;
inline Flags(const Flags &f) : i(f.i) {}
inline Flags() : i((T)0) {}
inline Flags(T f) : i(f) {}
inline Flags &operator=(const Flags &f) { i = f.i; return *this; }
inline Flags &operator&=(T mask) { i &= mask; return *this; }
inline Flags &operator|=(const Flags f) { i |= f.i; return *this; }
inline Flags &operator|=(const T f) { i |= f; return *this; }
inline Flags &operator^=(const Flags f) { i ^= f.i; return *this; }
inline Flags &operator^=(const T f) { i ^= f; return *this; }
inline Flags operator|(const Flags f) const { return Flags(i | f.i); }
inline Flags operator|(const T f) const { return Flags(i | f); }
inline Flags operator^(const Flags f) const { return Flags(i ^ f.i); }
inline Flags operator^(const T f) const { return Flags(i ^ f); }
inline Flags operator&(const Flags f) const { return Flags(i & f.i); }
inline Flags operator&(const T f) const { return Flags(i & f); }
inline Flags operator~() const { return Flags(~i); }
inline bool operator !() const { return !i; }
inline bool testFlag(const T f) const
{ return (i & f) == f && (f != 0 || i == f ); }
// inline bool operator==(const T f) const { return i==f; }
inline T operator()() { return i; }
inline operator T() const { return i; }
};
typedef Flags<unsigned short> Flags2B;
typedef Flags<unsigned int> Flags4B;
typedef Flags<unsigned long> Flags8B;
} // uLib
#endif // FLAGS_H

View File

@@ -0,0 +1,38 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
# if HAVE_CHECK
TESTS = SmartPointerTest \
SmartVectorTest \
VectorTest \
ObjectFlagsTest \
ObjectParametersTest \
ObjectCopyTest \
StaticInterfaceTest \
CommaInitTest \
DebugTTreeDumpTest \
BoostTest \
BoostAccumulatorTest \
PropertiesTest \
SignalTest \
SerializeTest \
SerializeDreadDiamondTest \
DreadDiamondParameters \
ObjectPropableTest \
TypeIntrospectionTraversal \
OptionsTest
# UuidTest
# else
# TEST =
# endif
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la $(AM_LIBS_BOOST) $(AM_LIBS_ROOT)
check_PROGRAMS = $(TESTS)
all: $(TESTS)

View File

@@ -0,0 +1,50 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(ObjectParameters);
END_TESTING;
}

View File

@@ -0,0 +1,69 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Core/Object.h"
using namespace uLib;
//class Derived : public uLib::Object {
//public:
// Derived(int flags) : uLib::Object(flags) {}
// enum Flags {
// a = 1<<0, // 1
// b = 1<<1, // 2
// c = 1<<2 // 4
// };
//};
int main() {
BEGIN_TESTING(ObjectFlags);
// Object o(2);
// o.flags() = 4;
// o.flags() |= 1;
// TEST1( o.flags() == 5);
// o.flags() &= 1;
// TEST1( o.flags() == 1);
// TEST1( o.flags().testFlag(1) );
// Derived d( Derived::a | Derived::b);
// d.flags() = Derived::c;
// d.flags() |= Derived::a;
// TEST1( d.flags() == Derived::a | Derived::c);
// d.flags() &= 1;
// TEST1( d.flags() == Derived::a);
// TEST1( d.flags().testFlag(Derived::a) );
END_TESTING
}

View File

@@ -0,0 +1,61 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "boost/archive/xml_oarchive.hpp"
#include "boost/archive/xml_iarchive.hpp"
#include "Core/Object.h"
#include "Math/Dense.h"
#include "testing-prototype.h"
using namespace uLib;
int main() {
}

View File

@@ -0,0 +1,237 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Types.h"
#include "Core/Object.h"
#include "Core/ObjectProps.h"
#include "Core/StringReader.h"
#include "Math/Dense.h"
#include "boost/archive/text_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include "testing-prototype.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// STRUCTURES //
struct A : virtual Object {
uLibTypeMacro(A, Object)
properties() {
int p_a;
Vector3f p_3f;
};
int m_a;
};
void A::init_properties() {
$_init();
$$.p_a = 0;
$$.p_3f << 1,2,3;
}
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A, Object) { ar & AR(m_a); }
ULIB_SERIALIZE_OBJECT_PROPS(A) { ar & AR(p_a) & AR(p_3f); }
struct B : A {
uLibTypeMacro(B,A)
properties() {
std::string p;
};
B() : m_b(324) {}
int m_b;
};
void B::init_properties() {
$_init();
$$.p = "ciao";
}
ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B,A) { ar & AR(m_b); }
ULIB_SERIALIZE_OBJECT_PROPS(B) { ar & AR(p); }
struct C {
int m_c;
std::string m_str;
};
ULIB_SERIALIZABLE(C)
ULIB_SERIALIZE(C) { ar & AR(m_c) & AR(m_str); }
struct D : virtual Object, B {
uLibTypeMacro(D,Object,B)
properties() {
C p_c;
};
};
void D::init_properties() {
$_init();
$$.p_c.m_c = 1234;
}
ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D,Object) {}
ULIB_SERIALIZE_OBJECT_PROPS(D) {
ar & AR(p_c);
}
class E : public C, public D {
uLibTypeMacro(E,D,C)
public:
E() : m_Ea(5552368) {}
int m_Ea;
};
ULIB_SERIALIZABLE_OBJECT(E)
ULIB_SERIALIZE_OBJECT(E,C,D) {
ar & AR(m_Ea);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TESTS //
int test_xml_direct() {
// TEST ARCHIVE SAVE AND LOAD direct //
E o; o.init_properties();
o.$$.p_c.m_str = "works";
{
std::ofstream file("test.xml");
Archive::xml_oarchive ar(file);
ar << NVP(o);
}
o.$$.p_c.m_str = "hola";
{
std::ifstream file("test.xml");
Archive::xml_iarchive ar(file);
ar >> NVP(o);
}
std::cout << o.$$.p_c.m_str << "\n";
return ( o.$$.p_c.m_str == "works" );
}
int test_xml_pointer() {
// TEST ARCHIVE SAVE AND LOAD from pointer //
E *o = new E; o->init_properties();
o->$$.p_c.m_str = "works";
{
std::ofstream file("test.xml");
Archive::xml_oarchive ar(file);
ar << NVP(o);
}
o->$$.p_c.m_str = "hola";
{
std::ifstream file("test.xml");
Archive::xml_iarchive ar(file);
ar >> NVP(o);
}
std::cout << o->$$.p_c.m_str << "\n";
return ( o->$$.p_c.m_str == "works" );
}
int test_xml_objsave() {
// TEST SELF SAVE
E o; o.init_properties();
o.$(B).p = "works";
{
std::ofstream file("test.xml");
Object::SaveXml(file,o);
}
o.$(B).p = "hola";
{
std::ifstream file("test.xml");
Object::LoadXml(file,o);
}
std::cout << o.$(B).p << "\n";
return ( o.$(B).p == "works" );
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MAIN //
int main()
{
BEGIN_TESTING(PropableTest);
TEST1( test_xml_direct() );
TEST1( test_xml_pointer() );
TEST1( test_xml_objsave() );
END_TESTING;
}

View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Options.h"
#include "testing-prototype.h"
using namespace uLib;
int main(int argc, char **argv)
{
BEGIN_TESTING(Boost ProgramOptions);
std::string optfile("configuration.ini");
int a = 0;
int b = 0;
Options opt;
opt.add_options()
("help", "printout help")
("value",&a,"value")
("config",&optfile,"config_file");
opt.add_config_options()
("B.value",&b,"b vlaue");
opt.parse_command_line(argc,argv);
opt.parse_config_file(optfile.c_str());
std::cout << "a = " << a << "\n";
std::cout << "b = " << b << "\n";
END_TESTING;
}

View File

@@ -0,0 +1,96 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <boost/signals2/signal.hpp>
#include "Core/Object.h"
#include "testing-prototype.h"
#define emit
template <typename T, bool copyable = true>
class property
{
typedef boost::signals2::signal<void(const property<T>& )> signal_t;
public:
property() : m_changed(new signal_t) {}
property(const T in) : value(in) , m_changed(new signal_t) {}
inline operator T const & () const { return value; }
inline operator T & () { return value; }
inline T & operator = (const T &i) { value = i; return value; }
template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
inline signal_t & valueChanged() { return *m_changed; }
private:
T value;
boost::shared_ptr<signal_t> m_changed;
};
//template <typename T>
//class property <T,false> {
// typedef boost::signals2::signal<void( T )> signal_t;
//public:
// property() : m_changed() {}
// property(const T in) : value(in) , m_changed() {}
// inline operator T const & () const { return value; }
// inline operator T & () { valueChanged()(value); return value; }
// inline T & operator = (const T &i) { value = i; valueChanged()(value); return value; }
// template <typename T2> T2 & operator = (const T2 &i) { T2 &guard = value; } // Assign exact identical types only.
// inline signal_t &valueChanged() { return m_changed; }
//private:
// property(const property<T> &);
// property<T> &operator = (const property<T>&);
// T value;
// signal_t m_changed;
//};
// test generic void function slot //
void PrintSlot(const property<int> &i) { std::cout << "slot called, new value = " << i << "!\n"; }
int main()
{
}

View File

@@ -0,0 +1,114 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Object.h"
#include "testing-prototype.h"
using namespace uLib;
struct A : Object {
uLibTypeMacro(A,Object)
A() : numa(5552368) {}
int numa;
};
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) {
ar & AR(numa);
}
struct B : virtual Object {
uLibTypeMacro(B,Object)
B() : numb(5552369) {}
int numb;
};
ULIB_SERIALIZABLE_OBJECT(B)
ULIB_SERIALIZE_OBJECT(B,Object) { ar & AR(numb); }
struct C : B {
uLibTypeMacro(C,B)
C() : numc(5552370) {}
int numc;
};
ULIB_SERIALIZABLE_OBJECT(C)
ULIB_SERIALIZE_OBJECT(C,B) { ar & AR(numc); }
struct D : A,B {
uLibTypeMacro(D,A,B)
D() : numd(5552371) {}
int numd;
};
ULIB_SERIALIZABLE_OBJECT(D)
ULIB_SERIALIZE_OBJECT(D,A,B) { ar & AR(numd); }
main() {
A o; o.init_properties();
Archive::xml_oarchive(std::cout) << NVP(o);
}

View File

@@ -0,0 +1,249 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include "Core/Object.h"
#include "Core/Archives.h"
#include "ParticlePhysics/MuonTomography/MuonScatter.h"
#include "testing-prototype.h"
using namespace uLib;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MANUAL SERIALIZATION //
struct V3f {
float x,y,z;
V3f()
{ x = y = z =0; }
V3f(float x, float y, float z) :
x(x), y(y), z(z) {}
template <class Archive>
void serialize (Archive &ar,unsigned int v) {
ar
& "<" & NVP(x) & NVP(y) & NVP(z) & ">";
}
};
ULIB_CLASS_EXPORT_KEY(V3f);
ULIB_CLASS_EXPORT_IMPLEMENT(V3f);
inline std::ostream &
operator <<(std::ostream &o, const V3f &v) {
Archive::hrt_oarchive(o) << v;
return o;
}
inline std::istream &
operator >>(std::istream &is, V3f &v) {
Archive::hrt_iarchive(is) >> v;
return is;
}
int test_V3f() {
// testing human readble archive with simple serializable structure //
V3f v1(1,2,3),v2,v3,v4;
std::cout << "v --> " << v1 << "\n";
std::stringstream ss; ss << v1;
std::cout << "ss.v --> " << ss.str() << "\n";
Archive::hrt_iarchive ar(ss); ar >> v2;
std::cout << "v2 --> " << v2 << "\n";
std::stringstream("<2 3 4>") >> v3;
std::cout << "v3 --> " << v3 << "\n";
// std::cout << "insert V3f string to parse: "; std::cin >> v4;
// std::cout << "v4 --> " << v4 << "\n";
return (1);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// OBJECT SERIALIZATION //
class A : public virtual Object {
uLibTypeMacro(A,Object)
ULIB_SERIALIZE_ACCESS
public:
A() : m_a(5552368) {}
properties() {
std::string p_a;
};
uLibRefMacro (a,int);
private:
int m_a;
};
void A::init_properties() {
$_init();
$$.p_a = "A property string";
}
ULIB_SERIALIZABLE_OBJECT(A)
ULIB_SERIALIZE_OBJECT(A,Object) {
ar
& "Object A : "
& "--> m_a = " & AR(m_a)
& "\n";
}
ULIB_SERIALIZE_OBJECT_PROPS(A) {
ar
& "Object A properties: "
& "---> p_a = " & AR(p_a) & "\n";
}
int testing_xml_class() {
A a; a.init_properties();
{
std::ofstream file("test.xml");
Archive::xml_oarchive(file) << NVP(a);
}
a.a() = 0;
a.$$.p_a = "zero string";
{
std::ifstream file("test.xml");
Archive::xml_iarchive(file) >> NVP(a);
}
Archive::xml_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
}
int testing_hrt_class() {
A a; a.init_properties();
{
std::ofstream file("test.xml");
Archive::hrt_oarchive(file) << NVP(a);
}
a.a() = 0;
a.$$.p_a = "zero string";
{
// ERRORE FIX !
// std::ifstream file("test.xml");
// Archive::hrt_iarchive(file) >> NVP(a);
}
Archive::hrt_oarchive(std::cout) << NVP(a);
return ( a.a() == 5552368 && a.$$.p_a == "A property string" );
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MUON SCATTER EXAMPLE //
int testing_mu()
{
std::stringstream ss;
MuonScatter mu;
mu.SetMomentumIn(555);
mu.SetMomentumOut(2368);
{
std::ofstream file("test.txt");
file << mu;
}
mu.SetMomentumIn(0);
mu.SetMomentumOut(0);
{
std::ifstream file("test.txt");
file >> mu;
}
std::cout << mu << "\n";
}
int main() {
BEGIN_TESTING(Serialize Test);
TEST1( test_V3f() );
TEST1( testing_xml_class() );
// testing_hrt_class(); ///// << ERRORE in HRT with properties
TEST1( testing_mu() );
END_TESTING;
}

View File

@@ -0,0 +1,115 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <typeinfo>
#include "testing-prototype.h"
#include "Core/Types.h"
#include "Core/Object.h"
#include "Core/Signal.h"
using namespace uLib;
class Ob1 : public Object {
public:
signals:
void V0();
int V1(int a);
};
// should be done by moc //
void Ob1::V0() {
ULIB_SIGNAL_EMIT(Ob1::V0);
}
int Ob1::V1(int a) {
ULIB_SIGNAL_EMIT(Ob1::V1,a);
}
class Ob2 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob2 prints V0\n" << std::flush;
}
};
class Ob3 : public Object {
public slots:
void PrintV0() {
std::cout << "Ob3 prints V0\n" << std::flush;
}
void PrintNumber(int n) {
std::cout << "Ob3 is printing number: " << n << "\n";
}
};
int main() {
BEGIN_TESTING(Signals);
Ob1 ob1;
Ob2 ob2;
Ob3 ob3;
Object::connect(&ob1,&Ob1::V0,&ob2,&Ob2::PrintV0);
Object::connect(&ob1,&Ob1::V0,&ob3,&Ob3::PrintV0);
Object::connect(&ob1,&Ob1::V1,&ob3,&Ob3::PrintNumber);
// not working yet
// Object::connect(&ob1,SIGNAL(V0(),&ob2,SLOT(PrintV0())
ob1.PrintSelf(std::cout);
emit ob1.V0();
emit ob1.V1(5552368);
END_TESTING;
}

View File

@@ -0,0 +1,94 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "Core/SmartPointer.h"
#include "testing-prototype.h"
using namespace uLib;
namespace Test {
struct ObjectMockInterface {
virtual void PrintValue()=0;
virtual int& Value()=0;
};
class ObjectMock : ObjectMockInterface {
int value;
public:
int& Value() { return value; }
void PrintValue() { std::cout << "Value: " << value << "\n"; }
};
} // Test
bool test_smpt(SmartPointer<Test::ObjectMock> &p) {
SmartPointer<Test::ObjectMock> spt = p;
spt->Value() = 5552368;
{
SmartPointer<Test::ObjectMock> copy = spt;
copy->Value() = 123;
}
return (spt->Value() == 123);
}
int main () {
BEGIN_TESTING(SmartPointer);
// HOLD REFERENCE //
{
SmartPointer<Test::ObjectMock> spt(new Test::ObjectMock);
TEST1(test_smpt(spt));
}
{
SmartPointer<Test::ObjectMock> spt;
TEST1(test_smpt(spt));
}
{
SmartPointer<Test::ObjectMock> spt = new SmartPointer<Test::ObjectMock>;
TEST1(test_smpt(spt));
}
// TAKE REFERENCE //
{
Test::ObjectMock obj;
SmartPointer<Test::ObjectMock> spt(obj);
TEST1(test_smpt(spt));
}
END_TESTING;
}

View File

@@ -0,0 +1,120 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include "Core/Vector.h"
#include "Core/Object.h"
using namespace uLib;
static int instanziated_objects_number;
class ObjectTest : public Object {
public:
ObjectTest() {
data[0] = 0;
data[1] = 1;
data[2] = 2;
instanziated_objects_number++;
}
ObjectTest(const ObjectTest &copy) {
data[0] = copy.data[0];
data[1] = copy.data[1];
data[2] = copy.data[2];
instanziated_objects_number++;
}
~ObjectTest()
{
instanziated_objects_number--;
}
float data[3];
};
int main() {
BEGIN_TESTING(SmartVector);
instanziated_objects_number =0;
///////////////////////// SMART POINTER FUNCIONALITY ///////////////////////
// int smart vector //
SmartVector<int> sv(10);
for (int i=0;i<10;++i)
sv[i] = i;
// new shallow copy inside a code block //
{
SmartVector<int> newsv = sv;
newsv[5] = 5552368;
TEST1(sv[5] == newsv[5]);
}
// verify that newsv destruction does not delete instance //
TEST1( sv[5] == 5552368 );
SmartVector<ObjectTest> svo(10);
for (int i=0;i<10;++i)
svo[i] = ObjectTest();
TEST1(instanziated_objects_number == 10);
{
SmartVector<ObjectTest> newsvo = svo;
newsvo[5].data[1] = 5552368.0;
TEST1(svo[5].data[1] == newsvo[5].data[1]);
TEST1(instanziated_objects_number == 10);
}
TEST1(instanziated_objects_number == 10);
/////////////////////////// ITERATOR FUNCIONALITY //////////////////////////
Vector<int> v(10);
Vector<int>::Iterator it;
int i=1;
for(it=v.begin() ; it==v.end(); it++, i++)
*it = i;
for(i = 0; i<v.size(); i++)
TEST1( v[i] = i+1 );
Vector<int>::ConstIterator cit;
i=1;
for(cit=v.begin(); cit==v.end(); cit++, i++)
TEST1( *cit == i+1 );
END_TESTING
}

View File

@@ -0,0 +1,112 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "testing-prototype.h"
#include <Core/StaticInterface.h>
namespace uLib {
//// INTERFACE TO COMPLEX CLASS /////
namespace Interface {
struct Test {
MAKE_TRAITS
template<class Self> void check_structural() {
uLibCheckFunction(Self,test,bool,int,float);
uLibCheckMember(Self,testmemb,int);
}
};
}
struct Test {
bool test(int i, float f){}
int testmemb;
};
//// INTERFAC TO SIMPLE CLASS ///////////
namespace Interface {
struct Simple {
MAKE_TRAITS
template<class Self> void check_structural() {
uLibCheckMember(Self,memb1,int);
uLibCheckMember(Self,memb2,float);
}
};
}
struct Simple {
int memb1;
float memb2;
};
/////////////////////////
template <class T>
class UseTest {
public:
UseTest() {
Interface::IsA<T,Interface::Test>();
T t;
int i; float f;
t.test(i,f);
}
};
template <class T>
class UseSimple {
public:
UseSimple() {
Interface::IsA<T,Interface::Simple>();
}
};
}
int main()
{
BEGIN_TESTING(Static Interface);
uLib::UseTest<uLib::Test> u;
uLib::UseSimple<uLib::Simple> s;
END_TESTING;
}

View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <string>
#include "Core/Types.h"
#include "Core/Object.h"
#include "testing-prototype.h"
using namespace uLib;
int main() {
}

View File

@@ -0,0 +1,45 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include "Core/Object.h"
#include "Core/Uuid.h"
#include "testing-prototype.h"
using namespace uLib;
int main()
{
BEGIN_TESTING(uuid);
END_TESTING;
}

View File

@@ -0,0 +1,84 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Core/Vector.h>
#include "testing-prototype.h"
#include <algorithm>
template < typename T >
struct __Cmp {
bool operator()(const T &data, const float value) {
return data <= value;
}
};
template<typename _Tp, typename _CmpT>
inline const unsigned long
VectorSplice(const _Tp &_it, const _Tp &_end, const float value, _CmpT _comp)
{
_Tp it = _it;
_Tp end = _end-1;
for(it; it != end; )
{
if ( _comp(*it, value) ) it++;
else if( _comp(*end, value) )
{
std::swap(*it,*end--);
}
else --end;
}
return it - _it;
}
int main()
{
BEGIN_TESTING(Vector);
uLib::Vector<float> v;
v << 5,4,3,2,6,1,2,3,65,7,32,23,4,3,45,4,34,3,4,4,3,3,4,2,2,3;
int id = VectorSplice(v.begin(),v.end(),3,__Cmp<float>());
std::cout << "id: " << id << "\n";
std::cout << "vector: ";
for(uLib::Vector<float>::Iterator it = v.begin(); it!=v.end(); it++)
std::cout << *it <<" ";
std::cout << std::endl;
// std::sort(v.begin(),v.end(),LT<float>());
END_TESTING;
}

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;

View File

@@ -0,0 +1,38 @@
# HEADERS
set(HEADERS
DetectorChamber.h
ExperimentFitEvent.h
GeantEvent.h
HitMC.h
MuonScatter.h
MuonEvent.h
MuonError.h
ChamberHitEvent.h
Hit.h
LinearFit.h
Solid.h
Matter.h
Scene.h
)
# SOURCES
set(SOURCES
Solid.cpp
Scene.cpp
)
set(LIBRARIES
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Eigen_LIBRARY}
${Geant4_LIBRARIES}
${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
${PACKAGE_LIBPREFIX}Detectors
)
uLib_add_shared_library(${uLib-module})
add_subdirectory(testing)

View File

@@ -0,0 +1,56 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CHAMBERHITEVENT_H
#define U_CHAMBERHITEVENT_H
#include "Core/Vector.h"
#include "Hit.h"
#include "ChamberDetector.h"
namespace uLib {
class ChamberHitEventData
{
public:
uLibConstRefMacro (Hits, Vector<HitData> )
uLibGetMacro (Idv, ChamberDetector::ID)
private:
friend class ChamberHitEvent;
Vector<HitData> m_Hits;
DetectorChamber::ID m_Idv; // -> chamber/view
};
class ChamberHitEvent : public ChamberHitEventData {
public:
uLibRefMacro (Hits, Vector<HitData> )
uLibSetMacro (Idv, ChamberDetector::ID)
};
}
#endif // CHAMBERHITEVENT_H

View File

@@ -0,0 +1,48 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CHAMBERDETECTOR_H
#define U_CHAMBERDETECTOR_H
#include "Core/Types.h"
#include "Math/ContainerBox.h"
namespace uLib {
class DetectorChamber : public ContainerBox {
public:
private:
};
}
#endif // CHAMBERDETECTOR_H

View File

@@ -0,0 +1,48 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_EXPERIMENTFITEVENT_H
#define U_EXPERIMENTFITEVENT_H
namespace uLib {
class ExperimentFitEventData {
public:
private:
};
}
#endif // EXPERIMENTFITEVENT_H

View File

@@ -0,0 +1,69 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_GEANTEVENT_H
#define U_GEANTEVENT_H
#include "Core/Types.h"
#include "Core/Vector.h"
#include "Math/Dense.h"
#include "ChamberHitEvent.h"
namespace uLib {
class GeantEventData {
public:
uLibGetMacro (EventID, Id_t )
uLibGetMacro (Momentum,Scalarf )
uLibConstRefMacro (GenPos, Vector3f)
uLibConstRefMacro (GenDir, Vector3f)
uLibConstRefMacro (ChEvents,Vector<ChamberHitEventData>)
private:
friend class GeantEvent;
Id_t m_EventID;
Scalarf m_Momentum;
Vector3f m_GenPos;
Vector3f m_GenDir;
Vector<ChamberHitEventData> m_ChEvents;
};
class GeantEvent {
public:
uLibSetMacro (EventID, Id_t )
uLibSetMacro (Momentum,Scalarf )
uLibRefMacro (GenPos, Vector3f)
uLibRefMacro (GenDir, Vector3f)
uLibRefMacro (ChEvents,Vector<ChamberHitEventData>)
};
}
#endif // GEANTEVENT_H

View File

@@ -0,0 +1,41 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_DETECTORS_HIERARCHICALENCODING_H
#define U_DETECTORS_HIERARCHICALENCODING_H
#include <Core/BitCoding.h>
namespace uLib {
} // uLib
#endif // HIERARCHICALENCODING_H

70
src/Detectors/Hit.h Normal file
View File

@@ -0,0 +1,70 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef HIT_H
#define HIT_H
#include "Math/BitCode.h"
namespace uLib {
class HitRawCode_CMSDrift :
public BitCode4<unsigned short,6,3,2,5>
{
typedef unsigned short T;
public:
HitRawCode_CMSDrift() : BitCode4(0) {}
HitRawCode_CMSDrift(const Vector4i &v) : BitCode4(v) {}
HitRawCode_CMSDrift(T Chamber, T ROB, T TDC, T Channel ) {
(*this) << Chamber, ROB, TDC, Channel;
}
inline T Chamber() const { return m_data.bitf.field1; }
inline void SetChamber(const T data) { m_data.bitf.field1 = data; }
inline T ROB() const { return m_data.bitf.field2; }
inline void SetROB(const T data) { m_data.bitf.field2 = data; }
inline T TDC() const { return m_data.bitf.field3; }
inline void SetTDC(const T data) { m_data.bitf.field3 = data; }
inline T Channel() const { return m_data.bitf.field4; }
inline void SetChannel(const T data) { m_data.bitf.field4 = data; }
};
}
#endif // HIT_H

67
src/Detectors/HitMC.h Normal file
View File

@@ -0,0 +1,67 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_HITMC_H
#define U_HITMC_H
#include "Core/Macros.h"
#include "Math/Dense.h"
#include "Hit.h"
namespace uLib {
class HitMCData : public HitData{
public:
enum Type {
PrimaryMu,
SecondaryMu,
DeltaRay
};
uLibConstRefMacro(Position,HPoint3f)
uLibGetMacro(Type, enum Type)
private:
HPoint3f m_Position;
enum Type m_Type;
};
class HitMC : public HitMCData {
public:
uLibRefMacro(Position,HPoint3f)
uLibSetMacro(Type, enum Type)
};
}
#endif // HITMC_H

73
src/Detectors/LinearFit.h Normal file
View File

@@ -0,0 +1,73 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_LINEARFIT_H
#define U_LINEARFIT_H
#include "Core/Macros.h"
#include "Math/Dense.h"
#include "ChamberDetector.h"
namespace uLib {
class LinearFitData {
public:
uLibConstRefMacro(Position,Vector2f)
uLibConstRefMacro(Slope,Vector2f)
uLibConstRefMacro(PositionError,Vector2f)
uLibConstRefMacro(SlopeError,Vector2f)
uLibGetMacro(HitsNumber,int)
uLibGetMacro(Idv,ChamberDetector::ID)
private:
friend class LinearFit;
Vector2f m_Position;
Vector2f m_Slope;
Vector2f m_PositionError;
Vector2f m_SlopeError;
int m_HitsNumber;
DetectorChamber::ID m_Idv;
};
class LinearFit : public LinearFitData {
public:
uLibRefMacro(Position,Vector2f)
uLibRefMacro(Slope,Vector2f)
uLibRefMacro(PositionError,Vector2f)
uLibRefMacro(SlopeError,Vector2f)
uLibSetMacro(HitsNumber,int)
uLibSetMacro(Idv,ChamberDetector::ID)
};
}
#endif // LINEARFIT_H

25
src/Detectors/Makefile.am Normal file
View File

@@ -0,0 +1,25 @@
include $(top_srcdir)/Common.am
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Detectors
library_include_HEADERS = DetectorChamber.h \
ExperimentFitEvent.h \
GeantEvent.h \
HitMC.h \
MuonScatter.h \
MuonEvent.h \
MuonError.h \
ChamberHitEvent.h \
Hit.h \
LinearFit.h \
Solid.h \
Matter.h \
Scene.h
_DETECTORS_SOURCES = \
Solid.cpp \
Scene.cpp
noinst_LTLIBRARIES = libmutomdetectors.la
libmutomdetectors_la_SOURCES = ${_DETECTORS_SOURCES}

71
src/Detectors/Matter.h Normal file
View File

@@ -0,0 +1,71 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef MATTER_H
#define MATTER_H
#include "Core/Object.h"
class G4Element;
class G4Material;
namespace uLib {
////////////////////////////////////////////////////////////////////////////////
//// ELEMENT ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Element {
public:
uLibRefMacro(G4Data,G4Element *)
private:
G4Element *m_G4Data;
};
////////////////////////////////////////////////////////////////////////////////
//// MATERIAL //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
class Material : public Object {
public:
uLibRefMacro(G4Data,G4Material *)
private:
G4Material *m_G4Data;
};
}
#endif // MATTER_H

58
src/Detectors/MuonError.h Normal file
View File

@@ -0,0 +1,58 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MUONERROR_H
#define U_MUONERROR_H
#include "Core/Macros.h"
#include "Math/Dense.h"
namespace uLib {
class MuonErrorData {
friend class MuonError;
public:
uLibConstRefMacro(Theta,Scalarf)
uLibConstRefMacro(Phi,Scalarf)
private:
Scalarf m_Theta;
Scalarf m_Phi;
};
class MuonError : public MuonErrorData {
public:
uLibRefMacro(Theta,Scalarf)
uLibRefMacro(Phi,Scalarf)
};
} // end ulib space
#endif // U_MUONERROR_H

75
src/Detectors/MuonEvent.h Normal file
View File

@@ -0,0 +1,75 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MUONEVENT_H
#define U_MUONEVENT_H
#include "Core/Macros.h"
#include "Math/Dense.h"
namespace uLib {
class MuonEventData {
friend class MuonEvent;
public:
uLibConstRefMacro(LineIn,HLine3f)
uLibConstRefMacro(LineOut,HLine3f)
uLibGetMacro(Momentum,Scalarf)
private:
HLine3f m_LineIn;
HLine3f m_LineOut;
Scalarf m_Momentum;
};
class MuonEvent : public MuonEventData {
public:
uLibRefMacro(LineIn,HLine3f)
uLibRefMacro(LineOut,HLine3f)
uLibRefMacro(Momentum,Scalarf)
};
inline std::ostream&
operator<< (std::ostream& stream, const MuonEventData &mu) {
stream << " MuonEventData: --------------- \n"
<< " P: " << mu.GetMomentum() << "\n"
<< " IN: " << mu.LineIn() << "\n"
<< " OUT: " << mu.LineOut() << "\n"
<< " ------------------------------ \n";
return stream;
}
} // end ulib space
#endif // U_MUONEVENT_H

View File

@@ -0,0 +1,80 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MUONSCATTER_H
#define U_MUONSCATTER_H
#include "Core/Macros.h"
#include "Math/Dense.h"
namespace uLib {
class MuonScatter {
public:
uLibConstRefMacro(LineIn,HLine3f)
uLibConstRefMacro(ErrorIn,HError3f)
uLibConstRefMacro(LineOut,HLine3f)
uLibConstRefMacro(ErrorOut,HError3f)
uLibRefMacro(LineIn,HLine3f)
uLibRefMacro(ErrorIn,HError3f)
uLibRefMacro(LineOut,HLine3f)
uLibRefMacro(ErrorOut,HError3f)
uLibSetMacro(Momentum,Scalarf)
uLibSetMacro(MomentumPrime,Scalarf)
uLibGetMacro(Momentum,Scalarf)
uLibGetMacro(MomentumPrime,Scalarf)
protected:
HLine3f m_LineIn;
HLine3f m_LineOut;
HError3f m_ErrorIn;
HError3f m_ErrorOut;
Scalarf m_Momentum;
Scalarf m_MomentumPrime;
};
typedef MuonScatter MuonScatterData;
inline std::ostream&
operator<< (std::ostream& stream, const MuonScatterData &mu) {
stream << " MuonScatterData: ------------- \n"
<< " P: " << mu.GetMomentum() << " Pprim: " << mu.GetMomentumPrime() << "\n"
<< " IN: " << mu.LineIn() << "\n"
<< " " << mu.ErrorIn() << "\n"
<< " OUT: " << mu.LineOut() << "\n"
<< " " << mu.ErrorOut() <<"\n"
<< " ------------------------------ \n";
return stream;
}
}
#endif // U_MUONSCATTER_H

74
src/Detectors/Scene.cpp Normal file
View File

@@ -0,0 +1,74 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Geant4/G4Material.hh>
#include <Geant4/G4NistManager.hh>
#include <Geant4/G4LogicalVolume.hh>
#include "Core/Vector.h"
#include "Matter.h"
#include "Solid.h"
#include "Scene.h"
namespace uLib {
class DetectorsScenePimpl {
public:
// members //
//Vector<Solid> m_Solids;
};
DetectorsScene::DetectorsScene() :
d(new DetectorsScenePimpl())
{}
DetectorsScene::~DetectorsScene()
{
delete d;
}
void DetectorsScene::AddSolid(const Solid &solid)
{
// d->m_Solids.push_back(solid);
}
}

52
src/Detectors/Scene.h Normal file
View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef SCENE_H
#define SCENE_H
#include "Core/Object.h"
#include "Core/Vector.h"
#include "Solid.h"
namespace uLib {
class DetectorsScene : public Object {
public:
DetectorsScene();
~DetectorsScene();
void AddSolid(const Solid &solid);
private:
class DetectorsScenePimpl *d;
};
}
#endif // SCENE_H

114
src/Detectors/Solid.cpp Normal file
View File

@@ -0,0 +1,114 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
// G4 Solid //
#include <Geant4/G4Material.hh>
#include <Geant4/G4NistManager.hh>
#include <Geant4/G4LogicalVolume.hh>
// Tessellated solid //
#include <Geant4/G4TessellatedSolid.hh>
#include <Geant4/G4TriangularFacet.hh>
#include <Geant4/G4ThreeVector.hh>
#include "Math/Dense.h"
#include "Solid.h"
namespace uLib {
class DetectorsSolidPimpl {
public:
static G4ThreeVector getG4Vector3f(const Vector3f &vector) {
return G4ThreeVector( vector(0), vector(1), vector(2) );
}
};
Solid::Solid() :
m_Logical (new G4LogicalVolume(NULL,NULL,"unnamed_solid")),
m_Material(NULL)
{}
Solid::Solid(const char *name) :
m_Logical(new G4LogicalVolume(NULL,NULL,name)),
m_Material(NULL)
{}
void Solid::SetNistMaterial(const char *name)
{
G4NistManager *nist = G4NistManager::Instance();
if (m_Material) delete m_Material;
m_Material = nist->FindOrBuildMaterial(name);
m_Logical->SetMaterial(m_Material);
}
void Solid::SetMaterial(G4Material *material)
{
if(material)
{
m_Material = material;
m_Logical->SetMaterial(material);
}
}
TessellatedSolid::TessellatedSolid(const char *name) :
BaseClass(name),
m_Solid(new G4TessellatedSolid(name))
{}
void TessellatedSolid::SetMesh(TriangleMesh &mesh)
{
G4TessellatedSolid *ts = this->m_Solid;
for (int i=0; i<mesh.Triangles().size(); ++i) {
const Vector3i &trg = mesh.Triangles().at(i);
G4TriangularFacet *facet = new G4TriangularFacet(
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(0))),
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(1))),
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(2))),
ABSOLUTE);
ts->AddFacet((G4VFacet *)facet);
}
this->m_Logical->SetSolid(ts);
}
}

86
src/Detectors/Solid.h Normal file
View File

@@ -0,0 +1,86 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef SOLID_H
#define SOLID_H
#include "Core/Object.h"
#include "Math/Dense.h"
#include "Math/TriangleMesh.h"
#include "Detectors/Matter.h"
class G4Material;
class G4LogicalVolume;
class G4TessellatedSolid;
namespace uLib {
class Solid : public Object {
public:
Solid();
Solid(const char *name);
void SetNistMaterial(const char *name);
void SetMaterial(G4Material *material);
uLibGetMacro(Material,G4Material *)
uLibGetMacro(Logical,G4LogicalVolume *)
protected:
G4Material *m_Material;
G4LogicalVolume *m_Logical;
};
class TessellatedSolid : public Solid {
typedef Solid BaseClass;
public:
TessellatedSolid(const char *name);
void SetMesh(TriangleMesh &mesh);
uLibGetMacro(Solid,G4TessellatedSolid *)
private:
G4TessellatedSolid *m_Solid;
};
}
#endif // SOLID_H

View File

@@ -0,0 +1,18 @@
# TESTS
set( TESTS
GDMLSolidTest
HierarchicalEncodingTest
)
#set(LIBRARIES
# ${PACKAGE_LIBPREFIX}Core
# ${PACKAGE_LIBPREFIX}Math
# ${PACKAGE_LIBPREFIX}Detectors
# ${Boost_SERIALIZATION_LIBRARY}
# ${Boost_SIGNALS_LIBRARY}
# ${Boost_PROGRAM_OPTIONS_LIBRARY}
# ${Eigen_LIBRARY}
# ${Geant4_LIBRARIES}
# ${ROOT_LIBRARIES}
#)
uLib_add_tests(${uLib-module})

View File

@@ -0,0 +1,72 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <Geant4/G4RunManager.hh>
#include <Geant4/G4Material.hh>
#include <Geant4/G4NistManager.hh>
#include <Geant4/G4Box.hh>
#include <Geant4/G4TessellatedSolid.hh>
#include <Geant4/G4LogicalVolume.hh>
#include <Geant4/G4PVPlacement.hh>
#include <Geant4/G4GDMLParser.hh>
//#include <Geant4/G4GDMLRead.hh>
//#include <Geant4/G4GDMLReadSolids.hh>
#include "Detectors/Solid.h"
#include "testing-prototype.h"
int main()
{
// G4RunManager* runManager = new G4RunManager;
G4NistManager *nist = G4NistManager::Instance();
G4Material *air = nist->FindOrBuildMaterial("G4_AIR");
G4Box *box = new G4Box("box",5,5,5);
G4LogicalVolume box_lv(NULL,NULL,"box test");
box_lv.SetSolid(box);
box_lv.SetMaterial(air);
G4PVPlacement box_pl(0,G4ThreeVector(),&box_lv,"box test",0,0,0);
G4GDMLParser parser;
parser.Write("test_out.gdml",&box_lv);
}

View File

@@ -0,0 +1,50 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <iostream>
#include <Detectors/Hit.h>
#include "testing-prototype.h"
using namespace uLib;
int main() {
BEGIN_TESTING(Hierarchical Encoding);
HitRawCode_CMSDrift code;
code = Vector4i(5,6,2,8);
Vector4i v = code;
std::cout << code << "\n";
std::cout << v << "\n";
END_TESTING;
}

View File

@@ -0,0 +1,16 @@
include $(top_srcdir)/Common.am
#AM_DEFAULT_SOURCE_EXT = .cpp
# if HAVE_CHECK
TESTS = GDMLSolidTest
# else
# TEST =
# endif
LDADD = $(top_srcdir)/libmutom-${PACKAGE_VERSION}.la
check_PROGRAMS = $(TESTS)

View File

@@ -0,0 +1,37 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#define BEGIN_TESTING(name) \
static int _fail = 0; \
printf("..:: Testing " #name " ::..\n");
#define TEST1(val) _fail += (val)==0
#define TEST0(val) _fail += (val)!=0
#define END_TESTING return _fail;

View File

@@ -0,0 +1,35 @@
# SUBDIRS = .
include $(top_srcdir)/Common.am
DISTSOURCES = vtkviewport.cpp main.cpp
DISTHEADERS_MOC =
DISTHEADERS_NO_MOC =
FORMS = vtkviewport.ui
FORMHEADERS = $(FORMS:.ui=.h)
MOC_CC = $(FORMS:.ui=.moc.cpp) $(DISTHEADERS_MOC:.h=.moc.cpp)
bin_PROGRAMS = QTVtkViewport
BUILT_SOURCES = $(FORMHEADERS) $(MOC_CC)
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = $(FORMS)
QTVtkViewport_SOURCES = $(DISTSOURCES) $(DISTHEADERS_MOC) $(DISTHEADERS_NO_MOC)
nodist_QTVtkViewport_SOURCES = $(MOC_CC)
QTVtkViewport_LDADD = $(top_srcdir)/libmutom.la
.ui.h: $(FORMS)
$(UIC) -o ui_$@ $<
.ui.hpp: $(FORMS_HPP)
$(UIC) -o $@ $<
.h.moc.cpp:
$(MOC) -o $@ $<
SUFFIXES = .h .ui .moc.cpp

View File

@@ -0,0 +1,18 @@
#-------------------------------------------------
#
# Project created by QtCreator 2012-08-30T18:59:53
#
#-------------------------------------------------
QT += core gui
TARGET = QVTKViewport2
TEMPLATE = app
SOURCES += main.cpp\
vtkviewport.cpp
HEADERS += vtkviewport.h
FORMS += vtkviewport.ui

View File

@@ -0,0 +1,453 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.4.1, 2012-09-03T09:43:56. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QString" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QString" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">System</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">1</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Target.DesktopTarget</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 4.7.4 for GCC (Qt SDK) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">3</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 4.7.4 for GCC (Qt SDK) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">3</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 in PATH (System) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">4</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.3">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 in PATH (System) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">4</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.4">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 (System) Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">5</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.5">
<value type="QString" key="ProjectExplorer.BuildCOnfiguration.ToolChain">ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit.gdb</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 4.7.0 (System) Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory">/home/andrea/devel/MuonTomography/mutom/uLib/trunk/src/Gui/Qt/QVTKViewport2</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId">5</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">false</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">6</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">No deployment</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">false</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">false</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
</valuelist>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">QVTKViewport2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4RunConfiguration.BaseEnvironmentBase">2</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">QVTKViewport2.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.Qt4RunConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">false</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
<value type="QString">{f8bb0047-7f6e-45df-9cc8-e746abebf883}</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">10</value>
</data>
</qtcreator>

View File

@@ -0,0 +1,38 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include <QtGui/QApplication>
#include "vtkviewport.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
VtkViewport w;
w.show();
return a.exec();
}

View File

@@ -0,0 +1,41 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "vtkviewport.h"
#include "ui_vtkviewport.h"
VtkViewport::VtkViewport(QWidget *parent) :
QWidget(parent),
ui(new Ui::VtkViewport)
{
ui->setupUi(this);
}
VtkViewport::~VtkViewport()
{
delete ui;
}

View File

@@ -0,0 +1,49 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef VTKVIEWPORT_H
#define VTKVIEWPORT_H
#include <QWidget>
namespace Ui {
class VtkViewport;
}
class VtkViewport : public QWidget
{
Q_OBJECT
public:
explicit VtkViewport(QWidget *parent = 0);
~VtkViewport();
private:
Ui::VtkViewport *ui;
};
#endif // VTKVIEWPORT_H

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VtkViewport</class>
<widget class="QWidget" name="VtkViewport">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>536</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>140</x>
<y>170</y>
<width>161</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Hello World !</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

3
src/Makefile.am Normal file
View File

@@ -0,0 +1,3 @@
SUBDIRS = ltk Core Math Detectors Root

334
src/Math/Accumulator.h Normal file
View File

@@ -0,0 +1,334 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_DATABINNING_H
#define U_DATABINNING_H
#include "Core/Vector.h"
#include "Dense.h"
namespace uLib {
// TODO: USE BOOST ACCUMULATORS //
template <typename T>
class Accumulator_Mean {
typedef std::pair<T,unsigned long> Tmean;
public:
Accumulator_Mean() {
m_Means.push_back( Tmean(0,0) );
}
void operator()(const T data) {
T tmp = 0;
// for(typename std::vector<Tmean>::iterator it = m_Means.begin(); it < m_Means.back(); ++it)
// tmp += it->first/it->second;
for(int i=0; i<m_Means.size()-1;++i)
tmp += m_Means[i].first / m_Means[i].second;
m_Means.back().first += data - tmp;
m_Means.back().second += 1;
}
T operator()() const {
T mean = 0;
// for(typename std::vector<Tmean>::iterator it = m_Means.begin(); it < m_Means.end(); ++it) {
// mean += it->first/it->second; }
for(int i=0; i<m_Means.size();++i)
mean += m_Means[i].first / m_Means[i].second;
return mean;
}
void AddPass() { m_Means.push_back( Tmean(0,0) ); }
private:
Vector< Tmean > m_Means;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// accumulator Trim //
template < typename T, int subsample_size=200 >
class Accumulator_ABTrim {
public:
Accumulator_ABTrim() :
m_Avg(0),
m_InternalCount(0),
m_SizeA(0),
m_SizeB(0),
m_IdA(0),
m_IdB(0)
{}
Accumulator_ABTrim(const Accumulator_ABTrim &c) {
# pragma omp critical
{
m_Avg = c.m_Avg;
m_InternalCount = c.m_InternalCount;
m_SizeA = c.m_SizeA;
m_SizeB = c.m_SizeB;
m_IdA = c.m_IdA;
m_IdB = c.m_IdB;
memcpy (m_Av, c.m_Av, sizeof (m_Av));
}
}
void operator += (T value) {
if(m_InternalCount > subsample_size) {
// array complete and counter over subsample //
if( m_SizeA > 0 && value < m_ValA ) {
;// m_Avg += m_ValA;
}
else if (m_SizeB > 0 && value > m_ValB)
{
;// m_Avg += m_ValB;
}
else
{
m_Avg += value;
m_InternalCount++;
}
}
else if(m_InternalCount >=0) {
// array complete
if(m_SizeA > 0 && value < m_ValA)
{
m_Avg += m_ValA;
m_Av[m_IdA] = value;
for (unsigned int i=0; i < m_SizeA; i++)
if(m_Av[i] > m_Av[m_IdA])
{ m_IdA = i; m_ValA = m_Av[i]; }
}
else if(m_SizeB > 0 && value > m_ValB)
{
m_Avg += m_ValB;
m_Av[m_IdB] = value;
for (unsigned int i=m_SizeA; i < m_SizeA+m_SizeB; i++)
if(m_Av[i] < m_Av[m_IdB])
{ m_IdB = i; m_ValB = m_Av[i]; }
}
else {
m_Avg += value;
}
m_InternalCount++;
}
else { // m_InternalCount < 0
// array is not fullfilled
m_Av[m_SizeA+m_SizeB+m_InternalCount] = value;
m_InternalCount++;
if(m_InternalCount == 0) {
std::sort(m_Av,m_Av+m_SizeA+m_SizeB);
if(m_SizeA > 0) {
m_IdA = m_SizeA-1;
m_ValA = m_Av[m_IdA];
}
if(m_SizeB > 0) {
m_IdB = m_SizeA;
m_ValB = m_Av[m_SizeA];
}
}
}
}
T operator()() {
if(m_InternalCount <= 0) {
std::sort(m_Av, m_Av+m_SizeA+m_SizeB+m_InternalCount);
return m_Av[ (m_SizeA+m_SizeB+m_InternalCount) / 2]; // median value //
}
else {
// return (m_Avg + m_ValA * m_SizeA + m_ValB * m_SizeB) /
// (m_InternalCount + m_SizeA + m_SizeB);
return (m_Avg) / m_InternalCount;
}
}
void SetABTrim(int a, int b) {
if(a+b > subsample_size/2) {
m_SizeA = a/(a+b) * subsample_size/2;
m_SizeB = b/(a+b) * subsample_size/2;
}
else {
m_SizeA = a;
m_SizeB = b;
}
m_Avg = 0;
m_InternalCount = -m_SizeA-m_SizeB;
}
private:
T m_Av[subsample_size/2];
T m_Avg, m_ValA, m_ValB;
int m_IdA, m_IdB, m_InternalCount;
int m_SizeA, m_SizeB;
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Clip Accumulator //
template < typename T, int subsample_size=200 >
class Accumulator_ABClip {
public:
Accumulator_ABClip() :
m_Avg(0),
m_InternalCount(0),
m_SizeA(0),
m_SizeB(0),
m_IdA(0),
m_IdB(0)
{}
Accumulator_ABClip(const Accumulator_ABClip &c) {
# pragma omp critical
{
m_Avg = c.m_Avg;
m_InternalCount = c.m_InternalCount;
m_SizeA = c.m_SizeA;
m_SizeB = c.m_SizeB;
m_IdA = c.m_IdA;
m_IdB = c.m_IdB;
memcpy (m_Av, c.m_Av, sizeof (m_Av));
}
}
void operator += (T value) {
if(m_InternalCount > subsample_size) {
// array complete and counter over subsample //
if( m_SizeA > 0 && value < m_ValA ) {
m_Avg += m_ValA;
}
else if (m_SizeB > 0 && value > m_ValB) {
m_Avg += m_ValB;
}
else {
m_Avg += value;
}
m_InternalCount++;
}
else if(m_InternalCount >=0) {
// array complete
if(m_SizeA > 0 && value < m_ValA)
{
m_Avg += m_ValA;
m_Av[m_IdA] = value;
for (unsigned int i=0; i < m_SizeA; i++)
if(m_Av[i] > m_Av[m_IdA])
{ m_IdA = i; m_ValA = m_Av[i]; }
}
else if(m_SizeB > 0 && value > m_ValB)
{
m_Avg += m_ValB;
m_Av[m_IdB] = value;
for (unsigned int i=m_SizeA; i < m_SizeA+m_SizeB; i++)
if(m_Av[i] < m_Av[m_IdB])
{ m_IdB = i; m_ValB = m_Av[i]; }
}
else {
m_Avg += value;
}
m_InternalCount++;
}
else { // m_InternalCount < 0
// array is not fullfilled
m_Av[m_SizeA+m_SizeB+m_InternalCount] = value;
m_InternalCount++;
if(m_InternalCount == 0) {
std::sort(m_Av,m_Av+m_SizeA+m_SizeB);
if(m_SizeA > 0) {
m_IdA = m_SizeA-1;
m_ValA = m_Av[m_IdA];
}
if(m_SizeB > 0) {
m_IdB = m_SizeA;
m_ValB = m_Av[m_SizeA];
}
}
}
}
T operator()() {
if(m_InternalCount <= 0) {
std::sort(m_Av, m_Av+m_SizeA+m_SizeB+m_InternalCount);
return m_Av[ (m_SizeA+m_SizeB+m_InternalCount) / 2]; // median value //
}
else {
return (m_Avg + m_ValA * m_SizeA + m_ValB * m_SizeB) /
(m_InternalCount + m_SizeA + m_SizeB);
}
}
void SetABTrim(int a, int b) {
if(a+b > subsample_size/2) {
m_SizeA = a/(a+b) * subsample_size/2;
m_SizeB = b/(a+b) * subsample_size/2;
}
else {
m_SizeA = a;
m_SizeB = b;
}
m_Avg = 0;
m_InternalCount = -m_SizeA-m_SizeB;
}
private:
T m_Av[subsample_size/2];
T m_Avg, m_ValA, m_ValB;
int m_IdA, m_IdB, m_InternalCount;
int m_SizeA, m_SizeB;
};
} // uLib
#endif // U_DATABINNING_H

250
src/Math/BitCode.h Normal file
View File

@@ -0,0 +1,250 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MATH_BITCODE_H
#define U_MATH_BITCODE_H
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
//#include <Core/CommaInitializer.h>
#include <Math/Dense.h>
#include <Core/Mpl.h>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/set_c.hpp>
namespace uLib {
template < typename ContainerT, typename ContentT >
struct CommaInitializerBitCode
{
inline explicit CommaInitializerBitCode(ContainerT *container, ContentT s)
: container(container)
{
this->index = 0;
this->container->operator()().field1 = s;
}
inline CommaInitializerBitCode & operator, (ContentT s) {
this->index++;
if(index < container->size()) {
if(index == 1) container->operator()().field2 = s;
if(index == 2) container->operator()().field3 = s;
if(index == 3) container->operator()().field4 = s;
}
return *this;
}
ContainerT *container;
unsigned int index;
};
template <typename T, uint L1, uint L2>
class BitCode2
{
protected:
typedef T Type;
typedef BitCode2<T,L1,L2> ThisClass;
typedef CommaInitializerBitCode< ThisClass, T > CommaInit;
BOOST_STATIC_ASSERT_MSG( boost::is_unsigned<T>::value == 1, "CODE TYPE MUST BE UNSIGNED" );
BOOST_STATIC_ASSERT( L1+L2 == sizeof(T)*8 );
public:
struct BitField {
T field1 : L1;
T field2 : L2;
};
union CodeSet {
BitField bitf;
T value;
} m_data;
BitCode2() {}
BitCode2(const T& data) { m_data.value = data; }
BitCode2(const Vector2i & data) {
(*this) << data(0),data(1);
}
inline CommaInit operator <<(T scalar) { return CommaInit(this, scalar); }
static const int size() { return 2; }
BitField & operator()() { return m_data.bitf; }
const BitField & operator()() const { return m_data.bitf; }
operator Vector2i () { return Vector2i(m_data.bitf.field1,
m_data.bitf.field2); }
void set(const T data) { m_data.value = data; }
T get() const { return m_data.value; }
};
template <typename T, uint L1, uint L2>
std::ostream &
operator << (std::ostream &o, const BitCode2<T,L1,L2> &code) {
o << code().field1 << "," << code().field2;
return o;
}
template <typename T, uint L1, uint L2, uint L3>
class BitCode3
{
protected:
typedef T Type;
typedef BitCode3<T,L1,L2,L3> ThisClass;
typedef CommaInitializerBitCode< ThisClass, T > CommaInit;
BOOST_STATIC_ASSERT_MSG( boost::is_unsigned<T>::value == 1, "CODE TYPE MUST BE UNSIGNED" );
BOOST_STATIC_ASSERT( L1+L2+L3 == sizeof(T)*8 );
public:
struct BitField {
T field1 : L1;
T field2 : L2;
T field3 : L3;
};
union CodeSet {
BitField bitf;
T value;
} m_data;
BitCode3() {}
BitCode3(const T& data) { m_data.value = data; }
BitCode3(const Vector3i & data) {
(*this) << data(0),data(1),data(2);
}
inline CommaInit operator <<(T scalar) { return CommaInit(this, scalar); }
static const int size() { return 3; }
BitField & operator()() { return m_data.bitf; }
const BitField & operator()() const { return m_data.bitf; }
operator Vector3i () { return Vector3i(m_data.bitf.field1,
m_data.bitf.field2,
m_data.bitf.field3); }
void set(const T data) { m_data.value = data; }
T get() const { return m_data.value; }
};
template <typename T, uint L1, uint L2, uint L3>
std::ostream &
operator << (std::ostream &o, const BitCode3<T,L1,L2,L3> &code) {
o << code().field1 << "," << code().field2 << "," << code().field3;
return o;
}
template <typename T, uint L1, uint L2, uint L3, uint L4>
class BitCode4
{
protected:
typedef T Type;
typedef BitCode4<T,L1,L2,L3,L4> ThisClass;
typedef CommaInitializerBitCode< ThisClass, T > CommaInit;
BOOST_STATIC_ASSERT_MSG( boost::is_unsigned<T>::value == 1, "CODE TYPE MUST BE UNSIGNED" );
BOOST_STATIC_ASSERT( L1+L2+L3+L4 == sizeof(T)*8 );
public:
struct BitField {
T field1 : L1;
T field2 : L2;
T field3 : L3;
T field4 : L4;
};
union CodeSet {
BitField bitf;
T value;
} m_data;
BitCode4() {}
BitCode4(const T& data) { m_data.value = data; }
BitCode4(const Vector4i & data) {
(*this) << data(0),data(1),data(2),data(3);
}
inline CommaInit operator << (T scalar) { return CommaInit(this, scalar); }
static const int size() { return 4; }
BitField & operator()() { return m_data.bitf; }
const BitField & operator()() const { return m_data.bitf; }
operator Vector4i () { return Vector4i(m_data.bitf.field1,
m_data.bitf.field2,
m_data.bitf.field3,
m_data.bitf.field4); }
void set(const T data) { m_data.value = data; }
T get() const { return m_data.value; }
};
template <typename T, uint L1, uint L2, uint L3, uint L4>
std::ostream &
operator << (std::ostream &o, const BitCode4<T,L1,L2,L3,L4> &code) {
o << code().field1 << "," << code().field2 << "," << code().field3 << "," << code().field4;
return o;
}
template <typename T, uint L1, uint L2 = 0, uint L3 = 0>
class BitCode {
typedef boost::mpl::vector_c<T,L1,L2,L3> BitSet;
T m_data;
public:
struct value_printer
{
template< typename U > void operator()(U x)
{ std::cout << x << '\n'; }
};
void PrintSelf( ) {
// boost::mpl::for_each<BitSet>( value_printer() );
// std::cout << boost::mpl::at_c< BitSet,1 >::type::value << "\n";
}
int Get(unsigned short field) const {
return boost::mpl::at_c< BitSet, field >::type::value;
}
};
} // uLib
#endif // BITCODE_H

50
src/Math/CMakeLists.txt Normal file
View File

@@ -0,0 +1,50 @@
# HEADERS
set(HEADERS
ContainerBox.h
Dense.h
Geometry.h
Transform.h
StructuredData.h
StructuredGrid.h
VoxImage.h
VoxRaytracer.h
Utils.h
VoxImageFilter.h
VoxImageFilter.hpp
VoxImageFilterLinear.hpp
VoxImageFilterMedian.hpp
VoxImageFilterABTrim.hpp
VoxImageFilterBilateral.hpp
VoxImageFilterThreshold.hpp
VoxImageFilter2ndStat.hpp
VoxImageFilterCustom.hpp
Accumulator.h
TriangleMesh.h
BitCode.h
)
# SOURCES
set(SOURCES
VoxRaytracer.cpp
StructuredData.cpp
StructuredGrid.cpp
VoxImage.cpp
TriangleMesh.cpp
Dense.cpp
)
set(LIBRARIES
${Boost_SERIALIZATION_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Eigen_LIBRARY}
${ROOT_LIBRARIES}
${PACKAGE_LIBPREFIX}Core
${PACKAGE_LIBPREFIX}Math
)
uLib_add_shared_library(${uLib-module})
add_subdirectory(testing)

98
src/Math/ContainerBox.h Normal file
View File

@@ -0,0 +1,98 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_CONTAINERBOX_H
#define U_CONTAINERBOX_H
#include "Geometry.h"
namespace uLib {
class ContainerBox : public AffineTransform {
public:
ContainerBox() : m_LocalT(this) {}
ContainerBox(const ContainerBox &copy) :
m_LocalT(this),
AffineTransform(copy)
{
// FIX for performance //
this->SetOrigin(copy.GetOrigin());
this->SetSize(copy.GetSize());
}
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
void SetSize(const Vector3f &v) {
Vector3f pos = this->GetOrigin();
m_LocalT = AffineTransform(this);
m_LocalT.Scale(v);
m_LocalT.SetPosition(pos);
}
inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
// FIX... //
inline void FlipLocalAxes(int first, int second)
{ m_LocalT.FlipAxes(first,second); }
Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
inline Vector4f GetWorldPoint(const Vector4f &v) const {
return m_LocalT.GetWorldMatrix() * v;
}
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
return this->GetWorldPoint(Vector4f(x,y,z,1));
}
inline Vector4f GetLocalPoint(const Vector4f &v) const {
return m_LocalT.GetWorldMatrix().inverse() * v;
}
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
return this->GetLocalPoint(Vector4f(x,y,z,1));
}
protected:
private:
AffineTransform m_LocalT;
};
}
#endif // CONTAINERBOX_H

52
src/Math/Dense.cpp Normal file
View File

@@ -0,0 +1,52 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "Dense.h"
#include "Core/Archives.h"
ULIB_SERIALIZE(uLib::HPoint3f) {
ar & boost::serialization::make_nvp(NULL,boost::serialization::base_object<uLib::HPoint3f::BaseClass,uLib::HPoint3f>(ob));
}
ULIB_SERIALIZE(uLib::HVector3f) {
ar & boost::serialization::make_nvp(NULL,boost::serialization::base_object<uLib::HVector3f::BaseClass,uLib::HVector3f>(ob));
}
ULIB_SERIALIZE(uLib::HLine3f) {
ar
& "HLine -> ( origin: " & AR(origin) & "; direction: " & AR(direction) & ") ";
}
ULIB_SERIALIZE(uLib::HError3f) {
ar
& "HLine -> ( poserr: " & AR(position_error) & "; direrr: " & AR(direction_error) & ") ";
}

280
src/Math/Dense.h Normal file
View File

@@ -0,0 +1,280 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2012 Andrea Rigoni Garola <andrea@pcimg05>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef ULIB_DENSEMATRIX_H
#define ULIB_DENSEMATRIX_H
#include <stdlib.h>
#include <Eigen/Dense>
#include "Core/Types.h"
#include "Core/Serializable.h"
//// BOOST SERIALIZATION ///////////////////////////////////////////////////////
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/array.hpp>
namespace boost {
namespace serialization {
template<class Archive, class Scalar, int RowsAtCompileTime, int ColsAtCompileTime>
void serialize(Archive & ar, ::Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> & m, const unsigned int /*version*/) {
ar & boost::serialization::make_array(m.data(), RowsAtCompileTime * ColsAtCompileTime);
}
} // serialization
} // boost
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// EIGEN VECTOR STREAM INTERACTIONS ////////////////////////////////////////////
// this is needed by boost::lexical_cast to cope with Eigens Vectors ///////////
namespace Eigen {
template <typename T, int size>
std::istream & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) {
std::string str;
for( unsigned int i=0; i<size; i++) {
is >> std::skipws;
is >> str;
if(is.fail()) vec(i) = 0;
else vec(i) = boost::lexical_cast<T>(str);
}
return is;
}
template <typename T, int size>
std::ostream & operator << (std::ostream &os, const Eigen::Matrix<T,size,1> &vec) {
os << vec.transpose();
return os;
}
} // Eigen
////////////////////////////////////////////////////////////////////////////////
namespace uLib {
typedef int Scalari;
typedef unsigned int Scalarui;
typedef long Scalarl;
typedef unsigned long Scalarul;
typedef float Scalarf;
typedef double Scalard;
typedef Eigen::Matrix<int,1,1> Matrix1i;
typedef Eigen::Matrix2i Matrix2i;
typedef Eigen::Matrix3i Matrix3i;
typedef Eigen::Matrix4i Matrix4i;
typedef Eigen::Matrix<float,1,1> Matrix1f;
typedef Eigen::Matrix2f Matrix2f;
typedef Eigen::Matrix3f Matrix3f;
typedef Eigen::Matrix4f Matrix4f;
typedef Eigen::Matrix<int,1,1> Vector1i;
typedef Eigen::Vector2i Vector2i;
typedef Eigen::Vector3i Vector3i;
typedef Eigen::Vector4i Vector4i;
typedef Eigen::Matrix<float,1,1> Vector1f;
typedef Eigen::Vector2f Vector2f;
typedef Eigen::Vector3f Vector3f;
typedef Eigen::Vector4f Vector4f;
////////////////////////////////////////////////////////////////////////////////
// Vector String interaction ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*! Given a string consisting of a series of doubles with some
* delimiter, return an Eigen::Vector populated with those
* values, in the same order as they are given in the string.
*
* \param vec A double vector to be populated with the results
* \param str A string to be parsed as a series of doubles.
* \param delim Delimiters of the text (a typical default is " ," for comma and space-delimited text
*
*/
template <typename T, int size>
void VectorxT_StringTo(Eigen::Matrix<T,size,1> &vec, std::string str, const char *delim = " ,;\t\n") {
std::vector<std::string> strvec;
boost::algorithm::trim_if( str, boost::algorithm::is_any_of(delim));
boost::algorithm::split(strvec,str,boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
for( unsigned int i=0; i<size; i++) {
vec(i) = boost::lexical_cast<T>(strvec[i]);
}
}
template <typename T, int size>
std::string VectorxT_ToString(const Eigen::Matrix<T,size,1> &vec) {
std::stringstream sst;
sst << vec.transpose();
return sst.str();
}
//template <typename T, int size>
//Eigen::Matrix<T,size,1> & operator >> (std::istream &is, Eigen::Matrix<T,size,1> &vec) {
//}
template <typename T, int size>
void operator>> (std::string& str, Eigen::Matrix<T,size,1> &vec){
VectorxT_StringTo(vec,str);
}
////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS VECTORS //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
template <bool p>
class _HPoint3f : public Eigen::Matrix< Scalarf,4,1 > {
public:
typedef Eigen::Matrix< Scalarf,4,1 > BaseClass;
_HPoint3f<p>() : BaseClass(0,0,0,p) {}
_HPoint3f<p>(float x,float y,float z) : BaseClass(x,y,z,p) {}
_HPoint3f<p>(Vector3f &in) : BaseClass(in.homogeneous()) { this->operator()(3) = p; }
void operator delete(void* _p, size_t _s) {}
// This constructor allows to construct MyVectorType from Eigen expressions
template<typename OtherDerived>
inline _HPoint3f<p>(const Eigen::MatrixBase<OtherDerived>& other)
: BaseClass(other)
{ }
// This method allows to assign Eigen expressions to Vector3H
template<typename OtherDerived>
inline _HPoint3f<p> & operator= (const Eigen::MatrixBase <OtherDerived>& other)
{
this->BaseClass::operator=(other);
return *this;
}
};
typedef _HPoint3f<false> HVector3f;
typedef _HPoint3f<true> HPoint3f;
////////////////////////////////////////////////////////////////////////////////
////// HOMOGENEOUS LINE //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
struct _HLine3f
{
HPoint3f origin;
HVector3f direction;
};
typedef struct _HLine3f HLine3f;
inline std::ostream&
operator<< (std::ostream& stream, const HLine3f &line) {
stream << "HLine3f(" << "pt[" << line.origin.transpose() <<"] , dr[" << line.direction.transpose() << "]) ";
return stream;
}
struct _HError3f
{
HVector3f position_error;
HVector3f direction_error;
};
typedef struct _HError3f HError3f;
inline std::ostream&
operator<< (std::ostream& stream, const HError3f &err) {
stream << "HError3f(" << "ept[" << err.position_error.transpose() <<"] , edr[" << err.direction_error.transpose() << "]) ";
return stream;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// SERIALIZTION //
ULIB_SERIALIZABLE(uLib::HPoint3f)
ULIB_SERIALIZABLE(uLib::HVector3f)
ULIB_SERIALIZABLE(uLib::HLine3f)
ULIB_SERIALIZABLE(uLib::HError3f)
#endif // U_DENSEMATRIX_H

60
src/Math/Geometry.h Normal file
View File

@@ -0,0 +1,60 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_GEOMETRY_H
#define U_GEOMETRY_H
#include "Core/Object.h"
#include "Math/Dense.h"
#include "Math/Transform.h"
namespace uLib {
class Geometry : public AffineTransform {
public:
inline Vector4f GetWorldPoint(const Vector4f &v) const {
return this->GetWorldMatrix() * v;
}
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
return this->GetWorldPoint(Vector4f(x,y,z,1));
}
inline Vector4f GetLocalPoint(const Vector4f &v) const {
return this->GetWorldMatrix().inverse() * v;
}
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
return this->GetLocalPoint(Vector4f(x,y,z,1));
}
};
}
#endif // GEOMETRY_H

42
src/Math/Makefile.am Normal file
View File

@@ -0,0 +1,42 @@
SUBDIRS = .
include $(top_srcdir)/Common.am
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/Math
library_include_HEADERS = ContainerBox.h \
Dense.h \
Geometry.h \
Transform.h \
StructuredData.h\
StructuredGrid.h\
VoxImage.h \
VoxRaytracer.h \
Utils.h \
VoxImageFilter.h\
VoxImageFilter.hpp \
VoxImageFilterLinear.hpp \
VoxImageFilterMedian.hpp \
VoxImageFilterABTrim.hpp \
VoxImageFilterBilateral.hpp \
VoxImageFilterThreshold.hpp \
VoxImageFilter2ndStat.hpp \
VoxImageFilterCustom.hpp \
Accumulator.h \
TriangleMesh.h
_MATH_SOURCES = \
VoxRaytracer.cpp \
StructuredData.cpp \
StructuredGrid.cpp \
VoxImage.cpp \
TriangleMesh.cpp \
Dense.cpp
noinst_LTLIBRARIES = libmutommath.la
libmutommath_la_SOURCES = ${_MATH_SOURCES}

48
src/Math/Polydata.h Normal file
View File

@@ -0,0 +1,48 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef POLYDATA_H
#define POLYDATA_H
#include "Core/Object.h"
namespace uLib {
class Polydata : public Object {
public:
};
}
#endif // POLYDATA_H

49
src/Math/Quote.h Normal file
View File

@@ -0,0 +1,49 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#ifndef U_MATH_QUOTE_H
#define U_MATH_QUOTE_H
#include "Math/Dense.h"
namespace uLib {
class Quote : public Vector2f {
public:
uLibRefMacro(Offset,Scalarf);
private:
Scalarf m_Offset;
};
} // uLib
#endif // QUOTE_H

View File

@@ -0,0 +1,80 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "StructuredData.h"
using namespace uLib;
StructuredData::StructuredData(const Vector3i &size) :
m_Dims(size)
{
SetDataOrder();
}
void StructuredData::SetDims(const Vector3i &size)
{
this->m_Dims = size;
SetDataOrder();
}
void StructuredData::SetDataOrder(StructuredData::Order order)
{
int i = order & 0x3;
int j = (order >> 2) & 0x3;
int k = (order >> 4) & 0x3;
this->m_Increments[i] = 1;
this->m_Increments[j] = m_Dims[i];
this->m_Increments[k] = m_Dims[i] * m_Dims[j];
this->m_DataOrder = order;
}
bool StructuredData::IsInsideGrid(const Vector3i &v) const
{
int vok = 1;
vok *= (v(0) >= 0 && v(0) < m_Dims[0]);
vok *= (v(1) >= 0 && v(1) < m_Dims[1]);
vok *= (v(2) >= 0 && v(2) < m_Dims[2]);
return vok;
}
Vector3i StructuredData::UnMap(int index) const
{
Vector3i v( 0,0,0 );
Vector3i iv = m_Increments;
int id = 0;
for(int k=0; k<3; ++k) {
int inc = iv.maxCoeff(&id);
v(id) = index / inc;
index -= v(id) * inc;
iv(id) = 0;
}
return v;
}

Some files were not shown because too many files have changed in this diff Show More