Skip to content

Commit

Permalink
Merge pull request #152 from project8/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pslocum authored Jul 16, 2020
2 parents 0afdfbe + 7229eb2 commit df6226d
Show file tree
Hide file tree
Showing 29 changed files with 992 additions and 121 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required( VERSION 3.1 )

# Define the project
cmake_policy( SET CMP0048 NEW ) # version in project()
project( locust_mc VERSION 1.16.0)
project( locust_mc VERSION 1.16.1)

list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake )
include( PackageBuilder )
Expand Down Expand Up @@ -41,10 +41,19 @@ set (LOCUST_MC_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/Source/RxComponents/
${CMAKE_CURRENT_SOURCE_DIR}/Source/Transforms/
${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/
${CMAKE_CURRENT_SOURCE_DIR}/Source/IO/
${CMAKE_CURRENT_SOURCE_DIR}/Source/Distributions/
${CMAKE_CURRENT_SOURCE_DIR}/Source/Kassiopeia/
)

#if (locust_mc_BUILD_WITH_ROOT)
# set( LOCUST_MC_INCLUDE_DIRECTORIES ${LOCUST_MC_INCUDE_DIRECTORIES}
# ${CMAKE_CURRENT_SOURCE_DIR}/Source/IO/
# )
#endif (locust_mc_BUILD_WITH_ROOT)



include_directories( BEFORE ${LOCUST_MC_INCLUDE_DIRECTORIES} )


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM project8/p8compute_dependencies:v0.9.0 as locust_common
ARG build_type=Release
ENV LOCUST_BUILD_TYPE=$build_type

ENV LOCUST_TAG=v1.16.0
ENV LOCUST_TAG=v1.16.1
ENV LOCUST_BUILD_PREFIX=/usr/local/p8/locust/$LOCUST_TAG

RUN mkdir -p $LOCUST_BUILD_PREFIX &&\
Expand Down
21 changes: 16 additions & 5 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ set( LOCUST_MC_HEADER_FILES
RxComponents/LMCPatchAntenna.hh
RxComponents/LMCSlotAntenna.hh
RxComponents/LMCChannel.hh

)


Expand Down Expand Up @@ -139,7 +139,7 @@ set( LOCUST_MC_SOURCE_FILES
RxComponents/LMCReceiver.cc
RxComponents/LMCPatchAntenna.cc
RxComponents/LMCSlotAntenna.cc
RxComponents/LMCChannel.cc
RxComponents/LMCChannel.cc

)

Expand Down Expand Up @@ -197,14 +197,24 @@ if (locust_mc_BUILD_WITH_ROOT)
set( LOCUST_MC_HEADER_FILES ${LOCUST_MC_HEADER_FILES}
Core/LMCEvent.hh
Core/LMCTrack.hh
Generators/LMCFakeTrackSignalGenerator.hh
Core/LMCRunParameters.hh
Generators/LMCFakeTrackSignalGenerator.hh
IO/LMCFileWriter.hh
IO/LMCRootTreeWriter.hh
IO/LMCRootHistoWriter.hh
IO/LMCRootGraphWriter.hh
)

set( LOCUST_MC_SOURCE_FILES ${LOCUST_MC_SOURCE_FILES}
Core/LMCEvent.cc
Core/LMCTrack.cc
Generators/LMCFakeTrackSignalGenerator.cc
)
Core/LMCRunParameters.cc
Generators/LMCFakeTrackSignalGenerator.cc
IO/LMCFileWriter.cc
IO/LMCRootTreeWriter.cc
IO/LMCRootHistoWriter.cc
IO/LMCRootGraphWriter.cc
)


