Ejemplo n.º 1
0
/** Executes the algorithm. Reading in the file and creating and populating
 *  the output workspace
 *
 *  @throw runtime_error Thrown if algorithm cannot execute
 */
void LoadNexusProcessed::exec()
{
  progress(0,"Opening file...");

  //Throws an approriate exception if there is a problem with file access
  NXRoot root(getPropertyValue("Filename"));

  // "Open" the same file but with the C++ interface
  cppFile = new ::NeXus::File(root.m_fileID);

  //Find out how many first level entries there are
  int64_t nperiods = static_cast<int64_t>(root.groups().size());

  // Check for an entry number property
  int64_t entrynumber = static_cast<int64_t>(getProperty("EntryNumber"));

  if( entrynumber > 0 && entrynumber > nperiods )
  {
    g_log.error() << "Invalid entry number specified. File only contains " << nperiods << " entries.\n";
    throw std::invalid_argument("Invalid entry number specified.");
  }

  const std::string basename = "mantid_workspace_";
  if( nperiods == 1 || entrynumber > 0 )
  {
    if( entrynumber == 0 ) ++entrynumber;
    std::ostringstream os;
    os << entrynumber;
    API::Workspace_sptr workspace = loadEntry(root, basename + os.str(), 0, 1);
    //API::Workspace_sptr workspace = boost::static_pointer_cast<API::Workspace>(local_workspace);
    setProperty("OutputWorkspace", workspace);
  }
  else
  {
    WorkspaceGroup_sptr wksp_group(new WorkspaceGroup);
    //This forms the name of the group
    std::string base_name = getPropertyValue("OutputWorkspace");
    // First member of group should be the group itself, for some reason!
    base_name += "_";
    const std::string prop_name = "OutputWorkspace_";
    double nperiods_d = static_cast<double>(nperiods);
    for( int64_t p = 1; p <= nperiods; ++p )
    {
      std::ostringstream os;
      os << p;
      Workspace_sptr local_workspace = loadEntry(root, basename + os.str(), static_cast<double>(p-1)/nperiods_d, 1./nperiods_d);
      declareProperty(new WorkspaceProperty<API::Workspace>(prop_name + os.str(), base_name + os.str(),
          Direction::Output));
      wksp_group->add(base_name + os.str());
      setProperty(prop_name + os.str(), local_workspace);
    }

    // The group is the root property value
    setProperty("OutputWorkspace", boost::static_pointer_cast<Workspace>(wksp_group));

  }

  m_axis1vals.clear();
}
Ejemplo n.º 2
0
/* GfxEntryPanel::onBtnPrevImg
 * Called when the 'previous image' button is clicked
 *******************************************************************/
