20 #include <boost/date_time.hpp>
22 #include "ObjCryst/ObjCryst/Undo.h"
36 mTime = boost::posix_time::second_clock::local_time();
40 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
42 (*pos)->XMLOutput(ss,0);
43 mvpCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
48 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
50 (*pos)->XMLOutput(ss,0);
51 mvpDiffractionDataSingleCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
54 for(std::vector<PowderPattern*>::const_iterator pos=gPowderPatternRegistry.begin();pos!=gPowderPatternRegistry.end();++pos)
56 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
58 (*pos)->XMLOutput(ss,0);
59 mvpPowderPatternXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
64 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
66 (*pos)->XMLOutput(ss,0);
67 mvpOptimizationObjXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
74 mTime = boost::posix_time::second_clock::local_time();
78 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(&old): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
79 std::map<Crystal*, boost::shared_ptr<std::string> >::const_iterator pos2 = old.mvpCrystalXML.find(*pos);
80 if(pos2 != old.mvpCrystalXML.end())
82 if((*pos)->GetClockMaster() <= old.
GetClock())
83 mvpCrystalXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
87 (*pos)->XMLOutput(ss,0);
88 if(ss.str() == *(pos2->second))
89 mvpCrystalXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
91 mvpCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
97 (*pos)->XMLOutput(ss,0);
98 mvpCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
104 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(&old): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
105 std::map<DiffractionDataSingleCrystal*, boost::shared_ptr<std::string> >::const_iterator pos2 = old.mvpDiffractionDataSingleCrystalXML.find(*pos);
106 if(pos2 != old.mvpDiffractionDataSingleCrystalXML.end())
108 if((*pos)->GetClockMaster() <= old.
GetClock())
109 mvpDiffractionDataSingleCrystalXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
113 (*pos)->XMLOutput(ss,0);
114 if(ss.str() == *(pos2->second))
115 mvpDiffractionDataSingleCrystalXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
117 mvpDiffractionDataSingleCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
123 (*pos)->XMLOutput(ss,0);
124 mvpDiffractionDataSingleCrystalXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
128 for(std::vector<PowderPattern*>::const_iterator pos=gPowderPatternRegistry.begin();pos!=gPowderPatternRegistry.end();++pos)
130 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(&old): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
131 std::map<PowderPattern*, boost::shared_ptr<std::string> >::const_iterator pos2 = old.mvpPowderPatternXML.find(*pos);
132 if(pos2 != old.mvpPowderPatternXML.end())
134 if((*pos)->GetClockMaster() <= old.
GetClock())
135 mvpPowderPatternXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
139 (*pos)->XMLOutput(ss,0);
140 if(ss.str() == *(pos2->second))
141 mvpPowderPatternXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
143 mvpPowderPatternXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
149 (*pos)->XMLOutput(ss,0);
150 mvpPowderPatternXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
156 VFN_DEBUG_MESSAGE(
"XMLConfig::XMLConfig(&old): storing "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
157 std::map<OptimizationObj*, boost::shared_ptr<std::string> >::const_iterator pos2 = old.mvpOptimizationObjXML.find(*pos);
158 if(pos2 != old.mvpOptimizationObjXML.end())
161 (*pos)->XMLOutput(ss,0);
162 if(ss.str() == *(pos2->second))
163 mvpOptimizationObjXML[*pos] = boost::shared_ptr<std::string>(pos2->second);
165 mvpOptimizationObjXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
170 (*pos)->XMLOutput(ss,0);
171 mvpOptimizationObjXML[*pos] = boost::shared_ptr<std::string>(
new std::string(ss.str()));
179 VFN_DEBUG_ENTRY(
"XMLConfig::Restore()", 10)
180 std::list<RefinableObj*> vpRefObjUpdated;
181 std::list<OptimizationObj*> vpOptimObjUpdated;
182 std::list<RefinableObj*> vpRefObjDeleted;
183 std::list<OptimizationObj*> vpOptimObjDeleted;
185 for(std::map<
Crystal*, boost::shared_ptr<std::string> >::const_iterator pos= mvpCrystalXML.begin(); pos!=mvpCrystalXML.end();++pos)
187 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): found "<< pos->first->GetClassName() <<
":" << pos->first->GetName(), 10)
194 if(ss.str()== *(pos->second))
continue;
199 ss << *(pos->second);
200 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore():Crystal:xml="<<*(pos->second), 5)
201 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore():Crystal:xml="<<ss.str(), 5)
203 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore():Crystal:tag="<<tag, 5)
207 vpRefObjUpdated.push_back(p);
210 for(std::map<
DiffractionDataSingleCrystal*, boost::shared_ptr<std::string> >::const_iterator pos= mvpDiffractionDataSingleCrystalXML.begin(); pos!=mvpDiffractionDataSingleCrystalXML.end();++pos)
212 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): found "<< pos->first->GetClassName() <<
":" << pos->first->GetName(), 10)
219 if(ss.str()== *(pos->second))
continue;
229 vpRefObjUpdated.push_back(p);
232 for(std::map<
PowderPattern*, boost::shared_ptr<std::string> >::const_iterator pos= mvpPowderPatternXML.begin(); pos!=mvpPowderPatternXML.end();++pos)
234 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): found "<< pos->first->GetClassName() <<
":" << pos->first->GetName(), 10)
236 if(gPowderPatternRegistry.Find(pos->first) >= 0)
241 if(ss.str()== *(pos->second))
continue;
251 vpRefObjUpdated.push_back(p);
254 for(std::map<
OptimizationObj*, boost::shared_ptr<std::string> >::const_iterator pos= mvpOptimizationObjXML.begin(); pos!=mvpOptimizationObjXML.end();++pos)
256 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): found "<< pos->first->GetClassName() <<
":" << pos->first->GetName(), 10)
263 if(ss.str()== *(pos->second))
continue;
273 vpOptimObjUpdated.push_back(p);
278 if(mvpCrystalXML.find(*pos) == mvpCrystalXML.end()) vpRefObjDeleted.push_back(*pos);
281 if(mvpDiffractionDataSingleCrystalXML.find(*pos) == mvpDiffractionDataSingleCrystalXML.end()) vpRefObjDeleted.push_back(*pos);
283 for(std::vector<PowderPattern*>::const_iterator pos=gPowderPatternRegistry.begin();pos!=gPowderPatternRegistry.end();++pos)
284 if(mvpPowderPatternXML.find(*pos) == mvpPowderPatternXML.end()) vpRefObjDeleted.push_back(*pos);
287 if(mvpOptimizationObjXML.find(*pos) == mvpOptimizationObjXML.end()) vpOptimObjDeleted.push_back(*pos);
291 for(std::list<OptimizationObj*>::const_iterator pos = vpOptimObjDeleted.begin();pos!=vpOptimObjDeleted.end();++pos)
293 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): deleting "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
296 for(std::list<RefinableObj*>::const_reverse_iterator pos = vpRefObjDeleted.rbegin();pos!=vpRefObjDeleted.rend();++pos)
298 VFN_DEBUG_MESSAGE(
"XMLConfig::Restore(): deleting "<< (*pos)->GetClassName() <<
":" << (*pos)->GetName(), 10)
303 for(std::list<OptimizationObj*>::const_iterator pos = vpOptimObjUpdated.begin() ; pos!=vpOptimObjUpdated.end() ; ++pos) (*pos)->UpdateDisplay();
304 for(std::list<RefinableObj*>::const_iterator pos = vpRefObjUpdated.begin() ; pos!=vpRefObjUpdated.end() ; ++pos) (*pos)->UpdateDisplay();
305 VFN_DEBUG_EXIT(
"XMLConfig::Restore()", 10)
310 if(mvpCrystalXML.size() != rhs.mvpCrystalXML.size())
return false;
311 if(mvpDiffractionDataSingleCrystalXML.size() != rhs.mvpDiffractionDataSingleCrystalXML.size())
return false;
312 if(mvpPowderPatternXML.size() != rhs.mvpPowderPatternXML.size())
return false;
313 if(mvpOptimizationObjXML.size() != rhs.mvpOptimizationObjXML.size())
return false;
315 for(std::map<
Crystal*, boost::shared_ptr<std::string> >::const_iterator pos = mvpCrystalXML.begin(); pos!=mvpCrystalXML.end(); pos++)
317 std::map<Crystal*, boost::shared_ptr<std::string> >::const_iterator pos2 = rhs.mvpCrystalXML.find(pos->first);
318 if(pos2==rhs.mvpCrystalXML.end())
return false;
319 if(*(pos->second) != *(pos2->second))
return false;
322 for(std::map<
DiffractionDataSingleCrystal*, boost::shared_ptr<std::string> >::const_iterator pos = mvpDiffractionDataSingleCrystalXML.begin(); pos!=mvpDiffractionDataSingleCrystalXML.end(); pos++)
324 std::map<DiffractionDataSingleCrystal*, boost::shared_ptr<std::string> >::const_iterator pos2 = rhs.mvpDiffractionDataSingleCrystalXML.find(pos->first);
325 if(pos2==rhs.mvpDiffractionDataSingleCrystalXML.end())
return false;
326 if(*(pos->second) != *(pos2->second))
return false;
329 for(std::map<
PowderPattern*, boost::shared_ptr<std::string> >::const_iterator pos = mvpPowderPatternXML.begin(); pos!=mvpPowderPatternXML.end(); pos++)
331 std::map<PowderPattern*, boost::shared_ptr<std::string> >::const_iterator pos2 = rhs.mvpPowderPatternXML.find(pos->first);
332 if(pos2==rhs.mvpPowderPatternXML.end())
return false;
333 if(*(pos->second) != *(pos2->second))
return false;
336 for(std::map<
OptimizationObj*, boost::shared_ptr<std::string> >::const_iterator pos = mvpOptimizationObjXML.begin(); pos!=mvpOptimizationObjXML.end(); pos++)
338 std::map<OptimizationObj*, boost::shared_ptr<std::string> >::const_iterator pos2 = rhs.mvpOptimizationObjXML.find(pos->first);
339 if(pos2==rhs.mvpOptimizationObjXML.end())
return false;
340 if(*(pos->second) != *(pos2->second))
return false;
359 mMaxNb(maxnb), mpCurrentConfig(), mLock(false)
364 if(
mLock)
return false;
366 VFN_DEBUG_ENTRY(
"XMLConfigHistory::Store()", 10)
373 boost::shared_ptr<XMLConfig> newconf(
new XMLConfig(*previous));
374 if(*newconf == *previous)
376 VFN_DEBUG_EXIT(
"XMLConfigHistory::Store(): nothing new", 10)
384 (*fpObjCrystInformUser)(
"XMLConfigHistory::Store()");
386 VFN_DEBUG_EXIT(
"XMLConfigHistory::Store(): new config", 10)
412 boost::shared_ptr<XMLConfig> p;
416 std::list<boost::shared_ptr<XMLConfig> >::const_iterator pos;
421 (*fpObjCrystInformUser)(
"XMLConfigHistory::Previous()");
437 (*fpObjCrystInformUser)(
"XMLConfigHistory::Next()");
439 std::list<boost::shared_ptr<XMLConfig> >::const_reverse_iterator pos;
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
ObjRegistry< OptimizationObj > gOptimizationObjRegistry("List of all Optimization objects")
Global Registry for all OptimizationObj.
void(* fpObjCrystInformUser)(const string &)
Pointer to a function for passing info to the user during or after long/important processes (use scar...
XMLConfigHistory gConfigHistory
Global object to hold configurations history.
ObjRegistry< Crystal > gCrystalRegistry("List of all Crystals")
Global registry for all Crystal objects.
ObjRegistry< DiffractionDataSingleCrystal > gDiffractionDataSingleCrystalRegistry("Global DiffractionDataSingleCrystal Registry")
Global registry for all PowderPattern objects.
Crystal class: Unit cell, spacegroup, scatterers.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input the crystal structure from a stream.
DiffractionData object for Single Crystal analysis.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
Powder pattern class, with an observed pattern and several calculated components to modelize the patt...
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.
virtual const string & GetClassName() const
Name for this class ("RefinableObj", "Crystal",...).
Class to store & restore all top-level ObjCryst++ objects as their XML description.
RefinableObjClock mClock
Clock recording the creation of this XMLConfig.
XMLConfig()
Default cronstructor.
void Restore()
Restore the saved XML configuration.
bool operator!=(const XMLConfig &rhs) const
Non-equality operator.
bool operator==(const XMLConfig &rhs) const
Equality operator.
const RefinableObjClock & GetClock() const
Access the clock corresponding to the creation of this config.
Class to store XMLConfig configurations.
boost::shared_ptr< XMLConfig > mpCurrentConfig
The current configuration loaded (can be null if none is selected) This is reset every time a change ...
void Restore(boost::shared_ptr< XMLConfig > &p)
Restore a configuration.
XMLConfigHistory(const int maxnb=20)
Constructor.
std::list< boost::shared_ptr< XMLConfig > > GetList()
Access the list of configurations.
bool Next()
Reload the next (more recent) configuration in the list.
bool mLock
Lock used during Store and Restore.
std::list< boost::shared_ptr< XMLConfig > > mvpConfig
List of configurations.
int mMaxNb
Maximum number of stored configurations.
bool Store()
Store a new configuration.
bool Previous()
Reload the previous (older) configuration in the list.
Base object for Optimization methods.
virtual const string GetClassName() const
Get the name for this class type.
virtual void XMLOutput(ostream &os, int indent=0) const =0
Output a description of the object in XML format to a stream.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)=0
Input in XML format from a stream, restoring the set of refined objects and the associated cost funct...
const string & GetName() const
Get the name for this object.
Base object for Monte-Carlo Global Optimization methods.
class to input or output a well-formatted xml beginning or ending tag.
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
void Click()
Record an event for this clock (generally, the 'time' an object has been modified,...
virtual const string & GetName() const
Name of the object.