Ejemplo n.º 1
0
/** Execute the algorithm.
 *
 *  @throw runtime_error Thrown if algorithm cannot execute
 */
void SaveToSNSHistogramNexus::exec() {
  // NXMSetError(NULL, nexus_print_error);
  NXMEnableErrorReporting();

  // Retrieve the filename from the properties
  m_inputFilename = getPropertyValue("InputFileName");
  m_outputFilename = getPropertyValue("OutputFileName");
  m_compress = getProperty("Compress");

  inputWorkspace = getProperty("InputWorkspace");

  // We'll need to get workspace indices
  map = inputWorkspace->getDetectorIDToWorkspaceIndexMap();

  // Start the progress bar. 3 reports per histogram.
  prog = new Progress(this, 0, 1.0, inputWorkspace->getNumberHistograms() * 3);

  EventWorkspace_const_sptr eventWorkspace =
      boost::dynamic_pointer_cast<const EventWorkspace>(inputWorkspace);
  if (eventWorkspace) {
    eventWorkspace->sortAll(TOF_SORT, prog);
  }

  int ret;
  ret = this->copy_file(m_inputFilename.c_str(), NXACC_READ,
                        m_outputFilename.c_str(), NXACC_CREATE5);

  if (ret == NX_ERROR)
    throw std::runtime_error("Nexus error while copying the file.");
}
Ejemplo n.º 2
0
static char *field_generator(const char *text, int state)
{
    struct name_item *item, *t_item;
    static struct name_item *names = NULL, *last_item = NULL;
    char *res;
    int status, dataType;
    NXname name, nxclass;
    if (!state) {
        item = names;
        while (item != NULL) {
            if (item->name != NULL) {
                free(item->name);
                item->name = NULL;
            }
            t_item = item;
            item = item->next;
            t_item->next = NULL;
            free(t_item);
        }
        last_item = names = NULL;

        char matchtext[256], absdir[256], tmppath[256], prefix[256];

        prefix[0] = '\0';
        char *ptr = rindex(text+1, '/');
        if (ptr != NULL) {
            strncpy(prefix, text, ptr-text+1);
            prefix[ptr-text+1] = '\0';
        }

        parsepath(text, absdir, matchtext);

        /* check if we've got a dir already */
        NXMDisableErrorReporting();
        strcpy(tmppath, absdir);
        strcat(tmppath, "/");
        strcat(tmppath, matchtext);
        status = NXopengrouppath(the_fileId, tmppath);
        if (status == NX_OK) {
            strcpy(absdir, tmppath);
            strcpy(matchtext, "");
            if (strlen(text) > 0 && text[strlen(text)-1] != '/') {
                strcpy(prefix, text);
                strcat(prefix, "/");
            }
        } else {
            /* if not go into the dir part */
            status = NXopengrouppath(the_fileId, absdir);
        }
        NXMEnableErrorReporting();

        if (status == NX_ERROR)
            return NULL;

        if (NXinitgroupdir(the_fileId) != NX_OK)
            return NULL;

        do {
            status =
                NXgetnextentry(the_fileId, name, nxclass, &dataType);
            if (status == NX_ERROR)
                break;
            if (status == NX_OK) {
                if (strncmp(nxclass, "CDF", 3) == 0) {
                    ;
                } else if (strncmp(name, matchtext, strlen(matchtext)) == 0) {
                    item = (struct name_item *)
                           malloc(sizeof(struct name_item));
                    item->name = (char *)calloc(256, 1);
                    strcpy(item->name, prefix);
                    strcat(item->name, name);

                    if (strcmp(nxclass, "SDS") != 0) {
                        strcat(item->name, "/");
                    }
                    item->next = NULL;
                    if (last_item == NULL) {
                        names = item;
                    } else {
                        last_item->next = item;
                    }
                    last_item = item;
                }
            }
        } while (status == NX_OK);
        NXopengrouppath(the_fileId, path);
        last_item = names;
    }
    if (last_item != NULL) {
        res = strdup(last_item->name);
        last_item = last_item->next;
    } else {
        res = NULL;
    }
    return res;
}