aboutsummaryrefslogtreecommitdiff
path: root/src/test-zebra.c
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2019-01-15 01:08:54 -0600
committertlatorre <tlatorre@uchicago.edu>2019-01-15 01:08:54 -0600
commit9c910abe7a0359018677a874822d8742d0e616b9 (patch)
tree52dda30fd3c5b0eb78050dee4dec10bdf8557ed7 /src/test-zebra.c
parent272d793cda5456fb8a69d3e2a407bf24d3600cd4 (diff)
downloadsddm-9c910abe7a0359018677a874822d8742d0e616b9.tar.gz
sddm-9c910abe7a0359018677a874822d8742d0e616b9.tar.bz2
sddm-9c910abe7a0359018677a874822d8742d0e616b9.zip
update zebra library to be able to use links
This commit updates the zebra library files zebra.{c,h} so that it's now possible to traverse the data structure using links! This was originally motivated by wanting to figure out which MC particles were generated from the MCGN bank (from which it's only possible to access the tracks and vertices using structural links). I've also added a new test to test-zebra which checks the consistency of all of the next/up/orig, structural, and reference links in a zebra file.
Diffstat (limited to 'src/test-zebra.c')
-rw-r--r--src/test-zebra.c126
1 files changed, 121 insertions, 5 deletions
diff --git a/src/test-zebra.c b/src/test-zebra.c
index ffd0c50..86aff3c 100644
--- a/src/test-zebra.c
+++ b/src/test-zebra.c
@@ -3,12 +3,15 @@
#include "Record_Info.h"
#include "misc.h"
+char *filename;
+
typedef int testFunction(char *err);
int test_zdab(char *err)
{
+ /* Simple test to make sure we can read the 5 events from Muons.zdab. */
int rv;
- bank b;
+ zebraBank b;
int nzdabs = 0;
zebraFile *z = zebra_open("Muons.zdab");
@@ -19,16 +22,23 @@ int test_zdab(char *err)
}
while (1) {
- rv = next_bank(z, &b);
+ rv = zebra_read_next_logical_record(z);
if (rv == -1) {
- sprintf(err, "error getting bank: %s\n", zebra_err);
+ sprintf(err, "error getting logical record: %s", zebra_err);
goto err;
} else if (rv == 1) {
break;
}
- if (b.name == ZDAB_RECORD) nzdabs += 1;
+ rv = zebra_get_bank(z, &b, z->first_bank);
+
+ if (rv) {
+ sprintf(err, "error getting first bank: %s\n", zebra_err);
+ goto err;
+ }
+
+ if (b.idh == ZDAB_RECORD) nzdabs += 1;
}
if (nzdabs != 5) {
@@ -46,11 +56,110 @@ err:
return -1;
}
+int test_bank_links(zebraFile *z, uint32_t link, char *err)
+{
+ int i, rv;
+ zebraBank b1, b2;
+
+ rv = zebra_get_bank(z, &b1, link);
+
+ if (rv) {
+ sprintf(err, "error getting bank: %s\n", zebra_err);
+ goto err;
+ }
+
+ /* Test that all the structural links point back to the bank. */
+ for (i = 0; i < b1.num_structural_links; i++) {
+ if (b1.links[i] == 0) continue;
+
+ rv = zebra_get_bank(z, &b2, b1.links[i]);
+
+ if (rv) {
+ sprintf(err, "error getting bank: %s\n", zebra_err);
+ goto err;
+ }
+
+ /* Check that the up pointer points back to the original bank. */
+ if (b2.up != link) {
+ sprintf(err, "bank up pointer from bank %.4s does not point back to %.4s bank!",
+ b2.name, b1.name);
+ goto err;
+ }
+
+ rv = test_bank_links(z,b1.links[i],err);
+
+ if (rv) goto err;
+ }
+
+ if (b1.next) {
+ /* Test that the next/orig pointers are consistent. */
+ rv = zebra_get_bank(z, &b2, b1.next);
+
+ if (rv) {
+ sprintf(err, "error getting bank: %s\n", zebra_err);
+ goto err;
+ }
+
+ /* Check that the orig pointer points back to the original bank. */
+ if (b2.orig != link) {
+ sprintf(err, "bank orig pointer from bank %.4s does not point back to %.4s bank!",
+ b2.name, b1.name);
+ goto err;
+ }
+
+ rv = test_bank_links(z,b1.next,err);
+
+ if (rv) goto err;
+ }
+
+ return 0;
+
+err:
+ return -1;
+}
+
+int test_links(char *err)
+{
+ /* Tests that all the next/up/orig bank pointers in the zebra file are
+ * consistent. */
+ int rv;
+
+ zebraFile *z = zebra_open(filename);
+
+ if (!z) {
+ sprintf(err, "%s", zebra_err);
+ return 1;
+ }
+
+ while (1) {
+ rv = zebra_read_next_logical_record(z);
+
+ if (rv == -1) {
+ sprintf(err, "error getting logical record: %s", zebra_err);
+ goto err;
+ } else if (rv == 1) {
+ break;
+ }
+
+ if (test_bank_links(z,z->first_bank,err)) goto err;
+ }
+
+ zebra_close(z);
+
+ return 0;
+
+err:
+ zebra_close(z);
+
+ return -1;
+}
+
struct tests {
testFunction *test;
char *name;
} tests[] = {
- {test_zdab, "test_zdab"}
+ {test_zdab, "test_zdab"},
+ {test_links, "test_links"}
};
int main(int argc, char **argv)
@@ -60,6 +169,13 @@ int main(int argc, char **argv)
int retval = 0;
struct tests test;
+ if (argc < 2) {
+ fprintf(stderr, "usage: test-zebra FILENAME\n");
+ return 1;
+ }
+
+ filename = argv[1];
+
for (i = 0; i < LEN(tests); i++) {
test = tests[i];