Index: /snovis/head/applications/snovis_session.cc
===================================================================
--- /snovis/head/applications/snovis_session.cc	(revision 84)
+++ /snovis/head/applications/snovis_session.cc	(revision 85)
@@ -3,20 +3,12 @@
  */
 
-#include <snova/snova_const.hh>
-#include <snova/geometry2.hh>         // Geometry definition
-#include <snova/physics.hh>           // Physical proceses to consider
-#include <snova/generator.hh>         // Initial particles generator
-#include <snova/run.hh>               // User actions per run basis
-#include <snova/event.hh>             // User actions per event basis
-#include <snova/tracking.hh>          // User actions per track basis
-#include <snova/stacking.hh>          // User actions related with tracks stacking
-#include <snova/stepping.hh>          // User actions per step basis
-#include <snova/stepping_verbose.hh>  // Information dump per step basis
+#include <snova/snova_mgr.hh>
 
-#include <G4RunManager.hh>  // Program manager
-#include <G4UImanager.hh>   // User Interface manager
+#include <SNvertex/base_VG_factory.h>
+#include <SNvertex/CALO_basic_VG.h>
+#include <SNvertex/source_simple_VG.h>
 
-#include <bhep/bhep_svc.h>
-#include <bhep/sreader.h>
+#include <G4Runmanager.hh>
+#include <G4UImanager.hh>
 
 // G4Lab :
@@ -25,4 +17,31 @@
 
 using namespace snova;
+
+namespace snovis {
+  class mgr : public snova::snova_mgr {
+  public:
+    mgr(){}
+    virtual ~mgr(){}
+  public:
+    void run_sim(int argc , char** argv) {
+      G4UImanager* UI = G4UImanager::GetUIpointer();  
+
+      UI->ApplyCommand("/control/shell cp currentEvent.rndm currentRun.rndm");
+      UI->ApplyCommand("/random/setSavingFlag true");
+      UI->ApplyCommand("/random/resetEngineFrom currentRun.rndm");
+      UI->ApplyCommand("/tracking/storeTrajectory 1");
+      UI->ApplyCommand("/tracking/verbose 1");
+  
+      //G4RunManager* runManager = __runManager;
+      G4RunManager* runManager = G4RunManager::GetRunManager();
+
+      std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX
+      G4UIsession* session = 
+        new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX
+      session->SessionStart();
+      delete session;
+    }
+  };
+}
 
 int main( int argc , char** argv ) 
@@ -39,148 +58,63 @@
     return 1;
   }
-  std::string params_filename = SNOVISROOT+"/scripts/snova.par";
-  G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom";
 
-  // create a generic store:
-  bhep::gstore store;
-  G4cout << G4endl << "***** Reading parameters from '" 
-	 << params_filename << "' file ..." 
-	 << G4endl << G4endl;
+  int error_code=EXIT_SUCCESS;
+  try {
 
-  // and a reader:
-  bhep::sreader reader(store);
-  reader.file(params_filename);
-  reader.info_level(NORMAL);
-  reader.group("GLOBAL");
-  reader.read();
+    std::cout << "Hello, this is a sample program for class 'snova_mgr'!" << std::endl; 
+  
+    bool        debug           = false;
+    //std::string params_filename = snova::constants::DEF_PARAMS_FILENAME;
+    std::string params_filename = SNOVISROOT+"/scripts/snova.par";
+    //G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom";
+    std::string G4_macro        = "";
+    bool        visual_mode     = false;
+    
+    // A snova manager:
+    snovis::mgr my_snova_mgr;
 
-  G4String sim_verbosity = store.fetch_sstore("simulation_verbosity");
-  G4cout << "***** Simulation verbosity set to: " << sim_verbosity << G4endl;
+    // Configure some properties of the snova manager:
+    my_snova_mgr.set_debug(debug);                     // debug verbosity
+    my_snova_mgr.set_params_filename(params_filename); // the main simulation configuration file
+    my_snova_mgr.set_visual_mode(visual_mode);         // use X11 display
+    my_snova_mgr.set_G4_macro(G4_macro);               // run G4 macro
 
-  G4String G4Tracking_verbosity = store.fetch_sstore("G4Tracking_verbosity");
-  G4cout << "***** G4 Tracking verbosity set to: " << G4Tracking_verbosity << G4endl;
+    // Use a dedicated vertex generator factory:
+    snemo::base_VG_factory my_VG_factory;
+    my_VG_factory.add("CALO_basic",    snemo::CALO_basic_VG::new_CALO_basic_VG );
+    my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG );
+    // <here you may add more functors in the factory internal map... >
+    //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET!
 
-  G4String dst_fname = store.fetch_sstore("dst_fname");
-  G4cout << "***** DST output file name:" << dst_fname << G4endl;
+    my_VG_factory.init();
+    if( debug ) my_VG_factory.dump(std::cerr);
+    my_snova_mgr.set_VG_factory(my_VG_factory);
 
-  G4String gen_source = store.fetch_sstore("gen_source");
-  G4double gen_min_E  = store.fetch_dstore("gen_min_E");
-  G4double gen_max_E  = store.fetch_dstore("gen_max_E");
-  G4int    num_events = store.fetch_istore("num_events");
-  G4String part_name  = store.fetch_sstore("part_name");
+    // Build the guts of the simulation process within the snova manager:
+    std::cerr << "prog_snova2: debug: " 
+	      << "Build the guts" << std::endl; 
+    my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!)
 
