MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
moose Namespace Reference

Namespaces

 assertion
 
 detail
 
 details
 

Classes

class  AdExIF
 
class  AdThreshIF
 
class  Compartment
 
class  CompartmentBase
 
class  CompartmentDataHolder
 
class  ExIF
 
class  IntFireBase
 
class  IzhIF
 
class  LIF
 
class  normal_distribution
 
class  QIF
 
class  RNG
 
class  VClamp
 

Typedefs

template<typename T = double>
using MOOSE_NORMAL_DISTRIBUTION = moose::normal_distribution< T >
 
typedef std::random_device MOOSE_RANDOM_DEVICE
 
typedef
std::mersenne_twister_engine
< std::uint_fast32_t, 32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253 > 
MOOSE_RNG_DEFAULT_ENGINE
 
template<typename T = double>
using MOOSE_UNIFORM_DISTRIBUTION = std::uniform_real_distribution< T >
 

Enumerations

enum  serverity_level_ {
  trace, debug, info, warning,
  fixme, error, fatal, failed
}
 Enumerate type for debug and log. More...
 

Functions

void __dump__ (string msg, serverity_level_ type=debug, bool autoFormat=true)
 
string basename (const string &path)
 Givem path of MOOSE element, return its name. It's behaviour is like basename of unix command e.g. /a/b/c –> c. More...
 
int checkPath (const string &path)
 Checks if given path is correct. If not, return false and error-code as well. More...
 
string & clean_type_name (string &arg)
 
string colored (string msg)
 
string colored (string msg, string colorName)
 
string createMOOSEPath (const string &path)
 Create a POSIX compatible path from a given string. Remove/replace bad characters. More...
 
bool createParentDirs (const string &path)
 Create directories recursively needed to open the given file p. More...
 
string debugPrint (string msg, string prefix="DEBUG", string color=T_RESET, unsigned debugLevel=0)
 
bool endswith (const string &full, const string &ending)
 
std::string fix (const std::string userPath, const string &delimiters)
 
string fixPath (string path)
 Fix a path. For testing purpose. More...
 
string formattedMsg (string &msg)
 
const map< string, string > & getArgMap ()
 
string getExtension (const string &path, bool without_dot=true)
 Get the extension of a given filepath. More...
 
int getGlobalSeed ()
 
char innerType (char typecode)
 
bool isBackTick (char a)
 
string joinPath (string pathA, string pathB)
 Append pathB to pathA and return the result. More...
 