void GfxEntryPanel::onBtnPrevImg(wxCommandEvent& e)
{
	int num = gfx_canvas->getImage()->getSize();
	if (num > 1)
	{
		if (cur_index > 0)
			loadEntry(entry, cur_index - 1);
		else
			loadEntry(entry, num - 1);
	}
}
Ejemplo n.º 3
0
// -----------------------------------------------------------------------------
// Called when the 'previous image' button is clicked
// -----------------------------------------------------------------------------
void GfxEntryPanel::onBtnPrevImg(wxCommandEvent& e)
{
	int num = gfx_canvas_->image().size();
	if (num > 1)
	{
		if (cur_index_ > 0)
			loadEntry(entry_, cur_index_ - 1);
		else
			loadEntry(entry_, num - 1);
	}
}
Ejemplo n.º 4
0
MoodPlugin::MoodPlugin( QObject *parent, const char *name,
			      const QStringList &/*args*/ )
	: ktagebuchPlugin( parent, name )
{
	
	connect( ktagebuchapp, SIGNAL(saveEntry()),
		 SLOT(saveEntry()) );
	connect( ktagebuchapp, SIGNAL(loadEntry()),
		 SLOT(loadEntry()) );
	
        this->fileSystem=ktagebuchapp->getFileSystem();		
	mPrefs=new MoodPreferences("looknfeel",this);	
}
Ejemplo n.º 5
0
void process(void) {
    uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0;
    entry entry;
    int dump_version = processHeader();

    /* Exclude the final checksum for RDB >= 5. Will be checked at the end. */
    if (dump_version >= 5) {
        if (positions[0].size < 8) {
            printf("RDB version >= 5 but no room for checksum.\n");
            exit(1);
        }
        positions[0].size -= 8;
    }

    level = 1;
    while(positions[0].offset < positions[0].size) {
        positions[1] = positions[0];

        entry = loadEntry();
        if (!entry.success) {
            printValid(num_valid_ops, num_valid_bytes);
            printErrorStack(&entry);
            num_errors++;
            num_valid_ops = 0;
            num_valid_bytes = 0;

            /* search for next valid entry */
            uint64_t offset = positions[0].offset + 1;
            int i = 0;

            while (!entry.success && offset < positions[0].size) {
                positions[1].offset = (size_t)offset;                           WIN_PORT_FIX /* cast (size_t) */

                /* find 3 consecutive valid entries */
                for (i = 0; i < 3; i++) {
                    entry = loadEntry();
                    if (!entry.success) break;
                }
                /* check if we found 3 consecutive valid entries */
                if (i < 3) {
                    offset++;
                }
            }

            /* print how many bytes we have skipped to find a new valid opcode */
            if (offset < positions[0].size) {
                printSkipped(offset - positions[0].offset, offset);
            }

            positions[0].offset = (size_t)offset;                               WIN_PORT_FIX /* cast (size_t) */
        } else {
Ejemplo n.º 6
0
/* EntryPanel::revertEntry
 * Reverts any changes made to the entry since it was loaded into
 * the EntryPanel. Returns false if no changes have been made or
 * if the entry data wasn't saved
 *******************************************************************/
bool EntryPanel::revertEntry(bool confirm)
{
	if (modified && entry_data.hasData())
	{
		bool ok = true;

		// Prompt to revert if configured to
		if (confirm_entry_revert && confirm)
			if (wxMessageBox("Are you sure you want to revert changes made to the entry?", "Revert Changes", wxICON_QUESTION | wxYES_NO) == wxNO)
				ok = false;

		if (ok)
		{
			uint8_t state = entry->getState();
			entry->importMemChunk(entry_data);
			entry->setState(state);
			EntryType::detectEntryType(entry);
			loadEntry(entry);
		}

		return true;
	}

	return false;
}
Ejemplo n.º 7
0
/* EntryPanel::openEntry
 * 'Opens' the given entry (sets the frame label then loads it)
 *******************************************************************/
bool EntryPanel::openEntry(ArchiveEntry* entry)
{
	// Check entry was given
	if (!entry)
	{
		entry_data.clear();
		this->entry = NULL;
		return false;
	}

	// Set unmodified
	setModified(false);

	// Copy current entry content
	entry_data.clear();
	entry_data.importMem(entry->getData(true), entry->getSize());

	// Load the entry
	if (loadEntry(entry))
	{
		this->entry = entry;
		updateStatus();
		toolbar->updateLayout(true);
		Layout();
		return true;
	}
	else
	{
		theMainWindow->SetStatusText("", 1);
		theMainWindow->SetStatusText("", 2);
		return false;
	}
}
Ejemplo n.º 8
0
 InputIterator(std::shared_ptr<Bucket const> bucket)
     : mBucket(bucket), mEntryPtr(nullptr)
 {
     if (!mBucket->mFilename.empty())
     {
         CLOG(TRACE, "Bucket")
             << "Bucket::InputIterator opening file to read: "
             << mBucket->mFilename;
         mIn.open(mBucket->mFilename);
         loadEntry();
     }
 }
Ejemplo n.º 9
0
 InputIterator& operator++()
 {
     if (mIn)
     {
         loadEntry();
     }
     else
     {
         mEntryPtr = nullptr;
     }
     return *this;
 }
Ejemplo n.º 10
0
/* EntryPanel::revertEntry
 * Reverts any changes made to the entry since it was loaded into
 * the EntryPanel. Returns false if no changes have been made or
 * if the entry data wasn't saved
 *******************************************************************/
bool EntryPanel::revertEntry() {
	if (modified) {
		if (entry_data.hasData()) {
			entry->importMemChunk(entry_data);
			EntryType::detectEntryType(entry);
			loadEntry(entry);

			return true;
		}
	}

	return false;
}
Ejemplo n.º 11
0
list loadWeizmann( bool train, bool test, int n_train ) {
	std::vector< std::string > file_names = listDir( weizmann_dir+"/rgb/" );
	std::sort( file_names.begin(), file_names.end() );

	std::mt19937 rand;
	for( int i=1; i<(int)file_names.size(); i++ )
		std::swap( file_names[i], file_names[rand()%(i+1)] );

	list r;
	for( int i=train?0:n_train; (test || i<n_train) && i<file_names.size(); i++ ) {
		dict d = loadEntry( file_names[i] );
		if( len(d) )
			r.append( d );
	}
	return r;
}
Ejemplo n.º 12
0
void
MoodPlugin::init()
{
	toolbar=new KToolBar((QMainWindow*)ktagebuchapp,QMainWindow::Top);
	new QLabel(i18n("Mood :"),toolbar);
	combobox=new KComboBox(toolbar);
	
	KConfig *config = ktagebuchapp->getConfig();
	config->setGroup("Mood Plugin");
	if (!config->hasKey("moods"))
		mPrefs->save();
	QStringList strList=QStringList(config->readListEntry("moods"));
	for (QStringList::Iterator it=strList.begin();it!=strList.end();++it){
	    combobox->insertItem(i18n(*it));
	}
	combobox->show();	
	loadEntry();
}
Ejemplo n.º 13
0
static void loadBSD300( list & r, const std::string & type ) {
	std::string sets[] = {"train","val","test"};
	std::string cs_dir = berkeley_dir+"/cache/";
	std::ifstream is(berkeley_dir+"/bsd300_iids_"+type+".txt");
	mkdir( cs_dir );
	for (std::string s: sets)
		mkdir( cs_dir+s );
	
	while(is.is_open() && !is.eof()) {
		std::string l;
		std::getline(is,l);
		if( !l.empty() ) {
			dict d = loadEntry( l );
			if( len( d ) )
				r.append( d );
		}
	}
}
Ejemplo n.º 14
0
//main ()
int main (int argC, char *argV[]) {
//Call syntax check
    if (argC != 2) {
        printf ("Usage: %s Input_filename\n", argV[0]);
        exit (1);
    }
//Main variables
    FILE *inFile = NULL, *outFile = NULL;
    node *entry = NULL, *firstNode = NULL;
    int count = 0;
    char in;
//File creation and checks
    printf ("Opening files...\n");
    createFile (&inFile, argV[1], 'r');
    createOutputFile (&outFile, argV[1]);
//Load entries into DLL
    printf ("Files opened.  Loading entries...\n");
    while (1) {
//Stop conditions
        if (((ferror (inFile)) || (feof (inFile)))) {
            break;
        }
        entry = malloc (sizeof (node));
        initializeNode (entry);
        loadEntry (entry, inFile);
        firstNode = insertNode (entry, firstNode);
        entry = NULL;
//A counter so the user has some idea of how long it will take
        if (++count % 100000 == 0) {
            printf ("%d entries ordered...\n", count);
        }
    }
    fclose (inFile);
//Write ordered list to file
    printf ("%d entries ordered.  Writing to file...\n", count);
    printNodeList (firstNode, outFile);
//Close everything and free memory
    printf ("Writen.  Closing files and freeing memory...\n");
    fclose (outFile);
    return 0;
}
Ejemplo n.º 15
0
static void loadBSD500( list & r, const std::string & type, int max_entry=1<<30 ) {
	std::string sets[] = {"train","val","test"};
	std::string cs_dir = berkeley_dir+"/cache/";
	std::string im_dir = berkeley_dir+"/images/"+type+"/";
	
	mkdir( cs_dir );
	for (std::string s: sets)
		mkdir( cs_dir+s );
	
	std::vector<std::string> files = listDir( im_dir );
	std::sort( files.begin(), files.end() );
	int n = 0;
	for( std::string fn: files )
		if( fn.size() > 4 && fn.substr(fn.size()-4)==".jpg" ) {
			dict d = loadEntry( fn.substr(0,fn.size()-4) );
			if( len( d ) ) {
				r.append( d );
				n++;
				if( n >= max_entry )
					break;
			}
		}
}
Ejemplo n.º 16
0
/* GfxEntryPanel::loadEntry
 * Loads an entry into the entry panel if it is a valid image format
 *******************************************************************/
bool GfxEntryPanel::loadEntry(ArchiveEntry* entry)
{
	return loadEntry(entry, 0);
}
Ejemplo n.º 17
0
EntryEdict::EntryEdict( const QString &dict, const QString &entry )
: Entry( dict )
{
  loadEntry( entry );
}
Ejemplo n.º 18
0
void process() {
    uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0;
    entry entry;
    int dump_version = processHeader();

    /* Exclude the final checksum for RDB >= 5. Will be checked at the end. */
    if (dump_version >= 5) {
        if (positions[0].size < 8) {
            printf("RDB version >= 5 but no room for checksum.\n");
            exit(1);
        }
        positions[0].size -= 8;;
    }

    level = 1;
    while(positions[0].offset < positions[0].size) {
        positions[1] = positions[0];

        entry = loadEntry();
        if (!entry.success) {
            uint64_t offset;
            int i;
            printValid(num_valid_ops, num_valid_bytes);
            printErrorStack(&entry);
            num_errors++;
            num_valid_ops = 0;
            num_valid_bytes = 0;

            /* search for next valid entry */
            offset = positions[0].offset + 1;
            i = 0;

            while (!entry.success && offset < positions[0].size) {
                positions[1].offset = (size_t)offset;

                /* find 3 consecutive valid entries */
                for (i = 0; i < 3; i++) {
                    entry = loadEntry();
                    if (!entry.success) break;
                }
                /* check if we found 3 consecutive valid entries */
                if (i < 3) {
                    offset++;
                }
            }

            /* print how many bytes we have skipped to find a new valid opcode */
            if (offset < positions[0].size) {
                printSkipped(offset - positions[0].offset, offset);
            }

            positions[0].offset = (size_t)offset;
        } else {
            num_valid_ops++;
            num_valid_bytes += positions[1].offset - positions[0].offset;

            /* advance position */
            positions[0] = positions[1];
        }
        free(entry.key);
    }

    /* because there is another potential error,
     * print how many valid ops we have processed */
    printValid(num_valid_ops, num_valid_bytes);

    /* expect an eof */
    if (entry.type != REDIS_EOF) {
        /* last byte should be EOF, add error */
        errors.level = 0;
        SHIFT_ERROR(positions[0].offset, "Expected EOF, got %s", types[entry.type]);

        /* this is an EOF error so reset type */
        entry.type = -1;
        printErrorStack(&entry);

        num_errors++;
    }

    /* Verify checksum */
    if (dump_version >= 5) {
        uint64_t crc = crc64(0,positions[0].data,positions[0].size);
        uint64_t crc2;
        unsigned char *p = (unsigned char*)positions[0].data+positions[0].size;
        crc2 = ((uint64_t)p[0] << 0) |
               ((uint64_t)p[1] << 8) |
               ((uint64_t)p[2] << 16) |
               ((uint64_t)p[3] << 24) |
               ((uint64_t)p[4] << 32) |
               ((uint64_t)p[5] << 40) |
               ((uint64_t)p[6] << 48) |
               ((uint64_t)p[7] << 56);
        if (crc != crc2) {
            SHIFT_ERROR(positions[0].offset, "RDB CRC64 does not match.");
        } else {
            printf("CRC64 checksum is OK\n");
        }
    }

    /* print summary on errors */
    if (num_errors) {
        printf("\n");
        printf("Total unprocessable opcodes: %llu\n",
            (unsigned long long) num_errors);
    }
}
Ejemplo n.º 19
0
/* SwitchesEntryPanel::revertEntry
 * Undoes any changes made to the entry
 *******************************************************************/
bool SwitchesEntryPanel::revertEntry()
{
	ArchiveEntry* reload = entry;
	entry = NULL;
	return loadEntry(reload);
}
Ejemplo n.º 20
0
/* AnimatedEntryPanel::revertEntry
 * Undoes any changes made to the entry
 *******************************************************************/
bool AnimatedEntryPanel::revertEntry()
{
	ArchiveEntry* reload = entry;
	entry = NULL;
	return loadEntry(reload);
}
Ejemplo n.º 21
0
void process() {
    uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0;
    entry entry;
    processHeader();

    level = 1;
    while(positions[0].offset < positions[0].size) {
        positions[1] = positions[0];

        entry = loadEntry();
        if (!entry.success) {
            printValid(num_valid_ops, num_valid_bytes);
            printErrorStack(&entry);
            num_errors++;
            num_valid_ops = 0;
            num_valid_bytes = 0;

            /* search for next valid entry */
            uint64_t offset = positions[0].offset + 1;
            int i = 0;

            while (!entry.success && offset < positions[0].size) {
                positions[1].offset = offset;

                /* find 3 consecutive valid entries */
                for (i = 0; i < 3; i++) {
                    entry = loadEntry();
                    if (!entry.success) break;
                }
                /* check if we found 3 consecutive valid entries */
                if (i < 3) {
                    offset++;
                }
            }

            /* print how many bytes we have skipped to find a new valid opcode */
            if (offset < positions[0].size) {
                printSkipped(offset - positions[0].offset, offset);
            }

            positions[0].offset = offset;
        } else {
            num_valid_ops++;
            num_valid_bytes += positions[1].offset - positions[0].offset;

            /* advance position */
            positions[0] = positions[1];
        }
    }

    /* because there is another potential error,
     * print how many valid ops we have processed */
    //printValid(num_valid_ops, num_valid_bytes);
    db_stats.num_valid_ops = num_valid_ops;
    db_stats.num_valid_bytes = num_valid_bytes;

    /* expect an eof */
    if (entry.type != REDIS_EOF) {
        /* last byte should be EOF, add error */
        errors.level = 0;
        SHIFT_ERROR(positions[0].offset, 
            "Expected EOF, got %s", types[entry.type]);

        /* this is an EOF error so reset type */
        entry.type = -1;
        printErrorStack(&entry);

        num_errors++;
    }

    /* print summary on errors */
    if (num_errors) {
        printf("\n");
        printf("Total unprocessable opcodes: %llu\n",
            (unsigned long long) num_errors);
    }
}