Sigma
Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Sigma.Core.SigmaEnvironment Class Reference

A sigma environment, where all the magic happens. More...

Public Member Functions

void SetRandomSeed (int seed)
 Set the random seed used for all randomised computations for reproducibility. More...
 
TMonitor AddMonitor< TMonitor > (TMonitor monitor)
 Add a monitor to this environment. More...
 
void Prepare ()
 Prepare this environment for execution. Start all monitors. More...
 
ITrainer CreateTrainer (string name)
 Create a trainer with a certain unique name and add it to this environment. More...
 
TTrainer AddTrainer< TTrainer > (TTrainer trainer)
 Add a trainer to this environment. More...
 
void RemoveTrainer (ITrainer trainer)
 Remove a trainer (and its associated operator) from this environment. Note: Warning, this is probably not what you want. Trainer removal may cause inconsistent behaviour during execution. If the operator is currently running and cannot be disassociated this method will throw an exception. More...
 
async Task RunAsync ()
 
void Run ()
 Run this environment. Execute all registered options until stop is requested. Note: This method is blocking and executes in the calling thread. More...
 
void SignalStop ()
 Signal this environment to stop execution as soon as possible (if running). More...
 
void RequestAttachGlobalHook (IHook hook, string trainerName)
 Request for a hook to be attached to a certain trainer's operator (identified by its name). More...
 
void RequestAttachGlobalHook (IHook hook, ITrainer trainer)
 Request for a hook to be attached to a certain trainer's operator. More...
 
void RequestAttachGlobalHook (IHook hook, IOperator operatorToAttachTo)
 Request for a hook to be attached to a certain operator. More...
 
void RequestAttachLocalHook (IHook hook, string trainerName)
 Request for a hook to be attached to a certain trainer's operator (identified by its name). More...
 
void RequestAttachLocalHook (IHook hook, ITrainer trainer)
 Request for a hook to be attached to a certain trainer's operator. More...
 
void RequestAttachLocalHook (IHook hook, IOperator operatorToAttachTo)
 Request for a hook to be attached to a certain operator. More...
 
T [] ResolveGet< T > (string matchIdentifier, out string[] fullMatchedIdentifierArray, T[] values=null)
 Resolve all matching identifiers in this registry. For the detailed supported syntax IRegistryResolver. More...
 
T [] ResolveGet< T > (string matchIdentifier, T[] values=null)
 Resolve all matching identifiers in this registry. For the detailed supported syntax IRegistryResolver. More...
 
string [] ResolveSet< T > (string matchIdentifier, T value, bool addIdentifierIfNotExists=false, Type associatedType=null)
 Set a single given value of a certain type to all matching identifiers. For the detailed supported syntax IRegistryResolver. Note: The individual registries might throw an exception if a type-protected value is set to the wrong type. More...
 

Static Public Member Functions

static void EnableLogging ()
 Loads the log4net configuration from the corresponding xml file. See log4net for more details. More...
 
static SigmaEnvironment Create (string environmentName)
 Create an environment with a certain name. More...
 
static SigmaEnvironment GetOrCreate (string environmentName)
 Get environment if it already exists, create and return new one if it does not. More...
 
static SigmaEnvironment Get (string environmentName)
 Gets an environment with a given name, if previously created (null otherwise). More...
 
static bool Exists (string environmentName)
 Checks whether an environment exists with the given name. More...
 
static void Remove (string environmentName)
 Removes an environment with a given name. More...
 
static void Clear ()
 Removes all active environments. More...
 

Protected Member Functions

void FetchRunningOperators ()
 

Properties

bool StartOperatorsOnRun [get, set]
 If the IOperators should automatically start when calling Run. More...
 
bool Running = true [get, private set]
 If the SigmaEnvironment is currently running. More...
 
string Name [get]
 The unique name of this environment. More...
 
IRegistry Registry [get]
 The root registry of this environment where all exposed parameters are stored hierarchically. More...
 
IRegistryResolver RegistryResolver [get]
 The registry resolver corresponding to the registry used in this environment. For easier notation and faster access you can retrieve and using regex-style registry names and dot notation. More...
 
Random Random [get, private set]
 The random number generator to use for randomised operations for reproducibility. More...
 
static ITaskManager TaskManager [get, set]
 The task manager for this environment. More...
 
static IRegistry Globals [get]
 A global variable pool for globally relevant constants (e.g. workspace path). More...
 

Private Member Functions

 SigmaEnvironment (string name)
 
void InitialiseTrainers ()
 
void StartRunningOperators ()
 
void StopRunningOperators ()
 
void ProcessHooksToAttach ()
 

Static Private Member Functions

static void SetDefaultCulture (CultureInfo culture)
 This method sets the default culture. More...
 
static void RegisterGlobals ()
 Register all global parameters with an initial value and required associated type. More...
 

Private Attributes

readonly ISet< IMonitor_monitors
 
readonly IDictionary< string, ITrainer_trainersByName
 
readonly IDictionary< ITrainer, IOperator_runningOperatorsByTrainer
 
