10 modified files
LCGO
diff -u -r1.2 -r1.3
--- GNUmakefile 29 Sep 2006 16:29:14 -0000 1.2
+++ GNUmakefile 30 Oct 2006 10:52:18 -0000 1.3
@@ -7,6 +7,20 @@
CLASSPATH=$(WORK)/jars/$(JDOM):$(WORK)/jars/$(JEL)
+
+
+jsource := $(wildcard src/java/hep/gear/api/*.java)
+jsource += $(wildcard src/java/hep/gear/base/*.java)
+jsource += $(wildcard src/java/hep/gear/implementation/*.java)
+jsource += $(wildcard src/java/hep/gear/xml/*.java)
+
+cheaders := $(patsubst %.java, %.h, $(jsource) )
+cheaders := $(patsubst src/java/%, $(DIST)/include/%, $(cheaders) )
+
+GEARBASESOURCES = $(cheaders)
+
+
+
.PHONY : all
all: test
@@ -24,27 +38,51 @@
$(DIST)/lib/%.jar.so : $(WORK)/jars/%.jar
mkdir -p $(DIST)/lib
- gcj -fPIC -findirect-dispatch -shared -o $@ $<
+ gcj -g -fPIC -findirect-dispatch -shared -o $@ $<
# Not currently used
%.jar.a : %.jar
- gcj -c -findirect-dispatch -o $<.o $<
+ gcj -c -g -findirect-dispatch -o $<.o $<
ar rcs $@ $<.o
rm $<.o
-
+
$(DIST)/include/hep/lcgo/xml/reader/%.h: $(WORK)/jars/LCGO.jar
mkdir -p $(DIST)/include/hep/lcgo/xml/reader
gcjh --classpath=$< -d $(DIST)/include hep.lcgo.xml.reader.$*
-$(WORK)/jars/LCGO.jar: src/java/hep/lcgo/xml/reader/*.java src/java/hep/lcgo/xml/reader/util/*.java src/java/hep/lcgo/util/cache/*.java
+
+$(DIST)/include/hep/gear/api/%.h: $(WORK)/jars/LCGO.jar
+ mkdir -p $(DIST)/include/hep/gear/api
+ gcjh --classpath=$< -d $(DIST)/include hep.gear.api.$*
+
+$(DIST)/include/hep/gear/implementation/%.h: $(WORK)/jars/LCGO.jar
+ mkdir -p $(DIST)/include/hep/gear/implementation
+ gcjh --classpath=$< -d $(DIST)/include hep.gear.implementation.$*
+
+$(DIST)/include/hep/gear/base/%.h: $(WORK)/jars/LCGO.jar
+ mkdir -p $(DIST)/include/hep/gear/base
+ gcjh --classpath=$< -d $(DIST)/include hep.gear.base.$*
+
+$(DIST)/include/hep/gear/xml/%.h: $(WORK)/jars/LCGO.jar
+ mkdir -p $(DIST)/include/hep/gear/xml
+ gcjh --classpath=$< -d $(DIST)/include hep.gear.xml.$*
+
+
+$(WORK)/jars/LCGO.jar: src/java/hep/lcgo/xml/reader/*.java src/java/hep/lcgo/xml/reader/util/*.java src/java/hep/lcgo/util/cache/*.java $(jsource)
mkdir -p $(WORK)/classes
gcj -d $(WORK)/classes --classpath=$(CLASSPATH) -C $^
fastjar -cf $@ -C $(WORK)/classes .
-
-$(WORK)/includes: src/include/* $(DIST)/include/hep/lcgo/xml/reader/LCGOReader.h $(DIST)/include/hep/lcgo/xml/reader/Detector.h $(DIST)/include/hep/lcgo/xml/reader/Constant.h
+
+
+$(WORK)/includes: src/include/* $(DIST)/include/hep/lcgo/xml/reader/LCGOReader.h $(DIST)/include/hep/lcgo/xml/reader/Detector.h $(DIST)/include/hep/lcgo/xml/reader/Constant.h $(GEARBASESOURCES)
cp -r src/include/*.h $(DIST)/include
touch $@
-
+
+#$(WORK)/includes: src/include/* $(DIST)/include/hep/lcgo/xml/reader/LCGOReader.h $(DIST)/include/hep/lcgo/xml/reader/Detector.h $(DIST)/include/hep/lcgo/xml/reader/Constant.h $(DIST)/include/hep/gear/base/Vector3D.h $(DIST)/include/hep/gear/base/Vector2D.h $(DIST)/include/hep/gear/base/Point3D.h $(DIST)/include/hep/gear/base/Point2D.h
+# cp -r src/include/*.h $(DIST)/include
+# touch $@
+
+
$(WORK)/dist: $(DIST)/lib/$(XERCES).so $(DIST)/lib/$(JDOM).so $(DIST)/lib/$(JEL).so $(DIST)/lib/LCGO.jar.so $(DIST)/lib/LCGO.so $(WORK)/includes
touch $@
@@ -52,7 +90,9 @@
gcj -o $@ -fPIC -shared -I$(DIST)/include src/cpp/*.cc
test: test.cc $(WORK)/dist
- g++ -o $@ -I$(DIST)/include $< $(DIST)/lib/*.so -lgcj
+ gcj -g -c -o test.o -I$(DIST)/include test.cc
+ g++ -o $@ test.o $(DIST)/lib/*.so -lgcj
+# g++ -g -o $@ -I$(DIST)/include $< $(DIST)/lib/*.so -lgcj
.PHONY : run
run: test
@@ -61,6 +101,16 @@
.PHONY : clean
clean:
+ -rm -rf $(WORK)/classes
+ -rm -rf $(WORK)/dist
+ -rm -rf $(WORK)/includes
+ -rm -rf $(DIST)/include
+ -rm -rf $(DIST)/lib/LCGO*
+ -rm test
+
+
+.PHONY : realclean
+realclean:
-rm -rf $(WORK)
-rm -rf $(DIST)
-rm test
LCGO
diff -u -r1.1 -r1.2
--- GeometryReaderTest.xml 29 Sep 2006 16:27:16 -0000 1.1
+++ GeometryReaderTest.xml 30 Oct 2006 10:52:18 -0000 1.2
@@ -1,7 +1,7 @@
-<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
+<!-- lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
- xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
-
+ xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd" -->
+<lccdd>
<!-- info tag containing author, version, time, unique id (url) -->
<info name="GeometryReaderTest">
<comment>
@@ -44,6 +44,33 @@
</materials>
<detectors>
+ <detector name="VXD" geartype="VXDParameters">
+ <vxdType technology="CCD" />
+ <shell halfLength="135.000000" gap="0.040000" innerRadius="65.000000" outerRadius="65.493920" radLength="352.759946" />
+ <layers>
+ <layer nLadders="8" phi0="0.000000">
+ <ladder distance="15.000000" thickness="0.282240" width="13.000000" length="25.000000" offset="-1.455005" radLength="352.759946" />
+ <sensitive distance="15.282240" thickness="0.037440" width="13.000000" length="25.000000" offset="-1.455005" radLength="93.676203" />
+ </layer>
+ <layer nLadders="8" phi0="0.000000">
+ <ladder distance="26.000000" thickness="0.282240" width="22.000000" length="62.500000" offset="-1.398656" radLength="352.759946" />
+ <sensitive distance="26.282240" thickness="0.037440" width="22.000000" length="62.500000" offset="-1.398656" radLength="93.676203" />
+ </layer>
+ <layer nLadders="12" phi0="0.000000">
+ <ladder distance="38.000000" thickness="0.282240" width="22.000000" length="62.500000" offset="-2.571633" radLength="352.759946" />
+ <sensitive distance="38.282240" thickness="0.037440" width="22.000000" length="62.500000" offset="-2.571633" radLength="93.676203" />
+ </layer>
+ <layer nLadders="16" phi0="0.000000">
+ <ladder distance="49.000000" thickness="0.282240" width="22.000000" length="62.500000" offset="-3.592945" radLength="352.759946" />
+ <sensitive distance="49.282240" thickness="0.037440" width="22.000000" length="62.500000" offset="-3.592945" radLength="93.676203" />
+ </layer>
+ <layer nLadders="20" phi0="0.000000">
+ <ladder distance="60.000000" thickness="0.282240" width="22.000000" length="62.500000" offset="-4.422448" radLength="352.759946" />
+ <sensitive distance="60.282240" thickness="0.037440" width="22.000000" length="62.500000" offset="-4.422448" radLength="93.676203" />
+ </layer>
+ </layers>
+ </detector>
+
<detector id="1" name="VertexBarrel" type="MultiLayerTracker" readout="VtxBarrHits">
<layer id="1" inner_r = "vertex_inner_r" outer_z = "2.5*cm">
<slice material = "Silicon" thickness = "0.01*cm" sensitive = "yes" />
@@ -159,6 +186,10 @@
</layer>
</detector>
<detector id="9" name="MuonEndcap" reflect="true" type="CylindricalEndcapCalorimeter" readout="MuonEndcapHits">
+ <parameter name="SomeIntParameter" type="int"> 21 </parameter>
+ <parameter name="SomeDoubleParameter" type="double"> 42.3 </parameter>
+ <parameter name="SomeStringParameter" type="string" value="42 " />
+
<dimensions inner_r = "20.0*cm" inner_z = "287.0*cm" outer_r = "636.0*cm" />
<layer repeat="32">
<slice material = "Iron" thickness = "5.0*cm" />
@@ -172,6 +203,23 @@
<slice material="Tungsten" thickness = "35.*cm" sensitive = "yes" />
</layer>
</detector>
+ <detector id="0" name="SomeDetectorTest" geartype="GearParameters" type="UNKNOWN" insideTrackingVolume="false">
+
+ <parameter name="SomeIntParameter" type="int"> 21 </parameter>
+ <parameter name="AnotherIntParameter" type="int"> 42 </parameter>
+ <parameter name="SomeDoubleParameter" type="double"> 42.3 </parameter>
+ <parameter name="SomeStringParameter" type="string" value="42 " />
+
+ <parameter name="SomeIntParameters" type="IntVec"> 42 43 44 45 </parameter>
+ <parameter name="MoreIntParameters" type="IntVec"> 41 42 43 47 </parameter>
+ <parameter name="SomeDoubleParameters" type="DoubleVec"> 42.3 42.4 42.5 </parameter>
+ <parameter name="SomeStringParameters" type="StringVec" value="42 44 67 89 text number string 12345" />
+
+ </detector>
+
+
+
+
</detectors>
<readouts>
<readout name="MuonBarrHits">
LCGO
diff -u -r1.1 -r1.2
--- test.cc 29 Sep 2006 16:27:16 -0000 1.1
+++ test.cc 30 Oct 2006 10:52:18 -0000 1.2
@@ -1,12 +1,55 @@
#include <iostream>
#include "LCGO.h"
-#include "java/util/Map.h"
+
+#include <java/util/Map.h>
+#include <java/lang/String.h>
+#include <java/lang/Throwable.h>
+#include <java/lang/System.h>
+
+#include "hep/gear/api/GearMgr.h"
+#include "hep/gear/api/GearParameters.h"
+#include "hep/gear/base/UnknownParameterException.h"
+#include "hep/gear/implementation/GearParametersImpl.h"
+
+#include <cmath>
+
+using namespace hep::lcgo::xml::reader;
+using namespace hep::gear::api ;
+using namespace hep::gear::base ;
+using namespace hep::gear::implementation ;
+using namespace java::util;
+using namespace java::lang;
+using namespace std;
+
+// void lcgo_unexpected(){
+// try{
+// throw ;
+// }catch( java::lang::Exception* e){
+// std::cout << " A runtime error has occured : "
+// << e->toString()
+// << std::endl
+// << " the program will have to be terminated - sorry." << std::endl ;
+// exit(1) ;
+// }
+// }
+
+typedef JArray< ::java::lang::String *> JStringArray ;
+
+
+void testGearAPI( Detector* det ) ;
+void printString( const std::string& cstring ) ;
int main(int argc, char *argv[])
{
- using namespace hep::lcgo::xml::reader;
- using namespace java::util;
- using namespace std;
+
+
+ // fg: can't mix C++ and Java exceptions in compilation unit
+ // --- unexpected and terminate don't work for Java Exceptions...
+// std::set_unexpected( lcgo_unexpected ) ;
+// std::set_terminate( lcgo_unexpected ) ;
+
+ try{
+
LCGO lcgo("GeometryReaderTest.xml");
Detector* det = lcgo.getDetector();
@@ -14,4 +57,190 @@
cout << det << endl;
cout << constants << endl;
+
+ testGearAPI( det ) ;
+
+
+
+ }catch( java::lang::Throwable* e){
+
+ std::cout << " An uncaught Exception has been found: "
+ << e->toString()
+ << std::endl
+ << " the program will have to be terminated - sorry." << std::endl ;
+
+ std::cout << " ---- stack trace: ---------- " << std::endl ;
+// e->printStackTrace( ::java::lang::System::out ) ;
+// e->fillInStackTrace() ;
+// e->printStackTrace() ;
+ exit(1) ;
+ }
+
+
+}
+
+
+void testGearAPI( Detector* det ) {
+
+ // print user defined parameters:
+ GearMgr* gearmgr = det->gearMgr() ;
+
+
+ JStringArray* keys = gearmgr->getGearParameterKeys();
+
+ for(int i=0 ; i < keys->length ; i++){
+
+ // access to java arrays works only through elements !!??
+ String* s = elements(keys)[i] ;
+
+ GearParameters* p = gearmgr->getGearParameters( s ) ;
+
+ cout << " found gear parameters for detector : " << s << endl ;
+ cout << p->toString()
+ << endl ;
+
+
+
+ // try accessing an array of ints:
+
+ // -------------------- can't use c'tor of String with const char * !!??
+ try{
+ // jintArray jia = p->getIntVals( JvNewStringLatin1("SomeIntParameters") ) ;
+ // ----- optionally create a wrapper conversion class object
+ jintArray jia = p->getIntVals( cjstring("SomeIntParameters") ) ;
+
+ cout << " test: SomeIntParameters ["
+ << int(jia->length) << "] { " ;
+
+ for(int i=0 ; i< jia->length ; i++){
+
+ // ------ need cast to int for printout !!?? ------
+ cout << (int) elements(jia)[i] << ", " ;
+ if( elements(jia)[i] == 42 ) continue ;
+
+ }
+ cout << " } " << endl ;
+ }catch( UnknownParameterException* e){
+ // parameter wasn't set
+ }
+
+
+ // try accessing an array of doubles:
+
+ // -------------------- can't use c'tor of String with const char * !!??
+ try {
+
+ jdoubleArray jda = p->getDoubleVals( JvNewStringLatin1("SomeDoubleParameters") ) ;
+
+ cout << " test: SomeDoubleParameters ["
+ << int(jda->length) << "] { " ;
+
+ for(int i=0 ; i< jda->length ; i++){
+
+ // ------ need cast or temporary double for function calls !!?? ------
+ double val( elements(jda)[i] ) ;
+ cout << std::sin( val ) << ", " ;
+
+ }
+ cout << " } " << endl ;
+
+ }catch( UnknownParameterException* e){
+ // parameter wasn't set
+ }
+
+
+
+ // accessing basic type parameters:
+// int values: {SomeIntParameter=21}
+// double values: {SomeDoubleParameter=42.3}
+// string values: {SomeStringParameter=42 }
+
+ try{
+ int ival = p->getIntVal( JvNewStringLatin1("SomeIntParameter") ) ;
+ std::cout << " - found int SomeIntParameter : " << ival << std::endl ;
+ double dval = p->getDoubleVal( JvNewStringLatin1("SomeDoubleParameter") ) ;
+ std::cout << " - found double SomeDoubleParameter : " << dval << std::endl ;
+
+// String* sval = p->getStringVal( JvNewStringLatin1("SomeStringParameter") ) ;
+// std::cout << " - found double SomeStringParameter : " ;
+// printString( cjstring(sval) ) ;
+// std::cout << std::endl ;
+
+ cjstring sval = p->getStringVal( cjstring("SomeStringParameter") ) ;
+ std::cout << " - found double SomeStringParameter : "
+ << sval << std::endl ;
+
+
+
+ }catch( UnknownParameterException* e){
+ // parameter wasn't set
+ }
+
+
+ // ----- try to modify/extend the GearParameters------------
+ if( p->toString()->length() > 0 ) {
+ // ----- gjjh does not create inheritance for interfaces !!??
+ // ------ use ugly reinterpret_cast - is this dangerous ??
+ // GearParametersImpl* pImpl = reinterpret_cast<GearParametersImpl*>(p) ;
+ // ------ use old c-style / Java style cast !!??
+ // ----- this needs to be studied and understood !!
+ GearParametersImpl* pImpl = (GearParametersImpl*) p ;
+
+
+// jintArray newInts = JvNewIntArray( 3 ) ;
+// // ------ cannot assign to java array variables with operator [] !!??
+// newInts[0] = 1234 ;
+// newInts[1] = 12345 ;
+// newInts[2] = 123456 ;
+
+// pImpl->setIntVals( JvNewStringLatin1("SomeCoolNewIntvals") , newInts ) ;
+
+// jint* newIntsC = elements ( newInts ) ;
+
+
+ cjarray<int,jint> newIntsC( 3 ) ;
+ newIntsC[0] = 1234 ;
+ newIntsC[1] = 12345 ;
+ newIntsC[2] = 123456 ;
+ pImpl->setIntVals( JvNewStringLatin1("SomeCoolNewIntvals") , newIntsC.j_ar() ) ;
+
+
+ // test iterator
+ std::vector<int> stdv ;
+ std::copy( newIntsC.begin() , newIntsC.end() , std::back_inserter( stdv ) ) ;
+
+ // --- now modify existing parameters
+ try{
+ jintArray jia = p->getIntVals( JvNewStringLatin1("SomeIntParameters") ) ;
+
+ for(int i=0 ; i< jia->length ; i++){
+ elements(jia)[i] += 100000 ;
+ }
+
+
+ // modified parameters:
+ cout << " modified gear parameters for detector : " << s << endl ;
+ cout << p << endl ;
+
+ GearIntVec iv( jia ) ;
+ std::cout << " GearIntVec iv: " << iv << std::endl ;
+ std::cout << " jintarray: " << jia << std::endl ;
+ std::cout << " cjarray: " << cjarray<int,jint>(jia) << std::endl ;
+
+ }catch( UnknownParameterException* e){
+ // parameter wasn't set
+ }
+
+ }
+ }
+
+ // try instantiating a java object on the heap :
+ // GearParametersImpl someParams() ;
+
}
+
+/** test to calling a function that expects an std::string */
+void printString( const std::string& str ) {
+ std::cout << str ;
+}
+
LCGO/src/cpp
diff -u -r1.1 -r1.2
--- LCGO.cc 29 Sep 2006 16:27:17 -0000 1.1
+++ LCGO.cc 30 Oct 2006 10:52:20 -0000 1.2
@@ -1,10 +1,23 @@
#include "LCGO.h"
+#include "hep/gear/api/GearMgr.h"
+#include "hep/gear/api/GearParameters.h"
+#include "hep/gear/implementation/GearParametersImpl.h"
+#include "java/lang/System.h"
+
LCGO::LCGO(char* file)
{
JvCreateJavaVM(NULL);
JvAttachCurrentThread(NULL, NULL);
+ // initialize classes : - is this needed ? (not according to the gcj manual )
+ JvInitClass(& hep::gear::api::GearParameters::class$);
+ JvInitClass(& hep::gear::api::GearMgr::class$);
+ JvInitClass(& hep::gear::implementation::GearParametersImpl::class$);
+ JvInitClass(& java::lang::System::class$);
+
+
+
hep::lcgo::xml::reader::LCGOReader* reader = new hep::lcgo::xml::reader::LCGOReader();
detector = reader->read(JvNewStringLatin1(file));
}
LCGO/src/cpp
diff -u -r1.1 -r1.2
--- LCGOUtil.cc 29 Sep 2006 16:27:17 -0000 1.1
+++ LCGOUtil.cc 30 Oct 2006 10:52:20 -0000 1.2
@@ -1,4 +1,5 @@
#include "LCGOUtil.h"
+#include "hep/gear/api/GearParameters.h"
std::ostream& operator << (std::ostream& os, const java::lang::Object* obj)
{
@@ -13,3 +14,12 @@
JvFree(result);
return os;
}
+
+std::ostream& operator << (std::ostream& os, const GearIntVec& v){
+
+ os << " { " ;
+ for( int i=0 ; i< v.size() ; ++i){
+ os << v.at(i) << " , " ;
+ }
+ os << "} " << std::endl ;
+}
LCGO/src/include
diff -u -r1.1 -r1.2
--- LCGO.h 29 Sep 2006 16:27:17 -0000 1.1
+++ LCGO.h 30 Oct 2006 10:52:20 -0000 1.2
@@ -7,6 +7,7 @@
#include "hep/lcgo/xml/reader/Constant.h"
#include "LCGOUtil.h"
+#include <java/lang/String.h>
class LCGO {
@@ -19,4 +20,7 @@
hep::lcgo::xml::reader::Detector* detector;
};
+
+
+
#endif
LCGO/src/include
diff -u -r1.1 -r1.2
--- LCGOUtil.h 29 Sep 2006 16:27:17 -0000 1.1
+++ LCGOUtil.h 30 Oct 2006 10:52:21 -0000 1.2
@@ -6,6 +6,108 @@
#include <gcj/cni.h>
#include "java/lang/Object.h"
+#include <vector>
+#include <gcj/array.h>
+#include <algorithm>
+#include <string>
+
std::ostream& operator << (std::ostream& os, const java::lang::Object* obj);
+
+/** Conversion of jintArray to std::vector<int> */
+class GearIntVec : public std::vector<int>{
+
+ public:
+
+ GearIntVec( unsigned length ) : std::vector<int>( length) {}
+
+ GearIntVec(const jintArray jia ) : std::vector<int>( jia->length ) {
+
+ // assert( sizeof( int ) == sizeof( jint ) ) ;
+ std::copy( elements(jia) , elements(jia)+jia->length , begin() ) ;
+ }
+};
+template <class C, class J >
+class cjarray ;
+
+template <class C, class J >
+std::ostream& operator << (std::ostream& os, const cjarray< C, J >& a) {
+ os << " { " ;
+ for( int i=0 ; i< a.size() ; ++i){
+ os << a[i] << " , " ;
+ }
+ os << "} " << std::endl ;
+
+}
+
+/** Convenient access to JArray<> elements from c++ */
+template <class C, class J >
+class cjarray {
+
+protected:
+ JArray<J>* _ja ;
+
+public:
+ cjarray( JArray<J>* ja ) : _ja(ja) {}
+ cjarray( unsigned n) : _ja( JvNewIntArray(n) ) {}
+
+ size_t size() const { return _ja->length ;}
+ C operator[](unsigned i) const { return elements(_ja)[i] ; }
+ J& operator[](unsigned i) { return elements(_ja)[i] ; }
+
+ JArray<J>* j_ar() { return _ja ; }
+
+ C* begin() { return (C*) elements(_ja) ; }
+ C* end() { return (C*) elements(_ja)+_ja->length ; }
+
+} ;
+
+std::ostream& operator << (std::ostream& os, const GearIntVec& v) ;
+
+// inline
+// java::lang::String* c2j( const char* t) { return JvNewStringLatin1(t) ; }
+
+
+/** Conversion between jstring (java::lang::String*) and std::string/const char* */
+class cjstring {
+
+ private:
+ std::string _text ;
+
+ public:
+ cjstring( const std::string& str ) : _text( str ) {} ;
+
+ cjstring( const char* text) : _text( text ) {} ;
+
+ cjstring( jstring jstr ) {
+
+ int l = JvGetStringUTFLength(jstr);
+ char* t = new char[l+1];
+
+ JvGetStringUTFRegion(jstr,0,l,t);
+ *(t+l)='\0';
+ _text = t ;
+
+ delete[] t ;
+ } ;
+
+ /** Conversion to java string - creates new object on the (java) heap */
+ operator jstring() {
+ return JvNewStringLatin1(_text.c_str() ) ;
+ }
+
+ /** Conversion to c++ string for function calls */
+ operator const std::string&() { return _text ; }
+
+ /** Provide access to the c++ string */
+ std::string& str() { return _text ; }
+
+ /** Provide access to the c string - same as str().c_str() */
+ const char* c_str() { return _text.c_str() ; }
+};
+
+
+
#endif
+
+
LCGO/src/java/hep/lcgo/xml/reader
diff -u -r1.1 -r1.2
--- Detector.java 29 Sep 2006 16:27:18 -0000 1.1
+++ Detector.java 30 Oct 2006 10:52:21 -0000 1.2
@@ -1,17 +1,24 @@
package hep.lcgo.xml.reader;
+import hep.gear.api.GearMgr;
+import hep.gear.implementation.GearMgrImpl;
+
import java.util.HashMap;
import java.util.Map;
import org.jdom.Element;
+
+
/**
* Default class created to represent the parsed detector.
* @author tonyj
- * @version $Id: Detector.java,v 1.1 2006/09/29 16:27:18 tonyj Exp $
+ * @version $Id: Detector.java,v 1.2 2006/10/30 10:52:21 gaede Exp $
*/
public class Detector
{
private Header header;
+ private GearMgr _gearMgr = new GearMgrImpl() ;
+
private final Map/*<String,Constant>*/ constants = new HashMap/*<String,Constant>*/();
@@ -24,6 +31,8 @@
}
+ public GearMgr gearMgr() { return _gearMgr ; }
+
/**
* Called by the reader to associate a header with this detector
* @param header The header.
LCGO/src/java/hep/lcgo/xml/reader
diff -u -r1.1 -r1.2
--- LCGOElementFactory.java 29 Sep 2006 16:27:18 -0000 1.1
+++ LCGOElementFactory.java 30 Oct 2006 10:52:21 -0000 1.2
@@ -1,5 +1,7 @@
package hep.lcgo.xml.reader;
+import hep.gear.xml.GearXMLParameters;
+import hep.gear.xml.VXDParametersXML;
import hep.lcgo.xml.reader.util.DefaultElementFactory;
/**
@@ -16,5 +18,7 @@
register(Constant.class);
register(Detector.class);
register(Header.class);
- }
+ register(GearXMLParameters.class) ;
+ register(VXDParametersXML.class) ;
+ }
}
LCGO/src/java/hep/lcgo/xml/reader
diff -u -r1.1 -r1.2
--- LCGOReader.java 29 Sep 2006 16:27:18 -0000 1.1
+++ LCGOReader.java 30 Oct 2006 10:52:21 -0000 1.2
@@ -11,6 +11,12 @@
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
+
+import hep.gear.api.GearMgr;
+import hep.gear.api.GearParameters;
+import hep.gear.base.UnknownParameterException;
+import hep.gear.xml.GearXMLParameters;
+import hep.gear.xml.VXDParametersXML;
import hep.lcgo.xml.reader.util.CachingEntityResolver;
import hep.lcgo.xml.reader.util.ElementFactory;
import hep.lcgo.xml.reader.util.JDOMExpressionFactory;
@@ -24,94 +30,137 @@
* org.lcsim.geometry.GeometryReader class, which extends this.
*
* @author tonyj
- * @version $Id: LCGOReader.java,v 1.1 2006/09/29 16:27:18 tonyj Exp $
+ * @version $Id: LCGOReader.java,v 1.2 2006/10/30 10:52:21 gaede Exp $
*
*/
public class LCGOReader
{
- private ElementFactory factory;
-
- /**
- * Create a CompactReader using a DefaultElementFactory.
- */
- public LCGOReader()
- {
- this(new LCGOElementFactory());
- }
- /**
- * Create a CompactReader using the specified ElementFactory.
- * @param factory The ElementFactory to be used for creating elements as the file is parsed.
- */
- public LCGOReader(ElementFactory factory)
- {
- this.factory = factory;
- }
-
- public Detector read(String fileName) throws IOException, JDOMException, ElementCreationException
- {
- InputStream in = new FileInputStream(fileName);
- try
- {
- return read(in);
- }
- finally
- {
- in.close();
- }
- }
- /**
- * Read a compact geometry XML file.
- * @param in The input stream to read.
- * @throws java.io.IOException If an IO error occurs while reading the stream.
- * @throws org.jdom.JDOMException If invalid XML is found while reading the file.
- * @throws org.lcsim.geometry.compact.ElementFactory.ElementCreationException If the ElementFactory throws an ElementCreationException.
- * @return The parsed detector description.
- */
- public Detector read(InputStream in) throws IOException, JDOMException, ElementCreationException
- {
- JDOMExpressionFactory jdom = new JDOMExpressionFactory();
- SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
- builder.setFactory(jdom);
-
- builder.setValidation(true);
- builder.setFeature("http://apache.org/xml/features/validation/schema", true);
-
- // Add an EntityResolver that caches to ~/.cache
- builder.setEntityResolver(new CachingEntityResolver());
-
- Document doc = builder.build(in);
-
- Element lccdd = doc.getRootElement();
- Detector det = (Detector) factory.createElement(Detector.class,lccdd,null);
-
- readHeader(lccdd, det, jdom);
- return det;
- }
-
- private void readHeader(Element lccdd, Detector det, JDOMExpressionFactory jdom) throws JDOMException, ElementCreationException
- {
- Element info = lccdd.getChild("info");
- det.setHeader((Header) factory.createElement(Header.class,info,null));
- Element define = lccdd.getChild("define");
- for (Iterator i = define.getChildren("constant").iterator(); i.hasNext(); )
- {
- Element constant = (Element) i.next();
- Constant c = (Constant) factory.createElement(Constant.class,constant,null);
- jdom.addConstant(c.getName(),c.getValue());
- det.addConstant(c);
- }
- }
- // Fixme: Should not be here
- public static void main(String[] args) throws FileNotFoundException, IOException, JDOMException, ElementCreationException
- {
- LCGOReader reader = new LCGOReader();
- Detector det = reader.read(new FileInputStream(args[0]));
- Map constants = det.getConstants();
- for (Iterator i = constants.entrySet().iterator(); i.hasNext(); )
- {
- Map.Entry entry = (Map.Entry) i.next();
- Constant c = (Constant) entry.getValue();
- System.out.println(entry.getKey()+"="+c.getValue());
- }
- }
-}
+ private ElementFactory factory;
+
+ /**
+ * Create a CompactReader using a DefaultElementFactory.
+ */
+ public LCGOReader()
+ {
+ this(new LCGOElementFactory());
+ }
+ /**
+ * Create a CompactReader using the specified ElementFactory.
+ * @param factory The ElementFactory to be used for creating elements as the file is parsed.
+ */
+ public LCGOReader(ElementFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ public Detector read(String fileName) throws IOException, JDOMException, ElementCreationException
+ {
+ InputStream in = new FileInputStream(fileName);
+ try
+ {
+ return read(in);
+ }
+ finally
+ {
+ in.close();
+ }
+ }
+ /**
+ * Read a compact geometry XML file.
+ * @param in The input stream to read.
+ * @throws java.io.IOException If an IO error occurs while reading the stream.
+ * @throws org.jdom.JDOMException If invalid XML is found while reading the file.
+ * @throws org.lcsim.geometry.compact.ElementFactory.ElementCreationException If the ElementFactory throws an ElementCreationException.
+ * @return The parsed detector description.
+ */
+ public Detector read(InputStream in) throws IOException, JDOMException, ElementCreationException
+ {
+ JDOMExpressionFactory jdom = new JDOMExpressionFactory();
+ SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
+ builder.setFactory(jdom);
+
+ //builder.setValidation(true);
+ //builder.setFeature("http://apache.org/xml/features/validation/schema", true);
+
+ // Add an EntityResolver that caches to ~/.cache
+ builder.setEntityResolver(new CachingEntityResolver());
+
+ Document doc = builder.build(in);
+
+ Element lccdd = doc.getRootElement();
+ Detector det = (Detector) factory.createElement(Detector.class,lccdd,null);
+
+ readHeader(lccdd, det, jdom);
+ readSubdetectors( lccdd, det ) ;
+ return det;
+ }
+
+ private void readHeader(Element lccdd, Detector det, JDOMExpressionFactory jdom) throws JDOMException, ElementCreationException
+ {
+ Element info = lccdd.getChild("info");
+ det.setHeader((Header) factory.createElement(Header.class,info,null));
+ Element define = lccdd.getChild("define");
+ for (Iterator i = define.getChildren("constant").iterator(); i.hasNext(); )
+ {
+ Element constant = (Element) i.next();
+ Constant c = (Constant) factory.createElement(Constant.class,constant,null);
+ jdom.addConstant(c.getName(),c.getValue());
+ det.addConstant(c);
+ }
+ }
+
+ private void readSubdetectors( Element lccdd, Detector det)throws JDOMException, ElementCreationException{
+ Element detectors = lccdd.getChild("detectors") ;
+ for (Iterator i = detectors.getChildren("detector").iterator(); i.hasNext(); )
+ {
+ Element subdet = (Element) i.next();
+ String subdetName = subdet.getAttributeValue("name") ;
+ System.out.println(" --- LCGOReader : parsing subdetector: " + subdetName ) ;
+
+ String geartype = subdet.getAttributeValue("geartype") ;
+ if(geartype==null)
+ geartype = "UNKNWON" ;
+
+// FIXME: introduce common base for xml handler and use map to get appropriate handler
+ if( geartype.compareTo("VXDParameters") == 0 ){
+ VXDParametersXML vxdXML = (VXDParametersXML) factory.createElement(VXDParametersXML.class,subdet,null);
+ det.gearMgr().setVXDParameters( vxdXML.getVXDParameters() ) ;
+ } else {
+ // ---- first we read user defined generic parameters for every subdetector
+ GearXMLParameters p = (GearXMLParameters) factory.createElement(GearXMLParameters.class,subdet,null);
+ det.gearMgr().setGearParameters( subdetName , p.parameters() ) ;
+
+ System.out.print( p.parameters().toString() ) ;
+ }
+ // jdom.addConstant(c.getName(),c.getValue());
+// det.addConstant(c);
+ }
+
+ }
+
+
+ // Fixme: Should not be here
+ public static void main(String[] args) throws FileNotFoundException, IOException, JDOMException, ElementCreationException
+ {
+ LCGOReader reader = new LCGOReader();
+ Detector det = reader.read(new FileInputStream(args[0]));
+ Map constants = det.getConstants();
+ for (Iterator i = constants.entrySet().iterator(); i.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) i.next();
+ Constant c = (Constant) entry.getValue();
+ System.out.println(entry.getKey()+"="+c.getValue());
+ }
+ GearMgr gm = det.gearMgr() ;
+ String[] keys = gm.getGearParameterKeys() ;
+ for (int i = 0; i < keys.length; i++) {
+ GearParameters p = gm.getGearParameters(keys[i]) ;
+ try{
+ System.out.println( " ----- SomeIntVal : " + p.getIntVal("SomeIntVal") ) ;
+ }catch( UnknownParameterException e){
+ }
+
+ }
+
+ }
+}
\ No newline at end of file
CVSspam 0.2.8