lcsim/src/org/lcsim/recon/cluster/util
diff -N Samplexmlclass.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Samplexmlclass.java 22 Jun 2006 21:45:35 -0000 1.1
@@ -0,0 +1,236 @@
+package org.lcsim.recon.cluster.util;
+import java.io.*;
+import java.awt.*;
+import org.w3c.dom.*;
+import org.w3c.dom.Text.*;
+import javax.xml.parsers.*;
+import org.xml.sax.*;
+import java.lang.*;
+import java.io.StringReader;
+
+/**
+ The purpose of this class is to read information directly from a specified XML file into BarrelCalSegmentFinder.
+ @author Judith Odili
+ @version 1- 06/22/06 - 16:30
+ Called by @see org.lcsim.recon.muon.BarrelCalSegmentFinder
+ */
+public class Samplexmlclass
+{
+ /**
+ The "xmlfile" variable. Gets the value of the compact.xml file to be read from.
+ */
+ public File xmlfile;
+ /**
+ To declare the xml to read the values from.
+ @param f The file to be read from.
+ */
+ public void declarefile(File f)
+ {
+
+ xmlfile = f;
+ System.out.println(xmlfile);
+
+ }
+ /**
+ Get the Integer value of the subdetector Id.
+ @param detname The name of the subdetector.
+ @return The integer value of the subdetector id.
+ @throws ParserConfigurationException
+ @throws SAXParseException
+ @throws IOException
+ */
+ public int getSubdetId(String detname)
+ {
+ int s = 999;
+ boolean found= false;
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(xmlfile);
+ Element root = doc.getDocumentElement();
+ NodeList children = root.getChildNodes();
+ //int j = 0;
+ //Get number of children of the entire xml file without spaces
+ for(int i=0; i<=children.getLength(); i++)
+ {
+ Node child = children.item(i);
+ if (child instanceof Element)
+ {
+ Element childElement = (Element)child;
+ if (childElement.getTagName().equals("detectors"))
+ {
+
+ NodeList DetectorsChildren = childElement.getChildNodes();
+ for(int j=0; j<=DetectorsChildren.getLength(); j++)
+ {
+ Node Detectorschild = DetectorsChildren.item(j);
+ if (Detectorschild instanceof Element)
+ {
+ Element DetectorsChildElement = (Element)Detectorschild;
+ if (DetectorsChildElement.getTagName().equals("detector"))
+ {
+
+ String name = DetectorsChildElement.getAttribute("name");
+ if (detname.equalsIgnoreCase(name))
+ {
+ String id = DetectorsChildElement.getAttribute("id");
+ found = true;
+ s = Integer.valueOf(id).intValue();
+ //System.out.println("subdetid == "+ s);
+
+
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (ParserConfigurationException err)
+ {
+ System.out.println(" " + err.getMessage ());
+
+ }
+ catch (SAXParseException err)
+ {
+
+ System.out.println(" " + err.getMessage ());
+
+ }
+ catch (IOException err) {
+ System.out.println(" " + err.getMessage ());
+
+ }
+
+ catch (Throwable t) {
+ t.printStackTrace ();
+ }
+
+ if (found==true)
+ return s;
+ else
+ {
+ System.out.println("Invalid Detector Name:" + detname +" ID will be set to 999 ");
+ return 999;
+ }
+
+
+
+ }
+
+ /**
+ Get the String value from the readouts of the Barrel Hits.(e.g MuonBarrHits, HCalBarrHits, EcalBarrHits)
+ @param detname The name of the subdetector.
+ @return The String value of the Segmentation id.
+ @throws ParserConfigurationException
+ @throws SAXParseException
+ @throws IOException
+ */
+
+ public String getReadoutId(String detname)
+ {
+ String s= "Invalid ";
+ boolean found = false;
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(xmlfile);
+ Element root = doc.getDocumentElement();
+ NodeList children = root.getChildNodes();
+ //int j = 0;
+ //Get number of children of the entire xml file without spaces
+ for(int i=0; i<=children.getLength(); i++)
+ {
+ Node child = children.item(i);
+ if (child instanceof Element)
+ {
+ Element childElement = (Element)child;
+ if (childElement.getTagName().equals("readouts"))
+ {
+ //System.out.println("Readouts Found");
+
+ NodeList ReadoutsChildren = childElement.getChildNodes();
+ for(int j=0; j<=ReadoutsChildren.getLength(); j++)
+ {
+ Node Readoutschild = ReadoutsChildren.item(j);
+ if (Readoutschild instanceof Element)
+ {
+ Element ReadoutsChildElement = (Element)Readoutschild;
+ if (ReadoutsChildElement.getTagName().equals("readout"))
+ {
+ String name= ReadoutsChildElement.getAttribute("name");
+ //System.out.println("NAME == " + name);
+ String namestart= name.substring(0,1);
+ // System.out.println("NAMESTART == " + namestart);
+ if (detname.startsWith(namestart) && name.endsWith("BarrHits") )
+ {
+ //System.out.println("Barr Hits");
+ NodeList DetectorsChildren = ReadoutsChildElement.getChildNodes();
+
+ for(int l=0; l<DetectorsChildren.getLength(); l++)
+ {
+ Node Detectorschild = DetectorsChildren.item(l);
+ if (Detectorschild instanceof Element)
+ {
+ Element DetectorsChildElement = (Element)Detectorschild;
+ NodeList idcontent = DetectorsChildElement.getChildNodes();
+
+ if (DetectorsChildElement.getTagName().equals("id"))
+ {
+ //System.out.println("ID found");
+ Node N = ((Node)idcontent.item(0));
+ s = N.getNodeValue();
+ found=true;
+
+ }
+
+
+ }
+ }
+
+ }
+
+ }
+
+
+ }
+ }//end of readouts children
+
+ }
+
+ }
+
+ }//end of total children
+
+
+ }
+ catch (ParserConfigurationException err)
+ {
+ System.out.println(" " + err.getMessage ());
+
+ }
+ catch (SAXParseException err)
+ {
+
+ System.out.println(" " + err.getMessage ());
+
+ }
+ catch (IOException err) {
+ System.out.println(" " + err.getMessage ());
+
+ }
+
+ catch (Throwable t) {
+ t.printStackTrace ();
+ }
+
+ if (found == false)
+ System.out.println("Invalid Detector name.... "+ detname+ "....Id will be set to Invalid");
+ return s;
+ }
+
+}
\ No newline at end of file