[Avida-SVN] r2880 - in development/source: analyze cpu drivers main script tools

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Oct 24 13:10:44 PDT 2008


Author: brysonda
Date: 2008-10-24 16:10:44 -0400 (Fri, 24 Oct 2008)
New Revision: 2880

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/analyze/cAnalyzeGenotype.h
   development/source/cpu/cHardwareManager.cc
   development/source/drivers/cDriverStatusConduit.cc
   development/source/drivers/cDriverStatusConduit.h
   development/source/main/cAvidaConfig.cc
   development/source/script/ASAnalyzeLib.cc
   development/source/tools/tDataEntryCommand.h
Log:
AS: World::LoadBatch

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/analyze/cAnalyze.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -959,7 +959,7 @@
   // Construct a linked list of data types that can be loaded...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(input_file.GetFormat(), output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, input_file.GetFormat(), output_list);
   bool id_inc = input_file.GetFormat().HasString("id");
   
   // Setup the genome...
@@ -1011,7 +1011,7 @@
   cString test_value = cur_string.PopWord();
   
   // Get the dynamic command to look up the stat we need.
-  tDataEntryCommand<cAnalyzeGenotype> * stat_command = GetGenotypeDataCommand(stat_name);
+  tDataEntryCommand<cAnalyzeGenotype> * stat_command = cAnalyzeGenotype::GetDataCommand(m_world, stat_name);
   
   
   // Check for various possible errors before moving on...
@@ -1963,7 +1963,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -2009,7 +2009,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -2199,7 +2199,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
   
   // check if file is already in use.
   bool file_active = m_world->GetDataFileManager().IsOpen(filename);
@@ -2228,7 +2228,7 @@
   else cout << "Detailing Batches..." << endl;
   
   // Find its associated command...
-  tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetGenotypeDataCommand(keyword);
+  tDataEntryCommand<cAnalyzeGenotype>* cur_command = cAnalyzeGenotype::GetDataCommand(m_world, keyword);
   if (!cur_command) {
     cout << "error: no data entry, unable to detail batches" << endl;
     return;
@@ -2331,7 +2331,7 @@
   // Construct a linked list of details needed...
   tList<tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator<tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cStringList(cur_string), output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, cStringList(cur_string), output_list);
   
   
   // Setup the file...
