From HEP at Tennessee
Contents |
Introduction
The BRM Data Relay is meant to provide a direct route between the BRM readout crate and the experiment network. For a full explanation, see the relevant Powerpoint presentation.
If you have any questions about anything regarding this project, direct them to hollings@cern.ch.
Obtaining the Package
At the moment, if you want a compiled version, you must email Matt at hollings@cern.ch, and he will construct a zip file with all the jars necessary to get everything working for you. If you want the source, you may visit here for the subversion repository of the data.
Soon, as soon as Matt talks someone into having a central doc server/code repository for the BRM project, you may find this package there, but no telling when that will be.
Technical Documentation
If you are interested in the structure of the ch.cern.BRM package, you may find the javadoc generated documentation useful. It is here: http://hep.phys.utk.edu/~mhollin3/cms/brm-docs/ .
In general, unless you wish to use my relay framework (which shall be the next documentation that I will write), you are probably most interested in two classes: the ch.cern.BRM.DataTypes.DataPacket and the ch.cern.BRM.DataTypes.Crate class. These two classes are the two classes that are transferred over the network to clients (actually, the Crate is packaged inside the DataPacket, but we'll get to that momentarily). Thus, to obtain data from my server, you must partake in four main steps. I will list them here, and then go into more detail shortly.
te: A bit of Java knowledge is assumed; see the links below for links to Sun's documentation on the classes that you should be concerned with when picking up data for my server.
Step 1: Setup an ObjectInputStream on a Socket connection to my server Step 2: Accept data from the ObjectInputStream, and cast it as a DataPacket Step 3: Call the getData() method of the DataPacket, and cast the result as a Crate Step 4: Call the various get methods in the Crate class to get whatever data you are looking for
Step 1
I'll start off with some example code:
import java.io.*;
import java.net.*;
...
...
//Create a socket on the hostname "pccmsbrm5.cern.ch" on port 4445
Socket serverConnection = null;
try {
serverConnection = new Socket("pccmsbrm5.cern.ch", 4445);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(serverConnection.getInputStream());
} catch (IOException e) {
System.err.println("Failed to create ObjectInputStream. Terminating");
e.printStackTrace();
System.exit(0);
}
After this, you should be able to get data from my server using the ois object. That's really all there is to say about that.
Step 2
Once again, this can be most easily explained with sample code:
import ch.cern.BRM.DataTypes.DataPacket; ... ...
while(true) {
DataPacket data = null;
try {
data = (DataPacket)ois.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//Insert code here to do something with the data
}
Step 3
while(true) {
DataPacket data = null;
try {
data = (DataPacket)ois.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Crate crateData = (Crate)data.getData();
}
Step 4
Now, this deserves a bit more discussion. I will begin by explaining how this class is laid out.
Each crate has a collection of cards associated with it. For extensibility, the number of cards is arbitrary. However, you may find out how many cards are by calling one of two methods: getAcqCards() and getThreshCards(). These two methods produce the Map object that contains a List of AcquisitionCard objects and ThresholdCard objects, respectively. From the produced lists, you may call the size() method to get the number of cards in the List, like so:
myCrate.getAcqCards().size();
Of note: The CMW name of each card is what will recall a card from the Map produced by the getAcqCards() and getThreshCards() methods. If you need a List of these names, call the getAcqCardNames() and getThresCardNames() methods. See the examples below for details.
Now, there are some more classes to introduce: the Crate.BRMCard, Crate.BRMCard.Channel Crate.AcquisitionCard, Crate.ThresholdCard, and Crate.Data classes. The Crate.BRMCard is an abstract class that the Crate.AcquisitionCard and Crate.ThresholdCard inherit from. It provides methods to get the Crate.Data object associated with the card, get a specific sum associated with the card, etc. The Crate.BRMCard.Channel class provides a way to check the sums associated with a particular channel of the card. The Crate.AcquisitionCard and Crate.ThresholdCard are just there to make sure that there is a difference between the two cards available in the API; we may add specific functionality later if there is a need. The Crate.Data class provides a container for all the relevant data associated with a particular card.
Here are some quick recipes for using the Crate class:
Get a specific sum associated with the first card in the crate
String acqCardName = ((String)myCrate.getAcqCardNames().get(0)); int mySum = ((Crate.AcquisitionCard)myCrate.getAcqCards().get(acqCardName)).getSum(<zero based channel index>, <zero based sum index>);
Dump the crate to file in the standardized BLM format
File myFile = new File("test-dump.txt");
FileWriter fis = null;
try {
fis = new FileWriter(myFile);
fis.write(crateData.toAscii());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Write all sum 0's in every channel for the first card
I'll do this soon.