/** Gets the {@code Frame} at the given ({@code cycle} and {@code index}). */ public Frame getFrame(final int cycle, final int index) { final Sequence sequence = getSequence(cycle); if (sequence == null) return null; return sequence.getFrame(index); }
/** * Parses metadata from Prairie CFG file. This file is only present for * Prairie datasets recorded prior to version 5.2. */ private void parseCFG(final Document doc) { checkElement(doc.getDocumentElement(), "PVConfig"); final NodeList waitNodes = doc.getElementsByTagName("PVTSeriesElementWait"); if (waitNodes.getLength() > 0) { final Element waitElement = el(waitNodes, 0); waitTime = d(attr(waitElement, "waitTime")); } parseKeys(doc.getDocumentElement(), config); }
@Test public void testParseOldXML() throws ParserConfigurationException, SAXException, IOException { final Document xml = XMLTools.parseDOM(OLD_XML); final PrairieMetadata meta = new PrairieMetadata(xml, null, null); final Value positionCurrent = meta.getSequence(1).getFrame(1).getValue("positionCurrent"); final Value xAxis = positionCurrent.get("XAxis"); assertEquals("0.95", xAxis.value()); final Value yAxis = positionCurrent.get("YAxis"); assertEquals("-4.45", yAxis.value()); final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis"); assertEquals("-9", zAxis.get(0).value()); assertEquals("62.45", zAxis.get(1).value()); }
/** Parses metadata from Prairie XML file. */ private void parseXML(final Document doc) { final Element pvScan = doc.getDocumentElement(); checkElement(pvScan, "PVScan"); // parse <PVStateShard> key/value block parsePVStateShard(pvScan, scanValues); // parse acquisition date date = attr(pvScan, "date"); // iterate over all Sequence elements final NodeList sequenceNodes = doc.getElementsByTagName("Sequence"); for (int s = 0; s < sequenceNodes.getLength(); s++) { final Element sequenceElement = el(sequenceNodes, s); if (sequenceElement == null) continue; final Sequence sequence = new Sequence(sequenceElement); if (firstSequence == null) firstSequence = sequence; final int cycle = sequence.getCycle(); if (cycle < cycleMin) cycleMin = cycle; if (cycle > cycleMax) cycleMax = cycle; sequences.put(cycle, sequence); } }
/** * This step parses the Prairie metadata files into the Prairie-specific * metadata structure, {@link #meta}. */ private void parsePrairieMetadata() throws FormatException, IOException { LOGGER.info("Parsing Prairie metadata"); final Document xml, cfg, env; try { xml = parseDOM(xmlFile); cfg = parseDOM(cfgFile); env = parseDOM(envFile); } catch (ParserConfigurationException exc) { throw new FormatException(exc); } catch (SAXException exc) { throw new FormatException(exc); } meta = new PrairieMetadata(xml, cfg, env); sequences = meta.getSequences(); channels = meta.getActiveChannels(); if (channels == null || channels.length == 0) { throw new FormatException("No active channels found"); } }
/** * This steps populates the original metadata table (the tables returned by * {@link #getGlobalMetadata()} and {@link #getSeriesMetadata()}). */ private void populateOriginalMetadata() { final boolean minimumMetadata = isMinimumMetadata(); if (minimumMetadata) return; // populate global metadata addGlobalMeta("cycleCount", meta.getCycleCount()); addGlobalMeta("date", meta.getDate()); addGlobalMeta("waitTime", meta.getWaitTime()); addGlobalMeta("sequenceCount", sequences.size()); final ValueTable config = meta.getConfig(); for (final String key : config.keySet()) { addGlobalMeta(key, config.get(key).toString()); } addGlobalMeta("meta", meta); // populate series metadata final int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { setSeries(s); final Sequence sequence = sequence(s); addSeriesMeta("cycle", sequence.getCycle()); addSeriesMeta("indexCount", sequence.getIndexCount()); addSeriesMeta("type", sequence.getType()); } setSeries(0); }
/** * Parses details of the activated channels into the {@link #activeChannels} * data structure from the "channel" entry of the configuration. */ private void parseChannels() { final Value channels = config.get("channel"); if (!(channels instanceof ValueTable)) return; final ValueTable channelsTable = (ValueTable) channels; for (final String key : channelsTable.keySet()) { final Value value = channelsTable.get(key); // verify that the channel is active if (!b(value(value))) continue; // channel not active // parse the channel index (converting to a 1-based index!) final int channelIndex = i(key) + 1; // add the channel index to the active channels list activeChannels.add(channelIndex); } }
final Element pvStateShard = getFirstChild(el, "PVStateShard"); if (pvStateShard == null) return; final Element keyElement = el(svNodes, k); if (keyElement == null) continue; final String key = attr(keyElement, "key"); final String value = attr(keyElement, "value"); if (value != null) { table.put(key, new ValueItem(value, attr(keyElement, "description"))); continue; final Element ivElement = el(ivNodes, i); if (ivElement == null) continue; final String index = attr(ivElement, "index"); if (index == null) continue; // invalid <IndexedValue> element final String iValue = attr(ivElement, "value"); final String iDescription = attr(ivElement, "description"); subTable.put(index, new ValueItem(iValue, iDescription)); keyElement.getElementsByTagName("SubindexedValues"); for (int i = 0; i < sivNodes.getLength(); i++) { final Element sivElement = el(sivNodes, i); if (sivElement == null) continue; final String index = attr(sivElement, "index"); if (index == null) continue; // invalid <SubindexedValues> element final ValueTable subSubTable = new ValueTable(); sivElement.getElementsByTagName("SubindexedValue");
/** * Parses metadata from Prairie ENV file. This file is only present for * Prairie datasets recorded with version 5.2 or later. */ private void parseENV(final Document doc) { checkElement(doc.getDocumentElement(), "Environment"); parsePVStateShard(doc.getDocumentElement(), config); }
final NodeList keyNodes = el.getElementsByTagName("Key"); for (int k = 0; k < keyNodes.getLength(); k++) { final Element keyElement = el(keyNodes, k); if (keyElement == null) continue; final String key = attr(keyElement, "key"); final String value = attr(keyElement, "value"); final int underscore = key.indexOf('_'); if (underscore < 0) {
/** Gets the first child element with the given name. */ private Element getFirstChild(final Element el, final String name) { // NB: Unfortunately, the Element interface has no API method to obtain // _only_ direct children with a given name; the getElementsByTagName // method returns _all_ descendant elements with the given name. final NodeList nodeList = el.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { final Element child = el(nodeList, i); if (child == null) continue; if (name.equals(child.getNodeName())) return child; } return null; }
final int seriesCount = sequenceCount / sizeT; final Integer bitDepth = meta.getBitDepth(); int bpp = bitDepth == null ? -1 : bitDepth;
@Test public void testParseNewXML() throws ParserConfigurationException, SAXException, IOException { final Document xml = XMLTools.parseDOM(NEW_XML); final PrairieMetadata meta = new PrairieMetadata(xml, null, null); final ValueTable positionCurrent = (ValueTable) meta.getSequence(1).getFrame(1).getValue("positionCurrent"); final ValueTable xAxis = (ValueTable) positionCurrent.get("XAxis"); assertEquals("-621.412879412341", xAxis.value()); final ValueTable yAxis = (ValueTable) positionCurrent.get("YAxis"); assertEquals("255.652372573538", yAxis.value()); final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis"); assertEquals("28.15", zAxis.get(0).value()); assertEquals("111.23", zAxis.get(1).value()); } }
/** Parses metadata from Prairie XML file. */ private void parseXML(final Document doc) { final Element pvScan = doc.getDocumentElement(); checkElement(pvScan, "PVScan"); // parse <PVStateShard> key/value block parsePVStateShard(pvScan, scanValues); // parse acquisition date date = attr(pvScan, "date"); // iterate over all Sequence elements final NodeList sequenceNodes = doc.getElementsByTagName("Sequence"); for (int s = 0; s < sequenceNodes.getLength(); s++) { final Element sequenceElement = el(sequenceNodes, s); if (sequenceElement == null) continue; final Sequence sequence = new Sequence(sequenceElement); if (firstSequence == null) firstSequence = sequence; final int cycle = sequence.getCycle(); if (cycle < cycleMin) cycleMin = cycle; if (cycle > cycleMax) cycleMax = cycle; sequences.put(cycle, sequence); } }
/** * This step parses the Prairie metadata files into the Prairie-specific * metadata structure, {@link #meta}. */ private void parsePrairieMetadata() throws FormatException, IOException { LOGGER.info("Parsing Prairie metadata"); final Document xml, cfg, env; try { xml = parseDOM(xmlFile); cfg = parseDOM(cfgFile); env = parseDOM(envFile); } catch (ParserConfigurationException exc) { throw new FormatException(exc); } catch (SAXException exc) { throw new FormatException(exc); } meta = new PrairieMetadata(xml, cfg, env); sequences = meta.getSequences(); channels = meta.getActiveChannels(); if (channels == null || channels.length == 0) { throw new FormatException("No active channels found"); } }
/** * This steps populates the original metadata table (the tables returned by * {@link #getGlobalMetadata()} and {@link #getSeriesMetadata()}). */ private void populateOriginalMetadata() { final boolean minimumMetadata = isMinimumMetadata(); if (minimumMetadata) return; // populate global metadata addGlobalMeta("cycleCount", meta.getCycleCount()); addGlobalMeta("date", meta.getDate()); addGlobalMeta("waitTime", meta.getWaitTime()); addGlobalMeta("sequenceCount", sequences.size()); final ValueTable config = meta.getConfig(); for (final String key : config.keySet()) { addGlobalMeta(key, config.get(key).toString()); } addGlobalMeta("meta", meta); // populate series metadata final int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { setSeries(s); final Sequence sequence = sequence(s); addSeriesMeta("cycle", sequence.getCycle()); addSeriesMeta("indexCount", sequence.getIndexCount()); addSeriesMeta("type", sequence.getType()); } setSeries(0); }