@@ -2429,7 +2429,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  LoadGenotypeDataList(cur_string, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -4697,7 +4697,7 @@
   msg.Set("There are %d column args.", arg_list.GetSize());
   m_world->GetDriver().NotifyComment(msg);
   
-  LoadGenotypeDataList(arg_list, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
   
   m_world->GetDriver().NotifyComment("Args are loaded.");
   
@@ -4959,7 +4959,7 @@
   
   cout << "There are " << arg_list.GetSize() << " column args." << endl;
   
-  LoadGenotypeDataList(arg_list, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
   
   cout << "Args are loaded." << endl;
   
@@ -5305,7 +5305,7 @@
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
   cStringList arg_list(cur_string);
-  LoadGenotypeDataList(arg_list, output_list);
+  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
   const int num_traits = output_list.GetSize();
   
   // Setup the map_inst_set with the NULL instruction
@@ -9135,51 +9135,8 @@
 
 
 
-// Find a data entry bassed on a keyword
-tDataEntryCommand<cAnalyzeGenotype>* cAnalyze::GetGenotypeDataCommand(const cString& stat_entry) 
-{
-  cString arg_list = stat_entry;
-  cString stat_name = arg_list.Pop(':');
 
-  tDataEntry<cAnalyzeGenotype>* data_entry;
-  if (m_world->GetGenotypeDEDict().Find(stat_name, data_entry)) {
-    return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, arg_list);
-  }
-  
-  cerr << "warning: Format entry \"" << stat_name << "\" not found. Best match is \""
-       << m_world->GetGenotypeDEDict().NearMatch(stat_name) << "\"." << endl;
 
-  return NULL;
-}
-
-
-// Pass in the arguments for a command and fill out the entries in list format....
-void cAnalyze::LoadGenotypeDataList(cStringList arg_list,
-                                    tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list)
-{
-  // If no args were given, load all of the stats.
-  if (arg_list.GetSize() == 0) {
-    tArray<tDataEntry<cAnalyzeGenotype>*> data_entries;
-    m_world->GetGenotypeDEDict().GetValues(data_entries);
-    for (int i = 0; i < data_entries.GetSize(); i++)
-      output_list.PushRear(new tDataEntryCommand<cAnalyzeGenotype>(data_entries[i], ""));
-  }
-  // Otherwise, load only those listed.
-  else {
-    while (arg_list.GetSize() != 0) {
-      // Setup the next entry
-      cString cur_entry = arg_list.Pop();
-      
-      tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetGenotypeDataCommand(cur_entry);
-      if (cur_command) output_list.PushRear(cur_command);
-    }
-  }
-}
-
-
-
-
-
 void cAnalyze::AddLibraryDef(const cString & name,
                              void (cAnalyze::*_fun)(cString))
 {

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/analyze/cAnalyze.h	2008-10-24 20:10:44 UTC (rev 2880)
@@ -186,9 +186,6 @@
                      const cString& cell_flags="align=center", const cString& null_text = "0", bool print_text = true);
   int CompareFlexStat(const cFlexVar& org_stat, const cFlexVar& parent_stat, int compare_type = FLEX_COMPARE_MAX);
   
-  // Deal with genotype data list (linking keywords to stats)
-  tDataEntryCommand<cAnalyzeGenotype>* GetGenotypeDataCommand(const cString & stat_entry);
-  void LoadGenotypeDataList(cStringList arg_list, tList<tDataEntryCommand<cAnalyzeGenotype> > & output_list);
   
   void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString));
   void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &));

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/analyze/cAnalyzeGenotype.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -27,6 +27,8 @@
 
 #include "cAvidaContext.h"
 #include "cCPUTestInfo.h"
+#include "cDriverManager.h"
+#include "cDriverStatusConduit.h"
 #include "cHardwareBase.h"
 #include "cHardwareManager.h"
 #include "cInstSet.h"
@@ -42,8 +44,10 @@
 
 #include "tArray.h"
 #include "tAutoRelease.h"
-#include "tDataManager.h"
+#include "tDataEntry.h"
+#include "tDataEntryCommand.h"
 
+
 #include <cmath>
 using namespace std;
 
@@ -323,6 +327,46 @@
 
 
 
+// Find a data entry bassed on a keyword
+tDataEntryCommand<cAnalyzeGenotype>* cAnalyzeGenotype::GetDataCommand(cWorld* world, const cString& cmd) 
+{
+  cString arg_list = cmd;
+  cString entry_name = arg_list.Pop(':');
+  
+  tDataEntry<cAnalyzeGenotype>* data_entry;
+  if (world->GetGenotypeDEDict().Find(entry_name, data_entry)) {
+    return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, arg_list);
+  }
+  
+  cDriverManager::Status().NotifyWarning(cStringUtil::Stringf("data entry '%s' not found, best match is '%s'", *entry_name,
+                                                              *(world->GetGenotypeDEDict().NearMatch(entry_name))));
+  
+  return NULL;
+}
+
+
+// Pass in the arguments for a command and fill out the entries in list format....
+void cAnalyzeGenotype::LoadDataCommandList(cWorld* world, cStringList arg_list,
+                                    tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list)
+{
+  if (arg_list.GetSize() == 0) {
+    // If no args were given, load all of the stats.
+    tArray<tDataEntry<cAnalyzeGenotype>*> data_entries;
+    world->GetGenotypeDEDict().GetValues(data_entries);
+    for (int i = 0; i < data_entries.GetSize(); i++)
+      output_list.PushRear(new tDataEntryCommand<cAnalyzeGenotype>(data_entries[i], ""));
+  } else {
+    while (arg_list.GetSize() != 0) {
+      tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetDataCommand(world, arg_list.Pop());
+      if (cur_command) output_list.PushRear(cur_command);
+    }
+  }
+}
+
+
+
+
+
 int cAnalyzeGenotype::CalcMaxGestation() const
 {
   return m_world->GetConfig().TEST_CPU_TIME_MOD.Get() * genome.GetSize();

Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/analyze/cAnalyzeGenotype.h	2008-10-24 20:10:44 UTC (rev 2880)
@@ -66,6 +66,7 @@
 class cTestCPU;
 class cWorld;
 template<class T> class tDataEntry;
+template<class T> class tDataEntryCommand;
 template<class T> class tDictionary;
 
 
@@ -237,6 +238,9 @@
   
   static tDictionary<tDataEntry<cAnalyzeGenotype>*>* BuildDEDict(cWorld* world);
   static void DestroyDEDict(tDictionary<tDataEntry<cAnalyzeGenotype>*>* dedict);
+  
+  static tDataEntryCommand<cAnalyzeGenotype>* GetDataCommand(cWorld* world, const cString& cmd);
+  static void LoadDataCommandList(cWorld* world, cStringList arg_list, tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list);
 
   const cStringList & GetSpecialArgs() { return special_args; }
   void SetSpecialArgs(const cStringList & _args) { special_args = _args; }

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/cpu/cHardwareManager.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -68,7 +68,7 @@
 			default_filename = cHardwareGX::GetDefaultInstFilename();
 			break;      
 		default:
-      cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
+      cDriverManager::Status().SignalError("Unknown/Unsupported HARDWARE_TYPE specified", -1);
   }
 
   if (filename == "" || filename == "-") {
@@ -106,7 +106,7 @@
       hw = new cHardwareGX(m_world, in_org, m_inst_set);
       break;
     default:
-      cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
+      cDriverManager::Status().SignalError("Unknown/Unsupported HARDWARE_TYPE specified", -1);
       break;
   }
   