if (CMAKE_COMPILER_IS_GNUCXX)
Expand Down Expand Up @@ -235,6 +245,7 @@ if (locust_mc_BUILD_WITH_ROOT)
endforeach()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LMCDict.cxx
COMMAND rootcling -f LMCDict.cxx -c -inlineInputHeader ${includedirs}
${PROJECT_SOURCE_DIR}/Source/Core/LMCRunParameters.hh
${PROJECT_SOURCE_DIR}/Source/Core/LMCEvent.hh
${PROJECT_SOURCE_DIR}/Source/Core/LMCTrack.hh
${PROJECT_SOURCE_DIR}/Source/Core/LinkDef/LMCLinkDef.hh
Expand Down
23 changes: 23 additions & 0 deletions Source/Core/LMCRunParameters.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* LMCRunParameters.cc
*
* This class has access to both locust and ROOT libraries. The syntax is
* consistent with KTROOTData.cc and the instructions in
* https://root.cern.ch/root/Using.html . It is also mentioned in LMCEventLinkDef.hh .
*
* Created on: Jul 7, 2020
* Author: pslocum
*/


#include "LMCRunParameters.hh"
#include <iostream>

ClassImp(locust::RunParameters);

namespace locust
{
RunParameters::RunParameters() {}
RunParameters::~RunParameters() {}

}
37 changes: 37 additions & 0 deletions Source/Core/LMCRunParameters.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* LMCRunParameters.hh
*
* This class has access to both locust and ROOT libraries. The syntax is
* consistent with KTROOTData.hh and the instructions in
* https://root.cern.ch/root/Using.html . It is also mentioned in LMCEventLinkDef.hh .
* Created on: Jul 7, 2020
* Author: pslocum
*/



#ifndef LMCRUNPARAMETERS_HH_
#define LMCRUNPARAMETERS_HH_

#include "TObject.h"
#include "LMCRunParameters.hh"

namespace locust
{

class RunParameters : public TObject
{

public:
RunParameters();
virtual ~RunParameters();

double fNoise;
double fLOfrequency;

ClassDef(RunParameters,1) // Root syntax.

};

}
#endif /* LMCRUNPARAMETERS_HH_ */
147 changes: 147 additions & 0 deletions Source/Core/LMCSingleton.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* singleton.hh
*
* Created on: Nov 7, 2011
* Author: nsoblath
*/

#ifndef SCARAB_SINGLETON_HH_
#define SCARAB_SINGLETON_HH_

#include "destroyer.hh"
#include "error.hh"

#include <cstddef>
#include <mutex>

namespace scarab
{
/*!
\def allow_singleton_access( class_name )
Gives friend access to your class from scarab::singleton< class_name > and scarab::destroyer< class_name >
so that those classes can control the life of your singleton class.
*/
#define allow_singleton_access( class_name ) \
friend class scarab::singleton< class_name >; \
friend class scarab::destroyer< class_name >;

/*!
@class singleton
@author N.S. Oblath
@brief Base class that turns a class into a singleton
@details
To use:
1. Inherit your class from singleton< your_class >
2. Make your constructor and destructor protected (or private)
3. Add the `allow_singleton_access( your_class )` macro to your class definition to allow the base classes to access your class
The mutex f_mutex provides thread safety for creation and destruction of an instance of the singleton. It's available to the
derived class for thread-safe access to the object in general.
*/
template< class x_type >
class singleton
{
public:
static x_type* get_instance();
static void kill_instance();

template< class... x_args >
static x_type* create_instance( x_args... args );

private:
static void construct_instance();
static void delete_instance();

private:
static x_type* f_instance;
static destroyer< x_type > f_destroyer;

protected:
static std::mutex f_mutex;

protected:
singleton();

friend class destroyer< x_type >;
~singleton();
};

template< class x_type >
x_type* singleton< x_type >::f_instance = nullptr;

template< class x_type >
destroyer< x_type > singleton< x_type >::f_destroyer;

template< class x_type >
std::mutex singleton< x_type >::f_mutex;

template< class x_type >
x_type* singleton< x_type >::get_instance()
{
if( f_instance == nullptr )
{
std::unique_lock< std::mutex > t_lock( f_mutex );
construct_instance();
}
return f_instance;
}

template< class x_type >
void singleton< x_type >::kill_instance()
{
if( f_instance != nullptr )
{
std::unique_lock< std::mutex > t_lock( f_mutex );
delete_instance();
}
return;
}

template< class x_type >
template< class... x_args >
x_type* singleton< x_type >::create_instance( x_args... args )
{
if( f_instance != nullptr )
{
throw error() << "Instance already exists; create_instance can only be called before the instance exists";
}
std::unique_lock< std::mutex > t_lock( f_mutex );
f_instance = new x_type( args... );
f_destroyer.set_doomed( f_instance );
return f_instance;
}

template< class x_type >
void singleton< x_type >::construct_instance()
{
if( f_instance == nullptr )
{
f_instance = new x_type();
f_destroyer.set_doomed( f_instance );
}
}

template< class x_type >
void singleton< x_type >::delete_instance()
{
if( f_instance != nullptr )
{
delete f_instance;
f_instance = nullptr;
f_destroyer.set_doomed( nullptr );
}
}

template< class x_type >
singleton< x_type >::singleton()
{
}
template< class x_type >
singleton< x_type >::~singleton()
{
}

} /* namespace scarab */

