Print

Print


Hi,

I suggest putting the geometry data into your jar file as a resource to eliminate any dependency on the local file system.

The files need to be packaged correctly into the jar, which is a matter of configuring the resources section of your Maven project correctly (assuming you use Maven).

Then you may get the resource at runtime using a call similar to this:

InputStream is = getClass().getResourceAsStream("/path/to/geom/data.txt");

You need to replace the above string with the actual location in your jar.  (Jar files are technically just zip files, so they have an internal directory hierarchy containing class files and resources.)

The InputStream can then be easily parsed as text.  

Here are a bunch of solutions for doing this:

http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string

But the geometry could potentially change across runs, so this suggests to me that eventually a proper conditions system should be used like we have in lcsim, which would fetch the proper data based on run numbers and/or time stamps.  

But barring that you can load data directly from the jar as I've described.  It should work fine.

--Jeremy

-----Original Message-----
From: [log in to unmask] [mailto:[log in to unmask]] On Behalf Of Dylan Mead
Sent: Thursday, July 11, 2013 3:09 PM
To: Graf, Norman A.; kpix-beamtest-software
Subject: [KPIX-BEAMTEST-SOFTWARE] storing data in a .class?

Hi Norman,

I've been digging around online for a solution but you can only do so much when you're not sure how to ask the right question. Hopefully you can help.

Here is the problem. Our display class has a statically defined path to a text file that holds all of the geometry information that is used for drawing the detector. This screws up portability because anytime I go to use it on a different machine I have to edit the path in the KpixHepRepConverter.java to the new location of geometry.txt, recompile, and put geometry.txt in the right location on the other machine.

I would like to have a class that I can put in the package with the display. Then in the display class I could have a line like

double[][] sensorGeometry = GeometryClass.getGeometry();

Is this doable?

-Dylan

________________________________


Use REPLY-ALL to reply to list

To unsubscribe from the KPIX-BEAMTEST-SOFTWARE list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=KPIX-BEAMTEST-SOFTWARE&A=1 

########################################################################
Use REPLY-ALL to reply to list

To unsubscribe from the KPIX-BEAMTEST-SOFTWARE list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=KPIX-BEAMTEST-SOFTWARE&A=1