Casting SiteSet into appropriate type

+1 vote

I am writing a generic code that may allow for different SiteSet types, such as different values of spin. My code works fine, unless I save the SiteSet to memory, and then try to load it. As an example, I may have something like

SiteSet sites;
sites = SpinHalf(N);

Since sites is actually of type SpinHalf at run time, there is no issue. However, If I then try to save and then load this variable via

write(f, sites);

sites is now a basic site set, and thus loses operations such as 'op'. Is there a simple way to get around this, so I can keep my code general? Or do I have to, for example, write different code for each type of SiteSet?

Thanks,
Nick

+1 vote
answered by (470 points)

Actually I found a work around, so this is closed to me.

For those that are curious, here is my code

    auto sType = args->getString("SiteSet");
if     (sType == "SpinHalf"){ auto rSites = SpinHalf(args->getInt("N")); rSites.read(f); sites = rSites; }
else if(sType == "SpinOne") { auto rSites = SpinOne(args->getInt("N")); rSites.read(f); sites = rSites;  }
else if(sType == "SpinTwo") { auto rSites = SpinTwo(args->getInt("N")); rSites.read(f); sites = rSites;  }  }


so rSites is cast into the specific type needed, and then I read the SiteSet of interest into rSites, and then I just set sites = rSites.