readonly ConcurrentQueue< KeyValuePair< IHook, IOperator > > _globalHooksToAttach
 
readonly ConcurrentQueue< KeyValuePair< IHook, IOperator > > _localHooksToAttach
 
ManualResetEvent _processQueueEvent
 
bool _requestedStop
 
readonly ILog _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
 

Static Private Attributes

static readonly ILog ClazzLogger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
 

Detailed Description

A sigma environment, where all the magic happens.

Member Function Documentation

◆ AddMonitor< TMonitor >()

TMonitor Sigma.Core.SigmaEnvironment.AddMonitor< TMonitor > ( TMonitor  monitor)

Add a monitor to this environment.

Template Parameters
TMonitorThe type of the monitor to be added.
Parameters
monitorThe monitor to add.
Returns
The monitor given (for convenience).
Type Constraints
TMonitor :IMonitor 

◆ AddTrainer< TTrainer >()

TTrainer Sigma.Core.SigmaEnvironment.AddTrainer< TTrainer > ( TTrainer  trainer)

Add a trainer to this environment.

Template Parameters
TTrainerThe type of the trainer to add.
Parameters
trainerThe trainer to add.
Returns
The given trainer (for convenience).
Type Constraints
TTrainer :ITrainer 

◆ Clear()

static void Sigma.Core.SigmaEnvironment.Clear ( )
static

Removes all active environments.

◆ Create()

static SigmaEnvironment Sigma.Core.SigmaEnvironment.Create ( string  environmentName)
static

Create an environment with a certain name.

Parameters
environmentName
Returns
A new environment with the given name.

◆ CreateTrainer()

ITrainer Sigma.Core.SigmaEnvironment.CreateTrainer ( string  name)

Create a trainer with a certain unique name and add it to this environment.

Parameters
nameThe trainer name.
Returns
A new trainer with the given name.

◆ EnableLogging()

static void Sigma.Core.SigmaEnvironment.EnableLogging ( )
static

Loads the log4net configuration from the corresponding xml file. See log4net for more details.

◆ Exists()

static bool Sigma.Core.SigmaEnvironment.Exists ( string  environmentName)
static

Checks whether an environment exists with the given name.

Parameters
environmentNameThe environment name.
Returns
A boolean indicating if an environment with the given name exists.

◆ Get()

static SigmaEnvironment Sigma.Core.SigmaEnvironment.Get ( string  environmentName)
static

Gets an environment with a given name, if previously created (null otherwise).

Parameters
environmentNameThe environment name.
Returns
The existing with the given name or null.

◆ GetOrCreate()

static SigmaEnvironment Sigma.Core.SigmaEnvironment.GetOrCreate ( string  environmentName)
static

Get environment if it already exists, create and return new one if it does not.

Parameters
environmentName
Returns
A new environment with the given name or the environment already associated with the name.

◆ Prepare()

void Sigma.Core.SigmaEnvironment.Prepare ( )

Prepare this environment for execution. Start all monitors.

◆ RegisterGlobals()

static void Sigma.Core.SigmaEnvironment.RegisterGlobals ( )
staticprivate

Register all global parameters with an initial value and required associated type.

◆ Remove()

static void Sigma.Core.SigmaEnvironment.Remove ( string  environmentName)
static

Removes an environment with a given name.

Parameters
environmentNameThe environment name.

◆ RemoveTrainer()

void Sigma.Core.SigmaEnvironment.RemoveTrainer ( ITrainer  trainer)

Remove a trainer (and its associated operator) from this environment. Note: Warning, this is probably not what you want. Trainer removal may cause inconsistent behaviour during execution. If the operator is currently running and cannot be disassociated this method will throw an exception.

Parameters
trainerThe trainer to remove.

◆ RequestAttachGlobalHook() [1/3]

void Sigma.Core.SigmaEnvironment.RequestAttachGlobalHook ( IHook  hook,
string  trainerName 
)

Request for a hook to be attached to a certain trainer's operator (identified by its name).

Parameters
hookThe hook to attach.
trainerNameThe trainer name whose trainer's operator the hook should be attached to.

◆ RequestAttachGlobalHook() [2/3]

void Sigma.Core.SigmaEnvironment.RequestAttachGlobalHook ( IHook  hook,
ITrainer  trainer 
)

Request for a hook to be attached to a certain trainer's operator.

Parameters
hookThe hook to attach.
trainerThe trainer whose operator the hook should be attached to.

◆ RequestAttachGlobalHook() [3/3]

void Sigma.Core.SigmaEnvironment.RequestAttachGlobalHook ( IHook  hook,
IOperator  operatorToAttachTo 
)

Request for a hook to be attached to a certain operator.

Parameters
hookThe hook to attach.
operatorToAttachToThe operator to attach to.

◆ RequestAttachLocalHook() [1/3]

void Sigma.Core.SigmaEnvironment.RequestAttachLocalHook ( IHook  hook,
string  trainerName 
)

Request for a hook to be attached to a certain trainer's operator (identified by its name).

