void Buffer::clear()
{
   m_writePos = 0;
   m_readPos  = 0;
   m_validBytes = 0;
   checkIntegrity();
}
Example #2
0
void
Steady::init()
{
  if (_app.isRecovering())
  {
    Moose::out<<"\nCannot recover steady solves!\nExiting...\n"<<std::endl;
    return;
  }

  checkIntegrity();

  _problem.initialSetup();
  Moose::setup_perf_log.push("Output Initial Condition","Setup");

  // Write the output
  _output_warehouse.outputInitial();

  if (_output_initial)
  {
    _problem.output();
    _problem.outputPostprocessors();
    _problem.outputRestart();
  }



  Moose::setup_perf_log.pop("Output Initial Condition","Setup");
}
SettingsReader::SettingsReader()
{
    const bool first_start = globals::settings->value("first_start", true).toBool();
    if(first_start) {
        globals::settings->setValue("first_start", false);
        QMessageBox::information(NULL, "Please close LQ and then edit:", globals::settings->fileName().toAscii().data());
    }
    if(globals::settings->value("update_applied").toBool()) {
        UpdateInfoDlg u;
        u.show();
        u.exec();
        globals::settings->setValue("update_applied", false);
    }
    printf("Writing options to %s\n",
           globals::settings->fileName().toAscii().data());
    checkIntegrity(first_start);

    if(first_start) {
        const bool mobile = question("Is this a mobile?",
                                     "Are you running this on your mobile phone?");
        globals::settings->setValue("target",
                                    (mobile)?"mobile":"pc");
    }

    globals::MUSIC_ROOT = globals::settings->value("music_root").toString();
    globals::VIDEO_ROOT = globals::settings->value("video_root").toString();
    globals::MPLAYER_EXE = globals::settings->value("mplayer_name").toString();
}
Example #4
0
Settings::Settings()
{
	db = QSqlDatabase::addDatabase("QSQLITE");
	db.setDatabaseName("mls_config.sqlite");
	ASSERT_WITH_CODE(db.open(), "Error! Can't open configuration database", return);

	checkIntegrity();
}
int Buffer::writeNextCharString(const char* data)
{
   if(data == NULL) data = "";
   int len = strlen(data) + 1;
   bool ok = writeNextByteArray(reinterpret_cast<const uint8*>(data), len);
   checkIntegrity();
   return ok ? len : 0;
}
int Buffer::nprintf(size_t size, const char* format, ...)
{
   va_list args;
   va_start(args, format);
   int n = this->vnprintf(size, format, args);
   va_end(args);
   checkIntegrity();
   return n;
}
Example #7
0
void
EigenExecutionerBase::init()
{
  if (_app.isRecovering())
  {
    _console << "\nCannot recover eigenvalue solves!\nExiting...\n" << std::endl;
    return;
  }

  checkIntegrity();
  _eigen_sys.buildSystemDoFIndices(EigenSystem::EIGEN);

  if (getParam<bool>("auto_initialization"))
  {
    // Initialize the solution of the eigen variables
    // Note: initial conditions will override this if there is any by _problem.initialSetup()
    _eigen_sys.initSystemSolution(EigenSystem::EIGEN, 1.0);
  }
  _problem.initialSetup();
  _eigen_sys.initSystemSolutionOld(EigenSystem::EIGEN, 0.0);

  // check when the postprocessors are evaluated
  ExecFlagType bx_execflag = _problem.getUserObject<UserObject>(getParam<PostprocessorName>("bx_norm")).execBitFlags();
  if ((bx_execflag & EXEC_LINEAR) == EXEC_NONE)
    mooseError("Postprocessor "+getParam<PostprocessorName>("bx_norm")+" requires execute_on = 'linear'");

  if (isParamValid("normalization"))
    _norm_execflag = _problem.getUserObject<UserObject>(getParam<PostprocessorName>("normalization")).execBitFlags();
  else
    _norm_execflag = bx_execflag;

  // check if _source_integral has been evaluated during initialSetup()
  if ((bx_execflag & EXEC_INITIAL) == EXEC_NONE)
  {
    _problem.computeUserObjects(EXEC_LINEAR, UserObjectWarehouse::PRE_AUX);
    _problem.computeAuxiliaryKernels(EXEC_LINEAR);
    _problem.computeUserObjects(EXEC_LINEAR, UserObjectWarehouse::POST_AUX);
  }
  if (_source_integral==0.0) mooseError("|Bx| = 0!");

  // normalize solution to make |Bx|=_eigenvalue, _eigenvalue at this point has the initialized value
  makeBXConsistent(_eigenvalue);

  /* a time step check point */
  _problem.onTimestepEnd();

  Moose::setup_perf_log.push("Output Initial Condition","Setup");

  // Write the initial.
  // Note: We need to tempararily change the system time to make the output system work properly.
  _problem.timeStep() = 0;
  Real t = _problem.time();
  _problem.time() = _problem.timeStep();
  _problem.outputStep(EXEC_INITIAL);
  _problem.time() = t;
  Moose::setup_perf_log.pop("Output Initial Condition","Setup");
}
size_t Buffer::setWritePos(size_t newPos)
{  
   size_t old = m_writePos;
   if (newPos > m_validBytes) {
      newPos = m_validBytes;
   }
   m_writePos = newPos;
   checkIntegrity();
   return old;
}
bool Buffer::writeNextByteArray(const uint8* data, size_t n)
{
   size_t l = n;
   align32bit(l);
   if(!(m_dataLength - m_writePos < n) || 
      enlargeData(l + 4)) {

      // And copy.
      memcpy( m_data + m_writePos, data, n );
      m_writePos += n;
      
      if (m_writePos > m_validBytes) {
         m_validBytes = m_writePos;
      }
      checkIntegrity();
      return true;
   }
   checkIntegrity();
   return false;
}
Example #10
0
void
Steady::init()
{
  if (_app.isRecovering())
  {
    _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
    return;
  }

  checkIntegrity();
  _problem.execute(EXEC_PRE_MULTIAPP_SETUP);
  _problem.initialSetup();
}
Example #11
0
void
EigenExecutionerBase::init()
{
  if (_app.isRecovering())
  {
    _console << "\nCannot recover eigenvalue solves!\nExiting...\n" << std::endl;
    return;
  }

  checkIntegrity();
  _eigen_sys.buildSystemDoFIndices(EigenSystem::EIGEN);

  if (getParam<bool>("auto_initialization"))
  {
    // Initialize the solution of the eigen variables
    // Note: initial conditions will override this if there is any by _problem.initialSetup()
    _eigen_sys.initSystemSolution(EigenSystem::EIGEN, 1.0);
  }
  _problem.initialSetup();
  if (_source_integral==0.0) mooseError("|Bx| = 0!");
  _eigen_sys.initSystemSolutionOld(EigenSystem::EIGEN, 0.0);

  // check when the postprocessors are evaluated
  // TODO: Multiple execFlags support
  _bx_execflag = _problem.getUserObject<UserObject>(getParam<PostprocessorName>("bx_norm")).execFlags()[0];
  if (_solution_diff)
    _xdiff_execflag = _problem.getUserObject<UserObject>(getParam<PostprocessorName>("xdiff")).execFlags()[0];
  else
    _xdiff_execflag = EXEC_TIMESTEP;
  if (isParamValid("normalization"))
    _norm_execflag = _problem.getUserObject<UserObject>(getParam<PostprocessorName>("normalization")).execFlags()[0];
  else
    _norm_execflag = _bx_execflag;

  // normalize solution to make |Bx|=_eigenvalue, _eigenvalue at this point has the initialized value
  makeBXConsistent(_eigenvalue);

  /* a time step check point */
  _problem.onTimestepEnd();

  Moose::setup_perf_log.push("Output Initial Condition","Setup");

  // Write the initial.
  // Note: We need to tempararily change the system time to make the output system work properly.
  _problem.timeStep() = 0;
  Real t = _problem.time();
  _problem.time() = _problem.timeStep();
  _output_warehouse.outputInitial();
  _problem.time() = t;
  Moose::setup_perf_log.pop("Output Initial Condition","Setup");
}
Example #12
0
void
Steady::init()
{
  if (_app.isRecovering())
  {
    _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
    return;
  }

  checkIntegrity();
  _problem.initialSetup();

  _problem.outputStep(EXEC_INITIAL);
}
bool Buffer::writeNext32bit(int32 data)
{
   align32bit(m_writePos);
   if(!(m_dataLength - m_writePos < 4) || enlargeData(8)){
      m_data[m_writePos++] = uint8((data >> (3 * 8)) & 0x0ff);
      m_data[m_writePos++] = uint8((data >> (2 * 8)) & 0x0ff);
      m_data[m_writePos++] = uint8((data >>      8 ) & 0x0ff);
      m_data[m_writePos++] = uint8((data           ) & 0x0ff);
      if (m_writePos > m_validBytes) {
         m_validBytes = m_writePos;
      }
      checkIntegrity();
      return true;
   }
void EEPROMList::init(uint8_t elementSize, uint16_t startAddress, uint16_t maxMemorySize){
  infoAddress = startAddress;
  maxMemoryAddress = infoAddress + maxMemorySize; //TODO: check if it's a valid value
  loadListInfo();
  dataBaseAddress = infoAddress + sizeof(listInfo);
  buffer = (uint8_t*) malloc(sizeof(uint8_t*) * listInfo.elementSize);

  //TODO: this code removes the list if the hashcode is invalid, it should try to restore.
  if((listInfo.elementSize!=elementSize) || !checkIntegrity()){
    listInfo.elementSize = elementSize;
    listInfo.size = 0;
    listInfo.hashCode = 0;
    saveListInfo();
  }
}
Example #15
0
void
Steady::init()
{
  if (_app.isRecovering())
  {
    _console << "\nCannot recover steady solves!\nExiting...\n" << std::endl;
    return;
  }

  checkIntegrity();
  _problem.initialSetup();

  Moose::setup_perf_log.push("Output Initial Condition","Setup");
  _problem.outputStep(EXEC_INITIAL);
  Moose::setup_perf_log.pop("Output Initial Condition","Setup");
}
int Buffer::vnprintf(size_t size, const char* format, va_list args)
{
   int pos = getWritePos();
   if(!(m_dataLength - m_writePos < size) || enlargeData(size)){
      char* dst = reinterpret_cast<char*>(m_data + m_writePos);
      vsnprintf(dst, size, format, args);
      dst[size - 1] = '\0'; //No matter if truncated or not, this
                            //should be safe.
      int written = strlen(dst) + 1;
      m_writePos += written;
      if(m_validBytes < m_writePos){
         m_validBytes = m_writePos;
      }
   }
   checkIntegrity();
   return getWritePos() - pos;
}
// Read data from the python trajectory representation
Trajectory::Trajectory(py::object pytraj, RaveRobotObject::Ptr pr2) {
  py::dict traj = py::extract<py::dict>(pytraj);

  steps = py::extract<int>(traj["steps"]);

  // array of numbers (gripper dofs)
  lGripperTraj = toGripperTraj(steps, dictExtract(traj, "l_gripper"));
  rGripperTraj = toGripperTraj(steps, dictExtract(traj, "r_gripper"));

  // array of arrays of numbers (dofs of the whole arm)
  lArmTraj = toArmTraj(steps, dictExtract(traj, "l_arm"));
  rArmTraj = toArmTraj(steps, dictExtract(traj, "r_arm"));

  // array of booleans
  lGrabTraj = toGrabTraj(steps, dictExtract(traj, "l_grab"));
  rGrabTraj = toGrabTraj(steps, dictExtract(traj, "r_grab"));

  // array of array of vectors (warped tracked states)
  trackedStates = toTrackedStates(steps, dictExtract(traj, "tracked_states"), pr2);
  origTrackedStates = toTrackedStates(steps, dictExtract(traj, "orig_tracked_states"), pr2);

  assert(checkIntegrity());
}
Example #18
0
KstObject::UpdateType KstRVector::doUpdate(bool force) {
  int i, k, shift, n_read=0;
  int ave_nread;
  int new_f0, new_nf;
  bool start_past_eof = false;
  
  checkIntegrity();

  if (DoSkip && Skip < 2 && SPF == 1) {
    DoSkip = false;
  }

  if (!_file) {
    return NO_CHANGE;
  }

  // set new_nf and new_f0
  int fc = _file->frameCount(_field);
  if (ReqNF < 1) { // read to end of file
    new_f0 = ReqF0;
    new_nf = fc - new_f0;
  } else if (ReqF0 < 0) { // count back from end of file
    new_nf = fc;
    if (new_nf > ReqNF) {
      new_nf = ReqNF;
    }
    new_f0 = fc - new_nf;
  } else {
    new_f0 = ReqF0;
    new_nf = ReqNF;
    if (new_f0 + new_nf > fc) {
      new_nf = fc - new_f0;
    }
    if (new_nf <= 0) {
      // Tried to read starting past the end.
      new_f0 = 0;
      new_nf = 1;
      start_past_eof = true;
    }
  }

  if (DoSkip) {
    // change new_f0 and new_nf so they both lie on skip boundaries
    if (new_f0 != 0) {
      new_f0 = ((new_f0-1)/Skip+1)*Skip;
    }
    new_nf = (new_nf/Skip)*Skip;
  }

  if (NF == new_nf && F0 == new_f0 && !force) {
    return NO_CHANGE;
  }

  // shift vector if necessary
  if (new_f0 < F0 || new_f0 >= F0 + NF) { // No useful data around.
    reset();
  } else { // shift stuff rather than re-read
    if (DoSkip) {
      shift = (new_f0 - F0)/Skip;
      NF -= (new_f0 - F0);
      _numSamples = NF/Skip;
    } else {
      shift = SPF*(new_f0 - F0);
      NF -= (new_f0 - F0);
      _numSamples = (NF-1)*SPF+1;
    }

    // FIXME: use memmove()
    for (i = 0; i < _numSamples; i++) {
      _v[i] = _v[i+shift];
    }
  }

  if (DoSkip) {
    // reallocate V if necessary
    //kstdDebug() << "new_nf = " << new_nf << " and skip = " << Skip << " so new_nf/Skip+1 = " << (new_nf / Skip + 1) << endl;
    if (new_nf / Skip != _size) {
      bool rc = resize(new_nf/Skip);
      if (!rc) {
        // FIXME: handle failed resize
      }
    }
    // for debugging: _dontUseSkipAccel = true;
    if (!_dontUseSkipAccel) {
      int rc;
      int lastRead = -1;
      if (DoAve) {
        // We don't support boxcar inside data sources yet.
        _dontUseSkipAccel = true;
      } else {
        rc = _file->readField(_v + _numSamples, _field, new_f0, (new_nf - NF)/Skip, Skip, &lastRead);
        if (rc != -9999) {
          //kstdDebug() << "USED SKIP FOR READ - " << _field << " - rc=" << rc << " for Skip=" << Skip << " s=" << new_f0 << " n=" << (new_nf - NF)/Skip << endl;
          if (rc >= 0) {
            n_read = rc;
          } else {
            n_read = 0;
          }
        } else {
          _dontUseSkipAccel = true;
        }
      }
    }
    if (_dontUseSkipAccel) {
      n_read = 0;
      /** read each sample from the File */
      //kstdDebug() << "NF = " << NF << " numsamples = " << _numSamples << " new_f0 = " << new_f0 << endl;
      double *t = _v + _numSamples;
      int new_nf_Skip = new_nf - Skip;
      if (DoAve) {
        for (i = NF; new_nf_Skip >= i; i += Skip) {
          /* enlarge AveReadBuf if necessary */
          if (N_AveReadBuf < Skip*SPF) {
            N_AveReadBuf = Skip*SPF;
            AveReadBuf = static_cast<double*>(realloc(AveReadBuf, N_AveReadBuf*sizeof(double)));
            if (!AveReadBuf) {
              // FIXME: handle failed resize
            }
          }
          ave_nread = _file->readField(AveReadBuf, _field, new_f0+i, Skip);
          for (k = 1; k < ave_nread; k++) {
            AveReadBuf[0] += AveReadBuf[k];
          }
          if (ave_nread > 0) {
            *t = AveReadBuf[0]/double(ave_nread);
            n_read++;
          }
          ++t;
        }
      } else {
        for (i = NF; new_nf_Skip >= i; i += Skip) {
          //kstdDebug() << "readField " << _field << " start=" << new_f0 + i << " n=-1" << endl;
          n_read += _file->readField(t++, _field, new_f0 + i, -1);
        }
      }
    }
  } else {
    // reallocate V if necessary
    if ((new_nf - 1)*SPF + 1 != _size) {
      bool rc = resize((new_nf - 1)*SPF + 1);
      if (!rc) {
        // FIXME: handle failed resize
        abort();
      }
    }

    if (NF > 0) {
      NF--; /* last frame read was only partially read... */
    }

    // read the new data from file
    if (start_past_eof) {
      _v[0] = KST::NOPOINT;
      n_read = 1;
    } else if (_file->samplesPerFrame(_field) > 1) {
      assert(new_nf - NF - 1 > 0 || new_nf - NF - 1 == -1);
      assert(new_f0 + NF >= 0);
      assert(new_f0 + new_nf - 1 >= 0);
      n_read = _file->readField(_v+NF*SPF, _field, new_f0 + NF, new_nf - NF - 1);
      n_read += _file->readField(_v+(new_nf-1)*SPF, _field, new_f0 + new_nf - 1, -1);
    } else {
      //kstdDebug() << "Reading into _v=" << (void*)_v << " which has size " << _size << " and starting at offset " << NF*SPF << " for s=" << new_f0 + NF << " and n=" << new_nf - NF << endl;
      assert(new_f0 + NF >= 0);
      if (new_nf - NF > 0 || new_nf - NF == -1) {
        n_read = _file->readField(_v+NF*SPF, _field, new_f0 + NF, new_nf - NF);
      }
    }
  }

  NumNew = _size - _numSamples;
  NF = new_nf;
  F0 = new_f0;
  _numSamples += n_read;

  // if for some reason (eg, realtime reading an nfs mounted
  // dirfile) not all of the data was read, the data will never
  // be read; the samples will be filled in with the last data
  // point read, and a complete reset will be requested.
  // This is bad - I think it will be worthwhile
  // to add blocking w/ timeout to KstFile.
  // As a first fix, mount all nsf mounted dirfiles with "-o noac"
  _dirty = false;
  if (_numSamples != _size && !(_numSamples == 0 && _size == 1)) {
    //kstdDebug() << "SET DIRTY since _numSamples = " << _numSamples << " but _size = " << _size << endl;
    _dirty = true;
    for (i = _numSamples; i < _size; i++) {
      _v[i] = _v[0];
    }
  }

  if (NumNew > _size) {
    NumNew = _size;
  }
  if (NumShifted > _size) {
    NumShifted = _size;
  }

  return KstVector::internalUpdate(UPDATE);
}
bool RecipeDB::restore( const QString &file, QString *errMsg )
{
	kDebug();
	m_dumpFile = KFilterDev::deviceForFile(file,"application/x-gzip");
	if ( m_dumpFile->open( QIODevice::ReadOnly ) ) {

		m_dumpFile->setTextModeEnabled( true );
		QString firstLine = QString::fromUtf8(m_dumpFile->readLine()).trimmed();
		QString dbVersion = QString::fromUtf8(m_dumpFile->readLine()).trimmed();
		dbVersion = dbVersion.right( dbVersion.length() - dbVersion.indexOf(":") - 2 );
		if ( qRound(dbVersion.toDouble()*1e5) > qRound(latestDBVersion()*1e5) ) { //correct for float's imprecision
			if ( errMsg ) *errMsg = i18n( "This backup was created with a newer version of Krecipes and cannot be restored." );
			delete m_dumpFile;
			return false;
		}

		KConfigGroup config = KGlobal::config()->group( "DBType" );
		QString dbType = QString::fromUtf8(m_dumpFile->readLine()).trimmed();
		dbType = dbType.right( dbType.length() - dbType.indexOf(":") - 2 );
		if ( dbType.isEmpty() || !firstLine.startsWith("-- Generated for Krecipes") ) {
			if ( errMsg ) *errMsg = i18n("This file is not a Krecipes backup file or has become corrupt.");
			delete m_dumpFile;
			return false;
		}
		else if ( dbType != config.readEntry("Type",QString()) ) {
			if ( errMsg ) *errMsg = i18n("This backup was created using the \"%1\" backend.  It can only be restored into a database using this backend." ,dbType);
			delete m_dumpFile;
			return false;
		}

		process = new KProcess;

		QStringList command = restoreCommand();
		kDebug()<<"Restoring backup using: "<<command[0];
		*process << command;

		QApplication::connect( process, SIGNAL(started()), this, SLOT(processStarted()) );
		QApplication::connect( process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)) );
		QApplication::connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)) );
	
		m_processStarted = false;
		m_processFinished = false;
		m_processError = false;
		m_operationHalted = false;

		emit progressBegin(0,QString(),
			QString("<center><b>%1</b></center>%2")
				.arg(i18nc("@info:progress", "Restoring backup"))
				.arg(i18n("Depending on the number of recipes and amount of data, this could take some time.")),50);

		process->start();
		m_localEventLoop = new QEventLoop;
		m_localEventLoop->exec();

		if ( m_processError && !m_processStarted ) {
			if ( errMsg ) *errMsg = i18n("Unable to find or run the program '%1'.  Either it is not installed on your system or it is not in $PATH.",
				command.first());
			delete m_localEventLoop;
			delete process;
			process = NULL;
			delete m_dumpFile;
			emit progressDone();
			return false;
		}
	
		//We have to first wipe the database structure.  Note that if we load a dump
		//with from a previous version of Krecipes, the difference in structure
		// wouldn't allow the data to be inserted.  This remains forward-compatibity
		//by loading the old schema and then porting it to the current version.
		kDebug()<<"Wiping database...";
		empty(); //the user had better be warned!
		kDebug()<<"Database wiped.";
	
		kDebug()<<"Reading backup file...";
		m_timer = new QTimer;
		QApplication::connect( m_timer, SIGNAL(timeout()), this, SLOT(processReadDump()) );
		m_timer->start();
		m_localEventLoop->exec();
		delete m_timer;
		kDebug()<<"Done.";

		//Since the process will exit when all stdin has been sent and processed,
		//just loop until the process is no longer running.  If something goes
		//wrong, the user can still hit cancel.
		process->closeWriteChannel();
		if (!m_processFinished && !m_processError) {
			kDebug()<<"Waiting for process exit...";
			m_localEventLoop->exec();
		}

		delete m_localEventLoop;
		delete process;
		process = NULL;
		emit progressDone();

		//Since we just loaded part of a file, the database won't be in a usable state.
		//We'll wipe out the database structure and recreate it, leaving no data.
		if ( haltOperation ) {
			haltOperation=false;
			empty();
			checkIntegrity();
			delete m_dumpFile;
			if ( errMsg ) { *errMsg = i18n("Restore Failed"); }
			return false;
		}

		m_dumpFile->close();

		checkIntegrity();
	}