-
Notifications
You must be signed in to change notification settings - Fork 0
BeamFolders
BeamFolders are a C class used to access the intensity frontier
Beams Database
Currently it can accessdata from a given Data
Bundle
for a given time window; it tries to fetch the whole time window of data
for that bundle at
once and cache it, and let you pull data out of that cache.
<code class="CPP">
#include <ifbeam.h>
...
// We will need to have a time stamp that we want to query against
// Typically this will be retrieved from the event data (the trigger time of the event)
double when = 1323722800.0;
// We also need variables to hold the results of our queries
double ehmgpr, em121ds0, em121ds5;
vector<double> em12ds;
try {
// First instantiate/initialize the interface to the beams database
// This is the "beams folder" object that handles all the heavy lifting
// The call signature for this function is:
// the name of bundle of devices to retrieve (here this is "NuMI_Physics")
// Followed by the base address of the server (here "http://dbweb0.fnal.gov:......")
// Followed by a hint for the amount of data that you want to cache in seconds (here 1 hour = 3600 s)
std::unique_ptr<BeamFolder> bfp(new BeamFolder("NuMI_Physics", "http://dbweb0.fnal.gov/ifbeam",3600));
// Now we can make a query. Here we want to know the value of the device "E:HMGPR" at the time "when".
// The result is put in the variable "ehmgpr"
bfp->GetNamedData(when,"E:HMGPR",&ehmgpr);
// Similarly we can ask for multiple devices
bfp->GetNamedData(when,"E:M121DS[0],E:M121DS[5]",&em121ds0, &em121ds5);
// Or we can ask for a vectored device (a device that returns multiple entries)
em12ds = bfp->GetNamedVector(when,"E:M121DS[]");
// Some times we want to see a list of the times for each of the spills
// To do this we use the GetTimeList() function
// This function MUST be called AFTER at least one normal query for a base time has been made
// (i.e. the system needs to know a beginning time to start from)
std::cout << "time stamps:";
std::vector<double> times = bf.GetTimeList();
for (int i = 0; i < times.size(); i++) {
std::cout << times[i] << ", ";
}
std::cout << "\n";
std::cout << "variables:";
std::vector<std::string> vars = bfp->GetDeviceList();
for (int i = 0; i < vars.size(); i++) {
std::cout << vars[i] << ", ";
}
std::cout << "\n";
#ifdef VERSION_v1_1_FEATURES
double t1, t2;
bfp->GetNamedData(when,"E:M121DS@[0],E:M121DS@[5]",&em121ds0, &t1, &em121ds5, &t2);
#endif
} catch (WebAPIException we) {
std::cout << "Exception:" << we.what() << std::endl;
}
</code>
The constructor takes a few paramerters:
- bundle name --- see http://dbweb0.fnal.gov:8080/ifbeam/app/GUI/index for a list
- URI --- Generally "http://dbweb0.fnal.gov:8080/ifbeam"
- Time window --- width of time around first time requested to prefetch
Having constructed an object, you next want to fetch data...
This method loads the cache if needed from the database, and extracts
data from
the cache. It takes parameters:
- when --- the time for which you want the data
- namelist --- a string giving the variable names you want to extract, comma separated
- d1,d2,... --- addresses of one or more double variables to stuff the data into
Version v1_1 and later will also allow: GetNamedData(when,
"name1@,name2``,...", &d1, &t1, &d2, &t2 ...) where the names followed by at-signs ('``') yeild a data value and the time that the value was recorded. If you are getting a value with an array subscript and a time, you spell it "name@[3]".
Lets you set the time window to consider valid around a measurement. If
you ask for
a measurement at time T1, and the nearest measurement we have is at time
T2, consider
it an error if abs(T2-T1) > this window.
Parametrs:
- window --- time window width in seconds (defaults to 60 if not set).
Returns the current floating point valid window width.
Returns a vector variable from the cache (see GetNamedData) as an
std::Vector<double>{=html}
Parameters:
- when --- double seconds specifying time
- variable_name --- name of vector variable.
Version v1_1 and later also allow an optional double *actual_time third
parameter, which
lets you get the actual time the data was recorded.
Returns a std::vector<double>{=html} of the times in the current
cache.
Returns a std::vector<std::string>{=html} of the variable names in the
current cache.
If you have the ifbeam package setup via ups; you can compile simple programs with:
g++ ifbeam-demo.cc -o ifbeam-demo \
-I$IFBEAM_FQ_DIR/include \
-I$LIBWDA_FQ_DIR/include \
-I$IFDHC_FQ_DIR/inc \
-L$IFBEAM_LIB \
-L$LIBWDA_LIB \
-L$IFDHC_LIB \
-lifbeam -lifdh -lwda -lcurl
A full demo program is:
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "ifbeam.h"
int
main() {
double when = 1323722800.0;
double twhen = 1334332800.0;
double t2when = 1334332800.4;
double nodatatime = 1373970148.000000;
double ehmgpr, em121ds0, em121ds5, trtgtd;
double t1, t2;
BeamFolder::_debug = 1;
std::string teststr("1321032116708,E:HMGPR,TORR,687.125");
std::cout << std::setiosflags(std::ios::fixed);
// test with someone who doesn't have any data, to check error timeouts
// std::cout << "Trying a nonexistent location\n";
// BeamFolder bfu("NuMI_Physics_A9","http://bel-kwinith.fnal.gov/");
// bfu.set_epsilon(.125);
//
// try {
// bfu.GetNamedData(nodatatime,"E:HP121@[1]",&ehmgpr,&t1);
// std::cout << "got values " << ehmgpr << "for E:HP121[1]at time " << t1 << "\n";
// } catch (WebAPIException &we) {
// std::cout << "got exception:" << we.what() << "\n";
//}
std::cout << "Trying the default location\n";
BeamFolder bf("NuMI_Physics_A9");
bf.set_epsilon(.125);
try {
double tlist[] = {1386058021.613409,1386058023.279863,1386058079.149919,1386058080.816768};
for (int i = 0; i < 4 ; i++) {
bf.GetNamedData(tlist[i],"E:TRTGTD@",&trtgtd,&t1);
std::cout << "got values " << trtgtd << "for E:TRTGTD at time " << t1 << "\n";
}
} catch (WebAPIException &we) {
std::cout << "got exception:" << we.what() << "\n";
}
exit(0);
try {
bf.GetNamedData(nodatatime,"E:HP121@[1]",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:HP121[1]at time " << t1 << "\n";
} catch (WebAPIException &we) {
std::cout << "got exception:" << we.what() << "\n";
}
try {
bf.GetNamedData(nodatatime,"E:HP121@[1]",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:HP121[1]at time " << t1 << "\n";
} catch (WebAPIException &we) {
std::cout << "got exception:" << we.what() << "\n";
}
try {
bf.GetNamedData(t2when,"E:NOSUCHVARIABLE",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:HP121[1]at time " << t1 << "\n";
} catch (WebAPIException &we) {
std::cout << "got exception:" << we.what() << "\n";
}
try {
bf.GetNamedData(t2when,"E:HP121@[1]",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:HP121[1]at time " << t1 << "\n";
bf.GetNamedData(when,"E:TR101D@",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:TR101D at time " << t1 << "\n";
bf.GetNamedData(twhen,"E:TR101D@",&ehmgpr,&t1);
std::cout << "got values " << ehmgpr << "for E:TR101D at time " << t1 << "\n";
bf.GetNamedData(when,"E:HMGPR",&ehmgpr);
bf.GetNamedData(when,"E:M121DS[0],E:M121DS[5]",&em121ds0, &em121ds5);
std::cout << "got value " << ehmgpr << "for E:HMGPR\n";
std::cout << "got values " << em121ds0 << ',' << em121ds5 << "for E:M121DS[0,5]\n";
bf.GetNamedData(when,"E:M121DS@[0],E:M121DS@[5]",&em121ds0, &t1, &em121ds5, &t2);
std::cout << "got values " << em121ds0 << ',' << em121ds5 << "for E:M121DS[0,5] at time " << t1 << "\n";
std::cout << "time stamps:";
std::vector<double> times = bf.GetTimeList();
for (size_t i = 0; i < times.size(); i++) {
std::cout << times[i] << ", ";
}
std::cout << "\n";
std::cout << "variables:";
std::vector<std::string> vars = bf.GetDeviceList();
for (size_t i = 0; i < vars.size(); i++) {
std::cout << vars[i] << ", ";
}
std::cout << "\n";
std::cout << "vector E:M121DS[]:";
std::vector<double> values = bf.GetNamedVector(when,"E:M121DS[]");
for (size_t i = 0; i < values.size(); i++) {
std::cout << values[i] << ", ";
}
std::cout << "\n";
std::cout << "vector E:M121DS[] with time:";
values = bf.GetNamedVector(when,"E:M121DS[]",&t1);
std::cout << "at time: " << t1 << ": ";
for (size_t i = 0; i < values.size(); i++) {
std::cout << values[i] << ", ";
}
std::cout << "\n";
bf.GetNamedData(1323726316.528,"E:HMGPR",&ehmgpr);
std::cout << "got value " << ehmgpr << "for E:HMGPR\n";
bf.GetNamedData(1323726316.528,"E:HMGPR@",&ehmgpr, &t1);
std::cout << "got value " << ehmgpr << "for E:HMGPR at time " << t1 << "\n";
bf.GetNamedData(1323726318.594,"E:HMGPR",&ehmgpr);
std::cout << "got value " << ehmgpr << "for E:HMGPR\n";
bf.GetNamedData(1323726318.594,"E:HMGPR@",&ehmgpr,&t2);
std::cout << "got value " << ehmgpr << "for E:HMGPR at time " << t2 << "\n";
std::cout << "Done!\n";
} catch (WebAPIException &we) {
std::cout << "got exception:" << we.what() << "\n";
}
std::string name;
double t;
std::vector<double> vals;
int count = 0;
BeamFolderScanner bfs("NuMI_Physics_A9", 1334332800.4);
while( bfs.NextDataRow( t, name, vals ) && count++ < 100 ) {
std::cout << "got time "<< t << " name " << name << "values:" ;
for(unsigned i = 0; i < vals.size(); i++ )
std::cout << vals[i] << ", " ;
std::cout << "\n";
}
}