Modified: development/source/drivers/cDriverStatusConduit.cc
===================================================================
--- development/source/drivers/cDriverStatusConduit.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/drivers/cDriverStatusConduit.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -33,17 +33,15 @@
 using namespace std;
 
 
-void cDriverStatusConduit::SignalError(const cString& msg)
+void cDriverStatusConduit::SignalError(const cString& msg, int exit_code)
 {
   cerr << "error: " << msg << endl;
+  if (exit_code) {
+    cerr << "exiting..." << endl;
+    Avida::Exit(exit_code);
+  }
 }
 
-void cDriverStatusConduit::SignalFatalError(int exit_code, const cString& msg)
-{
-  cerr << "error: " << msg << endl << "exiting..." << endl;
-  Avida::Exit(exit_code);
-}
-
 void cDriverStatusConduit::NotifyWarning(const cString& msg)
 {
   cout << "warning: " << msg << endl;

Modified: development/source/drivers/cDriverStatusConduit.h
===================================================================
--- development/source/drivers/cDriverStatusConduit.h	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/drivers/cDriverStatusConduit.h	2008-10-24 20:10:44 UTC (rev 2880)
@@ -39,8 +39,7 @@
   virtual ~cDriverStatusConduit() { ; }
   
   // Signals
-  virtual void SignalError(const cString& msg);
-  virtual void SignalFatalError(int exit_code, const cString& msg);
+  virtual void SignalError(const cString& msg, int exit_code = 0);
   
   // Notifications
   virtual void NotifyWarning(const cString& msg);

Modified: development/source/main/cAvidaConfig.cc
===================================================================
--- development/source/main/cAvidaConfig.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/main/cAvidaConfig.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -73,10 +73,10 @@
     while ((errstr = err_it.Next())) cDriverManager::Status().SignalError(*errstr);
     if (init_file.WasFound()) {
       // exit the program if the requested configuration was found but could not be loaded
-      cDriverManager::Status().SignalFatalError(-1, cString("unable to open configuration file '") + filename + "'");
+      cDriverManager::Status().SignalError(cString("unable to open configuration file '") + filename + "'", -1);
     } else if (crash_if_not_found) {
       // exit the program if the requested configuration file is not found
-      cDriverManager::Status().SignalFatalError(-1, cString("configuration file '") + filename + "' not found"); 
+      cDriverManager::Status().SignalError(cString("configuration file '") + filename + "' not found", -1); 
     } else {
       // If we failed to open the config file, try creating it.
       cDriverManager::Status().NotifyWarning(

Modified: development/source/script/ASAnalyzeLib.cc
===================================================================
--- development/source/script/ASAnalyzeLib.cc	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/script/ASAnalyzeLib.cc	2008-10-24 20:10:44 UTC (rev 2880)
@@ -36,10 +36,14 @@
 #include "cDriverStatusConduit.h"
 #include "cGenome.h"
 #include "cGenomeUtil.h"
+#include "cGenotypeBatch.h"
 #include "cHardwareManager.h"
+#include "cInitFile.h"
 #include "cWorld.h"
 
+#include "tDataEntryCommand.h"
 
+
 class cWorld;
 
 
@@ -85,7 +89,71 @@
     return new cAnalyzeGenotype(world, seq, world->GetHardwareManager().GetInstSet());
   }
   
+  cGenotypeBatch* LoadBatchWithInstSet(cWorld* world, const cString& filename, cInstSet* inst_set)
+  {
+    cDriverStatusConduit& conduit = cDriverManager::Status();
+    conduit.NotifyComment(cString("Loading: ") + filename);
+    
+    cInitFile input_file(filename);
+    if (!input_file.WasOpened()) {
+      tConstListIterator<cString> err_it(input_file.GetErrors());
+      const cString* errstr = NULL;
+      while ((errstr = err_it.Next()))  conduit.SignalError(*errstr);
+      cString failstr(cStringUtil::Stringf("unable to load file: %s", *filename));
+      conduit.SignalError(failstr, 1);
+    }
+    
+    const cString filetype = input_file.GetFiletype();
+    if (filetype != "genotype_data") {
+      conduit.SignalError(cStringUtil::Stringf("unable to load files of type '%s'", *filetype), 1);;
+    }
+    
+    if (world->GetVerbosity() >= VERBOSE_ON) {
+      conduit.NotifyComment(cStringUtil::Stringf("Loading file of type: %s", *filetype));
+    }
+    
+    
+    // Construct a linked list of data types that can be loaded...
+    tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+    tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+    cAnalyzeGenotype::LoadDataCommandList(world, input_file.GetFormat(), output_list);
+    bool id_inc = input_file.GetFormat().HasString("id");
+    
+    // Setup the genome...
+    cGenome default_genome(1);
+    int load_count = 0;
+    cGenotypeBatch* batch = new cGenotypeBatch;
+    
+    for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+      cString cur_line = input_file.GetLine(line_id);
+      
+      cAnalyzeGenotype* genotype = new cAnalyzeGenotype(world, default_genome, *inst_set);
+      
+      output_it.Reset();
+      tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
+      while ((data_command = output_it.Next())) data_command->SetValue(genotype, cur_line.PopWord());
+      
+      // Give this genotype a name.  Base it on the ID if possible.
+      if (id_inc == false) genotype->SetName(cStringUtil::Stringf("org-%d", load_count++));
+      else genotype->SetName(cStringUtil::Stringf("org-%d", genotype->GetID()));
+      
+      // Add this genotype to the proper batch.
+      batch->List().PushRear(genotype);
+    }
+    
+    // Adjust the flags on this batch
+    batch->SetLineage(false);
+    batch->SetAligned(false);
+    
+    return batch;
+  }
   
+  cGenotypeBatch* LoadBatch(cWorld* world, const cString& filename)
+  {
+    return LoadBatchWithInstSet(world, filename, &world->GetHardwareManager().GetInstSet());
+  }
+  
+  
 };
 
 

Modified: development/source/tools/tDataEntryCommand.h
===================================================================
--- development/source/tools/tDataEntryCommand.h	2008-10-24 18:19:35 UTC (rev 2879)
+++ development/source/tools/tDataEntryCommand.h	2008-10-24 20:10:44 UTC (rev 2880)
@@ -29,7 +29,7 @@
 #include <iostream>
 
 #ifndef cFlexVar_h
-#define "cFlexVar.h"
+#include "cFlexVar.h"
 #endif
 
 #ifndef cStringList_h




More information about the Avida-cvs mailing list