void log (string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
 Log to console (and to a log-file) More...
 
template<typename A , typename B >
string mapToString (const map< A, B > &m, bool value=true)
 
string moosePathToUserPath (string path)
 When user gives a path /a/b/c, moose creates a path /a[0]/b[0]/c[0]. This is helpful in cases where one needs to create more than 1 element. More...
 
double mtrand (void)
 Generate a random double between 0 and 1. More...
 
void mtseed (unsigned int x)
 Set the global seed or all rngs. More...
 
string pathToName (const string &path)
 Return the name when path is given. Its behaviour is exactly the same as of basename command on unix system. More...
 
string random_string (const unsigned len)
 
void setGlobalSeed (int seed)
 
char shortFinfo (std::string ftype)
 
char shortType (std::string type)
 
void showDebug (const string msg)
 
void showError (string msg)
 
void showInfo (string msg)
 
void showWarn (string msg)
 
int strncasecmp (const std::string &a, const std::string &b, size_t n)
 Compares the two strings a and b for first n characters, ignoring the case of the characters. Return 0 in case both are same upto first n characters. Othere a non-zero value is returned. When n is smaller or equal to the size of both strings, positive is return if a is larger than b, or negative when a is smaller than b. More...
 
int testTrim ()
 
string toFilename (const string &path)
 Replace all directory sepearator with _. This creates a filepath which can be created in current directory without any need to create parent directory. More...
 
void tokenize (const string &str, const string &delimiters, vector< string > &tokens)
 
string toString (double x)
 Convert a given value to string. More...
 
std::string trim (const std::string myString, const string &delimiters)
 

Variables

unsigned long __rng_seed__ = 0
 A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set. Other's RNGs (except muparser) uses this seed to initialize them. By default it is initialized by random_device (see global.cpp). More...
 
static const char *const DELIMITERS =" \t\r\n"
 
static string levels_ [9]
 
moose::RNG< double > rng
 

Detailed Description

The Compartment class sets up an asymmetric compartment for branched nerve calculations. Handles electronic structure and also channels. This is not a particularly efficient way of doing this, so we should use a solver for any substantial calculations.

The CompartmentBase class sets up the interface for all the derived Compartment classes, used in branched nerve calculations. Handles electronic structure and also channels.

Typedef Documentation

template<typename T = double>
using moose::MOOSE_NORMAL_DISTRIBUTION = typedef moose::normal_distribution<T>

Definition at line 29 of file Distributions.h.

typedef std::random_device moose::MOOSE_RANDOM_DEVICE

MOOSE's random device. Use it from <random>

Definition at line 29 of file Definitions.h.

typedef std::mersenne_twister_engine< std::uint_fast32_t, 32, 624, 397, 31 , 0x9908b0df, 11 , 0xffffffff, 7 , 0x9d2c5680, 15 , 0xefc60000, 18, 1812433253 > moose::MOOSE_RNG_DEFAULT_ENGINE

Global random number generator engine. Everywhere we use this engine.

Definition at line 42 of file Definitions.h.

template<typename T = double>
using moose::MOOSE_UNIFORM_DISTRIBUTION = typedef std::uniform_real_distribution<T>

Definition at line 26 of file Distributions.h.

Enumeration Type Documentation

Enumerate type for debug and log.

Enumerator
trace 
debug 
info 
warning 
fixme 
error 
fatal 
failed 

Definition at line 76 of file print_function.hpp.

Function Documentation

void moose::__dump__ ( string  msg,
serverity_level_  type = debug,
bool  autoFormat = true 
)
inline

Definition at line 170 of file print_function.hpp.

References debug, error, failed, fixme, info, levels_, T_CYAN, T_GREEN, T_MAGENTA, T_RED, T_RESET, T_YELLOW, and warning.

Referenced by log(), showDebug(), showError(), showInfo(), and showWarn().

171  {
172  stringstream ss;
173  ss << "[" << levels_[type] << "] ";
174  bool set = false;
175  bool reset = true;
176  string color = T_GREEN;
177  if(type == warning || type == fixme )
178  color = T_YELLOW;
179  else if(type == debug )
180  color = T_CYAN;
181  else if(type == error || type == failed )
182  color = T_RED;
183  else if(type == info )
184  color = T_MAGENTA;
185 
186  for(unsigned int i = 0; i < msg.size(); ++i)
187  {
188  if('`' == msg[i])
189  {
190  if(!set and reset)
191  {
192  set = true;
193  reset = false;
194  ss << color;
195  }
196  else if(set && !reset)
197  {
198  reset = true;
199  set = false;
200  ss << T_RESET;
201  }
202  }
203  else if('\n' == msg[i])
204  ss << "\n | ";
205  else
206  ss << msg[i];
207  }
208 
209  /* Be safe than sorry */
210  if(!reset)
211  ss << T_RESET;
212  cout << ss.str() << endl;
213  cout.flush( );
214  }
static string levels_[9]

+ Here is the caller graph for this function:

string moose::basename ( const string &  path)
inline

Givem path of MOOSE element, return its name. It's behaviour is like basename of unix command e.g. /a/b/c –> c.

Returns

Definition at line 31 of file utility.h.

32  {
33  return path.substr( path.find_last_of('/') + 1 );
34  }
static char path[]
Definition: mfield.cpp:403
int moose::checkPath ( const string &  path)

Checks if given path is correct. If not, return false and error-code as well.

Parameters
pathPath name.
Returns
0 if path is all-right. Negative number if path is not OK.

Definition at line 50 of file global.cpp.

References BAD_CHARACTER_IN_PATH, EMPTY_PATH, and MISSING_BRACKET_AT_END.

Referenced by fixPath().

51  {
52  if( path.size() < 1)
53  return EMPTY_PATH;
54 
55  if( path.find_first_of( " \\!") != std::string::npos )
56  return BAD_CHARACTER_IN_PATH;
57 
58  if ( path[path.size() - 1 ] != ']')
59  {
61  }
62  return 0;
63  }
#define MISSING_BRACKET_AT_END
Definition: global.h:44
#define BAD_CHARACTER_IN_PATH
Definition: global.h:49
#define EMPTY_PATH
Definition: global.h:45
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

std::string & moose::clean_type_name ( string &  arg)

Definition at line 36 of file strutil.cpp.

37 {
38  for (size_t pos = arg.find(' '); pos != string::npos; pos = arg.find(' '))
39  {
40  arg.replace(pos, 1, 1, '_');
41  }
42  for (size_t pos = arg.find('<'); pos != string::npos; pos = arg.find('<'))
43  {
44  arg.replace(pos, 1, 1, '_');
45  }
46  for (size_t pos = arg.find('>'); pos != string::npos; pos = arg.find('>'))
47  {
48  arg.replace(pos, 1, 1, '_');
49  }
50  return arg;
51 }
string moose::colored ( string  msg)
inline

Definition at line 137 of file print_function.hpp.

References T_RED, and T_RESET.

138  {
139  stringstream ss;
140  ss << T_RED << msg << T_RESET;
141  return ss.str();
142  }
string moose::colored ( string  msg,
string  colorName 
)
inline

Definition at line 144 of file print_function.hpp.

References T_RESET.

145  {
146  stringstream ss;
147  ss << colorName << msg << T_RESET;
148  return ss.str();
149  }
string moose::createMOOSEPath ( const string &  path)

Create a POSIX compatible path from a given string. Remove/replace bad characters.

Parameters
pathReutrn path is given path if creation was successful, else directory is renamed to a filename.

Definition at line 105 of file global.cpp.

References path.

Referenced by moosePathToUserPath(), and Table::setOutfile().

106  {
107  string s = path; /* Local copy */
108  // Remove [0] from paths. They will be annoying for normal users.
109  std::string::size_type n = 0;
110  string zeroIndex("[0]");
111  while( (n = s.find( zeroIndex, n )) != std::string::npos )
112  s.erase( n, zeroIndex.size() );
113  return s;
114  }
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

bool moose::createParentDirs ( const string &  path)

Create directories recursively needed to open the given file p.

Create directory, recursively.

Parameters
pathWhen successfully created, returns created path, else convert path to a filename by replacing '/' by '_'.

Definition at line 122 of file global.cpp.

References failed, info, LOG, path, and warning.

Referenced by Table::setOutfile(), and Streamer::setOutFilepath().

123  {
124  // Remove the filename from the given path so we only have the
125  // directory.
126  string p = path;
127  bool failed = false;
128  size_t pos = p.find_last_of( '/' );
129  if( pos != std::string::npos )
130  p = p.substr( 0, pos );
131  else /* no parent directory to create */
132  return true;
133 
134  if( p.size() == 0 )
135  return true;
136 
137  string command( "mkdir -p ");
138  command += p;
139  int ret = system( command.c_str() );
140  struct stat info;
141  if( stat( p.c_str(), &info ) != 0 )
142  {
143  LOG( moose::warning, "cannot access " << p );
144  return false;
145  }
146  else if( info.st_mode & S_IFDIR )
147  {
148  LOG( moose::info, "Created directory " << p );
149  return true;
150  }
151  else
152  {
153  LOG( moose::warning, p << " is no directory" );
154  return false;
155  }
156  return true;
157  }
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

string moose::debugPrint ( string  msg,
string  prefix = "DEBUG",
string  color = T_RESET,
unsigned  debugLevel = 0 
)
inline

Definition at line 152 of file print_function.hpp.

References DEBUG_LEVEL, and T_RESET.

155  {
156  stringstream ss; ss.str("");
157  if(debugLevel <= DEBUG_LEVEL)
158  {
159  ss << setw(debugLevel/2) << "[" << prefix << "] "
160  << color << msg << T_RESET;
161  }
162  return ss.str();
163  }
bool moose::endswith ( const string &  full,
const string &  ending 
)

Definition at line 138 of file strutil.cpp.

Referenced by moose_Id_getPath().

139 {
140  if (full.length() < ending.length())
141  {
142  return false;
143  }
144  return (0 == full.compare(full.length() - ending.length(), ending.length(), ending));
145 }

+ Here is the caller graph for this function:

std::string moose::fix ( const std::string  myString,
const std::string &  delimiters = " \t\r\n" 
)

Fix the user-given path whenever possible

Definition at line 71 of file strutil.cpp.

References trim().

Referenced by moose_ObjId_init_from_path().

72 {
73  string trimmedPath = trim(userPath, delimiters);
74 
75  string fixedPath;
76  char prev = 0;
77 
78  // In this loop, we check if there are more than one '/' together. If yes,
79  // then accept only first one and reject other.
80  for(unsigned int i = 0; i < trimmedPath.size(); ++i)
81  {
82  const char c = trimmedPath[i];
83  if(c != '/' || c != prev)
84  fixedPath.push_back(c);
85  prev = c;
86  }
87  return fixedPath;
88 }
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string moose::fixPath ( string  path)

Fix a path. For testing purpose.

Parameters
pathPath as string.
Returns
A fixed path.

Definition at line 74 of file global.cpp.

References checkPath(), MISSING_BRACKET_AT_END, and path.

Referenced by HSolveUtils::gates(), and joinPath().

75  {
76  int pathOk = moose::checkPath( path );
77  if( pathOk == 0)
78  return path;
79  else if( pathOk == MISSING_BRACKET_AT_END)
80  return path + "[0]";
81  return path;
82  }
#define MISSING_BRACKET_AT_END
Definition: global.h:44
int checkPath(const string &path)
Checks if given path is correct. If not, return false and error-code as well.
Definition: global.cpp:50
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string moose::formattedMsg ( string &  msg)
inline

Definition at line 267 of file print_function.hpp.

References isBackTick().

Referenced by log().

268  {
269  remove_if(msg.begin(), msg.end(), isBackTick);
270  return msg;
271  }
bool isBackTick(char a)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const map< std::string, std::string > & moose::getArgMap ( )

Definition at line 41 of file setupenv.cpp.

References doRegressionTests, doUnitTests, getNumCores(), isInfinite, numCores, numNodes, and verbosity.

Referenced by setup_runtime_env().

42  {
43  static map<string, string> argmap;
44  if (argmap.empty()){
45  char * verbosity = getenv("VERBOSITY");
46  if (verbosity != NULL){
47  argmap.insert(pair<string, string>("VERBOSITY", string(verbosity)));
48  } else {
49  argmap.insert(pair<string, string>("VERBOSITY", "0"));
50  }
51  char * isSingleThreaded = getenv("SINGLETHREADED");
52  if (isSingleThreaded != NULL){
53  argmap.insert(pair<string, string>("SINGLETHREADED", string(isSingleThreaded)));
54  }
55  else {
56  argmap.insert(pair<string, string>("SINGLETHREADED", "0"));
57  }
58  char * isInfinite = getenv("INFINITE");
59  if (isInfinite != NULL){
60  argmap.insert(pair<string, string>("INFINITE", string(isInfinite)));
61  }
62  // else {
63  // argmap.insert(pair<string, string>("INFINITE", "0"));
64  // }
65 
66  char * numCores = getenv("NUMCORES");
67  if (numCores != NULL){
68  argmap.insert(pair<string, string>("NUMCORES", string(numCores)));
69  } else {
70  unsigned int cores = getNumCores();
71  stringstream s;
72  s << cores;
73  argmap.insert(pair<string, string>("NUMCORES", s.str()));
74  }
75  char * numNodes = getenv("NUMNODES");
76  if (numNodes != NULL){
77  argmap.insert(pair<string, string>("NUMNODES", string(numNodes)));
78  } // else {
79  // argmap.insert(pair<string, string>("NUMNODES", "1"));
80  // }
81  char * numProcessThreads = getenv("NUMPTHREADS");
82  if (numProcessThreads != NULL){
83  argmap.insert(pair<string, string>("NUMPTHREADS", string(numProcessThreads)));
84  }
85  char * doQuit = getenv("QUIT");
86  if (doQuit != NULL){
87  argmap.insert(pair<string, string>("QUIT", string(doQuit)));
88  } // else {
89  // argmap.insert(pair<string, string>("QUIT", "0"));
90  // }
91  char * doUnitTests = getenv("DOUNITTESTS");
92  if (doUnitTests != NULL){
93  argmap.insert(pair<string, string>("DOUNITTESTS", string(doUnitTests)));
94  } // else {
95  // argmap.insert(pair<string, string>("DOUNITTESTS", "0"));
96  // }
97  char * doRegressionTests = getenv("DOREGRESSIONTESTS");
98  if (doRegressionTests != NULL){
99  argmap.insert(pair<string, string>("DOREGRESSIONTESTS", string(doRegressionTests)));
100  } // else {
101  // argmap.insert(pair<string, string>("DOREGRESSIONTESTS", "0"));
102  // }
103 
104  }
105  return argmap;
106  }
static unsigned int numCores
static int isInfinite
static int doRegressionTests
unsigned getNumCores()
Definition: main.cpp:93
int verbosity
static unsigned int numNodes
static int doUnitTests

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string moose::getExtension ( const string &  path,
bool  without_dot = true 
)

Get the extension of a given filepath.

Parameters
pathGiven path.
Returns
Extension (with or without preceeding '.' )

Definition at line 170 of file global.cpp.

Referenced by Table::setOutfile(), and Streamer::setOutFilepath().

171  {
172  size_t dotPos = path.find_last_of( '.' );
173  if( dotPos == std::string::npos )
174  return "";
175 
176  if( without_dot )
177  return path.substr( dotPos + 1 );
178 
179  return path.substr( dotPos );
180  }
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

int moose::getGlobalSeed ( )

Get the global seed set by call of moose.seed( X )

seed (int).

Definition at line 206 of file global.cpp.

References __rng_seed__.

Referenced by GraupnerBrunel2012CaPlasticitySynHandler::reinitSeed().

207  {
208  return __rng_seed__;
209  }
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
Definition: global.cpp:45

+ Here is the caller graph for this function:

char moose::innerType ( char  typecode)

Definition at line 104 of file types.cpp.

104  {
105  static map<char, char> innerTypeMap;
106  if (innerTypeMap.empty()){
107  innerTypeMap.insert(pair<char, char>('D', 'd')); // vector<double>
108  innerTypeMap.insert(pair<char, char>('v', 'i')); // vector<int>
109  innerTypeMap.insert(pair<char, char>('M', 'l')); // vector<long>
110  innerTypeMap.insert(pair<char, char>('X', 'x')); // vector<Id>
111  innerTypeMap.insert(pair<char, char>('Y', 'y')); // vector<ObjId>
112  innerTypeMap.insert(pair<char, char>('C', 'c')); // vector<char>
113  innerTypeMap.insert(pair<char, char>('w', 'h')); // vector<short>
114  innerTypeMap.insert(pair<char, char>('N', 'I')); // vector<unsigned int>
115  innerTypeMap.insert(pair<char, char>('P', 'k')); // vector<unsigned long>
116  innerTypeMap.insert(pair<char, char>('A', 'L')); // vector<long long>
117  innerTypeMap.insert(pair<char, char>('B', 'K')); // vector<unsigned long long>
118  innerTypeMap.insert(pair<char, char>('F', 'f')); // vector<float>
119  innerTypeMap.insert(pair<char, char>('S', 's')); // vector<string>
120  innerTypeMap.insert(pair<char, char>('T', 'N')); // vector<vector<unsigned>>
121  innerTypeMap.insert(pair<char, char>('Q', 'v')); // vector<vector<int>>
122  innerTypeMap.insert(pair<char, char>('R', 'D')); // vector<vector<double>>
123  }
124  map<char, char>::iterator iter = innerTypeMap.find(typecode);
125  if (iter == innerTypeMap.end()){
126  return 0;
127  }
128  return iter->second;
129 }
bool moose::isBackTick ( char  a)
inline

Definition at line 260 of file print_function.hpp.

Referenced by formattedMsg().

261  {
262  if('`' == a)
263  return true;
264  return false;
265  }

+ Here is the caller graph for this function:

string moose::joinPath ( string  pathA,
string  pathB 
)

Append pathB to pathA and return the result.

If pathA does not have [indexs] at the end, append "[0]" to pathA and then add pathB to it. This version does not care if the result has '[0]' at its end.

Parameters
pathAFirst path.
pathBSecond path.
Returns
A string representing moose-path.

Definition at line 66 of file global.cpp.

References fixPath().

67  {
68  pathA = moose::fixPath( pathA );
69  string newPath = pathA + "/" + pathB;
70  return moose::fixPath( newPath );
71  }
string fixPath(string path)
Fix a path. For testing purpose.
Definition: global.cpp:74

+ Here is the call graph for this function:

void moose::log ( string  msg,
serverity_level_  type = debug,
bool  redirectToConsole = true,
bool  removeTicks = true 
)
inline

Log to console (and to a log-file)

Parameters
msgString, message to be written.
typeType of the message.
redirectToConsole
removeTicks

Definition at line 281 of file print_function.hpp.

References __dump__(), and formattedMsg().

Referenced by GssaVoxelPools::advance(), MarkovSolver::computeMatrixExponential(), estT(), SynChan::normalizeGbar(), moose::normal_distribution< double >::operator()(), ChannelStruct::powerN(), HHChannelBase::powerN(), HHChannel2D::powerN(), GssaVoxelPools::recalcTime(), RandSpike::reinit(), GraupnerBrunel2012CaPlasticitySynHandler::updateCaWeightFactors(), Nernst::updateE(), and NMDAChan::vProcess().

285  {
286 
287  if(redirectToConsole)
288  __dump__(msg, type, true);
289 
290  /* remove any backtick from the string. */
291  formattedMsg( msg );
292 
293  fstream logF;
294  logF.open( "__moose__.log", ios::app);
295  time_t rawtime; time(&rawtime);
296  struct tm* timeinfo;
297  timeinfo = localtime(&rawtime);
298 
299  logF << asctime(timeinfo) << ": " << msg;
300 
301  logF.close();
302  }
string formattedMsg(string &msg)
void __dump__(string msg, serverity_level_ type=debug, bool autoFormat=true)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename A , typename B >
string moose::mapToString ( const map< A, B > &  m,
bool  value = true 
)

Definition at line 95 of file print_function.hpp.

References value.

96  {
97  unsigned int width = 81;
98  unsigned int mapSize = m.size();
99  unsigned int size = 0;
100 
101  vector<string> row;
102 
103  /* Get the maximum size of any entry in map */
104  stringstream ss;
105  typename map<A, B>::const_iterator it;
106  for(it = m.begin(); it != m.end(); it++)
107  {
108  ss.str("");
109  ss << it->first;
110  if(value)
111  ss << ": " << it->second;
112  row.push_back(ss.str());
113  if(ss.str().size() > size)
114  size = ss.str().size()+1;
115  }
116 
117  unsigned int colums = width / size;
118  ss.str("");
119 
120  size_t i = 0;
121  for(unsigned int ii = 0; ii < row.size(); ii++)
122  {
123  if(i < colums)
124  {
125  ss << setw(size+1) << row[ii];
126  i++;
127  }
128  else
129  {
130  ss << endl;
131  i = 0;
132  }
133  }
134  return ss.str();
135  }
uint32_t value
Definition: moosemodule.h:42
string moose::moosePathToUserPath ( string  path)

When user gives a path /a/b/c, moose creates a path /a[0]/b[0]/c[0]. This is helpful in cases where one needs to create more than 1 element.

Parameters
pathRemoved '[0]' from path and return.
Returns

Definition at line 189 of file global.cpp.

References createMOOSEPath().

Referenced by Streamer::addTable(), Table::reinit(), and Streamer::reinit().

190  {
191  // Just write the moose path. Things becomes messy when indexing is
192  // used.
193  return createMOOSEPath( path );
194  }
string createMOOSEPath(const string &path)
Create a POSIX compatible path from a given string. Remove/replace bad characters.
Definition: global.cpp:105
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double moose::mtrand ( void  )

Generate a random double between 0 and 1.

Returns
A random number between 0 and 1.

Definition at line 97 of file global.cpp.

References rng, and moose::RNG< T >::uniform().

Referenced by addPos(), SteadyState::fitConservationRules(), makeAngleDistrib(), makeSizeDistrib(), RandSpike::process(), Gsolve::process(), pymoose_mtrand_(), SeqSynHandler::refillSynapseOrder(), RandSpike::reinit(), testSparseMsg(), and moose::Compartment::vRandInject().

98  {
99  return moose::rng.uniform( );
100  }
moose::RNG< double > rng
Definition: global.cpp:47
T uniform(const T a, const T b)
Generate a uniformly distributed random number between a and b.
Definition: RNG.h:90

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void moose::mtseed ( unsigned int  x)

Set the global seed or all rngs.

Seed seed for RNG.

Parameters
x
seed

Definition at line 89 of file global.cpp.

References __rng_seed__, isRNGInitialized, rng, and moose::RNG< T >::setSeed().

Referenced by pymoose_mtseed_(), and SeqSynHandler::refillSynapseOrder().

90  {
92  moose::rng.setSeed( x );
93  isRNGInitialized = true;
94  }
bool isRNGInitialized
Definition: global.cpp:34
void setSeed(const unsigned long seed)
If seed if 0 then set seed to a random number else set seed to the given number.
Definition: RNG.h:73
moose::RNG< double > rng
Definition: global.cpp:47
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
Definition: global.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string moose::pathToName ( const string &  path)

Return the name when path is given. Its behaviour is exactly the same as of basename command on unix system.

Parameters
path
Returns
name.

Definition at line 183 of file global.cpp.

184  {
185  return path.substr( path.find_last_of( '/' ) );
186  }
static char path[]
Definition: mfield.cpp:403
std::string moose::random_string ( const unsigned  size)

Generate random string of given length.

Definition at line 162 of file strutil.cpp.

163 {
164  static const char alphanum[] =
165  "0123456789"
166  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
167  "abcdefghijklmnopqrstuvwxyz";
168 
169  string s(len, '_' );
170  for (unsigned i = 0; i < len; ++i)
171  {
172  s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
173  }
174 
175  return s;
176 }
void moose::setGlobalSeed ( int  seed)

Set the seed for all random generator. When seed of a RNG is not set, this seed it used. It is set to -1 by default.

seed

Definition at line 211 of file global.cpp.

References __rng_seed__.

Referenced by testSparseMsg().

212  {
213  __rng_seed__ = seed;
214  }
unsigned long __rng_seed__
A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set...
Definition: global.cpp:45

+ Here is the caller graph for this function:

char moose::shortFinfo ( std::string  ftype)

Definition at line 87 of file types.cpp.

88 {
89  static map<string, char> finfomap;
90  if (finfomap.empty()){
91  finfomap.insert(pair<string, char>("srcFinfo", 's'));
92  finfomap.insert(pair<string, char>("destFinfo", 'd'));
93  finfomap.insert(pair<string, char>("sharedFinfo", 'x'));
94  finfomap.insert(pair<string, char>("valueFinfo", 'v'));
95  finfomap.insert(pair<string, char>("lookupFinfo", 'l'));
96  }
97  map <string, char>::iterator iter = finfomap.find(finfoType);
98  if (iter == finfomap.end()){
99  return 0;
100  }
101  return iter->second;
102 }
char moose::shortType ( string  name)

returns a single character code for a given string representation of data type. Mostly follows Python/C API's PyArg_ParseTuple convention.

Definition at line 41 of file types.cpp.

42 {
43  static map<string, char> typemap;
44  if (typemap.empty()){
45  typemap.insert(pair<string, char>("bool", 'b'));
46  typemap.insert(pair<string, char>("char", 'c'));
47  typemap.insert(pair<string, char>("int", 'i')); // python
48  typemap.insert(pair<string, char>("short", 'h')); // python
49  typemap.insert(pair<string, char>("unsigned short", 'H')); // python
50  typemap.insert(pair<string, char>("long", 'l')); // python
51  typemap.insert(pair<string, char>("long long", 'L')); // python
52  typemap.insert(pair<string, char>("unsigned int", 'I')); // python
53  typemap.insert(pair<string, char>("unsigned long", 'k')); // python
54  typemap.insert(pair<string, char>("unsigned long long", 'K')); // python
55  typemap.insert(pair<string, char>("float", 'f')); // python
56  typemap.insert(pair<string, char>("double", 'd')); // python
57  typemap.insert(pair<string, char>("string", 's')); // python
58  typemap.insert(pair<string, char>("Id", 'x')); // moose
59  typemap.insert(pair<string, char>("ObjId", 'y')); // moose
60  typemap.insert(pair<string, char>("DataId", 'z')); // moose
61  typemap.insert(pair<string, char>("vector<char>", 'C')); // moose
62  typemap.insert(pair<string, char>("vector<int>", 'v')); // moose
63  typemap.insert(pair<string, char>("vector<short>", 'w')); // moose
64  typemap.insert(pair<string, char>("vector<long>", 'M')); // moose
65  typemap.insert(pair<string, char>("vector<long long>", 'A')); // moose
66  typemap.insert(pair<string, char>("vector<unsigned long long>", 'B')); // moose
67  typemap.insert(pair<string, char>("vector<unsigned int>", 'N')); // moose
68  typemap.insert(pair<string, char>("vector<unsigned long>", 'P')); // moose
69  typemap.insert(pair<string, char>("vector<float>", 'F')); // moose
70  typemap.insert(pair<string, char>("vector<double>", 'D')); // moose
71  typemap.insert(pair<string, char>("vector<string>", 'S')); // moose
72  typemap.insert(pair<string, char>("vector<Id>", 'X')); // moose
73  typemap.insert(pair<string, char>("vector<ObjId>", 'Y')); // moose
74  typemap.insert(pair<string, char>("vector<DataId", 'Z')); //moose
75  typemap.insert(pair<string, char>("void", '_')); // moose
76  typemap.insert(pair<string, char>("vector< vector<unsigned int> >", 'T'));
77  typemap.insert(pair<string, char>("vector< vector<int> >", 'Q'));
78  typemap.insert(pair<string, char>("vector< vector<double> >", 'R'));
79  }
80  map<string, char>::iterator iter = typemap.find(name);
81  if (iter == typemap.end()){
82  return 0;
83  }
84  return iter->second;
85 }
static char name[]
Definition: mfield.cpp:401
void moose::showDebug ( const string  msg)
inline

Definition at line 229 of file print_function.hpp.

References __dump__(), and debug.

230  {
231 #ifdef DISABLE_DEBUG
232 
233 #else
235 #endif
236  }
void __dump__(string msg, serverity_level_ type=debug, bool autoFormat=true)

+ Here is the call graph for this function:

void moose::showError ( string  msg)
inline

Definition at line 238 of file print_function.hpp.

References __dump__(), and error.

Referenced by cnpy2::save_numpy().

239  {
241  }
void __dump__(string msg, serverity_level_ type=debug, bool autoFormat=true)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void moose::showInfo ( string  msg)
inline

Definition at line 219 of file print_function.hpp.

References __dump__(), and info.

220  {
222  }
void __dump__(string msg, serverity_level_ type=debug, bool autoFormat=true)

+ Here is the call graph for this function:

void moose::showWarn ( string  msg)
inline

Definition at line 224 of file print_function.hpp.

References __dump__(), and warning.

Referenced by cnpy2::change_shape_in_header(), Shell::doCreate(), Streamer::reinit(), cnpy2::save_numpy(), and Shell::warning().

225  {
227  }
void __dump__(string msg, serverity_level_ type=debug, bool autoFormat=true)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int moose::strncasecmp ( const std::string &  a,
const std::string &  b,
size_t  n 
)

Compares the two strings a and b for first n characters, ignoring the case of the characters. Return 0 in case both are same upto first n characters. Othere a non-zero value is returned. When n is smaller or equal to the size of both strings, positive is return if a is larger than b, or negative when a is smaller than b.

When n is larger than size of a or b, non-zero values is returned when a and b are not equal upto min(n, min(a.size(), b.size())) characters.

Parameters
aFirst string.
bSecond string.
nCompare up n characters/bytes.

Definition at line 148 of file strutil.cpp.

Referenced by NeuroNode::findStartNode(), and NeuroMesh::putSomaAtStart().

149 {
150  for( size_t i = 0; i < std::min(n, b.size()); ++i )
151  if( tolower(a[i]) != tolower(b[i]) )
152  return tolower(a[i]) - tolower(b[i]);
153 
154  if( b.size() < n )
155  return a.size() - b.size();
156 
157  return 0;
158 }

+ Here is the caller graph for this function:

int moose::testTrim ( )

Definition at line 90 of file strutil.cpp.

References trim().

91 {
92 
93  std::string testStrings [] =
94  {
95  " space at beginning",
96  "space at end ",
97  " space at both sides ",
98  "\ttab at beginning",
99  "tab at end\t",
100  "\ttab at both sides\t",
101  "\nnewline at beginning",
102  "newline at end\n",
103  "\nnewline at both sides\n",
104  "\n\tnewline and tab at beginning",
105  "space and tab at end \t",
106  " \rtab and return at both sides \r"
107  };
108 
109  std::string results[] =
110  {
111  "space at beginning",
112  "space at end",
113  "space at both sides",
114  "tab at beginning",
115  "tab at end",
116  "tab at both sides",
117  "newline at beginning",
118  "newline at end",
119  "newline at both sides",
120  "newline and tab at beginning",
121  "space and tab at end",
122  "tab and return at both sides"
123  };
124 
125  bool success = true;
126 
127  for (unsigned int i = 0; i < sizeof(testStrings)/sizeof(*testStrings); ++i )
128  {
129  std::string trimmed = trim(testStrings[i]);
130  success = (results[i].compare(trimmed)==0);
131 
132  cout << "'" << trimmed << "'" << (success ?" SUCCESS":"FAILED") << endl;
133  }
134  return success?1:0;
135 }
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53

+ Here is the call graph for this function:

string moose::toFilename ( const string &  path)

Replace all directory sepearator with _. This creates a filepath which can be created in current directory without any need to create parent directory.

Parameters
pathstring
Returns
filename without directory separator.

Definition at line 161 of file global.cpp.

References path.

Referenced by Table::setOutfile(), and Streamer::setOutFilepath().

162  {
163  string p = path;
164  std::replace(p.begin(), p.end(), '/', '_' );
165  std::replace(p.begin(), p.end(), '\\', '_' );
166  return p;
167  }
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

void moose::tokenize ( const std::string &  str,
const std::string &  delimiters,
std::vector< std::string > &  tokens 
)

Splits given string into tokens

Definition at line 19 of file strutil.cpp.

Referenced by ReadCell::addChannelMessage(), parseFinfoType(), ReadCell::readData(), and ReadCell::readScript().

20 {
21  // Token boundaries
22  string::size_type begin = str.find_first_not_of( delimiters, 0 );
23  string::size_type end = str.find_first_of( delimiters, begin );
24 
25  while ( string::npos != begin || string::npos != end )
26  {
27  // Found a token, add it to the vector.
28  tokens.push_back( str.substr( begin, end - begin ) );
29 
30  // Update boundaries
31  begin = str.find_first_not_of( delimiters, end );
32  end = str.find_first_of( delimiters, begin );
33  }
34 }

+ Here is the caller graph for this function:

string moose::toString ( double  x)

Convert a given value to string.

Template Parameters
T
Parameters
x
Returns
String representation

Definition at line 199 of file global.cpp.

Referenced by cnpy2::change_shape_in_header(), cnpy2::write_header(), and StreamerBase::writeToCSVFile().

200  {
201  char buffer[50];
202  sprintf(buffer, "%.17g", x );
203  return string( buffer );
204  }

+ Here is the caller graph for this function:

std::string moose::trim ( const std::string  myString,
const std::string &  delimiters = " \t\r\n" 
)

trims the leading and trailing white spaces

Definition at line 53 of file strutil.cpp.

Referenced by chopLine(), create_Id_from_path(), findModelType(), fix(), innerLoadXplot(), ReadCell::innerRead(), ReadKkit::innerRead(), Interpol2D::load(), moose_Id_init(), Func::reinit(), Function::reinit(), and testTrim().

54 {
55  if (myString.length() == 0 )
56  {
57  return myString;
58  }
59 
60  string::size_type end = myString.find_last_not_of(delimiters);
61  string::size_type begin = myString.find_first_not_of(delimiters);
62 
63  if(begin != string::npos)
64  {
65  return std::string(myString, begin, end-begin+1);
66  }
67 
68  return "";
69 }

+ Here is the caller graph for this function:

Variable Documentation

unsigned long moose::__rng_seed__ = 0

A global seed for all RNGs in moose. When moose.seed( x ) is called, this variable is set. Other's RNGs (except muparser) uses this seed to initialize them. By default it is initialized by random_device (see global.cpp).

Definition at line 45 of file global.cpp.

Referenced by getGlobalSeed(), mtseed(), GssaVoxelPools::reinit(), setGlobalSeed(), and ZombieCompartment::vReinit().

const char* const moose::DELIMITERS =" \t\r\n"
static

List of characters considered to be whitespace

Definition at line 17 of file strutil.h.

string moose::levels_[9]
static
Initial value:
= {
"TRACE", "DEBUG", "INFO", "WARNING", "FIXME" , "ERROR", "FATAL", "FAILED"
}

Definition at line 80 of file print_function.hpp.

Referenced by __dump__().

moose::RNG< double > moose::rng

Definition at line 47 of file global.cpp.

Referenced by mtrand(), ZombieCompartment::mtrand(), mtseed(), and ZombieCompartment::vReinit().