[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GT] SVN Commit r623 - trunk/GT



GeniusTrader SVN wrote:
Author: thomas
Date: 2008-05-03 03:36:52 +0200 (Sat, 03 May 2008)
New Revision: 623

Modified:
   trunk/GT/Conf.pm
   trunk/GT/Tools.pm
Log:
Correct alias resolution per RAS suggestion. Avoid repeated loading of object aliases. Remove hard-wired paths for object alias files.

Modified: trunk/GT/Conf.pm
===================================================================
--- trunk/GT/Conf.pm	2008-04-26 22:04:45 UTC (rev 622)
+++ trunk/GT/Conf.pm	2008-05-03 01:36:52 UTC (rev 623)
@@ -98,6 +98,28 @@
 	$conf{lc($key)} = $val;
     }
     close FILE;
+
+    # Load the various definition of aliases
+ + foreach my $kind ("Signals", "Indicators", "Systems", "CloseStrategy", + "MoneyManagement", "TradeFilters", "OrderFactory",
+                      "Analyzers")
+    {
+        foreach my $file (GT::Conf::_get_home_path()."/.gt/aliases/".lc($kind),
+         GT::Conf::get("Path::Aliases::$kind"))
+	{
+	    next unless defined $file;
+	    next if not -e $file;
+            open(ALIAS, "<", "$file") || die "Can't open $file : $!\n";
+	    while (defined($_=<ALIAS>)) {
+		if (/^\s*(\S+)\s+(.*)$/) {
+		    GT::Conf::default("Aliases::$kind\::$1", $2);
+		}
+	    }
+	    close ALIAS;
+	}
+    }
+
 }
=item C<< GT::Conf::clear() >>

Modified: trunk/GT/Tools.pm
===================================================================
--- trunk/GT/Tools.pm	2008-04-26 22:04:45 UTC (rev 622)
+++ trunk/GT/Tools.pm	2008-05-03 01:36:52 UTC (rev 623)
@@ -182,7 +182,7 @@
          .  "\nkey looked for was \"Aliases::Global::$name\"\n";
     }
     # The alias content may list another alias ...
-    while ($sysname !~ /^(I|Indicators|SY|Systems|S|Signals|CS|CloseStrategy|MM|MoneyManagement|TF|TradeFilters|OF|OrderFactory|A|Analyzers|PortfolioEvaluation)/i) {
+    while ($sysname !~ /:/) {
 	$sysname = resolve_alias($sysname);
     }
     my $n = 1;
@@ -212,11 +212,21 @@
 Return the complete description of the object designed by "alias". @param
 is the array of parameters as returned by GT::ArgsTree::parse_args().
-Object aliases can be defined in global files
-(/usr/share/geniustrader/aliases/indicators for example) or in custom
-files (~/.gt/aliases/indicators) or in the standard configuration file
-with entries like this one :
+Object aliases can be defined in global files (as defined in the option
+Path::Aliases::<object_kind>), for each kind of object (e.g., Signals, +Indicators, etc.), or in user-specific files (~/.gt/aliases/<object_kind>). +Such aliases are defined via the syntax
+  <alias_name>   <definition>
+
+For example
+  MyMean  { I:Generic:Eval ( #1 + #2 ) / 2 }
+
+An object alias can also be defined in the option file with the syntax
+  Aliases::<object_kind>::<alias_name>    <definition>
+
+For example:
+
  Aliases::Indicators::MyMean  { I:Generic:Eval ( #1 + #2 ) / 2 }
Then you can use this alias in any other place where you could have used
@@ -231,34 +241,6 @@
 sub resolve_object_alias {
     my ($alias, @param) = (@_);
- # Load the various definition of aliases
-    GT::Conf::default('Path::Aliases::Signals', '/usr/share/geniustrader/aliases/signals');
-    GT::Conf::default('Path::Aliases::Indicators', '/usr/share/geniustrader/aliases/indicators');
-    GT::Conf::default('Path::Aliases::Systems', '/usr/share/geniustrader/aliases/systems');
-    GT::Conf::default('Path::Aliases::CloseStrategy', '/usr/share/geniustrader/aliases/closestrategy');
-    GT::Conf::default('Path::Aliases::MoneyManagement', '/usr/share/geniustrader/aliases/moneymanagement');
-    GT::Conf::default('Path::Aliases::TradeFilters', '/usr/share/geniustrader/aliases/tradefilters');
-    GT::Conf::default('Path::Aliases::OrderFactory', '/usr/share/geniustrader/aliases/orderfactory');
-    GT::Conf::default('Path::Aliases::Analyzers', '/usr/share/geniustrader/aliases/analyzers');
- - foreach my $kind ("Signals", "Indicators", "Systems", "CloseStrategy", - "MoneyManagement", "TradeFilters", "OrderFactory",
-                      "Analyzers")
-    {
-        foreach my $file (GT::Conf::_get_home_path()."/.gt/aliases/".lc($kind),
-         GT::Conf::get("Path::Aliases::$kind"))
-	{
-	    next if not -e $file;
-            open(ALIAS, "<", "$file") || die "Can't open $file : $!\n";
-	    while (defined($_=<ALIAS>)) {
-		if (/^\s*(\S+)\s+(.*)$/) {
-		    GT::Conf::default("Aliases::$kind\::$1", $2);
-		}
-	    }
-	    close ALIAS;
-	}
-    }
- # Lookup the alias
     my $def = GT::Conf::get("Aliases\::$alias");


thomas

this change materially changes method GT::Conf::load([ $file ]) and
i'm not so sure for the better.

while i agree the change to loading the object alias files only once
is much better, doing it this way isn't, at least in my way of thinking.

i understand that system aliases are loaded via the $HOME/.gt/options
file and by extension the object alias files are logically loaded then
too, but the GT::Conf::load method never had that side effect before.

taking this a bit further, if an app (script) were to be developed that
expressly wanted to load a file other than $HOME/.gt/options from someplace
other than $HOME/.gt, by extension i'd expect it might want to get alias
files from that other someplace as well. this change doesn't support that
altered directory path.

even though it requires another method, say load_object_aliases() and
a call to it added (some how) in every script (application) i think
that would be the preferred solution.


an alternative, one that doesn't support an alternate directory (other
than the default GT::Conf::_get_home_path()."/.gt/aliases/", would be
a semaphore on GT::Tools::resolve_object_alias that inhibits multiple
loads. i think what would be simpler and have the same intent.

my $alias_loaded = 0;    # semaphore to inhibit multi alias loadings
sub resolve_object_alias {
   my ($alias, @param) = (@_);
   goto LOOKUP unless $alias_loaded == 0; # skip alias loading if already done
   ++$alias_loaded;
....
LOOKUP:
   # Lookup the alias

ras

ps -- GT::Tools::resolve_object_alias (isn't) wasn't called in the
unchanged version unless an object alias is detected via the "@" marker.
the "@" marker proposed removal would require GT::Tools::resolve_object_alias
to be called for every call to create_standard_object.

also note that GT::ArgsTree::parse_args (at least the ones i've got)
resolve object aliases using the "@" marker as well, that wasn't changed
in the proposed object_alias.patch

i'm still not clear why you dislike the "@" marker for object_aliases
other than they are inconsistent with system_aliases. but anyone that
has any defined and in use would likely be annoyed at any change made
to them, plus the work required to undocument the "@" marker would be
necessary, but very likely ignored.

-- ras