#endif /* SCARAB_SINGLETON_HH_ */
1 change: 1 addition & 0 deletions Source/Core/LinkDef/LMCLinkDef.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma link C++ namespace locust;

#pragma link C++ class locust::RunParameters+;
#pragma link C++ class locust::Event+;
#pragma link C++ class locust::Track+;

Expand Down
2 changes: 1 addition & 1 deletion Source/Distributions/LMCDistributionInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace locust
if(dist_name == "dirac" || dist_name == "fixed" )
fDistributionList.push_back( std::make_shared< DiracDistribution >(aParam) );

if(dist_name == "exponential")
else if(dist_name == "exponential")
fDistributionList.push_back( std::make_shared< ExponentialDistribution >(aParam) );

else if(dist_name == "gaussian")
Expand Down
22 changes: 13 additions & 9 deletions Source/Distributions/LMCExponentialDistribution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@ namespace locust
LOGGER( lmclog, "LMCExponentialDistribution" );

ExponentialDistribution::ExponentialDistribution(const scarab::param_node &aParam) :
fLambda( 1. )
fTau( 1. ),
fShift( 0. )
{
if(aParam.has("lambda"))
fLambda = aParam.get_value< double >( "lambda", fLambda );
if(aParam.has("tau"))
fTau = aParam.get_value< double >( "tau", fTau );
if(aParam.has("shift"))
fShift = aParam.get_value< double >( "shift", fShift );

fDistribution = std::exponential_distribution<double>(fLambda);
LDEBUG( lmclog, "Created exponential distribution. lambda: " <<fLambda);
fDistribution = std::exponential_distribution<double>(1. / fTau);
LDEBUG( lmclog, "Created exponential distribution. tau: " <<fTau<<" shift: "<<fShift);
}

ExponentialDistribution::ExponentialDistribution(const double &aLambda) :
fLambda( aLambda ),
fDistribution( aLambda )
ExponentialDistribution::ExponentialDistribution(const double &aTau, const double &aShift) :
fTau( aTau ),
fShift( aShift ),
fDistribution( aTau )
{
}

double ExponentialDistribution::Generate()
{
return fDistribution(*fRNEngine);
return fDistribution(*fRNEngine) + fShift;
}

} /* namespace locust */
5 changes: 3 additions & 2 deletions Source/Distributions/LMCExponentialDistribution.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ namespace locust

public:
ExponentialDistribution(const scarab::param_node &aParam);
ExponentialDistribution(const double &aLambda);
ExponentialDistribution(const double &aTau, const double &aShift);

double Generate();

private:
std::exponential_distribution<double> fDistribution;
double fLambda;
double fTau;
double fShift; //shift of exponential distribution from 0
};


Expand Down
Loading

0 comments on commit df6226d

Please sign in to comment.