Changeset 354859


Ignore:
Timestamp:
Feb 16, 2010, 5:26:59 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
7dad10, b1d8092
Parents:
7a1ce5
Message:

Moved control of molecules and periode to World.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    r7a1ce5 r354859  
    99
    1010#include "atom.hpp"
     11#include "molecule.hpp"
     12#include "periodentafel.hpp"
    1113#include "Descriptors/AtomDescriptor.hpp"
    1214
     
    1416
    1517/******************************* getter and setter ************************/
    16 periodentafel* World::getPeriode(){
     18periodentafel *&World::getPeriode(){
    1719  return periode;
    1820}
     
    2628}
    2729
     30int World::numAtoms(){
     31  return atoms.size();
     32}
     33
     34int World::numMolecules(){
     35  return molecules_deprecated->ListOfMolecules.size();
     36}
     37
     38molecule* World::createMolecule(){
     39  OBSERVE;
     40  molecule *mol = NULL;
     41  mol = new molecule(periode);
     42  molecules_deprecated->insert(mol);
     43  molecules.insert(mol);
     44  mol->signOn(this);
     45  return mol;
     46}
     47
     48
    2849/******************************* Singleton Stuff **************************/
    2950
     
    3556
    3657World::World() :
    37     dummyId(0)
     58    dummyId(0),
     59    periode(new periodentafel),
     60    molecules_deprecated(new MoleculeListClass)
    3861{}
    3962
    4063World::~World()
    41 {}
     64{
     65  delete periode;
     66}
    4267
    4368World* World::get(){
     
    5176
    5277void World::destroy(){
     78  // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
     79  theWorld->destroyLegacy();
     80  //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
     81
    5382  // boost supports RAII-Style locking, so we don't need to unlock
    5483  boost::mutex::scoped_lock guard(worldLock);
     
    5887
    5988World* World::reset(){
     89  // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
     90  theWorld->destroyLegacy();
     91  //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
     92
    6093  World* oldWorld = 0;
    6194  {
     
    81114/******************************* deprecated Legacy Stuff ***********************/
    82115
    83 MoleculeListClass *World::getMolecules() {
    84   return molecules;
     116MoleculeListClass *&World::getMolecules() {
     117  return molecules_deprecated;
    85118}
    86119
     
    91124}
    92125
     126void World::destroyLegacy(){
     127  //delete molecules_deprecated;
     128}
     129
    93130void World::unregisterAtom(atom *theAtom){
    94131  OBSERVE;
  • src/World.hpp

    r7a1ce5 r354859  
    1212#include <map>
    1313#include <vector>
     14#include <set>
    1415
    1516#include "Patterns/Observer.hpp"
     
    2021class MoleculeListClass;
    2122class atom;
     23class molecule;
    2224class AtomDescriptor;
    2325class AtomDescriptor_impl;
     
    2931
    3032  /***** getter and setter *****/
    31   periodentafel* getPeriode();
     33  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
     34  periodentafel *&getPeriode();
    3235  atom* getAtom(AtomDescriptor descriptor);
    3336  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     37  int numAtoms();
     38  int numMolecules();
     39
     40  /***** Methods to work with the World *****/
     41  molecule *createMolecule();
    3442private:
    3543  periodentafel *periode;
    3644  std::map<int,atom*> atoms;
     45  std::set<molecule*> molecules;
    3746
    3847
     
    5766   *****/
    5867public:
    59   MoleculeListClass *getMolecules();
     68  MoleculeListClass *&getMolecules();
    6069
    6170  // functions used for the WorldContent template mechanism
     
    6372  void unregisterAtom(atom *theAtom);
    6473private:
    65   MoleculeListClass *molecules;
     74  // this function cleans up anything that cannot be cleaned while the lock is active
     75  // at a later point all these cleanups have to be moved to the World Class so the deadlock and
     76  // race condition can both be avoided.
     77  void destroyLegacy();
     78
     79  MoleculeListClass *molecules_deprecated;
    6680
    6781  // this is needed to assign unique IDs to atoms... so far
  • src/builder.cpp

    r7a1ce5 r354859  
    7676#include "Actions/MethodAction.hpp"
    7777#include "Actions/small_actions.hpp"
     78#include "World.hpp"
    7879#include "version.h"
    7980
     
    21642165/********************************************** Main routine **************************************/
    21652166
     2167void cleanUp(config *configuration){
     2168  World::destroy();
     2169  delete(configuration);
     2170  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     2171    << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
     2172  Log() << Verbose(0) <<  "Remaining non-freed memory: "
     2173    << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
     2174  MemoryUsageObserver::purgeInstance();
     2175  logger::purgeInstance();
     2176  errorLogger::purgeInstance();
     2177  UIFactory::purgeInstance();
     2178  ActionRegistry::purgeRegistry();
     2179}
     2180
    21662181int main(int argc, char **argv)
    21672182{
    2168   periodentafel *periode = new periodentafel;
    2169     MoleculeListClass *molecules = new MoleculeListClass;
    21702183    molecule *mol = NULL;
    21712184    config *configuration = new config;
     
    21782191    setVerbosity(0);
    21792192    /* structure of ParseCommandLineOptions will be refactored later */
    2180     j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);
     2193    j = ParseCommandLineOptions(argc, argv,  World::get()->getMolecules(), World::get()->getPeriode(), *configuration, ConfigFileName);
    21812194    switch (j){
    21822195        case 255:
    21832196        case 2:
    21842197        case 1:
    2185             delete (molecules);
    2186             delete (periode);
    2187             delete (configuration);
    2188             Log() << Verbose(0) << "Maximum of allocated memory: " << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2189             Log() << Verbose(0) << "Remaining non-freed memory: " << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2190             MemoryUsageObserver::getInstance()->purgeInstance();
    2191             logger::purgeInstance();
    2192             errorLogger::purgeInstance();
     2198            cleanUp(configuration);
    21932199            return (j == 1 ? 0 : j);
    21942200        default:
    21952201            break;
    21962202    }
    2197     if(molecules->ListOfMolecules.size() == 0){
    2198         mol = new molecule(periode);
     2203    if(World::get()->numMolecules() == 0){
     2204        mol = World::get()->createMolecule();
    21992205        if(mol->cell_size[0] == 0.){
    22002206            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
     
    22042210            }
    22052211        }
    2206 
    22072212        mol->ActiveFlag = true;
    2208         molecules->insert(mol);
    22092213    }
    22102214
     
    22182222
    22192223      UIFactory::makeUserInterface(UIFactory::Text);
    2220       MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,molecules, configuration, periode, ConfigFileName);
     2224      MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,World::get()->getMolecules(), configuration, World::get()->getPeriode(), ConfigFileName);
    22212225      mainWindow->display();
    22222226      delete mainWindow;
    22232227    }
    22242228
    2225     if(periode->StorePeriodentafel(configuration->databasepath))
     2229    if(World::get()->getPeriode()->StorePeriodentafel(configuration->databasepath))
    22262230        Log() << Verbose(0) << "Saving of elements.db successful." << endl;
    22272231
     
    22292233        Log() << Verbose(0) << "Saving of elements.db failed." << endl;
    22302234
    2231     delete (molecules);
    2232     delete(periode);
    2233   delete(configuration);
    2234 
    2235 
    2236 
    2237   Log() << Verbose(0) <<  "Maximum of allocated memory: "
    2238     << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2239   Log() << Verbose(0) <<  "Remaining non-freed memory: "
    2240     << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2241   MemoryUsageObserver::purgeInstance();
    2242   logger::purgeInstance();
    2243   errorLogger::purgeInstance();
    2244   UIFactory::purgeInstance();
    2245   ActionRegistry::purgeRegistry();
     2235  cleanUp(configuration);
    22462236  return (0);
    22472237}
Note: See TracChangeset for help on using the changeset viewer.