Data data;
double timeStart = 0;
double t1 = 0;
double t2 = 0;
double timeEnd = 0;
int i;
int repeat = 4;
double r;
ConfigInfo configInfo;
if(numSamples == 0)
if(type == 1)
numSamples = 19960;
else
numSamples = 300000;
// Get configuration
if(err = tmsControl.getConfiguration(configInfo)){
return err.set(1, BString("Error: Getting Configuration: ") + err.getString());
}
numChans = configInfo.puReferences.size();
// Find out the current cycle number and type
if(err = tmsProcess.getCycleInfo(cn, ct)){
return err.set(1, BString("Error: Getting Cycle Number: ") + err.getString());
}
if(!quiet)
printf("Getting data from %d pick-ups for cycle: %u\n", configInfo.puReferences.size(), cn);
for(i = 0; i < repeat; i++){
dataInfo.cycleNumber = cn;
dataInfo.channel = 0;
dataInfo.cyclePeriod = CyclePeriodEvent0;
dataInfo.startTime = 0;
dataInfo.orbitNumber = 0;
dataInfo.bunchNumber = 0;
dataInfo.function = DataFunctionRaw;
dataInfo.argument = 0;
dataInfo.numValues = numSamples;
dataInfo.beyondPeriod = 0;
if(type == 1){
dataInfo.function = DataFunctionMean;
// dataInfo.startTime = 199;
// dataInfo.cyclePeriod = CyclePeriodEvent1;
// dataInfo.numValues = 40;
}
#ifdef ZAP
printf("Period: %d, Function: %d, Start: %d, Orbit: %d, Bunch: %d, NumValues: %d\n",
dataInfo.cyclePeriod, dataInfo.function, dataInfo.startTime, dataInfo.orbitNumber,
dataInfo.bunchNumber, dataInfo.numValues);
#endif
t1 = getTime();
if(err = tmsProcess.getData(dataInfo, data)){
return err.set(1, BString("Error: Getting Data: ") + err.getString());
}
t2 = getTime();
if(timeStart == 0.0)
timeStart = t2;
if(!quiet)
printf("CycleNum: %d Time: %fs NumValues: %d\n", cn, t2 - t1, data.numValues);
if(check){
#ifdef ZAP
#ifndef ZAP
if(err = dataCheck(data))
return err;
#else
dataCheck(data);
#endif
#else
if(err = dataCheck(data)){
printf("Error: Retry\n");
if(err = tmsProcess.getData(dataInfo, data)){
return err.set(1, BString("Error: Getting Data: ") + err.getString());
}
if(err = dataCheck(data)){
printf("Double Error\n");
return err;
}
}
#endif
}
// cn++;
// usleep(100000);
}
numSamples = data.numValues;
timeEnd = t2;
r = (sizeof(DataValue) * numSamples * (repeat - 1)) / (timeEnd - timeStart);
if(!quiet)
printf("Time to fetch data: %f DataRate: %fMBytes/sec\n", timeEnd - timeStart, r / (1024*1024));
return err;
}
void usage(void) {
cerr << "Usage:\ttmsTestData [options] hostname\n";
cerr << " -help - Help on command line parameters\n";
cerr << " -simdata - Set the system to use simulated timing signals and test data\n";
cerr << " -simdataall - Sets all PUPE boards in the system to use simulated timing signals and test data\n";
cerr << " -info - Prints information on the processing cycle\n";
cerr << " -numSamples <n> - The number of samples to read\n";
cerr << " -test <testName> - The Test to be performed: single - single channel all bunches, all - all bunches all channels\n";
cerr << " - allMean - Mean from all bunches all channels\n";
cerr << " -check - Check the data for validity\n";
cerr << " -cont - Continuous\n";
cerr << " -quiet - Only print errors\n";
cerr << " -channel <n> - Channel number\n";
}
static struct option options[] = {
{ "?", 0, NULL, 0 },
{ "h", 0, NULL, 0 },
{ "help", 0, NULL, 0 },
{ "simdata", 0, NULL, 0 },
{ "simdataall", 0, NULL, 0 },
{ "info", 0, NULL, 0 },
{ "check", 0, NULL, 0 },
{ "cont", 0, NULL, 0 },
{ "quiet", 0, NULL, 0 },
{ "numSamples", 1, NULL, 0 },
{ "test", 1, NULL, 0 },
{ "channel", 1, NULL, 0 },
{ 0,0,0,0 }
};
int main(int argc, char** argv){
BError err;
BString hostName = "localhost";
TmsProcess tmsProcess;
TmsControl tmsControl;
int optIndex = 0;
int c;
BString s;
int simData = 0;
int simDataAll = 0;
int info = 0;
int check = 0;
int cont = 0;
BString test;
int numSamples = 0;
int channel = 1;
while((c = getopt_long_only(argc, argv, "", options, &optIndex)) == 0){
s = options[optIndex].name;
if(s == "help" || s == "h" || s == "?"){
usage();
return 1;
}
else if(s == "simdata"){
simData = 1;
}
else if(s == "simdataall"){
simDataAll = 1;
}
else if(s == "info"){
info = 1;
}
else if(s == "check"){
check = 1;
}
else if(s == "cont"){
cont = 1;
}
else if(s == "quiet"){
quiet = 1;
}
else if(s == "test"){
test = optarg;
}
else if(s == "numSamples"){
numSamples = strtol(optarg, 0, 0);
}
else if(s == "channel"){
channel = strtol(optarg, 0, 0);
}
else {
usage();
return 1;
}
}
if(optind == argc){
usage();
return 1;
}
hostName = argv[optind++];
// Connect to the Control service