]> git.treefish.org Git - phys/latlib.git/blobdiff - configcache.cpp
minor changes to test.
[phys/latlib.git] / configcache.cpp
index 168de5e14494c122e8a262bd3176c223635a76fe..0cabc9d5e7e677b4c06487bba398098581330393 100644 (file)
@@ -72,8 +72,6 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc)
   string truncIn, truncOut;
 
   filedesc->filename = infile;
-  filedesc->doVirtualEquilibration = false;
-  filedesc->readEquilibratedConfigs = 0;
 
   if( infile.size() < 4 ) return false;
 
@@ -98,8 +96,6 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc)
            return false;
          break;
        case 2:
-         if (atoi(inParts) < NEQUI)
-           filedesc->doVirtualEquilibration = true;
          filedesc->nequi = atoi(inParts);
          break;
        case 3: 
@@ -183,7 +179,6 @@ void * configcache::getHeader(const string& headerid) {
 void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigned long> *excludeFileHashes)
 {
   readnewconfig = false;
-  nequileft = NEQUI;
 
   if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return;
 
@@ -195,12 +190,24 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigne
   while(true)
     {
       vector<infiledesc>::iterator inFileIt = getNextInfile(excludeFileHashes);
+      int iDidVirtualSkips;
 
-      if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return;
+      if( (!inFile.is_open()) && inFileIt == inFiles.end() ) {
+       if (readnewconfig)
+         nequileft = nequileft_internal;
+       return;
+      }
 
       while( (!inFile.is_open()) && inFiles.size() > 0 ) {
        openFileDesc = *inFileIt;
 
+       if (openFileDesc.nequi < NEQUI)
+         doVirtualEquilibration = true;
+       else
+         doVirtualEquilibration = false;
+
+       firstUsedConfig = true;
+
        if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush;
        inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary );
        
@@ -215,16 +222,17 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigne
 
       if( inFile.is_open() ) 
        {
-         if (openFileDesc.doVirtualEquilibration) {
+         if (doVirtualEquilibration) {
            if(log) *log << "CCACHE: Trying virtual equilibration." << endl << flush;
-           openFileDesc.doVirtualEquilibration = false;
-           for (int iskip=0; iskip < (NEQUI-openFileDesc.nequi)/openFileDesc.nskip; iskip++) {
+           doVirtualEquilibration = false;
+           for (iDidVirtualSkips=0; iDidVirtualSkips < (NEQUI-openFileDesc.nequi)/openFileDesc.nskip; iDidVirtualSkips++) {
              if( readFullBlock(tmpConfig, configSize) != configSize || ! inFile.is_open() )
                break;
-             else if ( (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip < nequileft ) {
+             else if ( (NEQUI-openFileDesc.nequi) - (iDidVirtualSkips+1)*openFileDesc.nskip < nequileft_internal ) {
                memcpy(configMem, tmpConfig, configSize);
-               nequileft = (NEQUI-openFileDesc.nequi) - (iskip+1)*openFileDesc.nskip;
+               nequileft_internal = NEQUI - openFileDesc.nequi - (iDidVirtualSkips+1)*openFileDesc.nskip;
                readnewconfig = true;
+               firstUsedConfig = false;
              }
            }
          }
@@ -233,8 +241,15 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigne
            {
              memcpy(configMem, tmpConfig, configSize);
              readnewconfig = true;
-             nequileft = NEQUI - openFileDesc.nequi - openFileDesc.readEquilibratedConfigs*openFileDesc.nskip;
-             openFileDesc.readEquilibratedConfigs++;
+             if (firstUsedConfig) {
+               firstUsedConfig = false;
+               if (openFileDesc.nequi < NEQUI)
+                 nequileft_internal = NEQUI - openFileDesc.nequi - iDidVirtualSkips*openFileDesc.nskip;
+               else
+                 nequileft_internal = NEQUI - openFileDesc.nequi;
+             }
+             nequileft_internal -= openFileDesc.nskip;
+             nequileft = nequileft_internal;
              return;
            }
          else {
@@ -308,6 +323,7 @@ void configcache::setPara(const string& parid, const double& value){
   inFiles.clear();
 
   refetchDataFiles = true;
+  nequileft_internal = NEQUI;
 }
 
 configcache::~configcache()