-  if (gen_source == "random") {
-    G4cout << "***** Generator data will follow a flat random distribution in: " << G4endl;
-    G4cout << "*****           Ekin  (Mev): (" << gen_min_E << " , " 
-	   << gen_max_E << ")" << G4endl;
-    G4cout << "*****           Theta (deg): (0 , 90)" <<  G4endl;
-    G4cout << "*****           Phi   (deg): (0 , 180)" <<  G4endl;
-    G4cout << "***** Initial events: " << num_events << " " << part_name << G4endl;
+    // Run the simulation:
+    std::cerr << "prog_snova2: debug: " 
+	      << "Run the simulation" << std::endl; 
+    my_snova_mgr.run_sim(argc,argv);
+
+    // Clean the snova manager
+    std::cerr << "prog_snova2: debug: " 
+	      << "Clean the snova manager" << std::endl; 
+    my_snova_mgr.reset(); // not mandatory for we do it in the d-tor.
+
+    std::cerr << "prog_snova2: debug: " 
+	      << "Done" << std::endl; 
   }
-  else {
-    G4cout << "***** Generator data source read from:" << gen_source << G4endl;
-    G4cout << "***** Initial events: " << num_events << " pairs of " << part_name << G4endl;
+  catch(std::exception & x){
+    std::cerr << "prog_snova2: error: " << x.what() << std::endl; 
+    error_code=EXIT_FAILURE;
   }
-
-  if(geom_filename=="") 
-    geom_filename = store.fetch_sstore("geom_file");
-
-  //G4String geom_filename = store.fetch_sstore("geom_file");
-  G4cout << "***** Reading geometry parameters from: '" 
-	 << geom_filename << "'" << G4endl;
-  G4cout << "***** Reading physics parameters from:  '" 
-	 << params_filename << "'" << G4endl;
-  
-  G4cout << "**********************************************************"
-	 << G4endl << G4endl;
-  
-  // The ihep::event service is generated. This server must be instantiated
-  // wherever you want to access all the info.
-  bhep::bhep_svc bsvc;  
-
-  // my Verbose output class:
-  G4VSteppingVerbose* verbosity = new stepping_verbose;
-  G4VSteppingVerbose::SetInstance(verbosity);
-
-  // Run manager:
-  G4RunManager* runManager = new G4RunManager;
-
-  // UserInitialization classes (mandatory)
-
-  // geometry
-  geometry* geom = new geometry(geom_filename,params_filename);
-  geom->set_info_level(sim_verbosity);
-  runManager->SetUserInitialization(geom);
-
-  // physics
-  physics* phys = new physics(params_filename);
-  phys->set_info_level(sim_verbosity);
-  runManager->SetUserInitialization(phys);
-
-  // UserAction classes
-  // generator
-  generator* my_gen = new generator( part_name , 
-				     gen_source , 
-				     gen_min_E , 
-				     gen_max_E , 
-				     geom->get_geom_mgr() , 
-				     params_filename );
-  my_gen->set_info_level(sim_verbosity);
-  runManager->SetUserAction(my_gen);
-
-  // run
-  run* my_run = new run(dst_fname);
-  runManager->SetUserAction(my_run);  
-
-  //event
-  snova::event* my_evt = new snova::event(part_name, dst_fname);
-  my_evt->set_info_level(sim_verbosity);
-  runManager->SetUserAction(my_evt);
-
-  // track
-  tracking* my_tracking = new tracking();
-  my_tracking->set_info_level(sim_verbosity);
-  runManager->SetUserAction(my_tracking);
-
-  // step
-  stepping* my_stepping = new stepping(part_name);
-  my_stepping->set_info_level(sim_verbosity);
-  runManager->SetUserAction(my_stepping);
-
-  // stack
-  stacking* my_stacking = new stacking(part_name);
-  my_stacking->set_info_level(sim_verbosity);
-  runManager->SetUserAction(my_stacking);
-
-
-  //Initialize G4 kernel
-  runManager->Initialize();
-
-    G4UImanager * UI = G4UImanager::GetUIpointer();  
-
-    G4String command = "/control/shell cp currentEvent.rndm currentRun.rndm";
-    UI->ApplyCommand(command);
-    command = "/random/setSavingFlag true";
-    UI->ApplyCommand(command);
-    command = "/random/resetEngineFrom currentRun.rndm";
-    UI->ApplyCommand(command);
-
-    command = "/tracking/verbose ";
-    UI->ApplyCommand(command + G4Tracking_verbosity);
-  
-    command = "/tracking/storeTrajectory 1";
-    UI->ApplyCommand(command);
-  
-  std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX
-  G4UIsession* session = new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX
-
-  session->SessionStart();
-  delete session;
-  
-  delete runManager;
-  delete verbosity;
-  
-  return 0;
+  catch(...){
+    std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl; 
+    error_code=EXIT_FAILURE;
+  }
+  return error_code;
 }
-
-// end of prog_snova.cc
