]> git.treefish.org Git - phys/latlib.git/blobdiff - configcache.cpp
dynamically allocating manymeans in jackknife methods to allow for large number of...
[phys/latlib.git] / configcache.cpp
index 35e85488d34e1a315301a283ad310e77df8a54b7..ef085d8cb25815d78d02ccbfc258ee4332b5f6d6 100644 (file)
@@ -72,8 +72,6 @@ bool configcache::isValidInFile(const string& infile, infiledesc *filedesc)
   string truncIn, truncOut;
 
   filedesc->filename = infile;
-  filedesc->doVirtualEquilibration = false;
-  filedesc->firstConfig = true;
 
   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: 
@@ -178,11 +174,9 @@ void * configcache::getHeader(const string& headerid) {
   return NULL;
 }
 
-/* returns number of equilibration-steps left with new read configuration 
-   or zero if no new configuration was read */
-void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigned long> *excludeFileHashes)
+void configcache::readConfig(bool *readnewconfig, int *nequileft, vector<unsigned long> *excludeFileHashes)
 {
-  readnewconfig = false;
+  *readnewconfig = false;
 
   if(DATADIR == "" || MODE == CACHE_MODE_DISABLED) return;
 
@@ -194,16 +188,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() ) {
-       cout << "RETURNING..." << endl;
-       nequileft = nequileft_internal;
+       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 );
        
@@ -218,33 +220,34 @@ 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_internal ) {
+             else if ( (NEQUI-openFileDesc.nequi) - (iDidVirtualSkips+1)*openFileDesc.nskip < nequileft_internal ) {
                memcpy(configMem, tmpConfig, configSize);
-               nequileft_internal = NEQUI - openFileDesc.nequi - (iskip+1)*openFileDesc.nskip;
-               cout << "blabla:" << nequileft_internal << endl;
-               readnewconfig = true;
+               nequileft_internal = NEQUI - openFileDesc.nequi - (iDidVirtualSkips+1)*openFileDesc.nskip;
+               *readnewconfig = true;
+               firstUsedConfig = false;
              }
            }
-           openFileDesc.firstConfig = false;
          }
 
          if( readFullBlock(tmpConfig, configSize) == configSize && inFile.is_open() )
            {
              memcpy(configMem, tmpConfig, configSize);
-             readnewconfig = true;
-             if (openFileDesc.firstConfig) {
-               openFileDesc.firstConfig = false;
-               nequileft_internal = NEQUI - openFileDesc.nequi;
+             *readnewconfig = true;
+             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;
-             cout << "sadasd:" << nequileft_internal << endl;
-             nequileft = nequileft_internal;
+             *nequileft = nequileft_internal;
              return;
            }
          else {
@@ -256,7 +259,7 @@ void configcache::readConfig(bool& readnewconfig, int& nequileft, vector<unsigne
 }
 
 void configcache::openOutFile(int actnequi)
-{
+{ 
   time_t secstamp = time(NULL);
 
   outFileName.str("");
@@ -312,12 +315,14 @@ int configcache::getParIndex(const string& parid){
 
 void configcache::setPara(const string& parid, const double& value){
   Paras[getParIndex(parid)].val = value;
+
   finishOutFile();
   if(inBuffer != NULL) { delete inBuffer; inBuffer=NULL; } 
   inFile.close();
   inFiles.clear();
 
   refetchDataFiles = true;
+  nequileft_internal = NEQUI;
 }
 
 configcache::~configcache()