Import Geant4 10.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-12-09 12:35:28 +01:00
parent 4ec577e5c4
commit a3452e42ac
3514 changed files with 210500 additions and 89628 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
# $Id: GNUmakefile 97990 2016-06-30 10:04:56Z gcosmo $
# $Id: GNUmakefile 100832 2016-11-02 15:32:45Z gcosmo $
# -----------------------------------------------------------------
# "gmake" makes default libraries for each subdomain.
# "gmake global" makes global libraries for each subdomain.
@@ -168,8 +168,8 @@ endif
banner:
@$(ECHO) "*************************************************************"
@$(ECHO) " Installation Geant4 version geant4-10-03-beta-01 "
@$(ECHO) " Copyright (C) 1994-2016 Geant4 Collaboration "
@$(ECHO) " Installation Geant4 version geant4-10-03 "
@$(ECHO) " Copyright (C) 1994-2017 Geant4 Collaboration "
@$(ECHO) "*************************************************************"
clean_libs::
+3 -3
View File
@@ -8,7 +8,7 @@
#
# Generated on : 24/9/2010
#
# $Id: CMakeLists.txt 93451 2015-10-22 14:53:57Z gcosmo $
# $Id: CMakeLists.txt 99561 2016-09-27 07:04:12Z gcosmo $
#
#------------------------------------------------------------------------------
@@ -17,11 +17,11 @@ if (GEANT4_USE_FREETYPE)
add_definitions(-DTOOLS_USE_EXPAT)
endif()
add_subdirectory(accumulables)
add_subdirectory(csv)
add_subdirectory(g4tools)
add_subdirectory(hntools)
add_subdirectory(management)
add_subdirectory(parameters)
add_subdirectory(root)
add_subdirectory(xml)
@@ -29,11 +29,11 @@ if(NOT GEANT4_BUILD_GRANULAR_LIBS)
include(Geant4MacroLibraryTargets)
GEANT4_GLOBAL_LIBRARY_TARGET(NAME G4analysis
COMPONENTS
accumulables/sources.cmake
csv/sources.cmake
g4tools/sources.cmake
hntools/sources.cmake
management/sources.cmake
parameters/sources.cmake
root/sources.cmake
xml/sources.cmake
)
+3 -3
View File
@@ -1,4 +1,4 @@
# $Id: GNUmakefile 94591 2015-11-25 11:13:33Z gcosmo $
# $Id: GNUmakefile 99561 2016-09-27 07:04:12Z gcosmo $
# --------------------------------------------------------------
#
@@ -18,8 +18,8 @@ endif
include $(G4INSTALL)/config/architecture.gmk
SUBDIRS = g4tools management hntools csv root xml parameters
SUBLIBS = G4tools G4analysismng G4hntools G4csv G4root G4xml G4parameters
SUBDIRS = g4tools management hntools csv root xml accumulables
SUBLIBS = G4tools G4analysismng G4hntools G4csv G4root G4xml G4accumulables
include $(G4INSTALL)/config/globlib.gmk
+106 -1
View File
@@ -1,4 +1,4 @@
$Id: History 97670 2016-06-07 08:22:37Z gcosmo $
$Id: History 101419 2016-11-17 10:36:30Z gcosmo $
-------------------------------------------------------------------
=========================================================
@@ -17,6 +17,111 @@ committal in the SVN repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
November 17, 2016 I. Hrivnacova (analysis-V10-02-25)
- Fixed compiler warning issued when G4VERBOSE is not set.
- Updated to g4tools 2.3.0 (Guy Barrand):
Adding methods to tools/impi for passing ntuple data.
See History_tools for the complete list of modifications.
November 03, 2016 I. Hrivnacova (analysis-V10-02-24)
- Updated to g4tools 2.2.0 (Guy Barrand):
Coverity fixes,
See History_tools for the complete list of modifications.
- Added prefix, postfix increment operators to G4Accumulable
October 30, 2016 I. Hrivnacova (analysis-V10-02-23)
- Simplified G4RootAnalysisManager::GetNtupleFileNumber() to avoid using
G4Threading::GetNumberOfRunningWorkerThreads() which seems to be failing
on gcc and icc plaftorms
- Added temporary debug printing from this method
October 28, 2016 I. Hrivnacova (analysis-V10-02-22)
- Merging ntuples in a selected number of output files
October 24, 2016 I. Hrivnacova (analysis-V10-02-21)
- Set back not merging ntuples by default.
- Fixed resetting ntuples (which was failing in case when
a new file is written per event and ntuples are created
after file is open (examples/advanced/gammaray_telescope
use case).
October 14, 2016 I. Hrivnacova (analysis-V10-02-20)
- Merging ntuples improvements:
- now working also when ntuples are booked after OpenFile (use case in AnaEx01)
- use directory if directory name is set
- added basketSize parameter in the SetNtupleMerging() public function
October 10, 2016 I. Hrivnacova (analysis-V10-02-19)
- Do not merge ntuples by default.
Merging ntuples requires the application to call CreateNtuple both on master
and workers, what is not done in all examples.
October 08, 2016 I. Hrivnacova (analysis-V10-02-18)
- Disabled code using the number of threads in G4RootAnalysisManager
untill this function is available in G4Threading;
user setting of numbert of reduced ntuple files is ignored.
October 08, 2016 I. Hrivnacova (analysis-V10-02-17)
- Fixed case in included file name
October 08, 2016 I. Hrivnacova (analysis-V10-02-16)
- Implemented merging of ntuples in MT mode:
- Added G4RootAnalysisManager::SetMerging(G4bool mergeNtuples, G4int nofReducedNtupleFile)
- Added G4RootPNtupleManager, G4RootMainNtupleManager classes
- Updated to g4tools 2.1.0 (Guy Barrand)
For parallel ntuple : handle properly the user std::vector for column of vector.
See History_tools for the complete list of modifications.
October 3, 2016 I. Hrivnacova (analysis-V10-02-15)
- Removing dependencies of accumulables on other analysis categories
October 3, 2016 G. Cosmo (analysis-V10-02-14)
- Fixed again GNUmakefile in "accumulables" module...
September 30, 2016 I. Hrivnacova (analysis-V10-02-13)
- Updated to g4tools 2.0.0 (Guy Barrand)
Added parallel ntuple : on a same booked nutple, pass baskets from threads
or mpi ranks to a "main ntuple" tied to a file.
See History_tools for the complete list of modifications.
September 27, 2016 G. Cosmo (analysis-V10-02-12)
- Fixed GNUmakefile in new "accumulables" module.
September 26, 2016 I. Hrivnacova (analysis-V10-02-11)
- Renamed G4Parameter in G4Accumulable (as suggested in CM in Ferrara)
including all related classes and the subdirectory parameters
in accumulables
September 8, 2016 I. Hrivnacova (analysis-V10-02-10)
- Enable creating/configurion profiles without cut values (vmin, vmax).
This feature was disabled by a check for the values in G4VAnalysisManager;
these values are now treated in a special way.
- Fixed duplicating Csv ntuple header
September 6, 2016 I. Hrivnacova (analysis-V10-02-09)
- Fixed writing CSV profiles
(to be propagated in the patch to 10.2)
July 4, 2016 I. Hrivnacova (analysis-V10-02-08)
- Adding missing inline keyword to functions defined in
G4ParameterManager.icc
June 24, 2016 I. Hrivnacova (analysis-V10-02-07)
- Fixing compilation with gcc: added missing include <functional>
June 23, 2016 I. Hrivnacova (analysis-V10-02-06)
- Extended and improved current implementation of parameters:
- The parameters names are optional
- Extended merge mode with kMaximum, kMinimum
and removed kUser (not needed anymore)
- Added access to paremeters via iterators and ids
(defined by the order of registering)
- Introduced G4MergeFunction<T> type and apply merging via a function
defined accorting to the merge mode
(thanks to Jonathan Madsen for providing an example of the code)
- Return 0. instead of 0 when the return type is double
- Return nullptr instead of 0
June 7, 2016 I. Hrivnacova (analysis-V10-02-05)
- Updated to g4tools 1.27.4 (Guy Barrand):
Fixed remaining Windows-64 compiler warnings.
+70
View File
@@ -1,3 +1,73 @@
2.3.0 :
- test/cpp/mpi_ntuple.cpp : use a maximum tools::impi interface which does not bring mpi.h.
- tools/mpi/pntuple : have the code using only the tools::impi interface.
- tools/mpi/wrmpi : pack_reset(), send_buffer() virtual methods implementations.
- tools/impi : pack_reset(), send_buffer() virtual methods.
2.2.0 :
- sg/vertices : supress m_xyzs_pos field to correct a Coverity issue.
- sg/atb_vertices : m_[xyzs,rgbas,nms]_pos protected. To correct Coverity issues.
- rroot/ntuple : initialize() : if(!_branch) => if(!_be) : seen by coverity.
- wroot/to : add code to write annotations.
- rroot/rall :
- add touplow.
2.1.0 : for parallel ntuple : handle properly the user std::vector for column of vector.
- ntuple_booking : add the set_user_obj() method and non-const columns() getter.
- rroot/branch_element : implement a show() method to show the m_obj address.
- rroot/branch : make virtual the show() method.
- test/cpp : pwroot.cpp, wroot_pntuple.cpp, mpi_ntuple.cpp : example of a vector column.
2.0.0 :
wroot : parallel ntuple : on a same booked nutple, pass baskets from threads or mpi ranks to a "main ntuple" tied to a file.
rroot : modifs to be in sync with the logic of wroot.
remove hbook, fortran and cernlib related things.
- tools/wroot,rroot : base_leaf, branch, key, basket, fac : remove ifile& relationship in constructors.
- tools/wroot,rroot : base_leaf, branch, basket : remove relationship to "manager" (exa remove m_branch in base_leaf).
- realloc, wps, tos, smatch, xml/tree, args, array, rcsv_histo, rcsv_ntuple, b2s, cmemT, glprims, hplot,
xml/loader : use size_t instead of unsigned int.
- viewplot, wps : a_anonymous arg to write ps file without date. It permits to compare files.
- snpf : _MSC_VER < 1900 : handle "_TWO_DIGIT_EXPONENT".
- rtausmeui : mem count.
- randT, randd, randf : pass templated math_func in arg to shoot (a_sqrt, a_log).
- path : suffix, nosuffix : avoid return of a std::string.
- mathd, mathf : rad2deg, deg2rad : use a static to do the computation once.
- cmathT : rm _conj functions.
- forit : vfor : reverse.
- impi, mpi/wrmpi : pack, unpack(int64).
- histo/base_histo, c1d, c2d, c3d, dps : unsigned int -> size_t.
- xml/loader : handle a_take_ctrl.
- io/iwbuf, sg/bmf, mf, line_set, group, axis, style_parser, cube, colormap, plots, atb_vertices,
text_freetype, text_hershey, pick_action, plotter : unsigned int -> size_t.
- sg/gl_manager, manage_zb, render_zb, primitive_visitor, render_action : unsigned int -> size_t.
- sg/primitive_visitor : *pos++ -> *pos;pos++.
- colorf : remove static color functions. They are put in colorfs.
- sg/vertices : is_visible().
- sg/field, field_desc : editable field.
- sg/legend, text, rgba, torche, infos_box, colormap, axis, text_style, back_area, style, style_colormap, line_style.
- test/cpp/viewplot.cpp : colorf::<color>() -> colorf_<color>().
- test/cpp/wroot.cpp : -megas option.
- test/cpp/mpi.cpp -> mpi_histos.cpp.
- test/cpp/rroot.cpp, rxrayfluo.cpp :
tools::rroot::key_to_<obj>(rfile,*key); : add the rfile at first argument.
char* buf = key->get_object_buffer(rfile,sz); : add the rfile at first argument.
tools::rroot::fac fac(std::cout); : replace rfile arg by std::cout.
- histo : cosmetic aEdges => a_edges.
- rroot : cosmetic rm not needed tools::rroot:: prefix.
- lina/qrot (rotf) : pass a_sqrt, a_fabs, a_sin, a_cos,... in arg.
- args : use mem::inc,dec.
- file, file_format, fileis, fsize : handle py, lua, jive. Isolate size() in a standalone file.
- raxml, xml/aidas : separate the xml parsing logic (in a xml/aidas file) from the expat reader.
(Have something similar than the xml style reading).
- sg : gl_manager, manager_zb : begin_render() : have two more args to pass the area size to render.
- sg : axis : pick() : use nodekit_pick(). It permits to pick and move an axis (in interactive apps).
1.27.4 :
- tools/value : Windows-64 : rm warnings when writing a void* in a string..
@@ -0,0 +1,18 @@
#------------------------------------------------------------------------------
# CMakeLists.txt
# Module : G4analysis
# Package: Geant4.src.G4analysis.G4analysismng
#
# CMakeLists.txt for building a single granular library.
#
# Created on : 15/07/2013
#
# $Id: CMakeLists.txt 99561 2016-09-27 07:04:12Z gcosmo $
#
#------------------------------------------------------------------------------
if(GEANT4_BUILD_GRANULAR_LIBS)
include(Geant4MacroLibraryTargets)
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
endif()
+17
View File
@@ -0,0 +1,17 @@
# $Id: GNUmakefile 66356 2012-12-18 09:02:32Z gcosmo $
# --------------------------------------------------------------------
# GNUmakefile for analysis/management sub-library.
# --------------------------------------------------------------------
name := G4accumulables
ifndef G4INSTALL
G4INSTALL = ../../..
endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/intercoms/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,83 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
// Class template for accumulables handled by Geant4 analysis
//
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
#ifndef G4Accumulable_h
#define G4Accumulable_h 1
#include "G4VAccumulable.hh"
#include "G4MergeMode.hh"
#include "globals.hh"
template <typename T>
class G4Accumulable : public G4VAccumulable
{
public:
G4Accumulable(const G4String& name, T initValue,
G4MergeMode mergeMode = G4MergeMode::kAddition);
G4Accumulable(T initValue,
G4MergeMode mergeMode = G4MergeMode::kAddition);
G4Accumulable(const G4Accumulable& rhs);
G4Accumulable() = delete;
virtual ~G4Accumulable();
// operators
G4Accumulable<T>& operator= (const G4Accumulable<T>& rhs);
G4Accumulable<T>& operator+=(const G4Accumulable<T>& rhs);
G4Accumulable<T>& operator*=(const G4Accumulable<T>& rhs);
G4Accumulable<T> operator++(int); // postfix increment
G4Accumulable<T>& operator++(); // prefix increment
G4Accumulable<T>& operator= (const T& rhs);
G4Accumulable<T>& operator+=(const T& rhs);
G4Accumulable<T>& operator*=(const T& rhs);
// methods
virtual void Merge(const G4VAccumulable& other) final;
virtual void Reset() final;
// get methods
T GetValue() const;
G4MergeMode GetMergeMode() const;
private:
// data members
T fValue;
T fInitValue;
G4MergeMode fMergeMode;
G4MergeFunction<T> fMergeFunction;
};
// inline functions
#include "G4Accumulable.icc"
#endif
@@ -0,0 +1,186 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
//
// utilities
//
//
// public functions
//
using namespace G4Accumulables;
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
: G4VAccumulable(name),
fValue(initValue),
fInitValue(initValue),
fMergeMode(mergeMode),
fMergeFunction(GetMergeFunction<T>(mergeMode))
{}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
: G4VAccumulable(),
fValue(initValue),
fInitValue(initValue),
fMergeMode(mergeMode),
fMergeFunction(GetMergeFunction<T>(mergeMode))
{}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
: G4VAccumulable(rhs),
fValue(rhs.fValue),
fInitValue(rhs.fInitValue),
fMergeMode(rhs.fMergeMode),
fMergeFunction(rhs.fMergeFunction)
{}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>::~G4Accumulable()
{}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
{
// check assignment to self
if (this == &rhs) return *this;
// base class assignment
G4VAccumulable::operator=(rhs);
// this class data assignment
fValue = rhs.fValue;
fInitValue = rhs.fInitValue;
fMergeMode = rhs.fMergeMode;
fMergeFunction = rhs.fMergeFunction;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
{
// only update the value from rhs
fValue += rhs.fValue;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
{
// only update the value from rhs
fValue *= rhs.fValue;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator=(const T& value)
{
// only update the value
fValue = value;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator+=(const T& value)
{
// only update the value
fValue += value;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator*=(const T& value)
{
// only update the value from rhs
fValue *= value;
return *this;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>
G4Accumulable<T>::operator++(int)
{
// postfix increment
G4Accumulable<T> temp = *this;
fValue++;
return temp;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>&
G4Accumulable<T>::operator++()
{
// prefix increment
fValue++;
return *this;
}
//_____________________________________________________________________________
template <typename T>
void G4Accumulable<T>::Merge(const G4VAccumulable& other)
{
// G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
// G4cout << " to master: " << fName << " " << fValue << G4endl;
fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
// G4cout << " new value: " << fName << " " << fValue << G4endl;
}
//_____________________________________________________________________________
template <typename T>
void G4Accumulable<T>::Reset()
{
fValue = fInitValue;
}
//_____________________________________________________________________________
template <typename T>
T G4Accumulable<T>::GetValue() const
{
return fValue;
}
@@ -0,0 +1,130 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AccumulableManager.hh 91012 2015-06-15 10:38:07Z ihrivnac $
// The common implementation of analysis manager classes.
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
#ifndef G4AccumulableManager_h
#define G4AccumulableManager_h 1
#include "G4Accumulable.hh"
#include "globals.hh"
#include <map>
#include <vector>
class G4AnalysisManagerState;
class G4VAccumulable;
class G4AccumulableManager
{
public:
virtual ~G4AccumulableManager();
// static methods
static G4AccumulableManager* Instance();
// Methods
// Create accumulables
//
template <typename T>
G4Accumulable<T>*
CreateAccumulable(const G4String& name, T value,
G4MergeMode mergeMode = G4MergeMode::kAddition);
template <typename T>
G4Accumulable<T>*
CreateAccumulable(T value,
G4MergeMode mergeMode = G4MergeMode::kAddition);
// Register existing accumulables
//
// templated accumulable
template <typename T>
G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
// user defined accumulable
G4bool RegisterAccumulable(G4VAccumulable* accumulable);
// Access registered accumulables
//
// Via name
// templated accumulable
template <typename T>
G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
// user defined accumulable
G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
// Via id (in the order of registering)
// templated accumulable
template <typename T>
G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
// user defined accumulable
G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
G4int GetNofAccumulables() const;
// Via vector iterators
std::vector<G4VAccumulable*>::iterator Begin();
std::vector<G4VAccumulable*>::iterator End();
std::vector<G4VAccumulable*>::const_iterator BeginConst() const;
std::vector<G4VAccumulable*>::const_iterator EndConst() const;
// Methods applied to all accumulables
void Merge();
void Reset();
private:
// hide ctor requiring master/worker specification
G4AccumulableManager(G4bool isMaster);
// metods
// Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
G4String GenerateName() const;
// Check if a name is already used in a map and print a warning
G4bool CheckName(const G4String& name, const G4String& where) const;
template <typename T>
G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
// constants
const G4String kBaseName = "accumulable";
// static data members
static G4AccumulableManager* fgMasterInstance;
static G4ThreadLocal G4AccumulableManager* fgInstance;
// data members
std::vector<G4VAccumulable*> fVector;
std::map<G4String, G4VAccumulable*> fMap;
std::vector<G4VAccumulable*> fAccumulablesToDelete;
};
#include "G4AccumulableManager.icc"
#endif
@@ -0,0 +1,135 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AccumulableManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>*
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
{
// Do not check type if nullptr
if ( ! accumulable ) return nullptr;
// check type
G4Accumulable<T>* taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
if ( ! taccumulable && warn ) {
G4ExceptionDescription description;
description << " " << "Accumulable " << accumulable->GetName()
<< " has different type";
G4Exception("G4AccumulableManager::GetAccumulable<T>",
"Analysis_W011", JustWarning, description);
return nullptr;
}
return taccumulable;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>*
G4AccumulableManager::CreateAccumulable(
const G4String& name, T value, G4MergeMode mergeMode)
{
// do not accept name if it is already used
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
// create accumulable
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
// register accumulable in the map and vector
RegisterAccumulable(accumulable);
fAccumulablesToDelete.push_back(accumulable);
return accumulable;
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>*
G4AccumulableManager::CreateAccumulable(
T value, G4MergeMode mergeMode)
{
return CreateAccumulable(G4String(), value, mergeMode);
}
//_____________________________________________________________________________
template <typename T>
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
{
return RegisterAccumulable(&accumulable);
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>*
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
{
// get G4VParammeter from the map
auto accumulable = GetAccumulable(name, warn);
return GetAccumulable<T>(accumulable, warn);
}
//_____________________________________________________________________________
template <typename T>
G4Accumulable<T>*
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
{
// get G4VParammeter from the map
auto accumulable = GetAccumulable(id, warn);
return GetAccumulable<T>(accumulable, warn);
}
//_____________________________________________________________________________
inline G4int G4AccumulableManager::GetNofAccumulables() const
{
return fVector.size();
}
//_____________________________________________________________________________
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
{
return fVector.begin();
}
//_____________________________________________________________________________
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
{
return fVector.end();
}
//_____________________________________________________________________________
inline std::vector<G4VAccumulable*>::const_iterator
G4AccumulableManager::BeginConst() const
{
return fVector.begin();
}
//_____________________________________________________________________________
inline std::vector<G4VAccumulable*>::const_iterator
G4AccumulableManager::EndConst() const
{
return fVector.end();
}
@@ -0,0 +1,94 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
#ifndef G4MergeMode_h
#define G4MergeMode_h 1
#include "globals.hh"
#include <functional>
#include <cmath>
// Enumeration for definition available binning schemes
enum class G4MergeMode {
kAddition, // "Or" if boolean type
kMultiplication, // "And" if boolean type
kMaximum, // "Or" if boolean type
kMinimum // "And" if boolean type
};
// Generic merge function
template <typename T>
using G4MergeFunction = std::function<T(const T&, const T&)>;
// Utility functions
namespace G4Accumulables {
G4MergeMode GetMergeMode(const G4String& mergeModeName);
template <typename T>
G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
{
switch ( mergeMode ) {
case G4MergeMode::kAddition:
// return std::bind([](const T& x, const T& y) { return x + y; });
return [](const T& x, const T& y) { return x + y; };
case G4MergeMode::kMultiplication:
return [](const T& x, const T& y) { return x * y; };
case G4MergeMode::kMaximum:
// return std::bind([](const T& x, const T& y) { return std::max(x,y);});
return [](const T& x, const T& y) { return std::max(x,y); };
case G4MergeMode::kMinimum:
// return std::bind([](const T& x, const T& y) { return std::min(x,y);});
return [](const T& x, const T& y) { return std::min(x,y); };
}
}
template <G4bool>
G4MergeFunction<G4bool> GetMergeFunction(G4MergeMode mergeMode)
{
switch ( mergeMode ) {
case G4MergeMode::kAddition:
case G4MergeMode::kMaximum:
// return std::bind([](const T& x, const T& y) { return x + y; });
return [](const G4bool& x, const G4bool& y) { return x || y; };
case G4MergeMode::kMultiplication:
case G4MergeMode::kMinimum:
return [](const G4bool& x, const G4bool& y) { return x && y; };
}
}
}
#endif
@@ -0,0 +1,65 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4CsvNtupleManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Value type independent base class for accumulables handled by Geant4 analysis
//
// Author: Ivana Hrivnacova, 04/09/2015 (ivana@ipno.in2p3.fr)
#ifndef G4VAccumulable_h
#define G4VAccumulable_h 1
#include "globals.hh"
class G4VAccumulable
{
// To allow G4AccumulableManager set name if not defined by user
friend class G4AccumulableManager;
public:
G4VAccumulable(const G4String& name = "");
G4VAccumulable(const G4VAccumulable& rhs);
virtual ~G4VAccumulable() {}
// operators
G4VAccumulable& operator=(const G4VAccumulable& rhs);
// methods
virtual void Merge(const G4VAccumulable& other) = 0;
virtual void Reset() = 0;
// get methods
G4String GetName() const;
protected:
G4String fName;
};
#include "G4VAccumulable.icc"
#endif
@@ -0,0 +1,50 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AccumulableManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
//_____________________________________________________________________________
inline G4VAccumulable::G4VAccumulable(const G4String& name)
: fName(name)
{}
//_____________________________________________________________________________
inline G4VAccumulable::G4VAccumulable(const G4VAccumulable& rhs)
: fName(rhs.fName)
{}
//_____________________________________________________________________________
inline G4VAccumulable& G4VAccumulable::operator=(const G4VAccumulable& rhs)
{
fName = rhs.fName;
return *this;
}
//_____________________________________________________________________________
inline G4String G4VAccumulable::GetName() const
{
return fName;
}
@@ -0,0 +1,52 @@
#------------------------------------------------------------------------------
# sources.cmake
# Module : G4hntools
# Package: Geant4.src.G4analysis.G4hntools
#
# Sources description for a library.
# Lists the sources and headers of the code explicitely.
# Lists include paths needed.
# Lists the internal granular and global dependencies of the library.
# Source specific properties should be added at the end.
#
# Generated on : 15/07/2013
#
# $Id: sources.cmake 91489 2015-07-20 12:53:29Z ihrivnac $
#
#------------------------------------------------------------------------------
# List external includes needed.
include_directories(${CLHEP_INCLUDE_DIRS})
# List internal includes needed.
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
include_directories(${CMAKE_SOURCE_DIR}/source/intercoms/include)
#
# Define the Geant4 Module.
#
include(Geant4MacroDefineModule)
GEANT4_DEFINE_MODULE(NAME G4accumulables
HEADERS
G4MergeMode.hh
G4AccumulableManager.hh
G4AccumulableManager.icc
G4Accumulable.hh
G4Accumulable.icc
G4VAccumulable.hh
G4VAccumulable.icc
SOURCES
G4MergeMode.cc
G4AccumulableManager.cc
GRANULAR_DEPENDENCIES
G4globman
G4intercoms
# G4analysismng
GLOBAL_DEPENDENCIES
G4global
G4intercoms
LINK_LIBRARIES
)
# List any source specific properties here
@@ -0,0 +1,216 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AccumulableManager.cc 91116 2015-06-20 12:33:45Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4AccumulableManager.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
// mutex in a file scope
namespace {
//Mutex to lock master manager when merging accumulables
G4Mutex mergeMutex = G4MUTEX_INITIALIZER;
}
G4AccumulableManager* G4AccumulableManager::fgMasterInstance = nullptr;
G4ThreadLocal G4AccumulableManager* G4AccumulableManager::fgInstance = nullptr;
//_____________________________________________________________________________
G4AccumulableManager* G4AccumulableManager::Instance()
{
if ( fgInstance == nullptr ) {
G4bool isMaster = ! G4Threading::IsWorkerThread();
fgInstance = new G4AccumulableManager(isMaster);
}
return fgInstance;
}
//_____________________________________________________________________________
G4AccumulableManager::G4AccumulableManager(G4bool isMaster)
: fVector(),
fMap()
{
if ( ( isMaster && fgMasterInstance ) || ( fgInstance ) ) {
G4ExceptionDescription description;
description
<< " "
<< "G4AccumulableAnalysisManager already exists."
<< "Cannot create another instance.";
G4Exception("G4AccumulableAnalysisManager::G4AccumulableAnalysisManager()",
"Analysis_F001", FatalException, description);
}
if ( isMaster ) fgMasterInstance = this;
fgInstance = this;
}
//_____________________________________________________________________________
G4AccumulableManager::~G4AccumulableManager()
{
// delete only accumulables create by the mager itself
for ( auto it : fAccumulablesToDelete ) {
delete it;
}
}
//
// private methods
//
//_____________________________________________________________________________
G4String G4AccumulableManager::GenerateName() const
{
G4String name = kBaseName;
std::ostringstream os;
os << fVector.size();
name.append("_");
name.append(os.str());
return name;
}
//_____________________________________________________________________________
G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& where) const
{
if ( fMap.find(name) == fMap.end() ) return true;
G4ExceptionDescription description;
description << " " << "Name " << name << " is already used." << G4endl;
description << " " << "Paremeter will be not created/registered.";
G4String method("G4AccumulableManager::");
method.append(where);
G4Exception(method, "Analysis_W002", JustWarning, description);
return false;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
{
auto name = accumulable->GetName();
// do not accept name if it is already used
if ( ! CheckName(name, "RegisterAccumulable") ) return false;
// generate name if empty
if ( ! name.length() ) {
name = GenerateName();
accumulable->fName = name;
}
fMap[name] = accumulable;
fVector.push_back(accumulable);
return true;
}
//_____________________________________________________________________________
G4VAccumulable*
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
{
// get G4VParammeter from the map
auto it = fMap.find(name);
if ( it == fMap.end() ) {
if ( warn) {
G4ExceptionDescription description;
description << " " << "accumulable " << name << " does not exist.";
G4Exception("G4AccumulableManager::GetAccumulable",
"Analysis_W011", JustWarning, description);
}
return nullptr;
}
return it->second;
}
//_____________________________________________________________________________
G4VAccumulable*
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
{
// get G4VParammeter from the vector
if ( id < 0 || id >= G4int(fVector.size()) ) {
if ( warn) {
G4ExceptionDescription description;
description << " " << "accumulable " << id << " does not exist.";
G4Exception("G4AccumulableManager::GetAccumulable",
"Analysis_W011", JustWarning, description);
}
return nullptr;
}
return fVector[id];
}
//_____________________________________________________________________________
void G4AccumulableManager::Merge()
{
// Do nothing if there are no accumulables registered
// or if master thread
if ( (! fVector.size()) || (! G4Threading::IsWorkerThread()) ) return;
// The manager on mastter must exist
if ( ! fgMasterInstance ) {
G4ExceptionDescription description;
description
<< " " << "No master G4AccumulableManager instance exists."
<< G4endl
<< " " << "Accumulables will not be merged.";
G4Exception("G4AccumulableManager::Merge()",
"Analysis_W031", JustWarning, description);
return;
}
// The worker manager just merges its accumulables to the master
// This operation needs a lock
// G4cout << "Go to merge accumulables" << G4endl;
G4AutoLock lock(&mergeMutex);
// the other manager has the vector with the "same" accumulables
auto it = fVector.begin();
for ( auto itMaster : fgMasterInstance->fVector ) {
// G4VAccumulable* masterAccumulable = itMaster;
// G4VAccumulable* accumulable = *(it++);
// masterAccumulable->Merge(*(accumulable));
itMaster->Merge(*(*(it++)));
}
lock.unlock();
}
//_____________________________________________________________________________
void G4AccumulableManager::Reset()
{
// Reset histograms and profiles
for ( auto it : fVector ) {
it->Reset();
}
}
@@ -0,0 +1,50 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id:$
// Author: Ivana Hrivnacova, 22/08/2013 (ivana@ipno.in2p3.fr)
#include "G4MergeMode.hh"
namespace G4Accumulables
{
//_____________________________________________________________________________
G4MergeMode GetMergeMode(const G4String& mergeModeName) {
if ( mergeModeName == "+" ) { return G4MergeMode::kAddition; }
else if ( mergeModeName == "*" ) { return G4MergeMode::kMultiplication; }
else {
G4ExceptionDescription description;
description
<< " \"" << mergeModeName << "\" merge mode is not supported." << G4endl
<< " " << "Addition will be applied.";
G4Exception("G4Analysis::GetMergeMode",
"Analysis_W013", JustWarning, description);
return G4MergeMode::kAddition;
}
}
}
@@ -30,6 +30,82 @@
#include "tools/wcsv_histo"
//_____________________________________________________________________________
template <>
inline
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p1d*>& htVector,
const std::vector<G4HnInformation*>& hnVector,
const G4String& hnType)
{
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
auto info = hnVector[i];
auto activation = info->GetActivation();
auto name = info->GetName();
// skip writing if activation is enabled and H1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
auto ht = htVector[i];
auto fileName = fFileManager->GetHnFileName(hnType, name);
std::ofstream hnFile(fileName);
auto result
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving " << hnType << " " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockHistoDirectoryName();
}
return true;
}
//_____________________________________________________________________________
template <>
inline
G4bool G4CsvAnalysisManager::WriteT(const std::vector<tools::histo::p2d*>& htVector,
const std::vector<G4HnInformation*>& hnVector,
const G4String& hnType)
{
for ( G4int i=0; i<G4int(htVector.size()); ++i ) {
auto info = hnVector[i];
auto activation = info->GetActivation();
auto name = info->GetName();
// skip writing if activation is enabled and H1 is inactivated
if ( fState.GetIsActivation() && ( ! activation ) ) continue;
auto ht = htVector[i];
auto fileName = fFileManager->GetHnFileName(hnType, name);
std::ofstream hnFile(fileName);
auto result
= tools::wcsv::pto(hnFile, ht->s_cls(), *ht);
if ( ! result ) {
G4ExceptionDescription description;
description << " " << "saving " << hnType << " " << name << " failed";
G4Exception("G4CsvAnalysisManager::Write()",
"Analysis_W022", JustWarning, description);
return false;
}
hnFile.close();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", fileName);
#endif
fFileManager->LockHistoDirectoryName();
}
return true;
}
//_____________________________________________________________________________
template <typename T>
inline
+3 -10
View File
@@ -87,22 +87,15 @@ void G4CsvNtupleManager::CreateTNtupleFromBooking(
ntupleDescription->fNtuple
= new tools::wcsv::ntuple(
*(ntupleDescription->fFile), G4cerr, ntupleDescription->fNtupleBooking);
fNtupleVector.push_back(ntupleDescription->fNtuple);
// write header (if activated)
if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
G4ExceptionDescription description;
description << " "
<< "Writing ntuple header has failed. ";
G4Exception("G4CsvNtupleManager::CreateNtupleFromBooking()",
"Analysis_W021", JustWarning, description);
}
fNtupleVector.push_back(ntupleDescription->fNtuple);
}
//_____________________________________________________________________________
void G4CsvNtupleManager::FinishTNtuple(
G4TNtupleDescription<tools::wcsv::ntuple>* ntupleDescription)
{
if ( ! ntupleDescription->fNtuple ) return;
// Write header if ntuple already exists
if ( ! WriteHeader(ntupleDescription->fNtuple) ) {
G4ExceptionDescription description;
+54 -161
View File
@@ -4,6 +4,11 @@
#ifndef tools_args
#define tools_args
#ifdef TOOLS_MEM
#include "mem"
#include "S_STRING"
#endif
#include "sout"
#include "strip"
#include "words"
@@ -16,11 +21,21 @@
namespace tools {
class args {
#ifdef TOOLS_MEM
TOOLS_SCLASS(tools::args)
#endif
public:
typedef std::pair<std::string,std::string> arg;
public:
args(){}
args(){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
args(int a_argc,char* a_argv[]){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
for(int index=0;index<a_argc;index++) {
std::string s(a_argv[index]);
std::string::size_type pos = s.find('=');
@@ -34,17 +49,37 @@ public:
}
}
}
args(const std::vector<std::string>& a_args){add(a_args);}
args(const std::vector<arg>& a_args):m_args(a_args){}
args(const std::vector<std::string>& a_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
add(a_args);
}
args(const std::vector<arg>& a_args):m_args(a_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
//args(const std::string& a_args,const std::string& a_sep = " ",bool a_strip = false){
args(const std::string& a_args,const std::string& a_sep,bool a_strip){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
std::vector<std::string> _args;
words(a_args,a_sep,false,_args);
add(_args,a_strip);
}
virtual ~args(){}
virtual ~args(){
#ifdef TOOLS_MEM
mem::decrement(s_class().c_str());
#endif
}
public:
args(const args& a_from):m_args(a_from.m_args){}
args(const args& a_from):m_args(a_from.m_args){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
args& operator=(const args& a_from){
m_args = a_from.m_args;
return *this;
@@ -59,8 +94,8 @@ public:
return false;
}
bool is_empty() const {return m_args.size()?false:true;}
unsigned int size() const {return m_args.size();}
unsigned int number() const {return m_args.size();} //back comp.
size_t size() const {return m_args.size();}
size_t number() const {return m_args.size();} //back comp.
bool find(const std::string& a_key,std::string& a_value,const std::string& a_def = "") const {
tools_vforcit(arg,m_args,it) {
if((*it).first==a_key) {
@@ -139,7 +174,7 @@ public:
void add_keyvals(const std::vector<std::string>& a_args,bool a_strip = false) {
//a_args must contain an even number of strings.
unsigned int sz_half = a_args.size()/2;
size_t sz_half = a_args.size()/2;
if((2*sz_half)!=a_args.size()) return;
for(std::vector<std::string>::const_iterator it = a_args.begin();it!=a_args.end();it+=2) {
if(a_strip) {
@@ -159,7 +194,7 @@ public:
}
int remove(const std::string& a_key){
unsigned int nbeg = m_args.size();
size_t nbeg = m_args.size();
for(std::vector<arg>::iterator it = m_args.begin();it!=m_args.end();) {
if(a_key==(*it).first) {
it = m_args.erase(it);
@@ -167,7 +202,7 @@ public:
++it;
}
}
return nbeg - m_args.size();
return int(nbeg) - int(m_args.size());
}
void remove_first(){m_args.erase(m_args.begin());}
@@ -202,25 +237,25 @@ public:
return false;
}
}
std::vector<std::string> files(bool a_skip_first = true) const {
void files(std::vector<std::string>& a_files,bool a_skip_first = true) const {
a_files.clear();
// Get the serie of trailing args not beginning with '-'
// and without a value (not of the form [-]xxx=yyy).
// Note that an argument like that in between arguments
// is NOT taken into account.
std::vector<std::string> _files;
if(m_args.empty()) return _files;
if(m_args.empty()) return;
std::vector<arg>::const_iterator it = m_args.begin();
if(a_skip_first) it++;
for(;it!=m_args.end();++it) {
if( ((*it).first.find('-')==0) || (*it).second.size() ) {
_files.clear();
a_files.clear();
} else {
_files.push_back((*it).first);
a_files.push_back((*it).first);
}
}
return _files;
}
bool argcv(int& a_argc,char**& a_argv) const {
// If using with :
// int argc;
@@ -330,15 +365,11 @@ inline bool check_min(const std::vector<std::string>& a_args,unsigned int a_numb
a_last.clear();
} else {
a_last = a_args[0];
for(unsigned int index=1;index<a_args.size();index++) {
a_last += " " + a_args[index];
}
for(size_t index=1;index<a_args.size();index++) a_last += " " + a_args[index];
}
} else {
a_last = a_args[a_number-1];
for(unsigned int index=a_number;index<a_args.size();index++) {
a_last += " " + a_args[index];
}
for(size_t index=a_number;index<a_args.size();index++) a_last += " " + a_args[index];
}
return true;
}
@@ -367,144 +398,6 @@ inline bool check_or_args(const std::vector<std::string>& aArgs,unsigned int a_1
return false;
}
inline std::string gui_toolkit(args& a_args,bool a_rm_in_args){
std::string driver;
a_args.find("-toolkit",driver);
if(a_rm_in_args) a_args.remove("-toolkit");
if(driver.empty()) {
if(a_args.is_arg("-Xt")||
a_args.is_arg("-xt")||
a_args.is_arg("-Xm")||
a_args.is_arg("-xm")||
a_args.is_arg("-Motif")||
a_args.is_arg("-motif")) {
driver = "Xt";
if(a_rm_in_args) {
a_args.remove("-Xt");
a_args.remove("-xt");
a_args.remove("-Xm");
a_args.remove("-xm");
a_args.remove("-Motif");
a_args.remove("-motif");
}
} else if(a_args.is_arg("-Win")||
a_args.is_arg("-win")||
a_args.is_arg("-Win32")||
a_args.is_arg("-win32")) {
driver = "Win";
if(a_rm_in_args) {
a_args.remove("-Win");
a_args.remove("-win");
a_args.remove("-Win32");
a_args.remove("-win32");
}
} else if(a_args.is_arg("-NextStep")||
a_args.is_arg("-nextstep")) {
driver = "NextStep";
if(a_rm_in_args) {
a_args.remove("-NextStep");
a_args.remove("-nextstep");
}
} else if(a_args.is_arg("-Gtk")||
a_args.is_arg("-gtk")) {
driver = "Gtk";
if(a_rm_in_args) {
a_args.remove("-Gtk");
a_args.remove("-gtk");
}
} else if(a_args.is_arg("-Qt")||
a_args.is_arg("-qt")) {
driver = "Qt";
if(a_rm_in_args) {
a_args.remove("-Qt");
a_args.remove("-qt");
}
} else if(a_args.is_arg("-SDL")||
a_args.is_arg("-sdl")) {
driver = "SDL";
if(a_rm_in_args) {
a_args.remove("-SDL");
a_args.remove("-sdl");
}
} else if(a_args.is_arg("-Net")||
a_args.is_arg("-net")) {
driver = "Net";
if(a_rm_in_args) {
a_args.remove("-Net");
a_args.remove("-net");
}
} else if(a_args.is_arg("-inex")) {
driver = "inex";
if(a_rm_in_args) {
a_args.remove("-inex");
}
}
}
return driver;
}
inline void window_size_from_args(const args& a_args,unsigned int& a_ww,unsigned int& a_wh) {
// return some common window size (in pixels).
if(a_args.is_arg("-iPod")||a_args.is_arg("-iPhone")) {
a_ww = 320;
a_wh = 480;
} else if(a_args.is_arg("-iPad")) {
a_ww = 768;
a_wh = 1024;
} else if(a_args.is_arg("-iPhone4")) {
a_ww = 640;
a_wh = 960;
} else if(a_args.is_arg("-wallino")) { //emulate LAL/wallino aspect ratio.
a_ww = 1024;
a_wh = 512;
} else if(a_args.is_arg("-SGS")) { //Samsung Galaxy S
//a_ww = 320;
//a_wh = 533;
a_ww = 480;
a_wh = 800;
} else {
if(a_args.find<unsigned int>("-ww",a_ww)) {
if(a_args.find<unsigned int>("-wh",a_wh)) return;
//A4 : we have ww but not wh :
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
} else { //we don't have ww.
if(a_args.find<unsigned int>("-wh",a_wh)) {
//A4 : we have wh but not ww :
a_ww = (unsigned int)(a_wh*(21.0f/29.7f));
} else {
//we have nothing. Take a ww of 700. With A4 wh is then 990.
a_ww = 700;
a_wh = (unsigned int)(a_ww*(29.7f/21.0f)); //29.7/21 = 1.414
}
}
}
if(a_args.is_arg("-land")){
unsigned int _ww = a_ww;
unsigned int _wh = a_wh;
a_ww = mx(_ww,_wh);
a_wh = mn(_ww,_wh);
}
if(a_args.is_arg("-portrait")){
unsigned int _ww = a_ww;
unsigned int _wh = a_wh;
a_ww = mn(_ww,_wh);
a_wh = mx(_ww,_wh);
}
}
inline void remove_window_size_args(args& a_args) {
//use with Wt apps.
a_args.remove("-iPod");
a_args.remove("-iPhone");
a_args.remove("-iPad");
a_args.remove("-iPhone4");
a_args.remove("-SGS");
a_args.remove("-ww");
a_args.remove("-wh");
a_args.remove("-land");
}
inline std::vector<std::string> to(int a_argc,char** a_argv) {
std::vector<std::string> v;
for(int index=0;index<a_argc;index++) v.push_back(a_argv[index]);
+13 -13
View File
@@ -109,13 +109,13 @@ public:
}
bool configure(const uints_t& a_orders) {
m_orders = a_orders;
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
if(dim==0) {
clear();
return false;
}
unsigned int _size = 1;
for(unsigned int index=0;index<dim;index++) {
for(size_t index=0;index<dim;index++) {
//if(m_orders[index]<0) {
//clear();
//return false;
@@ -126,15 +126,15 @@ public:
m_vector.assign(_size,zero());
m_offsets.resize(dim,0);
m_offsets[0] = 1;
for(unsigned int iaxis=1;iaxis<dim;iaxis++)
for(size_t iaxis=1;iaxis<dim;iaxis++)
m_offsets[iaxis] = m_offsets[iaxis-1] * m_orders[iaxis-1];
m_is.resize(dim);
m_is.assign(dim,0);
return true;
}
unsigned int dimension() const { return m_orders.size();}
size_t dimension() const { return m_orders.size();}
const uints_t& orders() const { return m_orders;}
unsigned int size() const {return m_vector.size();}
size_t size() const {return m_vector.size();}
bool set_value(const uints_t& a_is,const T& a_value) {
unsigned int off = 0;
if(!offset(a_is,off)) return false;
@@ -161,8 +161,8 @@ public:
const std::vector<T>& vector() const { return m_vector;}
std::vector<T>& vector() { return m_vector;}
bool fill(const std::vector<T>& a_values,cut_t* a_cut = 0) {
unsigned int dsize = a_values.size();
unsigned int di = 0;
size_t dsize = a_values.size();
size_t di = 0;
unsigned int index = 0;
for(vec_it_t it=m_vector.begin();it!=m_vector.end();++it,index++) {
if(!a_cut || (a_cut && accept(index,*a_cut)) ) {
@@ -312,11 +312,11 @@ public:
return status;
}
bool offset(const uints_t& a_is,unsigned int& a_offset) const {
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
a_offset = 0;
if(a_is.size()!=dim) return false;
if(dim==0) return false;
for(unsigned int iaxis=0;iaxis<dim;iaxis++) {
for(size_t iaxis=0;iaxis<dim;iaxis++) {
unsigned int i = a_is[iaxis];
if(i>=m_orders[iaxis]) {
a_offset = 0;
@@ -328,20 +328,20 @@ public:
}
bool indices(unsigned int a_offset,uints_t& a_is) const {
if(a_offset>=m_vector.size()) return false;
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
unsigned int off = a_offset;
for(int iaxis=dim-1;iaxis>=0;iaxis--) {
for(int iaxis=int(dim)-1;iaxis>=0;iaxis--) {
a_is[iaxis] = off/m_offsets[iaxis];
off -= a_is[iaxis] * m_offsets[iaxis];
}
return true;
}
bool accept(unsigned int a_index,const cut_t& a_cut) const {
unsigned int dim = m_orders.size();
size_t dim = m_orders.size();
if(a_cut.size()!=dim) return false;
if(!indices(a_index,const_cast<uints_t&>(m_is))) return false;
bool good = true;
for(unsigned int iaxis=0;iaxis<dim;iaxis++) {
for(size_t iaxis=0;iaxis<dim;iaxis++) {
if(m_is[iaxis]<a_cut[iaxis].first) {good = false;break;}
if(m_is[iaxis]>a_cut[iaxis].second) {good = false;break;}
}
+2 -2
View File
@@ -24,11 +24,11 @@ namespace tools {
inline void b2s(const std::vector<bool>& a_vals,std::string& a_s,const std::string& a_sep = "\n",bool a_sep_at_end = false) {
a_s.clear();
unsigned int number = a_vals.size();
size_t number = a_vals.size();
if(number<=0) return;
number--;
std::string stmp;
for(unsigned int index=0;index<number;index++) {
for(size_t index=0;index<number;index++) {
b2s(a_vals[index],stmp);
a_s += stmp;
a_s += a_sep;
+3 -3
View File
@@ -21,7 +21,7 @@ inline float _fabs(const float& a_x) {return ::fabsf(a_x);}
inline float _tan(const float& a_x) {return ::tanf(a_x);}
inline void _half_pi(float& a_v) {a_v = float(1.5707963267948965580E0);}
inline void _pi(float& a_v) {a_v = float(3.1415926535897931160E0);}
inline float _conj(const float& a_x) {return a_x;}
//inline float _conj(const float& a_x) {return a_x;}
//double
inline double _pow(const double& a_x,const double& a_y) {return ::pow(a_x,a_y);}
@@ -34,7 +34,7 @@ inline double _fabs(const double& a_x) {return ::fabs(a_x);}
inline double _tan(const double& a_x) {return ::tan(a_x);}
inline void _half_pi(double& a_v) {a_v = 1.5707963267948965580E0;}
inline void _pi(double& a_v) {a_v = 3.1415926535897931160E0;}
inline double _conj(const double& a_x) {return a_x;}
//inline double _conj(const double& a_x) {return a_x;}
//long double
#ifndef ANDROID
@@ -48,7 +48,7 @@ inline long double _fabs(const long double& a_x) {return ::fabsl(a_x);}
inline long double _tan(const long double& a_x) {return ::tanl(a_x);}
inline void _half_pi(long double& a_v) {a_v = 1.5707963267948965580E0;}
inline void _pi(long double& a_v) {a_v = 3.1415926535897931160E0;}
inline long double _conj(const long double& a_x) {return a_x;}
//inline long double _conj(const long double& a_x) {return a_x;}
#endif
}
+3 -3
View File
@@ -23,7 +23,7 @@ inline void cmem_free(T*& a_p){
}
template <class T>
inline T* cmem_alloc(unsigned int a_num){
inline T* cmem_alloc(size_t a_num){
if(a_num<=0) return 0;
T* p = (T*)::malloc(a_num*sizeof(T));
if(!p) return 0;
@@ -34,7 +34,7 @@ inline T* cmem_alloc(unsigned int a_num){
}
template <class T>
inline T* cmem_alloc_copy(const T* a_from,unsigned int a_num){
inline T* cmem_alloc_copy(const T* a_from,size_t a_num){
if(a_num<=0) return 0;
T* p = (T*)::malloc(a_num*sizeof(T));
if(!p) return 0;
@@ -42,7 +42,7 @@ inline T* cmem_alloc_copy(const T* a_from,unsigned int a_num){
mem::increment("cmem");
#endif
//::memcpy(p,a_from,a_num*sizeof(T));
for(unsigned int i=0;i<a_num;i++) p[i] = a_from[i];
for(size_t i=0;i<a_num;i++) p[i] = a_from[i];
return p;
}
+11 -4
View File
@@ -9,18 +9,19 @@
namespace tools {
class colorf : public vec4f {
typedef vec4f parent;
public: //for swig
typedef unsigned char uchar;
public:
TOOLS_SCLASS(tools::colorf) //for stype()
public:
colorf():vec4f(0,0,0,1){}
colorf(float a_r,float a_g,float a_b,float a_a = 1):vec4f(a_r,a_g,a_b,a_a){}
colorf():parent(0,0,0,1){}
colorf(float a_r,float a_g,float a_b,float a_a = 1,bool a_inc = true):parent(a_r,a_g,a_b,a_a,a_inc){}
virtual ~colorf() {}
public:
colorf(const colorf& a_from):vec4f(a_from){}
colorf(const colorf& a_from):parent(a_from){}
colorf& operator=(const colorf& a_from){
vec4f::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
@@ -39,6 +40,11 @@ public:
uchar bchar() const {return uchar(255.0f*m_data[2]);}
public:
//#define tools_stat_colorfs
#ifdef tools_stat_colorfs
//NOTE : the below are deprecated, use functions in inlib/colorfs.
// tools::colorf::white() replaced by tools::colorf_white()
// our forever 65 named colors taken long time ago from X11.
//NOTE : don't handle a static object because of mem balance.
@@ -120,6 +126,7 @@ public:
static colorf white() {return colorf(1,1,1);}
static colorf yellow() {return colorf(1,1,0);}
static colorf greenyellow() {return colorf(0.675792F,0.996109F,0.18359F);}
#endif
};
struct cmp_colorf {
@@ -0,0 +1,100 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_colorfs
#define tools_colorfs
#include "colors"
#include "colorf"
namespace tools {
#define TOOLS_COLORFS_STAT(a__name,a__r,a__g,a__b) \
inline const colorf& colorf_##a__name() {return get_color_##a__name<colorf>();}
//NOTE : false in the upper so that mem balance is ok at exit.
//0-9
TOOLS_COLORFS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORFS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORFS_STAT(black,0,0,0)
TOOLS_COLORFS_STAT(blue,0,0,1)
TOOLS_COLORFS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORFS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORFS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORFS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORFS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORFS_STAT(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORFS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORFS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORFS_STAT(navyblue,0,0,0.500008F)
TOOLS_COLORFS_STAT(navy,0,0,0.500008F)
TOOLS_COLORFS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORFS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORFS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORFS_STAT(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORFS_STAT(cyan,0,1,1)
TOOLS_COLORFS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORFS_STAT(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORFS_STAT(gold,0.996109F,0.839857F,0)
TOOLS_COLORFS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORFS_STAT(green,0,1,0)
TOOLS_COLORFS_STAT(darkgreen,0,0.390631F,0)
TOOLS_COLORFS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORFS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORFS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORFS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORFS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORFS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORFS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORFS_STAT(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORFS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORFS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORFS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORFS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORFS_STAT(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORFS_STAT(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORFS_STAT(magenta,1,0,1)
//40-49
TOOLS_COLORFS_STAT(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORFS_STAT(orange,0.996109F,0.644541F,0)
TOOLS_COLORFS_STAT(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORFS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORFS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORFS_STAT(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORFS_STAT(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORFS_STAT(red,1,0,0)
TOOLS_COLORFS_STAT(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORFS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORFS_STAT(orangered,0.996109F,0.269535F,0)
TOOLS_COLORFS_STAT(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORFS_STAT(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORFS_STAT(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORFS_STAT(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORFS_STAT(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORFS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORFS_STAT(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORFS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORFS_STAT(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORFS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORFS_STAT(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORFS_STAT(white,1,1,1)
TOOLS_COLORFS_STAT(yellow,1,1,0)
TOOLS_COLORFS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORFS_STAT
}
#endif
@@ -0,0 +1,185 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_colors
#define tools_colors
// our forever 65 named colors taken long time ago from X11.
namespace tools {
#define TOOLS_COLORS_SET(a__name,a__r,a__g,a__b) \
template <class COLOR>\
inline void set_color_##a__name(COLOR& a_color) {a_color.set_value(a__r,a__g,a__b,1);}
//0-9
TOOLS_COLORS_SET(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORS_SET(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORS_SET(black,0,0,0)
TOOLS_COLORS_SET(blue,0,0,1)
TOOLS_COLORS_SET(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORS_SET(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORS_SET(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORS_SET(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORS_SET(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORS_SET(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORS_SET(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORS_SET(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORS_SET(navyblue,0,0,0.500008F)
TOOLS_COLORS_SET(navy,0,0,0.500008F)
TOOLS_COLORS_SET(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORS_SET(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORS_SET(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORS_SET(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORS_SET(cyan,0,1,1)
TOOLS_COLORS_SET(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORS_SET(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORS_SET(gold,0.996109F,0.839857F,0)
TOOLS_COLORS_SET(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORS_SET(green,0,1,0)
TOOLS_COLORS_SET(darkgreen,0,0.390631F,0)
TOOLS_COLORS_SET(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORS_SET(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORS_SET(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORS_SET(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORS_SET(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORS_SET(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORS_SET(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORS_SET(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORS_SET(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORS_SET(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORS_SET(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORS_SET(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORS_SET(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORS_SET(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORS_SET(magenta,1,0,1)
//40-49
TOOLS_COLORS_SET(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORS_SET(orange,0.996109F,0.644541F,0)
TOOLS_COLORS_SET(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORS_SET(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORS_SET(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORS_SET(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORS_SET(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORS_SET(red,1,0,0)
TOOLS_COLORS_SET(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORS_SET(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORS_SET(orangered,0.996109F,0.269535F,0)
TOOLS_COLORS_SET(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORS_SET(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORS_SET(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORS_SET(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORS_SET(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORS_SET(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORS_SET(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORS_SET(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORS_SET(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORS_SET(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORS_SET(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORS_SET(white,1,1,1)
TOOLS_COLORS_SET(yellow,1,1,0)
TOOLS_COLORS_SET(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORS_SET
#define TOOLS_COLORS_STAT(a__name,a__r,a__g,a__b) \
template <class COLOR>\
inline const COLOR& get_color_##a__name() {static const COLOR s_v(a__r,a__g,a__b,1,false);return s_v;}
//NOTE : false in the upper so that mem balance is ok at exit.
//0-9
TOOLS_COLORS_STAT(aquamarine,0.496101F,0.996109F,0.828138F)
TOOLS_COLORS_STAT(mediumaquamarine,0.398444F,0.800793F,0.664073F)
TOOLS_COLORS_STAT(black,0,0,0)
TOOLS_COLORS_STAT(blue,0,0,1)
TOOLS_COLORS_STAT(cadetblue,0.371099F,0.617197F,0.62501F)
TOOLS_COLORS_STAT(cornflowerblue,0.390631F,0.58204F,0.925795F)
TOOLS_COLORS_STAT(darkslateblue,0.281254F,0.238285F,0.542977F)
TOOLS_COLORS_STAT(lightblue,0.675792F,0.843763F,0.898451F)
TOOLS_COLORS_STAT(lightsteelblue,0.68751F,0.765637F,0.867201F)
TOOLS_COLORS_STAT(mediumblue,0,0,0.800793F)
//10-19
TOOLS_COLORS_STAT(mediumslateblue,0.480476F,0.406256F,0.929702F)
TOOLS_COLORS_STAT(midnightblue,0.0976577F,0.0976577F,0.437507F)
TOOLS_COLORS_STAT(navyblue,0,0,0.500008F)
TOOLS_COLORS_STAT(navy,0,0,0.500008F)
TOOLS_COLORS_STAT(skyblue,0.527352F,0.8047F,0.917983F)
TOOLS_COLORS_STAT(slateblue,0.414069F,0.351568F,0.800793F)
TOOLS_COLORS_STAT(steelblue,0.273442F,0.50782F,0.703136F)
TOOLS_COLORS_STAT(coral,0.996109F,0.496101F,0.312505F)
TOOLS_COLORS_STAT(cyan,0,1,1)
TOOLS_COLORS_STAT(firebrick,0.695323F,0.132815F,0.132815F)
//20-29
TOOLS_COLORS_STAT(brown,0.644541F,0.164065F,0.164065F)
TOOLS_COLORS_STAT(gold,0.996109F,0.839857F,0)
TOOLS_COLORS_STAT(goldenrod,0.851575F,0.644541F,0.125002F)
TOOLS_COLORS_STAT(green,0,1,0)
TOOLS_COLORS_STAT(darkgreen,0,0.390631F,0)
TOOLS_COLORS_STAT(darkolivegreen,0.332036F,0.417975F,0.183597F)
TOOLS_COLORS_STAT(forestgreen,0.132815F,0.542977F,0.132815F)
TOOLS_COLORS_STAT(limegreen,0.195315F,0.800793F,0.195315F)
TOOLS_COLORS_STAT(mediumseagreen,0.234379F,0.699229F,0.441413F)
TOOLS_COLORS_STAT(mediumspringgreen,0,0.976577F,0.601572F)
//30-39
TOOLS_COLORS_STAT(palegreen,0.593759F,0.980484F,0.593759F)
TOOLS_COLORS_STAT(seagreen,0.17969F,0.542977F,0.339849F)
TOOLS_COLORS_STAT(springgreen,0,0.996109F,0.496101F)
TOOLS_COLORS_STAT(yellowgreen,0.601572F,0.800793F,0.195315F)
TOOLS_COLORS_STAT(darkslategrey,0.183597F,0.308598F,0.308598F)
TOOLS_COLORS_STAT(dimgrey,0.410163F,0.410163F,0.410163F)
TOOLS_COLORS_STAT(lightgrey,0.824231F,0.824231F,0.824231F)
TOOLS_COLORS_STAT(grey,0.750011F,0.750011F,0.750011F)
TOOLS_COLORS_STAT(khaki,0.937514F,0.898451F,0.546883F)
TOOLS_COLORS_STAT(magenta,1,0,1)
//40-49
TOOLS_COLORS_STAT(maroon,0.68751F,0.187503F,0.375006F)
TOOLS_COLORS_STAT(orange,0.996109F,0.644541F,0)
TOOLS_COLORS_STAT(orchid,0.851575F,0.437507F,0.83595F)
TOOLS_COLORS_STAT(darkorchid,0.597665F,0.195315F,0.796887F)
TOOLS_COLORS_STAT(mediumorchid,0.726574F,0.332036F,0.824231F)
TOOLS_COLORS_STAT(pink,0.996109F,0.750011F,0.792981F)
TOOLS_COLORS_STAT(plum,0.863294F,0.62501F,0.863294F)
TOOLS_COLORS_STAT(red,1,0,0)
TOOLS_COLORS_STAT(indianred,0.800793F,0.35938F,0.35938F)
TOOLS_COLORS_STAT(mediumvioletred,0.777356F,0.0820325F,0.519539F)
//50-59
TOOLS_COLORS_STAT(orangered,0.996109F,0.269535F,0)
TOOLS_COLORS_STAT(violetred,0.812512F,0.125002F,0.562509F)
TOOLS_COLORS_STAT(salmon,0.976577F,0.500008F,0.445319F)
TOOLS_COLORS_STAT(sienna,0.62501F,0.320317F,0.175784F)
TOOLS_COLORS_STAT(tan,0.820325F,0.703136F,0.546883F)
TOOLS_COLORS_STAT(thistle,0.843763F,0.746105F,0.843763F)
TOOLS_COLORS_STAT(turquoise,0.250004F,0.875013F,0.812512F)
TOOLS_COLORS_STAT(darkturquoise,0,0.8047F,0.816419F)
TOOLS_COLORS_STAT(mediumturquoise,0.281254F,0.816419F,0.796887F)
TOOLS_COLORS_STAT(violet,0.929702F,0.50782F,0.929702F)
//60-64
TOOLS_COLORS_STAT(blueviolet,0.539071F,0.167971F,0.882826F)
TOOLS_COLORS_STAT(wheat,0.957046F,0.867201F,0.699229F)
TOOLS_COLORS_STAT(white,1,1,1)
TOOLS_COLORS_STAT(yellow,1,1,0)
TOOLS_COLORS_STAT(greenyellow,0.675792F,0.996109F,0.18359F)
#undef TOOLS_COLORS_STAT
}
#endif
+17 -33
View File
@@ -27,25 +27,6 @@ inline bool exists(const std::string& a_string) {
return true;
}
inline bool size(const std::string& a_file,long& a_size){
FILE* file = ::fopen(a_file.c_str(),"rb");
if(!file) {
a_size = 0L;
return false;
}
//::rewind(file);
::fseek(file,0L,SEEK_END);
a_size = ::ftell(file);
::fclose(file);
return true;
}
inline bool is_empty(const std::string& a_file){
long sz;
if(!size(a_file,sz)) return true; //if not existing, consider it empty.
return (sz==0L)?true:false;
}
inline bool write(const std::string& a_file,const std::string& a_string) {
// a_string could contain \n separated lines.
FILE* file = ::fopen(a_file.c_str(),"wb");
@@ -198,20 +179,6 @@ inline bool write_bytes(const std::string& a_file,const char* a_buffer,size_t a_
return (nitem!=1?false:true);
}
inline bool is_aida(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<aida")?true:false;
return true;
}
inline bool num_csv_doubles(const std::string& a_string,char& a_sep,unsigned int& a_number){
if(a_string.empty()) {a_sep=0;a_number=0;return true;} //it is ok.
@@ -354,6 +321,22 @@ inline bool is_csv(const std::string& a_file,bool& a_is){
return is_csv(txt,a_is);
}
inline bool is_lua(const std::string& a_file,bool& a_is){
// look at suffix. Some file can't be guessed.
if(suffix(a_file)=="lua") {a_is = true;return true;}
//try to guess ?
a_is = false;
return true;
}
inline bool is_py(const std::string& a_file,bool& a_is){
// look at suffix. Some file can't be guessed.
if(suffix(a_file)=="py") {a_is = true;return true;}
//try to guess ?
a_is = false;
return true;
}
}}
#include "fileis"
@@ -616,5 +599,6 @@ protected:
}
#include "file_format" //backcomp
#include "fsize" //backcomp
#endif
@@ -34,6 +34,11 @@ TOOLS_GLOBAL_STRING(format_mac)
TOOLS_GLOBAL_STRING(format_cmnd)
TOOLS_GLOBAL_STRING(format_aida)
TOOLS_GLOBAL_STRING(format_bsg)
TOOLS_GLOBAL_STRING(format_jive)
TOOLS_GLOBAL_STRING(format_heprep)
TOOLS_GLOBAL_STRING(format_zheprep)
TOOLS_GLOBAL_STRING(format_lua)
TOOLS_GLOBAL_STRING(format_py)
#define TOOLS_GLOBAL_EXT(a_name)\
inline const std::string& s_ext_##a_name() {\
@@ -64,6 +69,11 @@ TOOLS_GLOBAL_EXT(mac)
TOOLS_GLOBAL_EXT(cmnd)
TOOLS_GLOBAL_EXT(aida)
TOOLS_GLOBAL_EXT(bsg)
TOOLS_GLOBAL_EXT(jive)
TOOLS_GLOBAL_EXT(heprep)
TOOLS_GLOBAL_EXT(zheprep)
TOOLS_GLOBAL_EXT(lua)
TOOLS_GLOBAL_EXT(py)
#undef TOOLS_GLOBAL_EXT
@@ -91,6 +101,11 @@ inline void formats(std::vector<std::string>& a_v) {
a_v.push_back(s_format_mac());
a_v.push_back(s_format_cmnd());
a_v.push_back(s_format_aida());
a_v.push_back(s_format_jive());
a_v.push_back(s_format_heprep());
a_v.push_back(s_format_zheprep());
a_v.push_back(s_format_lua());
a_v.push_back(s_format_py());
}
inline std::string ext_fmt(const std::string& a_ext) {
@@ -117,6 +132,11 @@ inline std::string ext_fmt(const std::string& a_ext) {
if(a_ext==s_ext_gdml()) return s_format_gdml();
if(a_ext==s_ext_mac()) return s_format_mac();
if(a_ext==s_ext_cmnd()) return s_format_cmnd();
if(a_ext==s_ext_jive()) return s_format_jive();
if(a_ext==s_ext_heprep()) return s_format_heprep();
if(a_ext==s_ext_zheprep()) return s_format_zheprep();
if(a_ext==s_ext_lua()) return s_format_lua();
if(a_ext==s_ext_py()) return s_format_py();
return s_format_guessed();
}
@@ -270,4 +270,54 @@ inline bool is_ps(const std::string& a_file,bool& a_is){
}}
#include "fsize"
namespace tools {
namespace file {
inline bool is_aida(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<aida")?true:false;
return true;
}
inline bool is_jive(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
if(::strstr((const char*)head,"<?ATLAS")) {a_is = true;return true;}
a_is = ::strstr((const char*)head,"<!DOCTYPE Event")?true:false;
return true;
}
inline bool is_heprep(const std::string& a_file,bool& a_is){
long sz;
if(!size(a_file,sz)) {a_is = false;return false;}
//NOTE : it assumes that the file is not compressed.
unsigned char head[1024];
{unsigned int num = 1024;
if(!signature(a_file,head,num)) {a_is = false;return false;}
if(num!=1024) {a_is = false;return true;}}
head[1023] = 0; //to have a C string.
a_is = ::strstr((const char*)head,"<heprep")?true:false;
return true;
}
}}
#endif
+5 -5
View File
@@ -61,11 +61,11 @@ inline bool find_with_dirs(std::ostream& a_out,
namespace tools {
inline bool find_with_path(std::ostream& a_out,
const std::string& a_env,
const std::string& a_file,
std::string& a_path,
bool a_verbose = false ) {
inline bool find_with_env(std::ostream& a_out,
const std::string& a_env,
const std::string& a_file,
std::string& a_path,
bool a_verbose = false ) {
std::string PATH;
if(!tools::getenv(a_env,PATH)) {
//look for a a_file in current directory.
@@ -10,6 +10,12 @@
#define tools_vforit(a__T,a__v,a__it) \
for(std::vector< a__T >::iterator (a__it) = (a__v).begin();(a__it)!=(a__v).end();++(a__it))
#define tools_vforcrit(a__T,a__v,a__it) \
for(std::vector< a__T >::const_reverse_iterator (a__it) = (a__v).rbegin();(a__it)!=(a__v).rend();++(a__it))
#define tools_vforrit(a__T,a__v,a__it) \
for(std::vector< a__T >::reverse_iterator (a__it) = (a__v).rbegin();(a__it)!=(a__v).rend();++(a__it))
#define tools_vforit_npp(a__T,a__v,a__it) \
for(std::vector< a__T >::iterator (a__it) = (a__v).begin();(a__it)!=(a__v).end();)
@@ -0,0 +1,34 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_fsize
#define tools_fsize
#include <string>
#include <cstdio>
namespace tools {
namespace file {
inline bool size(const std::string& a_file,long& a_size){
FILE* file = ::fopen(a_file.c_str(),"rb");
if(!file) {
a_size = 0L;
return false;
}
//::rewind(file);
::fseek(file,0L,SEEK_END);
a_size = ::ftell(file);
::fclose(file);
return true;
}
inline bool is_empty(const std::string& a_file){
long sz;
if(!size(a_file,sz)) return true; //if not existing, consider it empty.
return (sz==0L)?true:false;
}
}}
#endif
@@ -0,0 +1,46 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_get_lines
#define tools_get_lines
#include "cstr"
#include <string>
#include <vector>
namespace tools {
inline void get_lines(const std::string& a_string,std::vector<std::string>& a_lines){
// a_string is a list separated by "\n" or "\\n".
// For "xxx\n\nxxx", {"xxx","","xxx"} will be created.
// WARNING : if a_string is a Windows file name, it may
// contains a \n which is not a delimiter ; like ..\data\ntuples.hbook.
a_lines.clear();
size_t length = a_string.length();
if(!length) return;
char* cstring = str_dup(a_string.c_str());
if(!cstring) return;
size_t pos = 0;
length++;
for(size_t count=0;count<length;count++) {
if( (cstring[count]=='\n') ||
(cstring[count]=='\0') ||
( (cstring[count]=='\\') && (cstring[count+1]=='n') ) ) {
char shift_one = (cstring[count]=='\n' ? 1 : 0);
cstring[count] = '\0';
a_lines.push_back(cstring+pos);
if(shift_one==1) {
pos = count+1;
} else {
pos = count+2;
count++;
}
}
}
str_del(cstring);
}
}
#endif
+20 -28
View File
@@ -6,6 +6,8 @@
//same as OpenGL GL_[POINTS,etc...], but for the case we don't have OpenGL.
#include <cstddef> //size_t
namespace tools {
namespace gl {
@@ -34,10 +36,10 @@ inline bool is_line(mode_t a_mode) {
return false;
}
inline void cvt_2to3(unsigned int a_npt,const float* a_xys,float*& a_xyzs) {
inline void cvt_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
float x,y;
for(unsigned int i=0;i<a_npt;i++) {
for(size_t i=0;i<a_npt;i++) {
x = *vpos;vpos++;
y = *vpos;vpos++;
*a_xyzs = x;a_xyzs++;
@@ -47,11 +49,9 @@ inline void cvt_2to3(unsigned int a_npt,const float* a_xys,float*& a_xyzs) {
}
inline void triangle_fan_to_triangles(unsigned int a_npt,
const float* a_fxyzs,
const float* a_fnms,
float*& a_xyzs,
float*& a_nms) {
inline void triangle_fan_to_triangles(size_t a_npt,
const float* a_fxyzs,const float* a_fnms,
float*& a_xyzs,float*& a_nms) {
{const float* vpos = a_fxyzs;
@@ -64,7 +64,7 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
float z2 = *vpos;vpos++;
float x3,y3,z3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -96,7 +96,7 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
float z2 = *vpos;vpos++;
float x3,y3,z3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -118,11 +118,9 @@ inline void triangle_fan_to_triangles(unsigned int a_npt,
}}
}
inline void triangle_strip_to_triangles(unsigned int a_npt,
const float* a_fxyzs,
const float* a_fnms,
float*& a_xyzs,
float*& a_nms) {
inline void triangle_strip_to_triangles(size_t a_npt,
const float* a_fxyzs,const float* a_fnms,
float*& a_xyzs,float*& a_nms) {
{const float* vpos = a_fxyzs;
@@ -136,7 +134,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
float x3,y3,z3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -190,7 +188,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
float x3,y3,z3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
z3 = *vpos;vpos++;
@@ -232,9 +230,7 @@ inline void triangle_strip_to_triangles(unsigned int a_npt,
}}
}
inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void triangle_fan_to_triangles_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -245,7 +241,7 @@ inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
float y2 = *vpos;vpos++;
float x3,y3;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
@@ -267,9 +263,7 @@ inline void triangle_fan_to_triangles_2to3(unsigned int a_npt,
}
inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void triangle_strip_to_triangles_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -281,7 +275,7 @@ inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
float x3,y3;
bool flip = false;
for(unsigned int i=2;i<a_npt;i++) {
for(size_t i=2;i<a_npt;i++) {
x3 = *vpos;vpos++;
y3 = *vpos;vpos++;
@@ -322,9 +316,7 @@ inline void triangle_strip_to_triangles_2to3(unsigned int a_npt,
}
inline void line_strip_to_lines_2to3(unsigned int a_npt,
const float* a_xys,
float*& a_xyzs) {
inline void line_strip_to_lines_2to3(size_t a_npt,const float* a_xys,float*& a_xyzs) {
const float* vpos = a_xys;
@@ -332,7 +324,7 @@ inline void line_strip_to_lines_2to3(unsigned int a_npt,
float y1 = *vpos;vpos++;
float x2,y2;
for(unsigned int i=1;i<a_npt;i++) {
for(size_t i=1;i<a_npt;i++) {
x2 = *vpos;vpos++;
y2 = *vpos;vpos++;
@@ -8,19 +8,19 @@
////////////////////////////////////////////////////////
#ifdef TOOLS_MEM
#include <tools/mem>
#include "../mem"
#include <cstdlib>
namespace tools {
inline void* mem_alloc(size_t a_size){
tools::mem::increment(tools::s_malloc().c_str());
mem::increment(tools::s_malloc().c_str());
return ::malloc(a_size);
}
inline void* mem_realloc(void* a_ptr,size_t a_size){
if(a_ptr==NULL) tools::mem::increment(tools::s_malloc().c_str());
if(a_ptr==NULL) mem::increment(tools::s_malloc().c_str());
return ::realloc(a_ptr,a_size);
}
inline void mem_free(void* a_ptr){
if(a_ptr!=NULL) tools::mem::decrement(tools::s_malloc().c_str());
if(a_ptr!=NULL) mem::decrement(tools::s_malloc().c_str());
::free(a_ptr);
}
inline int mem_init( size_t /*maxFast*/) {return 1;}
@@ -2,78 +2,78 @@
#define tools_glutess_rename
/* G.Barrand : namespace protection : */
#define gluTessBeginContour inlib_gluTessBeginContour
#define gluTessBeginPolygon inlib_gluTessBeginPolygon
#define gluTessCallback inlib_gluTessCallback
#define gluTessEndContour inlib_gluTessEndContour
#define gluTessEndPolygon inlib_gluTessEndPolygon
#define gluTessNormal inlib_gluTessNormal
#define gluTessProperty inlib_gluTessProperty
#define gluTessVertex inlib_gluTessVertex
#define gluTessBeginContour tools_gluTessBeginContour
#define gluTessBeginPolygon tools_gluTessBeginPolygon
#define gluTessCallback tools_gluTessCallback
#define gluTessEndContour tools_gluTessEndContour
#define gluTessEndPolygon tools_gluTessEndPolygon
#define gluTessNormal tools_gluTessNormal
#define gluTessProperty tools_gluTessProperty
#define gluTessVertex tools_gluTessVertex
/* internal */
#define gluBeginPolygon inlib_gluBeginPolygon
#define gluDeleteTess inlib_gluDeleteTess
#define gluEndPolygon inlib_gluEndPolygon
#define gluGetTessProperty inlib_gluGetTessProperty
#define gluNewTess inlib_gluNewTess
#define gluNextContour inlib_gluNextContour
#define gluBeginPolygon tools_gluBeginPolygon
#define gluDeleteTess tools_gluDeleteTess
#define gluEndPolygon tools_gluEndPolygon
#define gluGetTessProperty tools_gluGetTessProperty
#define gluNewTess tools_gluNewTess
#define gluNextContour tools_gluNextContour
#define __gl_computeInterior inlib__gl_computeInterior
#define __gl_dictListDelete inlib__gl_dictListDelete
#define __gl_dictListDeleteDict inlib__gl_dictListDeleteDict
#define __gl_dictListInsertBefore inlib__gl_dictListInsertBefore
#define __gl_dictListNewDict inlib__gl_dictListNewDict
#define __gl_dictListSearch inlib__gl_dictListSearch
#define __gl_computeInterior tools__gl_computeInterior
#define __gl_dictListDelete tools__gl_dictListDelete
#define __gl_dictListDeleteDict tools__gl_dictListDeleteDict
#define __gl_dictListInsertBefore tools__gl_dictListInsertBefore
#define __gl_dictListNewDict tools__gl_dictListNewDict
#define __gl_dictListSearch tools__gl_dictListSearch
#define __gl_edgeEval inlib__gl_edgeEval
#define __gl_edgeIntersect inlib__gl_edgeIntersect
#define __gl_edgeSign inlib__gl_edgeSign
#define __gl_edgeEval tools__gl_edgeEval
#define __gl_edgeIntersect tools__gl_edgeIntersect
#define __gl_edgeSign tools__gl_edgeSign
/* done in memalloc.h :
#define __gl_memInit inlib__gl_memInit
#define __gl_memInit tools__gl_memInit
*/
#define __gl_meshAddEdgeVertex inlib__gl_meshAddEdgeVertex
#define __gl_meshCheckMesh inlib__gl_meshCheckMesh
#define __gl_meshConnect inlib__gl_meshConnect
#define __gl_meshDelete inlib__gl_meshDelete
#define __gl_meshDeleteMesh inlib__gl_meshDeleteMesh
#define __gl_meshDiscardExterior inlib__gl_meshDiscardExterior
#define __gl_meshMakeEdge inlib__gl_meshMakeEdge
#define __gl_meshNewMesh inlib__gl_meshNewMesh
#define __gl_meshSetWindingNumber inlib__gl_meshSetWindingNumber
#define __gl_meshSplice inlib__gl_meshSplice
#define __gl_meshSplitEdge inlib__gl_meshSplitEdge
#define __gl_meshTessellateInterior inlib__gl_meshTessellateInterior
#define __gl_meshTessellateMonoRegion inlib__gl_meshTessellateMonoRegion
#define __gl_meshUnion inlib__gl_meshUnion
#define __gl_meshZapFace inlib__gl_meshZapFace
#define __gl_noBeginData inlib__gl_noBeginData
#define __gl_noCombineData inlib__gl_noCombineData
#define __gl_noEdgeFlagData inlib__gl_noEdgeFlagData
#define __gl_noEndData inlib__gl_noEndData
#define __gl_noErrorData inlib__gl_noErrorData
#define __gl_noVertexData inlib__gl_noVertexData
#define __gl_pqHeapDelete inlib__gl_pqHeapDelete
#define __gl_pqHeapDeletePriorityQ inlib__gl_pqHeapDeletePriorityQ
#define __gl_pqHeapExtractMin inlib__gl_pqHeapExtractMin
#define __gl_pqHeapInit inlib__gl_pqHeapInit
#define __gl_pqHeapInsert inlib__gl_pqHeapInsert
#define __gl_pqHeapNewPriorityQ inlib__gl_pqHeapNewPriorityQ
#define __gl_pqSortDelete inlib__gl_pqSortDelete
#define __gl_pqSortDeletePriorityQ inlib__gl_pqSortDeletePriorityQ
#define __gl_pqSortExtractMin inlib__gl_pqSortExtractMin
#define __gl_pqSortInit inlib__gl_pqSortInit
#define __gl_pqSortInsert inlib__gl_pqSortInsert
#define __gl_pqSortIsEmpty inlib__gl_pqSortIsEmpty
#define __gl_pqSortMinimum inlib__gl_pqSortMinimum
#define __gl_pqSortNewPriorityQ inlib__gl_pqSortNewPriorityQ
#define __gl_projectPolygon inlib__gl_projectPolygon
#define __gl_renderBoundary inlib__gl_renderBoundary
#define __gl_renderCache inlib__gl_renderCache
#define __gl_renderMesh inlib__gl_renderMesh
#define __gl_transEval inlib__gl_transEval
#define __gl_transSign inlib__gl_transSign
#define __gl_vertCCW inlib__gl_vertCCW
#define __gl_vertLeq inlib__gl_vertLeq
#define __gl_meshAddEdgeVertex tools__gl_meshAddEdgeVertex
#define __gl_meshCheckMesh tools__gl_meshCheckMesh
#define __gl_meshConnect tools__gl_meshConnect
#define __gl_meshDelete tools__gl_meshDelete
#define __gl_meshDeleteMesh tools__gl_meshDeleteMesh
#define __gl_meshDiscardExterior tools__gl_meshDiscardExterior
#define __gl_meshMakeEdge tools__gl_meshMakeEdge
#define __gl_meshNewMesh tools__gl_meshNewMesh
#define __gl_meshSetWindingNumber tools__gl_meshSetWindingNumber
#define __gl_meshSplice tools__gl_meshSplice
#define __gl_meshSplitEdge tools__gl_meshSplitEdge
#define __gl_meshTessellateInterior tools__gl_meshTessellateInterior
#define __gl_meshTessellateMonoRegion tools__gl_meshTessellateMonoRegion
#define __gl_meshUnion tools__gl_meshUnion
#define __gl_meshZapFace tools__gl_meshZapFace
#define __gl_noBeginData tools__gl_noBeginData
#define __gl_noCombineData tools__gl_noCombineData
#define __gl_noEdgeFlagData tools__gl_noEdgeFlagData
#define __gl_noEndData tools__gl_noEndData
#define __gl_noErrorData tools__gl_noErrorData
#define __gl_noVertexData tools__gl_noVertexData
#define __gl_pqHeapDelete tools__gl_pqHeapDelete
#define __gl_pqHeapDeletePriorityQ tools__gl_pqHeapDeletePriorityQ
#define __gl_pqHeapExtractMin tools__gl_pqHeapExtractMin
#define __gl_pqHeapInit tools__gl_pqHeapInit
#define __gl_pqHeapInsert tools__gl_pqHeapInsert
#define __gl_pqHeapNewPriorityQ tools__gl_pqHeapNewPriorityQ
#define __gl_pqSortDelete tools__gl_pqSortDelete
#define __gl_pqSortDeletePriorityQ tools__gl_pqSortDeletePriorityQ
#define __gl_pqSortExtractMin tools__gl_pqSortExtractMin
#define __gl_pqSortInit tools__gl_pqSortInit
#define __gl_pqSortInsert tools__gl_pqSortInsert
#define __gl_pqSortIsEmpty tools__gl_pqSortIsEmpty
#define __gl_pqSortMinimum tools__gl_pqSortMinimum
#define __gl_pqSortNewPriorityQ tools__gl_pqSortNewPriorityQ
#define __gl_projectPolygon tools__gl_projectPolygon
#define __gl_renderBoundary tools__gl_renderBoundary
#define __gl_renderCache tools__gl_renderCache
#define __gl_renderMesh tools__gl_renderMesh
#define __gl_transEval tools__gl_transEval
#define __gl_transSign tools__gl_transSign
#define __gl_vertCCW tools__gl_vertCCW
#define __gl_vertLeq tools__gl_vertLeq
#endif
+16 -7
View File
@@ -25,6 +25,11 @@ public:
base_handle(){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
base_handle(const std::string& a_class):m_class(a_class){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
virtual ~base_handle(){
@@ -33,15 +38,20 @@ public:
#endif
}
protected:
base_handle(base_handle&){
base_handle(base_handle& a_from):m_class(a_from.m_class){
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
#endif
}
private:
//base_handle(const base_handle&){}
//base_handle& operator=(const base_handle&){return *this;}
base_handle& operator=(base_handle&){return *this;}
base_handle& operator=(base_handle& a_from){
m_class = a_from.m_class;
return *this;
}
public:
const std::string& object_class() const {return m_class;}
private:
std::string m_class;
};
template <class T>
@@ -52,9 +62,8 @@ public:
virtual base_handle* copy() {return new handle<T>(*this);}
virtual void disown() {m_owner = false;}
public:
handle(T* a_obj,bool a_owner = true)
:parent()
,m_obj(a_obj),m_owner(a_owner){}
handle(T* a_obj,bool a_owner = true):parent(),m_obj(a_obj),m_owner(a_owner){}
handle(const std::string& a_class,T* a_obj,bool a_owner = true):parent(a_class),m_obj(a_obj),m_owner(a_owner){}
virtual ~handle(){if(m_owner) delete m_obj;}
private:
handle(handle& a_from):parent(a_from){
@@ -161,7 +161,7 @@ public:
public:
// Partition :
bool configure(const std::vector<TC>& aEdges) {
bool configure(const std::vector<TC>& a_edges) {
// init :
m_number_of_bins = 0;
m_minimum_value = 0;
@@ -170,17 +170,17 @@ public:
m_bin_width = 0;
m_edges.clear();
// setup :
if(aEdges.size()<=1) return false;
bn_t number = (bn_t)aEdges.size()-1;
if(a_edges.size()<=1) return false;
bn_t number = (bn_t)a_edges.size()-1;
for(bn_t index=0;index<number;index++) {
if((aEdges[index]>=aEdges[index+1])) {
if((a_edges[index]>=a_edges[index+1])) {
return false;
}
}
m_edges = aEdges;
m_edges = a_edges;
m_number_of_bins = number;
m_minimum_value = aEdges[0];
m_maximum_value = aEdges[m_number_of_bins];
m_minimum_value = a_edges[0];
m_maximum_value = a_edges[m_number_of_bins];
m_fixed = false;
return true;
}
@@ -156,10 +156,10 @@ protected:
maxs.push_back(aXmax);
parent::configure(1,nbins,mins,maxs);
}
b1(const std::string& a_title,const std::vector<TC>& aEdges) {
b1(const std::string& a_title,const std::vector<TC>& a_edges) {
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(1);
edges[0] = aEdges;
edges[0] = a_edges;
parent::configure(1,edges);
}
@@ -177,9 +177,9 @@ public:
maxs.push_back(aXmax);
return parent::configure(1,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdges) {
bool configure(const std::vector<TC>& a_edges) {
std::vector< std::vector<TC> > edges(1);
edges[0] = aEdges;
edges[0] = a_edges;
return parent::configure(1,edges);
}
protected:
@@ -302,11 +302,11 @@ protected:
parent::configure(2,nbins,mins,maxs);
}
b2(const std::string& a_title,const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY) {
b2(const std::string& a_title,const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y) {
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(2);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
parent::configure(2,edges);
}
@@ -328,10 +328,10 @@ public:
return parent::configure(2,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY){
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y){
std::vector< std::vector<TC> > edges(2);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
return parent::configure(2,edges);
}
+12 -12
View File
@@ -328,15 +328,15 @@ public:
}
b3(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z)
{
parent::m_title = a_title;
std::vector< std::vector<TC> > edges(3);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[2] = aEdgesZ;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
edges[2] = a_edges_z;
parent::configure(3,edges);
}
@@ -363,13 +363,13 @@ public:
return parent::configure(3,nbins,mins,maxs);
}
bool configure(const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ){
bool configure(const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z){
std::vector< std::vector<TC> > edges(3);
edges[0] = aEdgesX;
edges[1] = aEdgesY;
edges[2] = aEdgesZ;
edges[0] = a_edges_x;
edges[1] = a_edges_y;
edges[2] = a_edges_z;
return parent::configure(3,edges);
}
@@ -12,6 +12,7 @@
#include <cmath>
#include <map> //for annotations
#include <ostream>
namespace tools {
namespace histo {
@@ -277,7 +278,7 @@ protected:
return true;
}
bool configure(dim_t a_dim,const std::vector< std::vector<TC> >& aEdges) {
bool configure(dim_t a_dim,const std::vector< std::vector<TC> >& a_edges) {
// Clear :
parent::m_bin_entries.clear();
parent::m_bin_Sw.clear();
@@ -304,7 +305,7 @@ protected:
parent::m_axes.resize(a_dim);
// Setup axes :
for(dim_t iaxis=0;iaxis<a_dim;iaxis++) {
if(!parent::m_axes[iaxis].configure(aEdges[iaxis])) {
if(!parent::m_axes[iaxis].configure(a_edges[iaxis])) {
//m_axes.clear();
return false;
}
@@ -392,6 +393,17 @@ public: //annotations :
return true;
}
void set_annotations(const annotations_t& a_annotations) {parent::m_annotations = a_annotations;}
void hprint_annotations(std::ostream& a_out) {
a_out << " * ANNOTATIONS :" << std::endl;
annotations_t::const_iterator it;
for(it=parent::m_annotations.begin();it!=parent::m_annotations.end();++it) {
//out << " * (" << index << ") "
a_out << " * " << (*it).first << " = " << (*it).second << std::endl;
}
}
protected:
bool is_compatible(const base_histo& a_histo){
if(parent::m_dimension!=a_histo.m_dimension) return false;
@@ -412,8 +424,9 @@ protected:
parent::m_bin_Sx2w[ibin][iaxis] += a_histo.m_bin_Sx2w[ibin][iaxis];
}
}
{dim_t nplane = parent::m_in_range_plane_Sxyw.size();
for(dim_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] += a_histo.m_in_range_plane_Sxyw[iplane];}
{size_t nplane = parent::m_in_range_plane_Sxyw.size();
for(size_t iplane=0;iplane<nplane;iplane++)
parent::m_in_range_plane_Sxyw[iplane] += a_histo.m_in_range_plane_Sxyw[iplane];}
parent::update_fast_getters();
}
@@ -527,8 +540,8 @@ protected:
parent::m_bin_Sx2w[ibin][iaxis] *= a_factor;
}
}
{dim_t nplane = parent::m_in_range_plane_Sxyw.size();
for(dim_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] *= a_factor;}
{size_t nplane = parent::m_in_range_plane_Sxyw.size();
for(size_t iplane=0;iplane<nplane;iplane++) parent::m_in_range_plane_Sxyw[iplane] *= a_factor;}
parent::update_fast_getters();
return true;
}
@@ -34,7 +34,7 @@ public:
return true;
}
unsigned int entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
public:
double sum_of_weights() const {
@@ -56,8 +56,8 @@ public:
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -132,9 +132,9 @@ public:
return status;
}
bool convert(const std::vector<double>& aEdges) {
bool convert(const std::vector<double>& a_edges) {
if(m_histo) return true;
m_histo = new histo::h1d(base_cloud::title(),aEdges);
m_histo = new histo::h1d(base_cloud::title(),a_edges);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -146,8 +146,8 @@ public:
return *m_histo;
}
bool fill_histogram(histo::h1d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ws[index])) return false;
}
return true;
@@ -47,8 +47,8 @@ public:
bool convert(const std::vector<double>&,const std::vector<double>&);
const histo::h2d& histogram() const;
bool fill_histogram(histo::h2d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_ws[index])) return false;
}
return true;
@@ -248,8 +248,8 @@ bool c2d::scale(double a_scale) {
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -305,10 +305,10 @@ bool c2d::fill(double aX,double aY,double aW){
}
inline
bool c2d::convert(const std::vector<double>& aEdgesX,const std::vector<double>& aEdgesY) {
bool c2d::convert(const std::vector<double>& a_edges_x,const std::vector<double>& a_edges_y) {
if(m_histo) return true;
m_histo = new histo::h2d(base_cloud::title(),
aEdgesX,aEdgesY);
a_edges_x,a_edges_y);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -337,7 +337,7 @@ const h2d& c2d::histogram() const {
inline
unsigned int c2d::entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
inline
+10 -11
View File
@@ -55,10 +55,9 @@ public:
const std::vector<double>&);
const histo::h3d& histogram() const;
bool fill_histogram(histo::h3d& a_histo) const {
unsigned int number = m_xs.size();
for(unsigned int index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_zs[index],m_ws[index]))
return false;
size_t number = m_xs.size();
for(size_t index=0;index<number;index++) {
if(!a_histo.fill(m_xs[index],m_ys[index],m_zs[index],m_ws[index])) return false;
}
return true;
}
@@ -307,8 +306,8 @@ bool c3d::scale(double a_scale) {
if(m_histo) {
return m_histo->scale(a_scale);
} else {
unsigned int number = m_ws.size();
for(unsigned int index=0;index<number;index++) m_ws[index] *= a_scale;
size_t number = m_ws.size();
for(size_t index=0;index<number;index++) m_ws[index] *= a_scale;
m_Sw *= a_scale;
m_Sxw *= a_scale;
m_Sx2w *= a_scale;
@@ -403,13 +402,13 @@ bool c3d::fill(double aX,double aY,double aZ,double aW){
inline
bool c3d::convert(
const std::vector<double>& aEdgesX
,const std::vector<double>& aEdgesY
,const std::vector<double>& aEdgesZ
const std::vector<double>& a_edges_x
,const std::vector<double>& a_edges_y
,const std::vector<double>& a_edges_z
) {
if(m_histo) return true;
m_histo = new histo::h3d(base_cloud::title(),
aEdgesX,aEdgesY,aEdgesZ);
a_edges_x,a_edges_y,a_edges_z);
if(!m_histo) return false;
bool status = fill_histogram(*m_histo);
clear();
@@ -423,7 +422,7 @@ double c3d::sum_of_weights() const {
inline
unsigned int c3d::entries() const {
return m_histo ? m_histo->all_entries() : m_ws.size();
return m_histo ? m_histo->all_entries() : (unsigned int)m_ws.size();
}
inline
@@ -102,7 +102,7 @@ public:
return *this;
}
public: //AIDA/Idata_point
unsigned int dimension() const {return m_measurements.size();}
size_t dimension() const {return m_measurements.size();}
measurement& coordinate(unsigned int a_coord) {
//WARNING : no check done on a_coord vs m_dim.
return m_measurements[a_coord];
@@ -150,7 +150,7 @@ public:
unsigned int dimension() const {return m_dim;}
void clear() {m_points.clear();}
unsigned int size() const {return m_points.size();}
size_t size() const {return m_points.size();}
const data_point& point(unsigned int a_index) const {
//WARNING : no check done on a_index.
@@ -203,8 +203,8 @@ public:
h1(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1(const std::string& a_title,const std::vector<TC>& aEdges)
:parent(a_title,aEdges){}
h1(const std::string& a_title,const std::vector<TC>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1(){}
public:
@@ -23,8 +23,8 @@ public:
h1d(const std::string& a_title,unsigned int aXnumber,double aXmin,double aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1d(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges){}
h1d(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1d(){}
public:
@@ -24,8 +24,8 @@ public:
h1df(const std::string& a_title,unsigned int aXnumber,float aXmin,float aXmax)
:parent(a_title,aXnumber,aXmin,aXmax){}
h1df(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges){}
h1df(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges){}
virtual ~h1df(){}
public:
@@ -160,8 +160,8 @@ public:
h2(const std::string& a_title,bn_t aXnumber,TC aXmin,TC aXmax,bn_t aYnumber,TC aYmin,TC aYmax)
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2(const std::string& a_title,const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
h2(const std::string& a_title,const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2(){}
@@ -24,9 +24,9 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2d(){}
@@ -27,9 +27,9 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aYnumber,aYmin,aYmax)
{}
h2df(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
virtual ~h2df(){}
@@ -197,10 +197,10 @@ public:
{}
h3(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
const std::vector<TC>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3(){}
@@ -28,10 +28,10 @@ public:
{}
h3d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
const std::vector<double>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3d(){}
@@ -31,10 +31,10 @@ public:
{}
h3df(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& aEdgesZ)
:parent(a_title,aEdgesX,aEdgesY,aEdgesZ)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
const std::vector<double>& a_edges_z)
:parent(a_title,a_edges_x,a_edges_y,a_edges_z)
{}
virtual ~h3df(){}
@@ -279,8 +279,8 @@ public:
m_bin_Sv2w.resize(parent::m_bin_number,0);
}
p1(const std::string& a_title,const std::vector<TC>& aEdges)
:parent(a_title,aEdges)
p1(const std::string& a_title,const std::vector<TC>& a_edges)
:parent(a_title,a_edges)
,m_cut_v(false)
,m_min_v(0)
,m_max_v(0)
@@ -289,8 +289,8 @@ public:
m_bin_Sv2w.resize(parent::m_bin_number,0);
}
p1(const std::string& a_title,const std::vector<TC>& aEdges,TV aVmin,TV aVmax)
:parent(a_title,aEdges)
p1(const std::string& a_title,const std::vector<TC>& a_edges,TV aVmin,TV aVmax)
:parent(a_title,a_edges)
,m_cut_v(true)
,m_min_v(aVmin)
,m_max_v(aVmax)
@@ -330,8 +330,8 @@ public:
m_max_v = 0;
return true;
}
bool configure(const std::vector<TC>& aEdges) {
if(!parent::configure(aEdges)) return false;
bool configure(const std::vector<TC>& a_edges) {
if(!parent::configure(a_edges)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -352,8 +352,8 @@ public:
m_max_v = aVmax;
return true;
}
bool configure(const std::vector<TC>& aEdges,TV aVmin,TV aVmax) {
if(!parent::configure(aEdges)) return false;
bool configure(const std::vector<TC>& a_edges,TV aVmin,TV aVmax) {
if(!parent::configure(a_edges)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -26,12 +26,12 @@ public:
:parent(a_title,aXnumber,aXmin,aXmax,aVmin,aVmax)
{}
p1d(const std::string& a_title,const std::vector<double>& aEdges)
:parent(a_title,aEdges)
p1d(const std::string& a_title,const std::vector<double>& a_edges)
:parent(a_title,a_edges)
{}
p1d(const std::string& a_title,const std::vector<double>& aEdges,double aVmin,double aVmax)
:parent(a_title,aEdges,aVmin,aVmax)
p1d(const std::string& a_title,const std::vector<double>& a_edges,double aVmin,double aVmax)
:parent(a_title,a_edges,aVmin,aVmax)
{}
virtual ~p1d(){}
+10 -10
View File
@@ -217,9 +217,9 @@ public:
}
p2(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
,m_cut_v(false)
,m_min_v(0)
,m_max_v(0)
@@ -229,10 +229,10 @@ public:
}
p2(const std::string& a_title,
const std::vector<TC>& aEdgesX,
const std::vector<TC>& aEdgesY,
const std::vector<TC>& a_edges_x,
const std::vector<TC>& a_edges_y,
TV aVmin,TV aVmax)
:parent(a_title,aEdgesX,aEdgesY)
:parent(a_title,a_edges_x,a_edges_y)
,m_cut_v(true)
,m_min_v(aVmin)
,m_max_v(aVmax)
@@ -272,8 +272,8 @@ public:
m_max_v = 0;
return true;
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY) {
if(!parent::configure(aEdgesX,aEdgesY)) return false;
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y) {
if(!parent::configure(a_edges_x,a_edges_y)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -294,8 +294,8 @@ public:
m_max_v = aVmax;
return true;
}
bool configure(const std::vector<TC>& aEdgesX,const std::vector<TC>& aEdgesY,TV aVmin,TV aVmax) {
if(!parent::configure(aEdgesX,aEdgesY)) return false;
bool configure(const std::vector<TC>& a_edges_x,const std::vector<TC>& a_edges_y,TV aVmin,TV aVmax) {
if(!parent::configure(a_edges_x,a_edges_y)) return false;
m_bin_Svw.clear();
m_bin_Sv2w.clear();
m_bin_Svw.resize(parent::m_bin_number,0);
@@ -32,16 +32,16 @@ public:
{}
p2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY)
:parent(a_title,aEdgesX,aEdgesY)
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y)
:parent(a_title,a_edges_x,a_edges_y)
{}
p2d(const std::string& a_title,
const std::vector<double>& aEdgesX,
const std::vector<double>& aEdgesY,
const std::vector<double>& a_edges_x,
const std::vector<double>& a_edges_y,
double aVmin,double aVmax)
:parent(a_title,aEdgesX,aEdgesY,aVmin,aVmax)
:parent(a_title,a_edges_x,a_edges_y,aVmin,aVmax)
{}
virtual ~p2d(){}
+11 -13
View File
@@ -148,7 +148,7 @@ private:
static void TGaxis_LabelsLimits(std::ostream& a_out,const char *label,
int &first,int &last) {
last = ::strlen(label)-1;
last = int(::strlen(label))-1;
for (int i=0; i<=last; i++) {
if (::strchr("1234567890-+.", label[i]) ) { first = i; return; }
}
@@ -457,9 +457,8 @@ public:
double timeoffset = 0;
if (OptionTime) {
if (IdF!=std::string::npos) {
int LnF = fTimeFormat.size();
std::string stringtimeoffset =
fTimeFormat.substr(IdF+2,LnF-(IdF+2));
int LnF = int(fTimeFormat.size());
std::string stringtimeoffset = fTimeFormat.substr(IdF+2,LnF-(IdF+2));
int yy, mm, dd, hh, mi, ss;
if (::sscanf(stringtimeoffset.c_str(),
"%d-%d-%d %d:%d:%d", &yy, &mm, &dd, &hh, &mi, &ss) == 6) {
@@ -482,7 +481,7 @@ public:
std::string::size_type Ids = stringtimeoffset.find("s");
if (Ids != std::string::npos) {
float dp;
int Lns = stringtimeoffset.size();
size_t Lns = stringtimeoffset.size();
std::string sdp = stringtimeoffset.substr(Ids+1,Lns-(Ids+1));
::sscanf(sdp.c_str(),"%g",&dp);
timeoffset += dp;
@@ -1268,7 +1267,7 @@ public:
snpf(CHTEMP,sizeof(CHTEMP),"%g",DWlabel);
int ndecimals = 0;
size_t ndecimals = 0;
if (OptionDecimals) {
char *dot = ::strchr(CHTEMP,'.');
if (dot) ndecimals = CHTEMP + ::strlen(CHTEMP) -dot;
@@ -1299,13 +1298,13 @@ public:
::strcpy(CHTEMP, "0");
::strcat(CHTEMP, &LABEL[first]);
::strcpy(LABEL, CHTEMP);
first = 1; last = ::strlen(LABEL);
first = 1; last = int(::strlen(LABEL));
}
if (LABEL[first] == '-' && LABEL[first+1] == '.') {
::strcpy(CHTEMP, "-0");
::strcat(CHTEMP, &LABEL[first+1]);
::strcpy(LABEL, CHTEMP);
first = 1; last = ::strlen(LABEL);
first = 1; last = int(::strlen(LABEL));
}
// We eliminate the non significant 0 after '.'
@@ -1339,9 +1338,8 @@ public:
// Appends fractionnal part if seconds displayed
if (DWlabel<0.9) {
double tmpdb;
int tmplast;
snpf(LABEL,sizeof(LABEL),
"%%S%7.5f",modf(timed,&tmpdb));
size_t tmplast;
snpf(LABEL,sizeof(LABEL),"%%S%7.5f",modf(timed,&tmpdb));
tmplast = ::strlen(LABEL)-1;
// We eliminate the non significiant 0 after '.'
@@ -1357,7 +1355,7 @@ public:
::strftime(LABEL,256,timeformattmp.c_str(),utctis);
::strcpy(CHTEMP,&LABEL[0]);
first = 0; last=::strlen(LABEL)-1;
first = 0; last=int(::strlen(LABEL))-1;
Wlabel = wTimeIni + (k+1)*DWlabel;
}
@@ -1793,7 +1791,7 @@ public:
std::string::size_type IdF = fTimeFormat.find("%F");
if (IdF!=std::string::npos) {
int LnF = fTimeFormat.size();
size_t LnF = fTimeFormat.size();
std::string stringtimeoffset = fTimeFormat.substr(IdF,LnF-IdF);
fTimeFormat = a_format;
fTimeFormat += stringtimeoffset;
+148 -92
View File
@@ -278,79 +278,7 @@ public:
return true;
}
bool contract(unsigned int a_factor,img<T>& a_res,bool a_force_res_owner = true) const {
// a_factor pixels are contracted in one.
if(a_factor==1) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
} else {
a_res.set(m_w,m_h,m_n,m_buffer,false);
}
return true;
}
if(!a_factor) {
a_res.make_empty();
return false;
}
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
unsigned int sz = nh*nw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* nb = new T[sz];
if(!nb) {
a_res.make_empty();
return false;
}
//T* npos = nb;
//for(unsigned int ipix=0;ipix<sz;ipix++) {*npos = 125;npos++;}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] nb;
a_res.make_empty();
return false;
}
unsigned int nfac = a_factor*a_factor;
for(unsigned int j=0;j<nh;j++) {
for(unsigned int i=0;i<nw;i++) {
// take mean value of a_factor*a_factor pixels :
for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
T* pos = m_buffer + (j*a_factor+fr)*(m_w*m_n) +(i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] += double(*pos);pos++;
}
}
}
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] /= double(nfac);
}
//position in the result image.
T* npos = nb + j * (nw * m_n) + i*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*npos = T(pixels[ipix]);npos++;
}
}
}
delete [] pixels;
a_res.set(nw,nh,m_n,nb,true);
return true;
}
bool contract(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
bool contract_raw(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
if((a_w==m_w)&&(a_h==m_h)) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
@@ -415,6 +343,129 @@ public:
return true;
}
bool contract(unsigned int a_w,unsigned int a_h,img<T>& a_res,bool a_force_res_owner = true) const {
//optimized version of contract_raw().
if((a_w==m_w)&&(a_h==m_h)) {
if(a_force_res_owner) {
a_res.copy(m_w,m_h,m_n,m_buffer);
} else {
a_res.set(m_w,m_h,m_n,m_buffer,false);
}
return true;
}
size_t sz = a_h*a_w*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* rb = new T[sz];
if(!rb) {
a_res.make_empty();
return false;
}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] rb;
a_res.make_empty();
return false;
}
{for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;}
unsigned int wfac = double(m_w)/double(a_w);
unsigned int hfac = double(m_h)/double(a_h);
if(!wfac) wfac = 1;
if(!hfac) hfac = 1;
double wfac_hfac = wfac*hfac;
//::printf("debug : %d %d, %d %d\n",a_h,a_w,hfac,wfac);
T* hpos;T* pos;T* hrpos;T* rpos;T* hhpos;T* _pos;double* ppos;
unsigned int i,j,fr,fc,ipix,i0;
unsigned int astride = a_w * m_n;
unsigned int mstride = m_w * m_n;
unsigned int wfacstride = wfac * m_n;
for(j=0;j<a_h;j++) {
hrpos = rb + j * astride;
hhpos = m_buffer + j*hfac*mstride;
for(i=0;i<a_w;i++) {
// take mean value of wfac*hfac pixels :
i0 = i*wfacstride;
hpos = hhpos;
for(fr=0;fr<hfac;fr++,hpos+=mstride) {
_pos = hpos + i0;
for(fc=0;fc<wfac;fc++,_pos+=m_n) {
pos = _pos;
ppos = pixels;
for(ipix=0;ipix<m_n;ipix++,pos++,ppos++) {
*ppos += double(*pos)/wfac_hfac;
// *ppos += double(*pos); //NOTE : doing the wfac_hfac division in the below loop is slower !
}
}
}
//position in the result image.
rpos = hrpos + i*m_n;
ppos = pixels;
for(ipix=0;ipix<m_n;ipix++,rpos++,ppos++) {
*rpos = T(*ppos);
// *rpos = T((*ppos)/wfac_hfac); //slower !
*ppos = 0;
}
}
}
delete [] pixels;
a_res.set(a_w,a_h,m_n,rb,true);
return true;
}
bool contract(unsigned int a_factor,img<T>& a_res,bool a_force_res_owner = true) const {
// a_factor pixels are contracted in one.
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
return contract(nw,nh,a_res,a_force_res_owner);
}
template <class TTO>
bool convert(img<TTO>& a_res) const {
a_res.make_empty();
unsigned int sz = m_w*m_h*m_n;
if(!sz) return false;
TTO* _buffer = new TTO[sz];
if(!_buffer) return false;
unsigned int i,j,ipix,imn;
unsigned int mwn = m_w*m_n;
T* _pos;T* pos;
TTO* _rpos;TTO* rpos;
for(j=0;j<m_h;j++) {
_pos = m_buffer + j*mwn;
_rpos = _buffer + j*mwn;
for(i=0;i<m_w;i++) {
imn = i*m_n;
pos = _pos + imn;
rpos = _rpos + imn;
for(ipix=0;ipix<m_n;ipix++,pos++,rpos++) *rpos = *pos;
}
}
a_res.set(m_w,m_h,m_n,_buffer,true);
return true;
}
bool get_part(unsigned int a_sx,unsigned int a_sy,unsigned int a_sw,unsigned int a_sh,img<T>& a_res) const {
if((a_sx>=m_w)||(a_sy>=m_h)){
@@ -767,34 +818,39 @@ public:
return false;
}
//unsigned int wbwn = wbw*an;
unsigned int awn = aw*an;
unsigned int rwn = rw*an;
bool has_border = a_bw||a_bh?true:false;
if(has_border) {
::memset(rb,a_bc,rsz*sizeof(T));
}
//optimize :
//unsigned int wbwn = wbw*an;
unsigned int awn = aw*an;
unsigned int rwn = rw*an;
unsigned int i,j,r;
//unsigned int c;
T* tile;T* pos;T* ptile;T* _pos;
//copy tiles :
unsigned int index = 0;
for(unsigned int j=0;j<a_rows;j++) {
for(unsigned int i=0;i<a_cols;i++) {
T* tile = a_imgs[index].buffer();
for(j=0;j<a_rows;j++) {
for(i=0;i<a_cols;i++) {
// index = a_cols*j+i
tile = a_imgs[index].buffer();
/*
if(has_border) {
for(unsigned int r=0;r<hbh;r++) {
T* pos = rb + (j*hbh+r)*rwn + i*wbwn;
::memset(pos,a_bc,wbwn*sizeof(T));
}
}
*/
//if(has_border) {
// for(unsigned int r=0;r<hbh;r++) {
// T* pos = rb + (j*hbh+r)*rwn + i*wbwn;
// ::memset(pos,a_bc,wbwn*sizeof(T));
// }
//}
{for(unsigned int r=0;r<ah;r++) {
T* pos = rb + (j*hbh+r+a_bh)*rwn + (i*wbw+a_bw)*rn;
T* ptile = tile+r*awn;
for(unsigned int c=0;c<awn;c++) *pos++ = *ptile++;
_pos = rb + (j*hbh+a_bh)*rwn + (i*wbw+a_bw)*rn;
{for(r=0;r<ah;r++) {
// pos = _pos + r*rwn;
// ptile = tile + r*awn;
// for(c=0;c<awn;c++,pos++,ptile++) *pos = *ptile;
::memcpy(_pos+r*rwn,tile+r*awn,awn*sizeof(T)); //optimize. (bof, we do not gain a lot).
}}
index++;
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
#include "typedefs"
namespace tools {
class impi {
@@ -14,18 +16,32 @@ public:
virtual ~impi(){}
public:
virtual bool pack(unsigned int) = 0;
virtual bool pack(uint64) = 0;
virtual bool pack(int64) = 0;
virtual bool pack(double) = 0;
virtual bool bpack(bool) = 0;
virtual bool spack(const std::string&) = 0;
virtual bool vpack(const std::vector<unsigned int>&) = 0;
virtual bool vpack(const std::vector<int>&) = 0;
virtual bool vpack(const std::vector<double>&) = 0;
virtual bool pack(uint32,const char*) = 0;
virtual bool pack(uint32,const int*) = 0;
virtual bool unpack(unsigned int&) = 0;
virtual bool unpack(uint64&) = 0;
virtual bool unpack(int64&) = 0;
virtual bool unpack(double&) = 0;
virtual bool bunpack(bool&) = 0;
virtual bool sunpack(std::string&) = 0;
virtual bool vunpack(std::vector<unsigned int>&) = 0;
virtual bool vunpack(std::vector<int>&) = 0;
virtual bool vunpack(std::vector<double>&) = 0;
virtual bool unpack(uint32&,char*&) = 0;
virtual bool unpack(uint32&,int*&) = 0;
// for tools::mpi::pntuple :
virtual void pack_reset() = 0;
virtual bool send_buffer(int,int) = 0;
};
}
@@ -59,7 +59,7 @@ public:
virtual bool write_std_vec_vec(const std_vec_vec_string_t&) = 0;
public:
virtual const char* buf() const = 0;
virtual uint32 length() const = 0;
virtual size_t length() const = 0;
};
}}
@@ -47,6 +47,10 @@ inline void vec_sub(const T* a_1,const T* a_2,T* a_res,unsigned int a_number) {
}
*/
#include "eqT"
#include <cstddef> //size_t
// common code to class mat and nmat.
#define TOOLS_MATCOM \
@@ -101,6 +105,32 @@ public:\
void set_random(RANDOM& a_random) {\
for(unsigned int i=0;i<dim2();i++) m_vec[i] = a_random.shoot();\
}\
template <class RANDOM>\
void set_symmetric_random(RANDOM& a_random) {\
unsigned int _D = dimension();\
{for(unsigned int r=0;r<_D;r++) set_value(r,r,a_random.shoot());}\
T rd;\
{for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
rd = a_random.shoot();\
set_value(r,c,rd);\
set_value(c,r,rd);\
}\
}}\
}\
template <class RANDOM>\
void set_antisymmetric_random(RANDOM& a_random) {\
unsigned int _D = dimension();\
{for(unsigned int r=0;r<_D;r++) set_value(r,r,zero());}\
T rd;\
{for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
rd = a_random.shoot();\
set_value(r,c,rd);\
set_value(c,r,minus_one()*rd);\
}\
}}\
}\
public:\
template <class VEC>\
bool mul_vec(VEC& a_vec,T a_tmp[]) const {\
@@ -122,6 +152,25 @@ public:\
delete [] res;\
return status;\
}\
\
bool mul_array(T a_vec[],T a_tmp[]) const {\
/* a_vec = this *= a_vec */\
unsigned int _dim = dimension();\
T* pos = a_tmp;\
for(unsigned int r=0;r<_dim;r++,pos++) {\
*pos = T();\
for(unsigned int c=0;c<_dim;c++) *pos += m_vec[r+c*_dim]*a_vec[c];\
}\
{for(unsigned int i=0;i<_dim;i++) a_vec[i] = a_tmp[i];}\
return true;\
}\
bool mul_array(T a_vec[]) const {\
T* res = new T[dimension()];\
bool status = mul_array(a_vec,res);\
delete [] res;\
return status;\
}\
\
void mul_mtx(const TOOLS_MAT_CLASS& a_m) {\
_mul_mtx(a_m.m_vec);\
}\
@@ -151,6 +200,18 @@ public:\
}\
return true;\
}\
\
template <class PREC>\
bool equal_prec(const TOOLS_MAT_CLASS& a_m,const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
if(&a_m==this) return true;\
T* tp = (T*)m_vec;\
T* mp = (T*)a_m.m_vec;\
for(unsigned int i=0;i<dim2();i++,tp++,mp++) {\
T diff = (*tp) - (*mp);\
if(a_fabs(diff)>=a_prec) return false;\
}\
return true;\
}\
\
void mx_diff(const TOOLS_MAT_CLASS& a_m,T& a_mx_diff) const {\
T* tp = (T*)m_vec;\
@@ -191,6 +252,49 @@ public:\
}\
return true;\
}\
\
public:\
template <class PREC>\
bool is_proportional_prec(const TOOLS_MAT_CLASS& a_right,const PREC& a_prec,PREC(*a_fabs)(const T&),T& a_factor) const {\
/* If true, then : a_right = a_factor * this.*/\
if(this==&a_right) {a_factor=T(1);return true;}\
T _zero = zero();\
a_factor = _zero;\
if(dimension()!=a_right.dimension()) return false;\
T* lp = (T*)m_vec;\
T* rp = (T*)a_right.m_vec;\
bool first = true;\
size_t _data_size = data_size();\
for(size_t i=0;i<_data_size;i++,lp++,rp++) {\
if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
continue;\
} else if( !numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
return false;\
} else if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && !numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
return false;\
} else {\
if(first) {\
a_factor = (*rp)/(*lp);\
first = false;\
} else {\
if(!numbers_are_equals((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
}\
}\
}\
return true;\
}\
\
template <class PREC>\
bool is_diagonal_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
T _zero = zero();\
unsigned int _D = dimension();\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=0;c<_D;c++) {\
if(c!=r) {if(!numbers_are_equals(value(r,c),_zero,a_prec,a_fabs)) return false;}\
}\
}\
return true;\
}\
\
const T* data() const {return m_vec;}\
unsigned int size() const {return dim2();}\
@@ -228,6 +332,18 @@ public:\
}\
return true;\
}\
\
template <class PREC>\
bool is_symmetric_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
unsigned int _D = dimension();\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
T diff = value(r,c)-value(c,r);\
if(a_fabs(diff)>=a_prec) return false;\
}\
}\
return true;\
}\
\
bool is_antisymmetric() const {\
unsigned int _D = dimension();\
@@ -479,11 +595,11 @@ public: /*operators*/\
return m_vec[a_r + a_c * dimension()];\
}\
\
T& operator[](unsigned int a_index) { /*for inlib/sg/sf_vec*/\
T& operator[](size_t a_index) { /*for inlib/sg/sf_vec*/\
/*WARNING : no check on a_index.*/\
return m_vec[a_index];\
}\
const T& operator[](unsigned int a_index) const {\
const T& operator[](size_t a_index) const {\
/*WARNING : no check on a_index.*/\
return m_vec[a_index];\
}\
@@ -16,6 +16,7 @@ class box3 {
protected:
typedef typename VEC3::elem_t T_t;
//static T_t num_max() {return std::numeric_limits<T_t>::max();} //max is a forever pain on Windows.
static T_t zero() {return T_t();}
protected:
box3(){
//make_empty();
@@ -120,6 +121,29 @@ public:
}
}
bool get_cube_size(T_t& a_dx,T_t& a_dy,T_t& a_dz,T_t(*a_sqrt)(T_t)) const {
if(!get_size(a_dx,a_dy,a_dz)) return false;
if((a_dx<=zero())&&(a_dy<=zero())&&(a_dz<=zero())) return false;
if((a_dx<=zero())&&(a_dy<=zero())) { //dz not 0 :
a_dx = T_t(0.1)*a_dz;
a_dy = T_t(0.1)*a_dz;
} else if((a_dy<=zero())&&(a_dz<=zero())) { //dx not 0 :
a_dy = T_t(0.1)*a_dx;
a_dz = T_t(0.1)*a_dx;
} else if((a_dz<=zero())&&(a_dx<=zero())) { //dy not 0 :
a_dz = T_t(0.1)*a_dy;
a_dx = T_t(0.1)*a_dy;
} else if(a_dx<=zero()) { //dy,dz not 0 :
a_dx = T_t(0.1)*a_sqrt(a_dy*a_dy+a_dz*a_dz);
} else if(a_dy<=zero()) { //dx,dz not 0 :
a_dy = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dz*a_dz);
} else if(a_dz<=zero()) { //dx,dy not 0 :
a_dz = T_t(0.1)*a_sqrt(a_dx*a_dx+a_dy*a_dy);
}
return true;
}
//NOTE : print is a Python keyword.
void dump(std::ostream& a_out) {
T_t dx,dy,dz;
@@ -27,6 +27,9 @@ public:
m_min.set_value( num_max(), num_max(), num_max());
m_max.set_value(-num_max(), -num_max(), -num_max());
}
bool get_cube_size(float& a_dx,float& a_dy,float& a_dz) const {
return parent::get_cube_size(a_dx,a_dy,a_dz,::sqrtf);
}
};
}
@@ -0,0 +1,18 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_eqT
#define tools_eqT
namespace tools {
template <class NUMBER,class PREC>
inline bool numbers_are_equals(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
NUMBER diff = a_left - a_right;
if(a_fabs(diff)>=a_prec) return false;
return true;
}
}
#endif
@@ -0,0 +1,94 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_geom2
#define tools_geom2
#include <vector>
#include <cstddef>
namespace tools {
template <class VEC2>
inline double is_left(const VEC2& P0,const VEC2& P1,const VEC2& P2){
return ( (P1.v0() - P0.v0()) * (P2.v1() - P0.v1())
- (P2.v0() - P0.v0()) * (P1.v1() - P0.v1()) );
}
template <class VEC2>
inline bool is_inside(const VEC2& a_P,const std::vector<VEC2>& a_V) {
// V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
// From :
// http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm
// Copyright 2001, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their application.
size_t n = a_V.size()-1;
int wn = 0; // the winding number counter
// loop through all edges of the polygon
for (size_t i=0; i<n; i++) { // edge from V[i] to V[i+1]
if (a_V[i].v1() <= a_P.v1()) { // start y <= P[1]
if (a_V[i+1].v1() > a_P.v1()) // an upward crossing
if (is_left( a_V[i], a_V[i+1], a_P) > 0) // P left of edge
++wn; // have a valid up intersect
} else { // start y > P[1] (no test needed)
if (a_V[i+1].v1() <= a_P.v1()) // a downward crossing
if (is_left( a_V[i], a_V[i+1], a_P) < 0) // P right of edge
--wn; // have a valid down intersect
}
}
return ((wn!=0)?true:false);
}
// the same done with std::pair.
template <class T>
inline double is_left(const std::pair<T,T>& P0,const std::pair<T,T>& P1,const std::pair<T,T>& P2){
return ( (P1.first - P0.first) * (P2.second - P0.second)
- (P2.first - P0.first) * (P1.second - P0.second) );
}
template <class T>
inline bool inside(const std::pair<T,T>& a_P,const std::vector< std::pair<T,T> >& a_V) {
// V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
// From :
// http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm
// Copyright 2001, softSurfer (www.softsurfer.com)
// This code may be freely used and modified for any purpose
// providing that this copyright notice is included with it.
// SoftSurfer makes no warranty for this code, and cannot be held
// liable for any real or imagined damage resulting from its use.
// Users of this code must verify correctness for their application.
size_t n = a_V.size()-1;
int wn = 0; // the winding number counter
// loop through all edges of the polygon
for (size_t i=0; i<n; i++) { // edge from V[i] to V[i+1]
if (a_V[i].second <= a_P.second) { // start y <= P[1]
if (a_V[i+1].second > a_P.second) // an upward crossing
if (is_left( a_V[i], a_V[i+1], a_P) > 0) // P left of edge
++wn; // have a valid up intersect
} else { // start y > P[1] (no test needed)
if (a_V[i+1].second <= a_P.second) // a downward crossing
if (is_left( a_V[i], a_V[i+1], a_P) < 0) // P right of edge
--wn; // have a valid down intersect
}
}
return ((wn!=0)?true:false);
}
}
#endif
@@ -6,6 +6,7 @@
#include "line"
#include "plane"
#include "vec3"
namespace tools {
+18 -18
View File
@@ -4,18 +4,18 @@
#ifndef tools_line
#define tools_line
#include "vec3"
namespace tools {
// Parametric description:
// l(t) = pos + t * dir
template <class T>
template <class VEC3>
class line {
protected:
typedef typename VEC3::elem_t T;
public:
line(){}
line(const vec3<T>& a_p0,const vec3<T>& a_p1) {
line(const VEC3& a_p0,const VEC3& a_p1) {
// Construct a line from two points lying on the line. If you
// want to construct a line from a position and a direction, use
// line(p, p + d).
@@ -45,7 +45,7 @@ public:
return *this;
}
public:
void set_value(const vec3<T>& a_p0,const vec3<T>& a_p1) {
void set_value(const VEC3& a_p0,const VEC3& a_p1) {
m_pos = a_p0;
m_dir = a_p0;
m_dir.multiply(-1);
@@ -59,11 +59,11 @@ public:
m_dir.normalize();
}
const vec3<T>& position() const {return m_pos;}
const vec3<T>& direction() const {return m_dir;}
const VEC3& position() const {return m_pos;}
const VEC3& direction() const {return m_dir;}
/* not tested :
vec3<T> closest_point(const vec3<T>& a_point) const {
VEC3 closest_point(const VEC3& a_point) const {
//from coin3d/SbLine.cpp.
//
@@ -81,7 +81,7 @@ public:
bool closest_points(const line<T>& a_line,
vec3<T>& a_on_this,vec3<T>& a_on_line) const {
VEC3& a_on_this,VEC3& a_on_line) const {
//from coin3d/SbLine.cpp.
//WARNING : if ret false, a_on_this, a_on_line not set.
@@ -91,11 +91,11 @@ public:
if(a_line.m_dir == m_dir) return false;
if(a_line.m_dir == T(-1)*m_dir) return false;
vec3<T> P0 = m_pos;
vec3<T> P1 = a_line.m_pos;
vec3<T> D0 = m_dir;
vec3<T> D1 = a_line.m_dir;
vec3<T> D0N = D0;
VEC3 P0 = m_pos;
VEC3 P1 = a_line.m_pos;
VEC3 D0 = m_dir;
VEC3 D1 = a_line.m_dir;
VEC3 D0N = D0;
T c[3], d[3];
@@ -116,8 +116,8 @@ public:
return true;
}
bool intersect(const line<T>& a_line,vec3<T>& a_out,const T& a_prec) const {
vec3<T> p,q;
bool intersect(const line<T>& a_line,VEC3& a_out,const T& a_prec) const {
VEC3 p,q;
if(!closest_points(a_line,p,q)) return false;
if((q-p).length()>a_prec) return false;
a_out = p;
@@ -126,8 +126,8 @@ public:
*/
protected:
vec3<T> m_pos;
vec3<T> m_dir; //normalized.
VEC3 m_pos;
VEC3 m_dir; //normalized.
};
}
+25 -105
View File
@@ -5,7 +5,7 @@
#define tools_mat
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
#include "MATCOM"
@@ -30,9 +30,11 @@ private:
}
#endif
public:
mat() {
mat(bool a_inc = true) {
#ifdef TOOLS_MEM
mem::increment(s_class().c_str());
if(a_inc) mem::increment(s_class().c_str());
#else
(void)a_inc;
#endif
#ifdef TOOLS_MAT_NEW
m_vec = new T[D*D];
@@ -160,18 +162,18 @@ inline nmat<T> copy(const mat<T,D>& a_from) {
}
template <class MAT>
inline void conjugate(MAT& a_m) {
inline void conjugate(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
typedef typename MAT::elem_t T;
T* pos = const_cast<T*>(a_m.data());
unsigned int D2 = a_m.dimension()*a_m.dimension();
for(unsigned int i=0;i<D2;i++,pos++) {
*pos = _conj(*pos); //T = std::complex<>
*pos = a_conj(*pos); //T = std::complex<>
}
}
template <class MAT>
inline void dagger(MAT& a_m) {
conjugate<MAT>(a_m);
inline void dagger(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
conjugate<MAT>(a_m,a_conj);
a_m.transpose();
}
@@ -359,37 +361,6 @@ inline void matrix_set(MAT& a_m
vec[1] = a_10;vec[3] = a_11;
}
template <class MAT>
inline void set_epsilon(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1,
-1, 0);
}
// Pauli matrices :
// P1 P2 P3
// 0 1 0 -i 1 0
// 1 0 i 0 0 -1
template <class MAT>
inline void set_P1(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1,
1, 0);
}
template <class MAT>
inline void set_P2(MAT& a_m) {
typedef typename MAT::elem_t T;
//T i;set_i(i); //with inlib::symbol
T i(0,1);
T _i = T(-1)*i;
matrix_set<MAT>(a_m, 0, _i,
i, 0);
}
template <class MAT>
inline void set_P3(MAT& a_m) {
matrix_set<MAT>(a_m, 1, 0,
0,-1);
}
////////////////////////////////////////////////
/// specific D=3 ///////////////////////////////
////////////////////////////////////////////////
@@ -407,27 +378,6 @@ inline void matrix_set(MAT& a_m
vec[2] = a_20;vec[5] = a_21;vec[8] = a_22;
}
// Generators of rotation group :
// Rk(i,j) = epsilon(k,i,j) i,j,k=1,2,3
template <class MAT>
inline void set_R1(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 0, 0,
0, 0, 1,
0,-1, 0);
}
template <class MAT>
inline void set_R2(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 0,-1,
0, 0, 0,
1, 0, 0);
}
template <class MAT>
inline void set_R3(MAT& a_m) {
matrix_set<MAT>(a_m, 0, 1, 0,
-1, 0, 0,
0, 0, 0);
}
////////////////////////////////////////////////
/// specific D=4 ///////////////////////////////
////////////////////////////////////////////////
@@ -447,56 +397,26 @@ inline void matrix_set(MAT& a_m
vec[3] = a_30;vec[7] = a_31;vec[11] = a_32;vec[15] = a_33;
}
template <class MAT,class RANDOM>
inline void set_random_antisym(MAT& a_m,RANDOM& a_rd) {
typedef typename MAT::elem_t T;
T v01 = a_rd.shoot();
T v02 = a_rd.shoot();
T v03 = a_rd.shoot();
T v12 = a_rd.shoot();
T v13 = a_rd.shoot();
T v23 = a_rd.shoot();
matrix_set(a_m,
0, v01, v02, v03,
-v01, 0, v12, v13,
-v02,-v12, 0, v23,
-v03,-v13,-v23, 0);
}
////////////////////////////////////////////////
/// specific D=5 ///////////////////////////////
////////////////////////////////////////////////
template <class MAT>
inline void set_eta(MAT& a_m) {
a_m.set_zero();
a_m.set_value(0,0, 1);
a_m.set_value(1,1,-1);
a_m.set_value(2,2,-1);
a_m.set_value(3,3,-1);
}
////////////////////////////////////////////////
/// specific D=6 ///////////////////////////////
////////////////////////////////////////////////
/*
template <class T>
inline void set_matrix(mat<T,6>& a_m
,const T& a_00,const T& a_01,const T& a_02,const T& a_03,const T& a_04,const T& a_05 //1 row
,const T& a_10,const T& a_11,const T& a_12,const T& a_13,const T& a_14,const T& a_15 //2 row
,const T& a_20,const T& a_21,const T& a_22,const T& a_23,const T& a_24,const T& a_25 //3 row
,const T& a_30,const T& a_31,const T& a_32,const T& a_33,const T& a_34,const T& a_35 //4 row
,const T& a_40,const T& a_41,const T& a_42,const T& a_43,const T& a_44,const T& a_45 //5 row
,const T& a_50,const T& a_51,const T& a_52,const T& a_53,const T& a_54,const T& a_55 //6 row
inline void matrix_set(MAT& a_m
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03,const typename MAT::elem_t& a_04 //1 row
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13,const typename MAT::elem_t& a_14 //2 row
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23,const typename MAT::elem_t& a_24 //3 row
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33,const typename MAT::elem_t& a_34 //4 row
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44 //5 row
){
//a_<R><C>
//vec[R + C * 6];
T* vec = const_cast<T*>(a_m.data());
vec[0] = a_00;vec[6] = a_01;vec[12] = a_02;vec[18] = a_03;vec[24] = a_04;vec[30] = a_05;
vec[1] = a_10;vec[7] = a_11;vec[13] = a_12;vec[19] = a_13;vec[25] = a_14;vec[31] = a_15;
vec[2] = a_20;vec[8] = a_21;vec[14] = a_22;vec[20] = a_23;vec[26] = a_24;vec[32] = a_25;
vec[3] = a_30;vec[9] = a_31;vec[15] = a_32;vec[21] = a_33;vec[27] = a_34;vec[33] = a_35;
vec[4] = a_40;vec[10] = a_41;vec[16] = a_42;vec[22] = a_43;vec[28] = a_44;vec[34] = a_45;
vec[5] = a_50;vec[11] = a_51;vec[17] = a_52;vec[23] = a_53;vec[29] = a_54;vec[35] = a_55;
//vec[R + C * 4];
typename MAT::elem_t* vec = const_cast<typename MAT::elem_t*>(a_m.data());
vec[0] = a_00;vec[5] = a_01;vec[10] = a_02;vec[15] = a_03;vec[20] = a_04;
vec[1] = a_10;vec[6] = a_11;vec[11] = a_12;vec[16] = a_13;vec[21] = a_14;
vec[2] = a_20;vec[7] = a_21;vec[12] = a_22;vec[17] = a_23;vec[22] = a_24;
vec[3] = a_30;vec[8] = a_31;vec[13] = a_32;vec[18] = a_33;vec[23] = a_34;
vec[4] = a_40;vec[9] = a_41;vec[14] = a_42;vec[19] = a_43;vec[24] = a_44;
}
*/
}
+47 -13
View File
@@ -6,7 +6,7 @@
#include "mat"
#include <cmath>
//#include <cmath>
namespace tools {
@@ -15,7 +15,7 @@ class mat4 : public mat<T,4> {
typedef mat<T,4> parent;
typedef mat<T,4> pr;
public:
mat4():parent() {}
mat4(bool a_inc = true):parent(a_inc) {}
mat4(const mat<T,4>& a_from):parent(a_from){}
virtual ~mat4() {}
public:
@@ -62,8 +62,8 @@ public:
void set_translate(const T& a_x,const T& a_y,const T& a_z) {
_set_translate(a_x,a_y,a_z,pr::m_vec);
}
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle) {
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec);
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
}
void set_ortho(const T& a_l,const T& a_r, //left,right
const T& a_b,const T& a_t, //bottom,top
@@ -155,6 +155,13 @@ public:
a_y = pr::m_vec[13];
a_z = pr::m_vec[14];
}
//void set_translate_only(const T& a_x,const T& a_y,const T& a_z) {
// pr::m_vec[12] = a_x;
// pr::m_vec[13] = a_y;
// pr::m_vec[14] = a_z;
//}
public:
void mul_4(T& a_x,T& a_y,T& a_z,T& a_p) const {
// a_[x,y,z,p] = this * a_[x,y,z,p]
@@ -211,6 +218,14 @@ public:
a_z = z;
}
void mul_trans_3(T& a_x,T& a_y,T& a_z) const {
// used in sg::healpix.
// a_[x,y,z] = trans_part(this) * a_[x,y,z]
a_x += pr::m_vec[12];
a_y += pr::m_vec[13];
a_z += pr::m_vec[14];
}
template <class VEC>
void mul_dir_3(VEC& a_dir) const {
mul_dir_3(a_dir[0],a_dir[1],a_dir[2]);
@@ -261,16 +276,15 @@ public:
pr::m_vec[15] = pr::m_vec[3]*a_x+pr::m_vec[7]*a_y+pr::m_vec[11]*a_z+pr::m_vec[15];
}
void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle) {
void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
T rot[16];
_set_rotate(a_x,a_y,a_z,a_angle,rot);
_set_rotate(a_x,a_y,a_z,a_angle,rot,a_sin,a_cos);
parent::_mul_mtx(rot);
}
void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,
const T& a_angle) {
void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
T _m[16];
_set_rotate(a_x,a_y,a_z,a_angle,_m);
_set_rotate(a_x,a_y,a_z,a_angle,_m,a_sin,a_cos);
parent::_left_mul_mtx(_m);
}
@@ -340,11 +354,11 @@ protected:
v[2] = 0;v[6] = 0;v[10] = a_3;v[14] = 0;
v[3] = 0;v[7] = 0;v[11] = 0;v[15] = T(1);
}
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,
const T& a_angle,T v[]) {
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T v[],T(*a_sin)(T),T(*a_cos)(T)) {
//WARNING : (a_x,a_y,a_z) must be a normalized vector.
T co = (T)::cos(a_angle);
T si = (T)::sin(a_angle);
T si = a_sin(a_angle);
T co = a_cos(a_angle);
T x = a_x;
T y = a_y;
T z = a_z;
@@ -447,6 +461,26 @@ public:
private:static void check_instantiation() {mat4<float> dummy;}
};
////////////////////////////////////////////////
/// common matrices : //////////////////////////
////////////////////////////////////////////////
template <class T>
inline const mat4<T>& mat4_zero() {
static const mat4<T> s_v(false); //inc mem count = false
return s_v;
}
/*
template <class T>
inline const mat4<T>& mat4_identity() {
static mat4<T> s_v(false);
static bool s_first = true;
if(s_first) {s_v.set_identity();s_first=false;}
return s_v;
}
*/
//for sf, mf :
template <class T>
inline const T* get_data(const mat4<T>& a_v) {return a_v.data();}
@@ -5,17 +5,19 @@
#define tools_mat4f
#include "mat4"
#include <cmath>
namespace tools {
class mat4f : public mat4<float> {
typedef mat4<float> parent;
public:
mat4f(){}
virtual ~mat4f() {}
public:
mat4f(const mat4f& a_from):mat4<float>(a_from){}
mat4f(const mat4f& a_from):parent(a_from){}
mat4f& operator=(const mat4f& a_from){
mat4<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
@@ -23,28 +25,38 @@ public:
float a_10,float a_11,float a_12,float a_13, //second row
float a_20,float a_21,float a_22,float a_23, //third row
float a_30,float a_31,float a_32,float a_33) //fourth row
:mat4<float>(a_00,a_01,a_02,a_03,
a_10,a_11,a_12,a_13,
a_20,a_21,a_22,a_23,
a_30,a_31,a_32,a_33)
:parent(a_00,a_01,a_02,a_03,
a_10,a_11,a_12,a_13,
a_20,a_21,a_22,a_23,
a_30,a_31,a_32,a_33)
{}
mat4f(const mat4<float>& a_from):mat4<float>(a_from){}
mat4f& operator=(const mat4<float>& a_from){
mat4<float>::operator=(a_from);
mat4f(const parent& a_from):parent(a_from){}
mat4f& operator=(const parent& a_from){
parent::operator=(a_from);
return *this;
}
public:
void set_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::set_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
void mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::mul_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
void left_mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,::sinf,::cosf);
}
public: //backward compatibility
void mul_2f(float& a_x,float& a_y) const {
mat4<float>::mul_2(a_x,a_y);
}
void mul_3f(float& a_x,float& a_y,float& a_z) const {
mat4<float>::mul_3(a_x,a_y,a_z);
}
void mul_dir_3f(float& a_x,float& a_y,float& a_z) const {
mat4<float>::mul_dir_3(a_x,a_y,a_z);
}
void mul_4f(float& a_x,float& a_y,float& a_z,float& a_w) const {
mat4<float>::mul_4(a_x,a_y,a_z,a_w);
void mul_2f(float& a_x,float& a_y) const {parent::mul_2(a_x,a_y);}
void mul_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_3(a_x,a_y,a_z);}
void mul_dir_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_dir_3(a_x,a_y,a_z);}
void mul_trans_3f(float& a_x,float& a_y,float& a_z) const {parent::mul_trans_3(a_x,a_y,a_z);}
void mul_4f(float& a_x,float& a_y,float& a_z,float& a_w) const {parent::mul_4(a_x,a_y,a_z,a_w);}
void mul_dir_3d(double& a_x,double& a_y,double& a_z) const { //used in sg::healpix
float x = float(a_x);
float y = float(a_y);
float z = float(a_z);
parent::mul_dir_3(x,y,z);
a_x = x;a_y = y;a_z = z;
}
public: //operators
};
@@ -8,21 +8,23 @@
namespace tools {
template <class T>
template <class VEC3>
class plane {
protected:
typedef typename VEC3::elem_t T;
public:
plane(){}
plane(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2) {
plane(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2) {
// Construct a plane given 3 points.
// Orientation is computed by taking (p1 - p0) x (p2 - p0) and
// pointing the normal in that direction.
vec3<T> P = a_p1;
VEC3 P = a_p1;
P.subtract(a_p0);
vec3<T> P2 = a_p2;
VEC3 P2 = a_p2;
P2.subtract(a_p0);
m_normal = P.cross(P2);
P.cross(P2,m_normal);
if(!m_normal.normalize()) {} //throw
m_distance =
m_normal.v0() * a_p0.v0() +
@@ -30,11 +32,11 @@ public:
m_normal.v2() * a_p0.v2();
}
plane(const vec3<T>& a_normal,const T& a_distance){
plane(const VEC3& a_normal,const T& a_distance){
set(a_normal,a_distance);
}
plane(const vec3<T>& a_normal,const vec3<T>& a_point){
plane(const VEC3& a_normal,const VEC3& a_point){
set(a_normal,a_point);
}
@@ -58,11 +60,11 @@ public:
m_distance += a_distance;
}
bool intersect(const line<T>& a_line,vec3<T>& a_intersection) const {
bool intersect(const line<VEC3>& a_line,VEC3& a_intersection) const {
// Intersect line and plane, returning true if there is an intersection
// false if line is parallel to plane
const vec3<T>& pos = a_line.position();
const vec3<T>& dir = a_line.direction();
const VEC3& pos = a_line.position();
const VEC3& dir = a_line.direction();
T d = m_normal.dot(dir);
if(d==T()) return false;
T t = (m_distance - m_normal.dot(pos))/d;
@@ -73,33 +75,33 @@ public:
return true;
}
bool is_in_half_space(const vec3<T>& a_point) const {
bool is_in_half_space(const VEC3& a_point) const {
// Returns true if the given point is within the half-space
// defined by the plane
//vec pos = m_normal * m_distance;
vec3<T> pos = m_normal;
VEC3 pos = m_normal;
pos.multiply(-m_distance);
pos.add(a_point);
return (m_normal.dot(pos) >= T() ? true : false);
}
const vec3<T>& normal() const {return m_normal;}
const VEC3& normal() const {return m_normal;}
T distance_from_origin() const {return m_distance;}
T distance(const vec3<T>& a_point) const {
T distance(const VEC3& a_point) const {
// Return the distance from point to plane. Positive distance means
// the point is in the plane's half space.
return a_point.dot(m_normal) - m_distance;
}
void set(const vec3<T>& a_normal,const T& a_distance){
void set(const VEC3& a_normal,const T& a_distance){
m_normal = a_normal;
if(!m_normal.normalize()) {} //throw
m_distance = a_distance;
}
void set(const vec3<T>& a_normal,const vec3<T>& a_point){
void set(const VEC3& a_normal,const VEC3& a_point){
// Construct a plane given normal and a point to pass through
// Orientation is given by the normal vector n.
m_normal = a_normal;
@@ -111,12 +113,12 @@ public:
}
public: //iv2sg
const vec3<T>& getNormal() const {return m_normal;}
const VEC3& getNormal() const {return m_normal;}
protected:
// equation of the plane is :
// norm[0]*x+norm[1]*y+norm[2]*z = dist
vec3<T> m_normal; //normalized.
VEC3 m_normal; //normalized.
T m_distance;
};
+35 -35
View File
@@ -6,23 +6,21 @@
// rotation done with quaternion.
#include "vec4"
#include "vec3"
#include "mat4"
namespace tools {
template <class T>
template <class VEC3,class VEC4>
class qrot {
protected:
//typedef typename VEC3::elem_t T3;
typedef typename VEC4::elem_t T; //we assume = T3
public:
qrot()
:m_quat(0,0,0,1) //zero rotation around the positive Z axis.
{}
qrot(const vec3<T>& a_axis,T a_radians){
if(!set_value(a_axis,a_radians)) {} //FIXME : throw
qrot(const VEC3& a_axis,T a_radians,T(*a_sin)(T),T(*a_cos)(T)){
if(!set_value(a_axis,a_radians,a_sin,a_cos)) {} //FIXME : throw
}
qrot(const vec3<T>& a_from,const vec3<T>& a_to){set_value(a_from,a_to);}
qrot(const VEC3& a_from,const VEC3& a_to,T(*a_sqrt)(T),T(*a_fabs)(T)){set_value(a_from,a_to,a_sqrt,a_fabs);}
virtual ~qrot(){}
public:
qrot(const qrot& a_from)
@@ -108,14 +106,14 @@ public:
}
bool set_value(const vec3<T>& a_axis,T a_radians) {
bool set_value(const VEC3& a_axis,T a_radians,T(*a_sin)(T),T(*a_cos)(T)) {
// Reset rotation with the given axis-of-rotation and rotation angle.
// Make sure axis is not the null vector when calling this method.
// From <http://www.automation.hut.fi/~jaro/thesis/hyper/node9.html>.
if(a_axis.length()==T()) return false;
m_quat.v3(::cos(a_radians/2));
T sineval = ::sin(a_radians/2);
vec3<T> a = a_axis;
m_quat.v3(a_cos(a_radians/2));
T sineval = a_sin(a_radians/2);
VEC3 a = a_axis;
a.normalize();
m_quat.v0(a.v0() * sineval);
m_quat.v1(a.v1() * sineval);
@@ -123,15 +121,15 @@ public:
return true;
}
bool set_value(const vec3<T>& a_from,const vec3<T>& a_to) {
bool set_value(const VEC3& a_from,const VEC3& a_to,T(*a_sqrt)(T),T(*a_fabs)(T)) {
// code taken from coin3d/SbRotation.
vec3<T> from(a_from);
VEC3 from(a_from);
if(from.normalize()==T()) return false;
vec3<T> to(a_to);
VEC3 to(a_to);
if(to.normalize()==T()) return false;
T dot = from.dot(to);
vec3<T> crossvec = from.cross(to);
VEC3 crossvec;from.cross(to,crossvec);
T crosslen = crossvec.normalize();
if(crosslen == T()) { // Parallel vectors
@@ -142,10 +140,10 @@ public:
// Ok, so they are parallel and pointing in the opposite direction
// of each other.
// Try crossing with x axis.
vec3<T> t = from.cross(vec3<T>(1,0,0));
VEC3 t;from.cross(VEC3(1,0,0),t);
// If not ok, cross with y axis.
if(t.normalize() == T()) {
t = from.cross(vec3<T>(0,1,0));
from.cross(VEC3(0,1,0),t);
t.normalize();
}
m_quat.set_value(t[0],t[1],t[2],0);
@@ -153,17 +151,17 @@ public:
} else { // Vectors are not parallel
// The fabs() wrapping is to avoid problems when `dot' "overflows"
// a tiny wee bit, which can lead to sqrt() returning NaN.
crossvec *= (T)::sqrt(half() * ::fabs(one() - dot));
crossvec *= (T)a_sqrt(half() * a_fabs(one() - dot));
// The fabs() wrapping is to avoid problems when `dot' "underflows"
// a tiny wee bit, which can lead to sqrt() returning NaN.
m_quat.set_value(crossvec[0], crossvec[1], crossvec[2],(T)::sqrt(half()*::fabs(one()+dot)));
m_quat.set_value(crossvec[0], crossvec[1], crossvec[2],(T)a_sqrt(half()*a_fabs(one()+dot)));
}
return true;
}
bool value(vec3<T>& a_axis,T& a_radians) const {
bool value(VEC3& a_axis,T& a_radians,T(*a_sin)(T),T(*a_acos)(T)) const { //WARNING a_acos and NOT a_cos
//WARNING : can fail.
if( (m_quat.v3()<minus_one()) || (m_quat.v3()> one()) ){ ////???
a_axis.set_value(0,0,1);
@@ -171,8 +169,8 @@ public:
return false;
}
a_radians = ::acos(m_quat.v3()) * 2;
T sineval = ::sin(a_radians/2);
a_radians = a_acos(m_quat.v3()) * 2;
T sineval = a_sin(a_radians/2);
if(sineval==T()) { //???
a_axis.set_value(0,0,1);
@@ -185,14 +183,15 @@ public:
return true;
}
void set_value(const mat4<T>& a_m) {
template <class MAT4>
void set_value(const MAT4& a_m,T(*a_sqrt)(T)) {
//WARNING : not tested.
//Set the rotation from the components of the given matrix.
T scalerow = a_m.v00() + a_m.v11() + a_m.v22();
if (scalerow > T()) {
T _s = ::sqrt(scalerow + a_m.v33());
T _s = a_sqrt(scalerow + a_m.v33());
m_quat.v3(_s * half());
_s = half() / _s;
@@ -207,7 +206,7 @@ public:
unsigned int j = (i+1)%3;
unsigned int k = (j+1)%3;
T _s = ::sqrt((a_m.value(i,i) - (a_m.value(j,j) + a_m.value(k,k))) + a_m.v33());
T _s = a_sqrt((a_m.value(i,i) - (a_m.value(j,j) + a_m.value(k,k))) + a_m.v33());
m_quat.set_value(i,_s * half());
_s = half() / _s;
@@ -218,11 +217,12 @@ public:
}
if (a_m.v33()!=one()) {
m_quat.multiply(one()/::sqrt(a_m.v33()));
m_quat.multiply(one()/a_sqrt(a_m.v33()));
}
}
void value(mat4<T>& a_m) const {
template <class MAT4>
void value(MAT4& a_m) const {
//Return this rotation in the form of a matrix.
const T x = m_quat.v0();
const T y = m_quat.v1();
@@ -255,7 +255,7 @@ public:
a_m.v33(w*w + x*x + y*y + z*z);
}
void mul_vec(const vec3<T>& a_in,vec3<T>& a_out) const {
void mul_vec(const VEC3& a_in,VEC3& a_out) const {
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
@@ -277,7 +277,7 @@ public:
a_out.set_value(v0,v1,v2);
}
void mul_vec(vec3<T>& a_v) const {
void mul_vec(VEC3& a_v) const {
const T x = m_quat.v0();
const T y = m_quat.v1();
const T z = m_quat.v2();
@@ -324,8 +324,8 @@ public:
}
public: //for io::streamer
const vec4<T>& quat() const {return m_quat;}
vec4<T>& quat() {return m_quat;}
const VEC4& quat() const {return m_quat;}
VEC4& quat() {return m_quat;}
protected:
static T one() {return T(1);}
@@ -333,7 +333,7 @@ protected:
static T half() {return T(0.5);}
protected:
vec4<T> m_quat;
VEC4 m_quat;
public:
//NOTE : don't handle a static object because of mem balance.
@@ -342,7 +342,7 @@ public:
// return s_v;
//}
private:static void check_instantiation() {qrot<float> v;}
//private:static void check_instantiation() {qrot<float> v;}
};
}
+20 -21
View File
@@ -8,35 +8,29 @@
#include "qrot"
#include "vec3f"
#include "vec4f"
#include "mat4f"
namespace tools {
class rotf : public qrot<float> {
rotf(float a_q0,float a_q1,float a_q2,float a_q3)
:qrot<float>(a_q0,a_q1,a_q2,a_q3)
{}
class rotf : public qrot<vec3f,vec4f> {
typedef qrot<vec3f,vec4f> parent;
private:
rotf(float a_q0,float a_q1,float a_q2,float a_q3):parent(a_q0,a_q1,a_q2,a_q3) {}
public:
rotf()
:qrot<float>() //zero rotation around the positive Z axis.
{}
rotf(const vec3f& a_axis,float a_radians)
:qrot<float>(a_axis,a_radians)
{}
rotf(const vec3f& a_from,const vec3f& a_to)
:qrot<float>(a_from,a_to)
{}
rotf():parent() {} //zero rotation around the positive Z axis.
rotf(const vec3f& a_axis,float a_radians):parent(a_axis,a_radians,::sinf,::cosf) {}
rotf(const vec3f& a_from,const vec3f& a_to):parent(a_from,a_to,::sqrtf,::fabsf) {}
virtual ~rotf(){}
public:
rotf(const rotf& a_from)
:qrot<float>(a_from)
{}
rotf(const rotf& a_from):parent(a_from) {}
rotf& operator=(const rotf& a_from){
qrot<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public:
rotf& operator*=(const rotf& a_q) {
qrot<float>::operator*=(a_q);
parent::operator*=(a_q);
return *this;
}
rotf operator*(const rotf& a_r) const {
@@ -46,11 +40,16 @@ public:
}
public:
bool set_value(const vec3f& a_from,const vec3f& a_to){
return qrot<float>::set_value(a_from,a_to);
return parent::set_value(a_from,a_to,::sqrtf,::fabsf);
}
bool set_value(const vec3f& a_from,float a_a){
return qrot<float>::set_value(a_from,a_a);
return parent::set_value(a_from,a_a,::sinf,::cosf);
}
bool value(vec3f& a_from,float a_a) const {
return parent::value(a_from,a_a,::sinf,::acosf); //WARNING acos and not cos
}
void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
void value(mat4f& a_m) const {parent::value(a_m);}
//NOTE : don't handle a static object because of mem balance.
//static const rotf& identity() {
@@ -67,7 +66,7 @@ namespace tools {
inline bool tos(const rotf& a_v,std::string& a_s) {
vec3f axis;
float angle;
float angle = 0;
if(!a_v.value(axis,angle)) {a_s.clear();return false;}
std::ostringstream strm;
strm << axis[0] << " "
+15 -12
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec2
#define tools_vec2
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -21,6 +21,7 @@ class vec2 {
}
#endif
public:
typedef T elem_t;
unsigned int dimension() const {return 2;}
public:
vec2(){
@@ -63,14 +64,16 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
T x() const {return m_data[0];}
T y() const {return m_data[1];}
const T& x() const {return m_data[0];}
const T& y() const {return m_data[1];}
T& x() {return m_data[0];}
T& y() {return m_data[1];}
void set_value(const T& a0,const T& a1) {
m_data[0] = a0;
@@ -91,12 +94,12 @@ public:
// return true;
//}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -145,11 +148,11 @@ public:
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -6,6 +6,7 @@
#include "vec2"
#include "../S_STRING"
#include <cmath>
namespace tools {
@@ -53,6 +54,22 @@ public: //operators
vec2f operator-() const {
return vec2f(-m_data[0],-m_data[1]);
}
public:
#define TOOLS_VEC2F_MORE_PREC
#ifdef TOOLS_VEC2F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
public: //iv2sg
bool equals(const vec2f& a_v,const float a_epsil) const {
//if(a_epsil<0.0f))
+102 -41
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec3
#define tools_vec3
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -71,17 +71,21 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
T v2() const { return m_data[2];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
const T& v2() const { return m_data[2];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
void v2(const T& a_value) { m_data[2] = a_value;}
T x() const {return m_data[0];}
T y() const {return m_data[1];}
T z() const {return m_data[2];}
const T& x() const {return m_data[0];}
const T& y() const {return m_data[1];}
const T& z() const {return m_data[2];}
T& x() {return m_data[0];}
T& y() {return m_data[1];}
T& z() {return m_data[2];}
void set_value(const T& a0,const T& a1,const T& a2) {
m_data[0] = a0;
@@ -105,14 +109,12 @@ public:
// return true;
//}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]
+m_data[1]*m_data[1]
+m_data[2]*m_data[2]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -124,10 +126,10 @@ public:
m_data[2] * aV.m_data[2]);
}
vec3<T> cross(const vec3<T>& aV) const {
return vec3<T>(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
void cross(const vec3<T>& aV,vec3<T>& a_value) const {
a_value.set_value(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
}
bool equal(const vec3& aV) const {
@@ -137,6 +139,23 @@ public:
return true;
}
template <class PREC>
bool equal_prec(const vec3& a_v,PREC a_prec,PREC(*a_fabs)(const T&)) const {
if(&a_v==this) return true;
for(unsigned int index=0;index<3;index++) {
T diff = m_data[index]-a_v.m_data[index];
if(a_fabs(diff)>=a_prec) return false;
}
return true;
}
vec3<T> _cross(const vec3<T>& aV) const {
//not effective.
return vec3<T>(m_data[1] * aV.m_data[2] - m_data[2] * aV.m_data[1],
m_data[2] * aV.m_data[0] - m_data[0] * aV.m_data[2],
m_data[0] * aV.m_data[1] - m_data[1] * aV.m_data[0]);
}
bool divide(const T& a_T) {
if(a_T==T()) return false;
m_data[0] /= a_T;
@@ -175,6 +194,7 @@ public:
m_data[2] -= a2;
}
/*
bool cos_angle(const vec3& a_v,T& a_cos) const {
//WARNING : if ret false, a_cos is not set.
if(length()==T()) return false;
@@ -183,21 +203,22 @@ public:
return true;
}
bool theta_phi(T& a_theta,T& a_phi) const {
*/
bool theta_phi(T& a_theta,T& a_phi,T(*a_sqrt)(T),T(*a_atan2)(T,T)) const {
//WARNING : if ret false, a_theta, a_phi are not set.
if(length()==T()) return false;
a_phi = (T)::atan2(m_data[1],m_data[0]);
T xy = (T)::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
a_theta = (T)::atan2(xy,m_data[2]);
if(length(a_sqrt)==T()) return false;
a_phi = a_atan2(m_data[1],m_data[0]);
T xy = a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]);
a_theta = a_atan2(xy,m_data[2]);
return true;
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -241,6 +262,7 @@ public: //for inlib/sg/sf_vec
typedef unsigned int size_type;
size_type size() const {return 3;}
const T* data() const {return m_data;}
size_type data_size() const {return 3;} //for eqT.
public: //for iv2sg
const T* getValue() const {return m_data;}
void setValue(const T& a0,const T& a1,const T& a2) {
@@ -296,30 +318,69 @@ template <class T>
inline const T* get_data(const vec3<T>& a_v) {return a_v.data();}
template <class T>
inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm) {
a_nm = (a_p1-a_p0).cross(a_p2-a_p1);
a_nm.normalize();
inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm,
vec3<T>& a_tmp_1,vec3<T>& a_tmp_2,T(*a_sqrt)(T)) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_nm);
a_nm.normalize(a_sqrt);
}
template <class T>
inline vec3<T> direction(const vec3<T>& a_p0,
const vec3<T>& a_p1,
const vec3<T>& a_p2) {
/*
template <class VEC3>
inline void normal(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_nm) {
VEC3 tmp1,tmp2;
normal(a_p0,a_p1,a_p2,a_nm,tmp1,tmp2);
}
*/
template <class VEC3>
inline void direction(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_value) {
// Orientation is computed by taking (p1 - p0) x (p2 - p0)
vec3<T> P = a_p1;
VEC3 P = a_p1;
P.subtract(a_p0);
vec3<T> P2 = a_p2;
VEC3 P2 = a_p2;
P2.subtract(a_p0);
return P.cross(P2);
P.cross(P2,a_value);
}
template <class VEC3>
inline void area(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,typename VEC3::elem_t& a_value,
VEC3& a_tmp_1,VEC3& a_tmp_2,VEC3& a_tmp_3) {
// area of the triangle (a_p0,a_p1,a_p2)
typedef typename VEC3::elem_t T;
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_tmp_3);
a_value = a_tmp_3.length()/T(2);
}
template <class VEC3>
inline void area(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,typename VEC3::elem_t& a_value) {
VEC3 tmp1,tmp2,tmp3;
area(a_p0,a_p1,a_p2,a_value,tmp1,tmp2,tmp3);
}
template <class T>
inline vec3<T> direction(const T& a_0_x,const T& a_0_y,const T& a_0_z,
const T& a_1_x,const T& a_1_y,const T& a_1_z,
const T& a_2_x,const T& a_2_y,const T& a_2_z) {
return direction(vec3<T>(a_0_x,a_0_y,a_0_z),
vec3<T>(a_1_x,a_1_y,a_1_z),
vec3<T>(a_2_x,a_2_y,a_2_z));
inline void direction(const T& a_0_x,const T& a_0_y,const T& a_0_z,
const T& a_1_x,const T& a_1_y,const T& a_1_z,
const T& a_2_x,const T& a_2_y,const T& a_2_z,vec3<T>& a_value) {
direction(vec3<T>(a_0_x,a_0_y,a_0_z),
vec3<T>(a_1_x,a_1_y,a_1_z),
vec3<T>(a_2_x,a_2_y,a_2_z),a_value);
}
}
@@ -6,25 +6,27 @@
#include "vec3"
#include "../S_STRING"
#include <cmath>
namespace tools {
class vec3d : public vec3<double> {
typedef vec3<double> parent;
public:
TOOLS_SCLASS(tools::vec3d) //for stype()
public:
vec3d():vec3<double>(){}
vec3d(const double a_vec[3]):vec3<double>(a_vec){}
vec3d(double a0,double a1,double a2):vec3<double>(a0,a1,a2){}
vec3d():parent(){}
vec3d(const double a_vec[3]):parent(a_vec){}
vec3d(double a0,double a1,double a2):parent(a0,a1,a2){}
virtual ~vec3d() {}
public:
vec3d(const vec3d& a_from):vec3<double>(a_from){}
vec3d(const vec3d& a_from):parent(a_from){}
vec3d& operator=(const vec3d& a_from){
vec3<double>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
vec3d(const vec3<double>& a_from):vec3<double>(a_from){}
vec3d(const parent& a_from):parent(a_from){}
public: //operators
vec3d operator*(double a_v) const {
@@ -63,6 +65,9 @@ public: //operators
vec3d operator-() const {
return vec3d(-m_data[0],-m_data[1],-m_data[2]);
}
public:
double length() const {return parent::length(::sqrt);}
double normalize() {return parent::normalize(::sqrt);}
private:static void check_instantiation() {vec3d v(0,0,0);v.set_value(1,1,1);}
};
@@ -6,25 +6,27 @@
#include "vec3"
#include "../S_STRING"
#include <cmath> //sqrt
namespace tools {
class vec3f : public vec3<float> {
typedef vec3<float> parent;
public:
TOOLS_SCLASS(tools::vec3f) //for stype()
public:
vec3f():vec3<float>(){}
vec3f(const float a_vec[3]):vec3<float>(a_vec){}
vec3f(float a0,float a1,float a2):vec3<float>(a0,a1,a2){}
vec3f():parent(){}
vec3f(const float a_vec[3]):parent(a_vec){}
vec3f(float a0,float a1,float a2):parent(a0,a1,a2){}
virtual ~vec3f() {}
public:
vec3f(const vec3f& a_from):vec3<float>(a_from){}
vec3f(const vec3f& a_from):parent(a_from){}
vec3f& operator=(const vec3f& a_from){
vec3<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
vec3f(const vec3<float>& a_from):vec3<float>(a_from){}
vec3f(const parent& a_from):parent(a_from){}
public: //operators
vec3f operator*(float a_v) const {
@@ -63,7 +65,26 @@ public: //operators
vec3f operator-() const {
return vec3f(-m_data[0],-m_data[1],-m_data[2]);
}
public:
#define TOOLS_VEC3F_MORE_PREC
#ifdef TOOLS_VEC3F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
bool theta_phi(float& a_theta,float& a_phi) const {
return parent::theta_phi(a_theta,a_phi,::sqrtf,::atan2f);
}
public: //iv2sg
bool equals(const vec3f& a_v,const float a_epsil) const {
//if(a_epsil<0.0f))
@@ -87,6 +108,30 @@ inline vec3f operator*(float a_f,const vec3f& a_v) {
return res;
}
#define TOOLS_VEC3F_MORE_PREC
#ifdef TOOLS_VEC3F_MORE_PREC
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
a_tmp_1 = a_p1;
a_tmp_1.subtract(a_p0);
a_tmp_2 = a_p2;
a_tmp_2.subtract(a_p1);
a_tmp_1.cross(a_tmp_2,a_nm);
a_nm.normalize();
}
#else
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
normal<float>(a_p0,a_p1,a_p2,a_nm,a_tmp_1,a_tmp_2,::sqrtf);
}
#endif
}
#include <vector>
+14 -15
View File
@@ -4,10 +4,10 @@
#ifndef tools_vec4
#define tools_vec4
#include <cmath> //sqrt
#include <cstddef> //size_t
#ifdef TOOLS_MEM
#include "mem"
#include "../mem"
#endif
namespace tools {
@@ -15,6 +15,7 @@ namespace tools {
template <class T>
class vec4 {
#ifdef TOOLS_MEM
public:
static const std::string& s_class() {
static const std::string s_v("tools::vec4");
return s_v;
@@ -24,6 +25,7 @@ protected:
static T zero() {return T();}
static T minus_one() {return T(-1);}
public:
typedef T elem_t;
unsigned int dimension() const {return 4;}
public:
vec4(){
@@ -78,10 +80,10 @@ public:
return *this;
}
public:
T v0() const { return m_data[0];}
T v1() const { return m_data[1];}
T v2() const { return m_data[2];}
T v3() const { return m_data[3];}
const T& v0() const { return m_data[0];}
const T& v1() const { return m_data[1];}
const T& v2() const { return m_data[2];}
const T& v3() const { return m_data[3];}
void v0(const T& a_value) { m_data[0] = a_value;}
void v1(const T& a_value) { m_data[1] = a_value;}
@@ -117,15 +119,12 @@ public:
return true;
}
T length() const {
return (T)::sqrt(m_data[0]*m_data[0]
+m_data[1]*m_data[1]
+m_data[2]*m_data[2]
+m_data[3]*m_data[3]);
T length(T(*a_sqrt)(T)) const {
return a_sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]);
}
T normalize() {
T norme = length();
T normalize(T(*a_sqrt)(T)) {
T norme = length(a_sqrt);
if(norme==T()) return T();
divide(norme);
return norme;
@@ -219,11 +218,11 @@ public:
}
public: //operators
T& operator[](unsigned int a_index) {
T& operator[](size_t a_index) {
//WARNING : no check on a_index.
return m_data[a_index];
}
const T& operator[](unsigned int a_index) const {
const T& operator[](size_t a_index) const {
//WARNING : no check on a_index.
return m_data[a_index];
}
@@ -6,22 +6,24 @@
#include "vec4"
#include "../S_STRING"
#include <cmath>
namespace tools {
class vec4f : public vec4<float> {
typedef vec4<float> parent;
public:
TOOLS_SCLASS(tools::vec4f) //for stype()
public:
vec4f():vec4<float>() {}
vec4f(const float a_vec[4]):vec4<float>(a_vec) {}
vec4f(const float& a0,const float& a1,const float& a2,const float& a3)
:vec4<float>(a0,a1,a2,a3){}
vec4f():parent() {}
vec4f(const float a_vec[4]):parent(a_vec) {}
vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true)
:parent(a0,a1,a2,a3,a_inc){}
virtual ~vec4f() {}
public:
vec4f(const vec4f& a_from):vec4<float>(a_from){}
vec4f(const vec4f& a_from):parent(a_from){}
vec4f& operator=(const vec4f& a_from){
vec4<float>::operator=(a_from);
parent::operator=(a_from);
return *this;
}
public: //operators
@@ -60,6 +62,22 @@ public: //operators
vec4f operator-() const {
return vec4f(-m_data[0],-m_data[1],-m_data[2],-m_data[3]);
}
public:
#define TOOLS_VEC4F_MORE_PREC
#ifdef TOOLS_VEC4F_MORE_PREC
float length() const {
return float(::sqrt(m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2]+m_data[3]*m_data[3]));
}
float normalize() {
float norme = length();
if(!norme) return 0;
divide(norme);
return norme;
}
#else
float length() const {return parent::length(::sqrtf);}
float normalize() {return parent::normalize(::sqrtf);}
#endif
};
}
@@ -12,7 +12,7 @@ namespace tools {
class long_out : public std::string {
typedef std::string parent;
public:
long_out(const long& a_value) {
long_out(long a_value) {
char s[512];
snpf(s,sizeof(s),"%ld",a_value);
parent::operator+=(s);
+27 -2
View File
@@ -18,8 +18,14 @@ inline double pi() {return 3.1415926535897931160E0;}
inline double two_pi() {return 6.2831853071795862320E0;}
inline double half_pi() {return 1.5707963267948965580E0;}
inline double deg2rad() {return pi()/180.0;}
inline double rad2deg() {return 180.0/pi();}
inline double deg2rad() {
static const double s_v = pi()/180.0;
return s_v;
}
inline double rad2deg() {
static const double s_v = 180.0/pi();
return s_v;
}
// for Lib/ExpFunc.
inline bool in_domain_all(double){return true;}
@@ -34,8 +40,27 @@ inline bool in_domain_acos(double a_x){
return true;
}
/*
inline double angle_modulo(double a_angle) {
int64 div = a_angle/two_pi();
double rest = a_angle - div*two_pi();
if(rest<0) rest += two_pi();
return rest;
}
*/
}
//#include "power"
#include <cmath>
namespace tools {
inline double dconj(const double& a_x) {return a_x;}
inline double dfabs(const double& a_x) {return ::fabs(a_x);} //if passing a_fabs(const T&).
inline double dsqrt(const double& a_x) {return ::sqrt(a_x);}
}
#endif
+31 -12
View File
@@ -4,8 +4,6 @@
#ifndef tools_mathf
#define tools_mathf
#include <cmath>
namespace tools {
//have : static const fpi = (float)3.1415926535897931160E0; ???
@@ -14,6 +12,33 @@ inline float fpi() {return (float)3.1415926535897931160E0;}
inline float ftwo_pi() {return (float)6.2831853071795862320E0;}
inline float fhalf_pi() {return (float)1.5707963267948965580E0;}
//inline float fdeg2rad() {return fpi()/180.0f;} //0.0174f
//inline float frad2deg() {return 180.0f/fpi();}
inline float fdeg2rad() {
static const float s_v = fpi()/180.0f; //0.0174f
return s_v;
}
inline float frad2deg() {
static const float s_v = 180.0f/fpi();
return s_v;
}
inline int fround(float a_x) {
// From CoinGL/src/base/SbViewportRegion.cpp.
if (a_x == (float) (int(a_x))) return int(a_x);
else return (a_x>0.0f) ? int(a_x+0.5f) : -int(0.5f-a_x);
}
inline float fstep(float a_x) {return a_x<0.0f?0.0f:1.0f;}
}
#include <cmath>
namespace tools {
inline float fcos(float x) {return (float)::cos(double(x));}
inline float fsin(float x) {return (float)::sin(double(x));}
inline float facos(float x) {return (float)::acos(double(x));}
@@ -27,19 +52,13 @@ inline float fexp(float x) {return (float)::exp(double(x));}
inline float flog(float x) {return (float)::log(double(x));}
inline float flog10(float x) {return (float)::log10(double(x));}
inline float ffloor(float x) {return (float)::floor(double(x));}
inline float ffabs(float x) {return (float)::fabs(double(x));}
inline float fceil(float x) {return (float)::ceil(double(x));}
inline float fdeg2rad() {return fpi()/180.0f;} //0.0174f
inline float frad2deg() {return 180.0f/fpi();}
inline float fcosh(float x) {return (float)::cosh(double(x));}
inline float fsinh(float x) {return (float)::sinh(double(x));}
inline int fround(float a_x) {
// From CoinGL/src/base/SbViewportRegion.cpp.
if (a_x == (float) (int(a_x))) return int(a_x);
else return (a_x>0.0f) ? int(a_x+0.5f) : -int(0.5f-a_x);
}
inline float ffabs(float x) {return (float)::fabs(double(x));}
inline float fstep(float a_x) {return a_x<0.0f?0.0f:1.0f;}
inline float ffabsc(const float& x) {return (float)::fabs(double(x));}
}
+4 -4
View File
@@ -41,17 +41,17 @@ public:
}
}
static void decrement(const char* a_class){
counter()--;
static void decrement(const char* a_class,unsigned int a_num = 1){
counter() -= a_num;
if(check_by_class()) {
mem_list::iterator it;
for(it=list().begin();it!=list().end();++it) {
if(!::strcmp((*it).first.c_str(),a_class)) {
(*it).second--;
(*it).second -= a_num;
return;
}
}
list().push_back(std::pair<std::string,int>(std::string(a_class),-1));
list().push_back(std::pair<std::string,int>(std::string(a_class),-int(a_num)));
}
}
@@ -13,10 +13,17 @@ extern "C" {
typedef void* MPI_Comm;
typedef void* MPI_Datatype;
#define MPI_UNSIGNED 0
#define MPI_DOUBLE 0
#define MPI_UNSIGNED_CHAR 0
#define MPI_CHAR 0
#define MPI_UNSIGNED 0
#define MPI_DOUBLE 0
#define MPI_UNSIGNED_CHAR 0
#define MPI_CHAR 0
#define MPI_LONG 0
#define MPI_INT 0
#define MPI_UNSIGNED_LONG 0
#define MPI_LONG_LONG 0
#define MPI_UNSIGNED_LONG_LONG 0
#define MPI_ANY_SOURCE 0
#define MPI_SUCCESS 1
@@ -32,7 +39,11 @@ inline int MPI_Unpack(const void*,int,int*,void*,int,MPI_Datatype,MPI_Comm){retu
/// to pass h2mpi, hs2mpi /////////////////////////////////////
///////////////////////////////////////////////////////////////
typedef int MPI_Status;
struct _MPI_Status {
int MPI_SOURCE;
int MPI_TAG;
};
typedef _MPI_Status MPI_Status;
inline int MPI_Probe(int,int,MPI_Comm,MPI_Status*){return 0;}
inline int MPI_Get_count(const MPI_Status*,MPI_Datatype,int*){return 0;}
@@ -264,5 +264,3 @@ protected:
}}
#endif
//exlib_build_use inlib mpi
@@ -0,0 +1,198 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_mpi_pntuple
#define tools_mpi_pntuple
// pntuple = for parallel ntupling.
#include <tools/wroot/base_pntuple>
#include <tools/S_STRING>
#include <tools/impi>
namespace tools {
namespace mpi {
class pntuple : public tools::wroot::base_pntuple {
typedef tools::wroot::base_pntuple parent;
public:
static tools::uint32 protocol_basket() {return 1;}
static tools::uint32 protocol_end_fill() {return 2;}
public:
pntuple(std::ostream& a_out,
bool a_byte_swap,tools::uint32 a_compression,
const std::string& a_name,const std::string& a_title,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_name,a_title,a_verbose)
{}
pntuple(std::ostream& a_out,bool a_byte_swap,tools::uint32 a_compression,tools::wroot::seek a_seek_directory,
const std::vector<tools::uint32>& a_basket_sizes,const tools::ntuple_booking& a_bkg,bool a_verbose)
:parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_basket_sizes,a_bkg,a_verbose)
{}
virtual ~pntuple() {}
protected:
pntuple(const pntuple& a_from):parent(a_from){}
pntuple& operator=(const pntuple& a_from){parent::operator=(a_from);return *this;}
protected:
class basket_add : public virtual tools::wroot::branch::iadd_basket {
typedef tools::wroot::branch::iadd_basket parent;
public:
virtual bool add_basket(tools::wroot::basket& a_basket) {
m_mpi.pack_reset();
if(!m_mpi.pack(protocol_basket())) return false;
if(!m_mpi.pack(m_icol)) return false;
if(!m_mpi.spack(a_basket.object_name())) return false;
if(!m_mpi.spack(a_basket.object_title())) return false;
if(!m_mpi.pack(a_basket.last())) return false;
if(!m_mpi.pack(a_basket.nev_buf_size())) return false;
if(!m_mpi.pack(a_basket.nev())) return false;
if(a_basket.entry_offset()) {
if(!m_mpi.bpack(true)) return false;
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.entry_offset())) return false;
} else {
if(!m_mpi.bpack(false)) return false;
}
if(a_basket.displacement()) {
if(!m_mpi.bpack(true)) return false;
if(!m_mpi.pack(a_basket.nev_buf_size(),a_basket.displacement())) return false;
} else {
if(!m_mpi.bpack(false)) return false;
}
if(!m_mpi.pack(a_basket.datbuf().length(),a_basket.datbuf().buf())) return false;
if(!m_mpi.send_buffer(m_dest,m_tag)) return false;
return true;
}
public:
basket_add(file& a_file,tools::impi& a_mpi,int a_dest,int a_tag,tools::uint32 a_icol)
:m_file(a_file),m_mpi(a_mpi),m_dest(a_dest),m_tag(a_tag),m_icol(a_icol)
{}
protected:
basket_add(const basket_add& a_from):parent()
,m_file(a_from.m_file),m_mpi(a_from.m_mpi),m_dest(a_from.m_dest),m_tag(a_from.m_tag),m_icol(a_from.m_icol)
{}
basket_add& operator=(const basket_add& a_from){
m_file = a_from.m_file;
m_dest = a_from.m_dest;
m_tag = a_from.m_tag;
m_icol = a_from.m_icol;
return *this;
}
protected:
file m_file;
tools::impi& m_mpi;
int m_dest;
int m_tag;
tools::uint32 m_icol;
};
public:
bool add_row(tools::impi& a_mpi,int a_dest,int a_tag) {
if(m_cols.empty()) return false;
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->add();
tools::uint32 icol = 0;
tools_vforit(tools::wroot::icol*,m_cols,it) {
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
if(!(*it)->get_branch()->pfill(_badd)) return false;
}
tools_vforit(tools::wroot::icol*,m_cols,it) (*it)->set_def();
return true;
}
protected:
void end_leaves(std::vector<tools::uint32>& a_lengths,std::vector<int>& a_mxs) const {
a_lengths.clear();
a_mxs.clear();
tools_vforcit(tools::wroot::icol*,m_cols,it) {
tools::wroot::base_leaf* _leaf = (*it)->get_leaf();
tools::wroot::leaf_string* _leafs = _leaf?tools::id_cast<tools::wroot::base_leaf,tools::wroot::leaf_string>(*_leaf):0;
if(_leafs) {
a_lengths.push_back(_leafs->length());
a_mxs.push_back(_leafs->get_max());
}
}
}
public:
bool end_fill(tools::impi& a_mpi,int a_dest,int a_tag) {
tools::uint32 icol = 0;
tools_vforit(tools::wroot::icol*,m_cols,it) {
basket_add _badd(m_file,a_mpi,a_dest,a_tag,icol);icol++;
if(!(*it)->get_branch()->end_pfill(_badd)) return false;
}
std::vector<tools::uint32> lengths;
std::vector<int> mxs;
end_leaves(lengths,mxs);
a_mpi.pack_reset();
if(!a_mpi.pack(protocol_end_fill())) return false;
if(!a_mpi.vpack(lengths)) return false;
if(!a_mpi.vpack(mxs)) return false;
if(!a_mpi.send_buffer(a_dest,a_tag)) return false;
return true;
}
protected:
};
inline tools::wroot::basket* get_basket(std::ostream& a_out,tools::impi& a_mpi,
bool a_byte_swap,tools::wroot::seek a_seek_directory,
tools::uint32 a_basket_size) {
std::string oname;
if(!a_mpi.sunpack(oname)) return 0;
std::string otitle;
if(!a_mpi.sunpack(otitle)) return 0;
tools::uint32 last,nev_buf_size,nev;
if(!a_mpi.unpack(last)) return 0;
if(!a_mpi.unpack(nev_buf_size)) return 0;
if(!a_mpi.unpack(nev)) return 0;
int* entry_offset = 0;
{bool not_null;
if(!a_mpi.bunpack(not_null)) return 0;
if(not_null) {
tools::uint32 n;
if(!a_mpi.unpack(n,entry_offset)) return 0;
}}
int* displacement = 0;
{bool not_null;
if(!a_mpi.bunpack(not_null)) return 0;
if(not_null) {
tools::uint32 n;
if(!a_mpi.unpack(n,displacement)) return 0;
}}
tools::uint32 _size;
char* _buffer;
if(!a_mpi.unpack(_size,_buffer)) {a_out << "unpack(buffer) failed."<< std::endl;return 0;}
// wbasket fields set at file writing :
//m_buf_size,m_buffer,m_nbytes,m_object_size,m_date,m_cycle,m_seek_key
//::printf("debug : col = %d, %s, %s, %lu\n",
// icol,rbasket.object_class().c_str(),rbasket.object_name().c_str(),rbasket.seek_key());
tools::wroot::basket* basket = new tools::wroot::basket(a_out,a_byte_swap,a_seek_directory,
oname,otitle,"TBasket",a_basket_size,
false/*verbose*/);
basket->datbuf().write_fast_array(_buffer,_size);
basket->set_nev(last,nev_buf_size,nev,entry_offset,displacement);
delete [] _buffer;
return basket;
}
}}
#endif
@@ -0,0 +1,70 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_mpi_wait_buffer
#define tools_mpi_wait_buffer
#ifdef TOOLS_USE_NATIVE_MPI
#include <mpi.h>
#else
#include "dummy_mpi.h"
#endif
#include <ostream>
namespace tools {
namespace mpi {
inline bool wait_buffer(std::ostream& a_out,int a_rank,int a_src,int a_tag,const MPI_Comm& a_comm,
int& a_buffer_size,char*& a_buffer,int& a_probe_src,bool a_verbose = false) {
a_buffer = 0;
a_buffer_size = 0;
a_probe_src = -1;
MPI_Status status;
if(::MPI_Probe(a_src,a_tag,a_comm,&status)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Probe : failed." << std::endl;
return false;
}
if(::MPI_Get_count(&status,MPI_CHAR,&a_buffer_size)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Get_count : failed." << std::endl;
a_buffer_size = 0;
return false;
}
a_probe_src = status.MPI_SOURCE;
if(!a_buffer_size) {
a_out << "exlb::mpi::wait_buffer : MPI_Get_count returns zero data." << std::endl;
a_probe_src = -1;
return false;
}
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : get_count " << a_buffer_size << std::endl;
a_buffer = new char[a_buffer_size];
if(!a_buffer) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : can't alloc buffer of size " << a_buffer_size << std::endl;
a_buffer_size = 0;
a_probe_src = -1;
return false;
}
if(::MPI_Recv(a_buffer,a_buffer_size,MPI_CHAR,status.MPI_SOURCE,status.MPI_TAG,a_comm,&status)!=MPI_SUCCESS) {
a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : MPI_Recv : failed." << std::endl;
a_buffer_size = 0;
delete [] a_buffer;
a_buffer = 0;
a_probe_src = -1;
return false;
}
if(a_verbose) a_out << "tools::mpi::wait_buffer : rank " << a_rank << " : unpack data ..." << std::endl;
return true;
}
}}
#endif
@@ -72,6 +72,4 @@ protected:
}}
//exlib_build_use inlib mpi
#endif
+162 -16
View File
@@ -12,7 +12,6 @@
#include <tools/impi>
#include <tools/vdata>
#include <tools/typedefs>
#include <tools/realloc>
#include <tools/mnmx>
#include <ostream>
@@ -21,13 +20,34 @@
#include <tools/mem>
#endif
// the below must be in sync with inlib/typedefs
#ifdef _MSC_VER
//typedef __int64 int64;
//typedef unsigned __int64 uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
#define TOOLS_MPI_INT64 MPI_LONG_LONG
#elif defined(_LP64)
// 64 Bit Platforms
//typedef long int64;
//typedef unsigned long uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG
#define TOOLS_MPI_INT64 MPI_LONG
#else
// 32-Bit Platforms
//typedef long long int64;
//typedef unsigned long long uint64;
#define TOOLS_MPI_UINT64 MPI_UNSIGNED_LONG_LONG
#define TOOLS_MPI_INT64 MPI_LONG_LONG
#endif
namespace tools {
namespace mpi {
class wrmpi : public virtual tools::impi {
typedef tools::impi parent;
protected:
public:
typedef unsigned int num_t;
protected:
static const std::string& s_class() {
static const std::string s_v("tools::mpi::wrmpi");
return s_v;
@@ -43,6 +63,26 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool pack(tools::uint64 a_val) {
tools::uint32 sz = tools::uint32(sizeof(tools::uint64));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
if(::MPI_Pack(&a_val,1,TOOLS_MPI_UINT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Pack(uint64) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(tools::int64 a_val) {
tools::uint32 sz = tools::uint32(sizeof(tools::int64));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
if(::MPI_Pack(&a_val,1,TOOLS_MPI_INT64,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Pack(int64) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(double a_val) {
tools::uint32 sz = tools::uint32(sizeof(double));
if(m_pos+sz>m_max) {if(!expand2(m_size+sz)) return false;}
@@ -95,13 +135,27 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool vpack(const std::vector<int>& a_v) {
if(!pack((num_t)a_v.size())) return false;
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(int));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<int*>(tools::vec_data(a_v)),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(std::vector<int>) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool vpack(const std::vector<double>& a_v) {
if(!pack((num_t)a_v.size())) return false;
tools::uint32 sz = (tools::uint32)(a_v.size()*sizeof(double));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),
MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
if(::MPI_Pack(const_cast<double*>(tools::vec_data(a_v)),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(tools::vec_data(a_v),a_v.size(),MPI_DOUBLE,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
@@ -111,6 +165,37 @@ public: //inlib::mpi::impi
m_pos += sz;
return true;
}
virtual bool pack(tools::uint32 a_size,const char* a_buffer) {
if(!pack((num_t)a_size)) return false;
tools::uint32 sz = (tools::uint32)(a_size*sizeof(char));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<char*>(a_buffer),a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(a_buffer,a_size,MPI_CHAR,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(char*) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
virtual bool pack(tools::uint32 a_size,const int* a_buffer) {
if(!pack((num_t)a_size)) return false;
tools::uint32 sz = (tools::uint32)(a_size*sizeof(int));
if((m_pos+sz)>m_max) {if(!expand2(m_size+sz)) return false;}
#ifdef TOOLS_USE_MPI_PACK_NOT_CONST
if(::MPI_Pack(const_cast<int*>(a_buffer),a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#else
if(::MPI_Pack(a_buffer,a_size,MPI_INT,m_buffer,m_size,&m_ipos,m_comm)!=MPI_SUCCESS) {
#endif
m_out << "tools::mpi::wrmpi : MPI_Pack(int*) failed." << std::endl;
return false;
}
m_pos += sz;
return true;
}
public: //inlib::mpi::impi
virtual bool unpack(unsigned int& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_UNSIGNED,m_comm)!=MPI_SUCCESS) {
@@ -120,6 +205,22 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool unpack(tools::uint64& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_UINT64,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(uint64) failed." << std::endl;
a_val = 0;
return false;
}
return true;
}
virtual bool unpack(tools::int64& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,TOOLS_MPI_INT64,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(int64) failed." << std::endl;
a_val = 0;
return false;
}
return true;
}
virtual bool unpack(double& a_val) {
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,&a_val,1,MPI_DOUBLE,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(double) failed." << std::endl;
@@ -150,6 +251,17 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool vunpack(std::vector<int>& a_v) {
num_t num;
if(!unpack(num)) {a_v.clear();return false;}
a_v.resize(num);
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,tools::vec_data(a_v),a_v.size(),MPI_INT,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(std::vector<int>) failed." << std::endl;
a_v.clear();
return false;
}
return true;
}
virtual bool vunpack(std::vector<double>& a_v) {
num_t num;
if(!unpack(num)) {a_v.clear();return false;}
@@ -172,7 +284,52 @@ public: //inlib::mpi::impi
}
return true;
}
virtual bool unpack(tools::uint32& a_size,char*& a_buffer) {
num_t num;
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
a_buffer = new char[num];
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_CHAR,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(char*) failed." << std::endl;
delete [] a_buffer;
a_size = 0;
a_buffer = 0;
return false;
}
a_size = num;
return true;
}
virtual bool unpack(tools::uint32& a_size,int*& a_buffer) {
num_t num;
if(!unpack(num)) {a_size = 0;a_buffer = 0;return false;}
a_buffer = new int[num];
if(::MPI_Unpack(m_buffer,m_size,&m_ipos,a_buffer,num,MPI_INT,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi : MPI_Unpack(int*) failed." << std::endl;
delete [] a_buffer;
a_size = 0;
a_buffer = 0;
return false;
}
a_size = num;
return true;
}
virtual void pack_reset() {
delete [] m_buffer;
m_size = 128;
m_buffer = new char[m_size];
//if(!m_buffer) {}
m_max = m_buffer+m_size;
m_pos = m_buffer;
m_ipos = 0; //IMPORTANT
}
virtual bool send_buffer(int a_dest,int a_tag) { // used in tools/mpi/pntuple.
if(::MPI_Send(m_buffer,m_ipos,MPI_CHAR,a_dest,a_tag,m_comm)!=MPI_SUCCESS) {
m_out << "tools::mpi::wrmpi::send_buffer : MPI_Send() failed for rank destination " << a_dest << "." << std::endl;
return false;
}
return true;
}
public:
wrmpi(std::ostream& a_out,const MPI_Comm& a_comm,tools::uint32 a_size = 128) // we expect a_size!=0
:m_out(a_out)
@@ -236,15 +393,7 @@ public:
#else
const char* buffer() const {return m_buffer;}
#endif
void pack_reset() {
delete [] m_buffer;
m_size = 128;
m_buffer = new char[m_size];
//if(!m_buffer) {}
m_max = m_buffer+m_size;
m_pos = m_buffer;
m_ipos = 0; //IMPORTANT
}
protected:
bool expand2(tools::uint32 a_new_size) {return expand(tools::mx<tools::uint32>(2*m_size,a_new_size));} //CERN-ROOT logic.
@@ -280,6 +429,3 @@ protected:
}}
#endif
//exlib_build_use inlib mpi
@@ -36,6 +36,7 @@ public:
const std::string& name() const {return m_name;}
cid cls_id() const {return m_cid;}
void* user_obj() const {return m_user_obj;}
void set_user_obj(void* a_obj) {m_user_obj = a_obj;}
protected:
std::string m_name;
cid m_cid;
@@ -74,6 +75,7 @@ public:
const std::string& name() const {return m_name;}
const std::string& title() const {return m_title;}
const std::vector<column_booking>& columns() const {return m_columns;}
std::vector<column_booking>& columns() {return m_columns;}
void set_name(const std::string& a_s) {m_name = a_s;}
void set_title(const std::string& a_s) {m_title = a_s;}
+23 -8
View File
@@ -8,18 +8,18 @@
namespace tools {
inline std::string suffix(const std::string& a_string,bool a_back = true) {
inline void suffix(const std::string& a_string,std::string& a_value,bool a_back = true) {
// If a_string = dir0/dir1/dir2/dir3/name.xxx
// return xxx
// a_value = xxx
std::string::size_type pos = a_back?a_string.rfind('.'):a_string.find('.');
if(pos==std::string::npos) return "";
if(pos==std::string::npos) {a_value.clear();return;}
pos++;
return a_string.substr(pos,a_string.size()-pos);
a_value = a_string.substr(pos,a_string.size()-pos);
}
inline std::string nosuffix(const std::string& a_string,bool a_back = true){
inline void nosuffix(const std::string& a_string,std::string& a_value,bool a_back = true){
// If a_string = dir0/dir1/dir2/dir3/name.xxx
// return name
// a_value = name
// Start searching after the last / (or last \ for Windows).
std::string::size_type pos = a_string.rfind('/');
if(pos==std::string::npos) pos = a_string.rfind('\\');
@@ -27,8 +27,11 @@ inline std::string nosuffix(const std::string& a_string,bool a_back = true){
else pos++;
std::string s = a_string.substr(pos,a_string.size()-pos);
std::string::size_type dot_pos = a_back?s.rfind('.'):s.find('.');
if(dot_pos==std::string::npos) return s;
return s.substr(0,dot_pos);
if(dot_pos==std::string::npos) {
a_value = s;
} else {
a_value = s.substr(0,dot_pos);
}
}
inline void base_name(const std::string& a_path,std::string& a_value) {
@@ -57,6 +60,18 @@ inline void base_name(const std::string& a_path,std::string& a_value) {
a_value = a_path.substr(pos,a_path.size()-pos);
}
inline std::string suffix(const std::string& a_string,bool a_back = true) {
std::string value;
suffix(a_string,value,a_back);
return value;
}
inline std::string nosuffix(const std::string& a_string,bool a_back = true){
std::string value;
nosuffix(a_string,value,a_back);
return value;
}
inline std::string base_name(const std::string& a_path) { //deprecated.
std::string value;
base_name(a_path,value);
@@ -85,6 +85,125 @@ inline unsigned int tex_mem_limit() {
}}
///////////////////////////////////////////////////////////////////
/// backcomp : for OnX/source/Core/atat.cxx : /////////////////////
///////////////////////////////////////////////////////////////////
//NOTE : we avoid to have std includes here to be sure
// that in the below ifdef things come only from the compiler.
namespace tools {
inline const char* os() {
#if TARGET_OS_IPHONE
static const char s_s[] = "iOS";
#elif defined(ANDROID)
static const char s_s[] = "Android";
#elif defined(_WIN32)
static const char s_s[] = "Windows_NT";
#elif __APPLE__
static const char s_s[] = "Darwin";
#elif defined(__linux)
static const char s_s[] = "Linux";
#elif defined(__alpha)
static const char s_s[] = "OSF1";
#elif defined(__CYGWIN__)
static const char s_s[] = "CYGWIN";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
inline const char* processor() {
#if defined(__GNUC__)
#if defined(__ppc__)
static const char s_s[] = "ppc";
#elif defined(__ppc64__)
static const char s_s[] = "ppc64";
#elif defined(__i386__)
static const char s_s[] = "i386";
#elif defined(__x86_64__)
static const char s_s[] = "x86_64";
#elif defined(__ia64__)
static const char s_s[] = "ia64";
#else
static const char s_s[] = "unknown";
#endif
#elif defined(_MSC_VER)
#if defined(_M_IX86)
static const char s_s[] = "ix86";
#elif defined(_M_X64)
static const char s_s[] = "x64";
#else
static const char s_s[] = "unknown";
#endif
#elif defined(__alpha)
static const char s_s[] = "alpha";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
inline const char* compiler_name() {
#if defined(__clang__)
static const char s_s[] = "clang";
#elif defined(__GNUC__)
static const char s_s[] = "gcc";
#elif defined(_MSC_VER)
static const char s_s[] = "cl";
#elif defined(__alpha)
static const char s_s[] = "cxx";
#else
static const char s_s[] = "unknown";
#endif
return s_s;
}
}
#include "tosu" //does not bring any std include.
namespace tools {
inline char* compiler() {
static char s_s[128];
char* pos = s_s;
unsigned int l;
toss(compiler_name(),pos,l);pos += l;
#if defined(__clang__)
*pos++ = '_';
tosu<unsigned int>(__clang_major__,pos,l);pos += l;
tosu<unsigned int>(__clang_minor__,pos,l);pos += l;
tosu<unsigned int>(__clang_patchlevel__,pos,l);pos += l;
#elif defined(__GNUC__)
*pos++ = '_';
tosu<unsigned int>(__GNUC__,pos,l);pos += l;
tosu<unsigned int>(__GNUC_MINOR__,pos,l);pos += l;
tosu<unsigned int>(__GNUC_PATCHLEVEL__,pos,l);pos += l;
#elif defined(_MSC_VER)
*pos++ = '_';
tosu<unsigned int>(_MSC_VER,pos,l);pos += l;
//_mfc_
//tosu<unsigned int>(_MFC_VER,pos,l);pos += l;
#elif defined(__alpha)
#else
#endif
return s_s;
}
}
#endif
+59 -21
View File
@@ -4,14 +4,13 @@
#ifndef tools_randT
#define tools_randT
#include "cmathT"
#include "mathd"
namespace tools {
template <class FLAT,class REAL>
class rgauss {
typedef REAL(*math_func)(REAL); //for rootcint.
//public:
// typedef REAL value_t;
public:
rgauss(FLAT& a_flat,REAL a_mean = 0,REAL a_std_dev = 1)
:m_flat(a_flat),m_mean(a_mean),m_std_dev(a_std_dev){}
@@ -24,19 +23,18 @@ public:
return *this;
}
public:
REAL shoot() {
// Shoot random numbers according a
// rgaussian distribution of mean 0 and sigma 1.
REAL shoot(math_func a_sqrt,math_func a_log) const {
REAL v1,v2,r,fac;
do {
v1 = REAL(2) * m_flat.shoot() - REAL(1);
v2 = REAL(2) * m_flat.shoot() - REAL(1);
r = v1*v1 + v2*v2;
} while (r>REAL(1));
fac = _sqrt(-REAL(2)*_log(r)/r);
fac = a_sqrt(-REAL(2)*a_log(r)/r);
return (v2 * fac) * m_std_dev + m_mean;
}
FLAT& flat() {return m_flat;}
void set_seed(unsigned int a_seed) {m_flat.set_seed(a_seed);}
protected:
FLAT& m_flat;
REAL m_mean;
@@ -46,23 +44,19 @@ protected:
template <class FLAT,class REAL>
class rbw {
public:
rbw(FLAT& a_flat,REAL a_mean = 0,REAL a_gamma = 1)
:m_flat(a_flat),m_mean(a_mean),m_gamma(a_gamma){
_half_pi(m_half_pi);
}
rbw(FLAT& a_flat,REAL a_mean = 0,REAL a_gamma = 1):m_flat(a_flat),m_mean(a_mean),m_gamma(a_gamma){}
virtual ~rbw(){}
public:
rbw(const rbw& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean),m_gamma(a_from.m_gamma),m_half_pi(a_from.m_half_pi){}
rbw(const rbw& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean),m_gamma(a_from.m_gamma){}
rbw& operator=(const rbw& a_from) {
m_mean = a_from.m_mean;
m_gamma = a_from.m_gamma;
m_half_pi = a_from.m_half_pi;
return *this;
}
public:
REAL shoot() const {
REAL shoot(const REAL& a_half_pi,REAL(*a_tan)(REAL)) const {
REAL rval = REAL(2) * m_flat.shoot() - REAL(1);
REAL displ = (REAL(1)/REAL(2)) * m_gamma * _tan(rval * m_half_pi);
REAL displ = (REAL(1)/REAL(2)) * m_gamma * a_tan(rval * a_half_pi);
return m_mean + displ;
}
FLAT& flat() {return m_flat;}
@@ -70,11 +64,11 @@ protected:
FLAT& m_flat;
REAL m_mean;
REAL m_gamma;
REAL m_half_pi;
};
template <class FLAT,class REAL>
class rexp {
typedef REAL(*math_func)(REAL); //for rootcint.
public:
rexp(FLAT& a_flat,REAL a_rate = 1):m_flat(a_flat),m_rate(a_rate){}
virtual ~rexp(){}
@@ -82,12 +76,12 @@ public:
rexp(const rexp& a_from):m_flat(a_from.m_flat),m_rate(a_from.m_rate){}
rexp& operator=(const rexp& a_from) {m_rate = a_from.m_rate;return *this;}
public:
REAL shoot() const {
REAL shoot(math_func a_log) const {
REAL v;
do {
v = m_flat.shoot();
} while(v<=REAL(0));
return -_log(v)/m_rate;
return -a_log(v)/m_rate;
}
FLAT& flat() {return m_flat;}
protected:
@@ -130,7 +124,7 @@ public:
rdir3(const rdir3& a_from):m_flat(a_from.m_flat){}
rdir3& operator=(const rdir3&) {return *this;}
public:
void shoot(REAL& a_x,REAL& a_y,REAL& a_z) const {
void shoot(REAL& a_x,REAL& a_y,REAL& a_z,REAL(*a_sqrt)(REAL)) const {
// from gsl_ran_dir_3d.
REAL s;
do {
@@ -140,7 +134,7 @@ public:
}
while (s > REAL(1));
a_z = REAL(2) * s - REAL(1);
REAL a = REAL(2) * _sqrt(REAL(1) - s);
REAL a = REAL(2) * a_sqrt(REAL(1) - s);
a_x *= a;
a_y *= a;
}
@@ -149,6 +143,50 @@ protected:
FLAT& m_flat;
};
// from Geant4/G4Poisson.hh :
// NOTE : not used yet.
template <class FLAT,class REAL,class UINT>
class rpoiss {
public:
rpoiss(FLAT& a_flat,REAL a_mean = 1):m_flat(a_flat),m_mean(a_mean){}
virtual ~rpoiss(){}
public:
rpoiss(const rpoiss& a_from):m_flat(a_from.m_flat),m_mean(a_from.m_mean){}
rpoiss& operator=(const rpoiss& a_from) {
m_mean = a_from.m_mean;
return *this;
}
public:
UINT shoot(const REAL& a_two_pi,REAL(*a_sqrt)(REAL),REAL(*a_log)(REAL),REAL(*a_exp)(REAL),REAL(*a_cos)(REAL)) const {
UINT number = 0;
if(m_mean <= 16) {
REAL position = m_flat.shoot();
REAL poissonValue = a_exp(-m_mean);
REAL poissonSum = poissonValue;
while(poissonSum <= position) {
number++;
poissonValue *= m_mean/REAL(number);
poissonSum += poissonValue;
}
return number;
}
// m_mean > 16 :
REAL t = a_sqrt(-REAL(2)*a_log(m_flat.shoot()));
REAL y = a_two_pi*m_flat.shoot();
t *= a_cos(y);
REAL value = m_mean + t*a_sqrt(m_mean) + REAL(0.5);
if(value <= REAL(0)) return UINT(0);
static const REAL limit = REAL(2e9);
if(value >= limit) return UINT(limit);
return UINT(value);
}
FLAT& flat() {return m_flat;}
void set_seed(unsigned int a_seed) {m_flat.set_seed(a_seed);}
protected:
FLAT& m_flat;
REAL m_mean;
};
}
#endif
+56 -15
View File
@@ -21,22 +21,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
protected:
rtausmed m_flat;
};
class rbwd : public rbw<rtausmed,double> {
typedef rbw<rtausmed,double> parent;
public:
rbwd(double a_mean = 0,double a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwd(){}
public:
rbwd(const rbwd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwd& operator=(const rbwd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
double shoot() const {return parent::shoot(::sqrt,::log);}
protected:
rtausmed m_flat;
};
@@ -53,6 +39,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
double shoot() const {return parent::shoot(::log);}
protected:
rtausmed m_flat;
};
@@ -85,6 +73,59 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
void shoot(double& a_x,double& a_y,double& a_z) const {
parent::shoot(a_x,a_y,a_z,::sqrt);
}
protected:
rtausmed m_flat;
};
}
#include "mathd"
namespace tools {
class rbwd : public rbw<rtausmed,double> {
typedef rbw<rtausmed,double> parent;
public:
rbwd(double a_mean = 0,double a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwd(){}
public:
rbwd(const rbwd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwd& operator=(const rbwd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
double shoot() const {return parent::shoot(half_pi(),::tan);}
protected:
rtausmed m_flat;
};
}
#include "typedefs"
namespace tools {
// NOTE : not used yet.
class rpoissd : public rpoiss<rtausmed,double,uint64> {
typedef rpoiss<rtausmed,double,uint64> parent;
public:
rpoissd(double a_mean = 1):parent(m_flat,a_mean),m_flat(){}
virtual ~rpoissd(){}
public:
rpoissd(const rpoissd& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rpoissd& operator=(const rpoissd& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
uint64 shoot() const {return parent::shoot(two_pi(),::sqrt,::log,::exp,::cos);}
protected:
rtausmed m_flat;
};
+27 -15
View File
@@ -21,22 +21,8 @@ public:
m_flat = a_from.m_flat;
return *this;
}
protected:
rtausmef m_flat;
};
class rbwf : public rbw<rtausmef,float> {
typedef rbw<rtausmef,float> parent;
public:
rbwf(float a_mean = 0,float a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwf(){}
public:
rbwf(const rbwf& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwf& operator=(const rbwf& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
float shoot() const {return parent::shoot(::sqrtf,::logf);}
protected:
rtausmef m_flat;
};
@@ -53,6 +39,32 @@ public:
m_flat = a_from.m_flat;
return *this;
}
public:
float shoot() const {return parent::shoot(::logf);}
protected:
rtausmef m_flat;
};
}
#include "mathf"
namespace tools {
class rbwf : public rbw<rtausmef,float> {
typedef rbw<rtausmef,float> parent;
public:
rbwf(float a_mean = 0,float a_gamma = 1):parent(m_flat,a_mean,a_gamma),m_flat(){}
virtual ~rbwf(){}
public:
rbwf(const rbwf& a_from):parent(m_flat),m_flat(a_from.m_flat){}
rbwf& operator=(const rbwf& a_from) {
parent::operator=(a_from);
m_flat = a_from.m_flat;
return *this;
}
public:
float shoot() const {return parent::shoot(fhalf_pi(),::tanf);}
protected:
rtausmef m_flat;
};

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