Parameters
hookThe hook to attach.
trainerNameThe trainer name whose trainer's operator the hook should be attached to.

◆ RequestAttachLocalHook() [2/3]

void Sigma.Core.SigmaEnvironment.RequestAttachLocalHook ( IHook  hook,
ITrainer  trainer 
)

Request for a hook to be attached to a certain trainer's operator.

Parameters
hookThe hook to attach.
trainerThe trainer whose operator the hook should be attached to.

◆ RequestAttachLocalHook() [3/3]

void Sigma.Core.SigmaEnvironment.RequestAttachLocalHook ( IHook  hook,
IOperator  operatorToAttachTo 
)

Request for a hook to be attached to a certain operator.

Parameters
hookThe hook to attach.
operatorToAttachToThe operator to attach to.

◆ ResolveGet< T >() [1/2]

T [] Sigma.Core.SigmaEnvironment.ResolveGet< T > ( string  matchIdentifier,
out string []  fullMatchedIdentifierArray,
T []  values = null 
)

Resolve all matching identifiers in this registry. For the detailed supported syntax IRegistryResolver.

Template Parameters
TThe most specific common type of the variables to retrieve.
Parameters
matchIdentifierThe full match identifier.
fullMatchedIdentifierArrayThe fully matched identifiers corresponding to the given match identifier.
valuesAn array of values found at the matching identifiers, filled with the values found at all matching identifiers (for reuse and optimisation if request is issued repeatedly).
Returns
An array of values found at the matching identifiers. The parameter values is used if it is large enough and not null.

◆ ResolveGet< T >() [2/2]

T [] Sigma.Core.SigmaEnvironment.ResolveGet< T > ( string  matchIdentifier,
T []  values = null 
)

Resolve all matching identifiers in this registry. For the detailed supported syntax IRegistryResolver.

Template Parameters
TThe most specific common type of the variables to retrieve.
Parameters
matchIdentifierThe full match identifier.
valuesAn array of values found at the matching identifiers, filled with the values found at all matching identifiers (for reuse and optimisation if request is issued repeatedly).
Returns
An array of values found at the matching identifiers. The parameter values is used if it is large enough and not null.

◆ ResolveSet< T >()

string [] Sigma.Core.SigmaEnvironment.ResolveSet< T > ( string  matchIdentifier,
value,
bool  addIdentifierIfNotExists = false,
Type  associatedType = null 
)

Set a single given value of a certain type to all matching identifiers. For the detailed supported syntax IRegistryResolver. Note: The individual registries might throw an exception if a type-protected value is set to the wrong type.

Template Parameters
TThe type of the value.
Parameters
matchIdentifierThe full match identifier.
valueThe value to set.
addIdentifierIfNotExistsIndicate if the last (local) identifier should be added if it doesn't exist yet.
associatedTypeOptionally set the associated type (IRegistry). If no associated type is set, the one of the registry will be used (if set).
Returns
A list of fully qualified matches to the match identifier.

◆ Run()

void Sigma.Core.SigmaEnvironment.Run ( )

Run this environment. Execute all registered options until stop is requested. Note: This method is blocking and executes in the calling thread.

◆ SetDefaultCulture()

static void Sigma.Core.SigmaEnvironment.SetDefaultCulture ( CultureInfo  culture)
staticprivate

This method sets the default culture.

Parameters
cultureThe culture that will be the new default.

◆ SetRandomSeed()

void Sigma.Core.SigmaEnvironment.SetRandomSeed ( int  seed)

Set the random seed used for all randomised computations for reproducibility.

Parameters
seed

◆ SignalStop()

void Sigma.Core.SigmaEnvironment.SignalStop ( )

Signal this environment to stop execution as soon as possible (if running).

Property Documentation

◆ Globals

IRegistry Sigma.Core.SigmaEnvironment.Globals
staticget

A global variable pool for globally relevant constants (e.g. workspace path).

◆ Name

string Sigma.Core.SigmaEnvironment.Name
get

The unique name of this environment.

◆ Random

Random Sigma.Core.SigmaEnvironment.Random
getprivate set

The random number generator to use for randomised operations for reproducibility.

◆ Registry

IRegistry Sigma.Core.SigmaEnvironment.Registry
get

The root registry of this environment where all exposed parameters are stored hierarchically.

◆ RegistryResolver

IRegistryResolver Sigma.Core.SigmaEnvironment.RegistryResolver
get

The registry resolver corresponding to the registry used in this environment. For easier notation and faster access you can retrieve and using regex-style registry names and dot notation.

◆ Running

bool Sigma.Core.SigmaEnvironment.Running = true
getprivate set

If the SigmaEnvironment is currently running.

◆ StartOperatorsOnRun

bool Sigma.Core.SigmaEnvironment.StartOperatorsOnRun
getset

If the IOperators should automatically start when calling Run.

◆ TaskManager

ITaskManager Sigma.Core.SigmaEnvironment.TaskManager
staticgetset

The task manager for this environment.


The documentation for this class was generated from the following file: