25 sprintf(buf,
"%d", i);
32 printf(
"int[%d] has [", size);
33 for (
int i=0; i<size; i++) {
44 printf(
"int[%d] has [", size);
45 for (
int i=0; i<size; i++) {
57 printf(
"FAIL: %s\n", text);
63int main(
int argc,
char *argv[])
68 signal(SIGILL, SIG_DFL);
69 signal(SIGBUS, SIG_DFL);
70 signal(SIGSEGV, SIG_DFL);
71 signal(SIGPIPE, SIG_DFL);
74 const char* hostname = NULL;
75 const char* exptname = NULL;
77 const char* filename = argv[1];
80 bool jsonfile =
false;
85 else if (strstr(filename,
".xml")!=0)
87 else if (strstr(filename,
".json")!=0)
89 else if (strstr(filename,
"null")!=0)
103 printf(
"Using NullOdb\n");
109 printf(
"Using MidasOdb\n");
112 int err = midas->
connect(hostname, exptname,
"test_mvodb");
115 fprintf(stderr,
"Cannot connect to MIDAS, error %d\n", err);
121 printf(
"Using MidasOdb: MIDAS support not available, sorry.\n");
127 printf(
"Using XmlOdb\n");
132 printf(
"Using JsonOdb\n");
137 printf(
"Using FileDumpOdb\n");
141 printf(
"Cannot open input file \"%s\"\n",filename);
154 if ((eventId & 0xFFFF) != 0x8000)
168 printf(
"Failed to load ODB from input file \"%s\"\n",filename);
174 fprintf(stderr,
"Cannot make MVOdb object, error: %s\n", odberror.
fErrorString.c_str());
179 printf(
"Starting tests:\n");
184 odb->
RI(
"runinfo/run number", &runno);
186 printf(
"read run number (RI): %d\n", runno);
190 assert(test != NULL);
198 printf(
"This ODB is read-only!\n");
202 printf(
"Test create-and-read of all data types (set default values):\n");
206 test->
RI(
"cycle", &cycle,
true);
207 printf(
"RI() cycle: %d\n", cycle);
210 test->
RI(
"int", &ivalue,
true);
211 printf(
"RI() int: %d\n", ivalue);
214 test->
RF(
"float", &fvalue,
true);
215 printf(
"RF() float: %f\n", fvalue);
218 test->
RD(
"double", &dvalue,
true);
219 printf(
"RD() double: %f\n", dvalue);
221 bool bvalue_a =
false;
222 test->
RB(
"bool_a", &bvalue_a,
true);
223 printf(
"bool_a: %d\n", bvalue_a);
225 bool bvalue_b =
true;
226 test->
RB(
"bool_b", &bvalue_b,
true);
227 printf(
"bool_b: %d\n", bvalue_b);
229 uint16_t u16value = 0xabcd;
230 test->
RU16(
"u16", &u16value,
true);
231 printf(
"RU16() u16: 0x%04x\n", u16value);
233 uint32_t u32value = 0x12345678;
234 test->
RU32(
"u32", &u32value,
true);
235 printf(
"RU32() u32: 0x%08x\n", u32value);
237 std::string svalue =
"test string";
238 test->
RS(
"string", &svalue,
true);
239 printf(
"RS() string: \"%s\"\n", svalue.c_str());
242 printf(
"Test write of all data types (overwrite default values):\n");
245 test->
WI(
"cycle", cycle+1);
247 int wi = 10 + 100*cycle;
249 float wf = 11.1 + 100*cycle;
250 test->
WF(
"float", wf);
251 double wd = 22.2 + 100*cycle;
252 test->
WD(
"double", wd);
254 test->
WB(
"bool_a", wba);
256 test->
WB(
"bool_b", wbb);
257 uint16_t wu16 = 0xcdef;
258 test->
WU16(
"u16", wu16);
259 uint32_t wu32 = 0xdeadf00d;
260 test->
WU32(
"u32", wu32);
261 std::string ws =
"write test string cycle " +
toString(cycle);
262 test->
WS(
"string", ws.c_str());
265 printf(
"Test read of new values for all data types:\n");
269 test->
RI(
"int", &ri);
270 printf(
"int: %d -> %d -> %d\n", ivalue, wi, ri);
273 test->
RF(
"float", &rf);
274 printf(
"float: %f -> %f -> %f\n", fvalue, wf, rf);
277 test->
RD(
"double", &rd);
278 printf(
"double: %f -> %f -> %f\n", dvalue, wd, rd);
281 test->
RB(
"bool_a", &rba);
282 printf(
"bool_a: %d -> %d -> %d\n", bvalue_a, wba, rba);
285 test->
RB(
"bool_b", &rbb);
286 printf(
"bool_b: %d -> %d -> %d\n", bvalue_b, wbb, rbb);
288 uint16_t ru16 = 0x4444;
289 test->
RU16(
"u16", &ru16);
290 printf(
"u16: 0x%04x -> 0x%04x -> 0x%04x\n", u16value, wu16, ru16);
292 uint32_t ru32 = 0x55555555;
293 test->
RU32(
"u32", &ru32);
294 printf(
"u32: 0x%08x -> 0x%08x -> 0x%08x\n", u32value, wu32, ru32);
296 std::string rs =
"rs";
297 test->
RS(
"string", &rs);
298 printf(
"string: \"%s\" -> \"%s\" -> \"%s\"\n", svalue.c_str(), ws.c_str(), rs.c_str());
301 printf(
"Test read arrays of all data types:\n");
305 printf(
"read int array ia:\n");
310 test->
RIA(
"ia", &ia,
true);
311 printf(
"RIA() returned: ");
317 printf(
"read non-existant array ia-noexist:\n");
322 test->
RIA(
"ia-noexist", &ia);
323 printf(
"RIA() returned: ");
331 test->
RIA(
"ia10zero", &ia,
true, 10);
336 test->
RIA(
"ia10", &ia,
true, 10);
341 test->
RIA(
"createia10", NULL,
true, 10);
345 std::vector<uint32_t> u32a;
346 u32a.push_back(0x11110000);
347 u32a.push_back(0x22220000);
348 u32a.push_back(0x33330000);
349 u32a.push_back(0x44440000);
350 test->
RU32A(
"dwa", &u32a,
true);
354 std::vector<double> da;
359 test->
RDA(
"da", &da,
true, 0);
363 std::vector<float> fa;
369 test->
RFA(
"fa", &fa,
true, 0);
373 std::vector<bool> ba;
377 test->
RBA(
"ba", &ba,
true, 0);
381 std::vector<std::string> sa;
382 sa.push_back(
"line1");
383 sa.push_back(
"line2");
384 sa.push_back(
"line3");
385 sa.push_back(
"line4");
386 test->
RSA(
"sa", &sa,
true, 0, 32);
392 test->
RSA(
"sa10", &sa,
true, 10, 32);
394 test->
RSA(
"createsa10", NULL,
true, 10, 32);
398 printf(
"Test string sizes:\n");
402 test->
WS(
"test_size",
"12345");
404 test->
RS(
"test_size", &s);
405 printf(
"read test_size [%s]\n", s.c_str());
408 test->
WS(
"test_size_32",
"1234567890", 32);
410 test->
RS(
"test_size_32", &s);
411 printf(
"read test_size_32 [%s]\n", s.c_str());
414 test->
WS(
"test_size_5",
"1234567890", 5);
416 test->
RS(
"test_size_5", &s);
417 printf(
"read test_size_5 [%s]\n", s.c_str());
420 std::string s =
"1234567890";
421 test->
RS(
"test_rsize", &s,
true);
422 printf(
"read test_rsize [%s]\n", s.c_str());
425 std::string s =
"123456";
426 test->
RS(
"test_size_r32", &s,
true, 32);
427 printf(
"read test_size_r32 [%s]\n", s.c_str());
430 std::string s =
"1234567890";
431 test->
RS(
"test_size_r8", &s,
true, 8);
432 printf(
"read test_size_r8 [%s]\n", s.c_str());
435 test->
RSA(
"test_size_a8", NULL,
true, 2, 8);
436 std::string s =
"1234567890";
437 test->
WSAI(
"test_size_a8", 0, s.c_str());
438 test->
RSAI(
"test_size_a8", 0, &s);
439 printf(
"read test_size_a8 [%s]\n", s.c_str());
443 printf(
"Test creating and resizing arrays:\n");
447 test->
RIA(
"create_ia15", NULL,
true, 15);
448 test->
RBA(
"create_ba12", NULL,
true, 12);
449 test->
RSA(
"create_sa5", NULL,
true, 5, 32);
452 test->
RIA(
"resize_ia10", NULL,
true, 5);
453 test->
RIA(
"resize_ia10", NULL,
true, 10);
454 test->
RSA(
"resize_sa3", NULL,
true, 5, 32);
455 test->
WSAI(
"resize_sa3", 0,
"00000000");
456 test->
WSAI(
"resize_sa3", 1,
"11111111");
457 test->
WSAI(
"resize_sa3", 2,
"22222222");
458 test->
WSAI(
"resize_sa3", 3,
"33333333");
459 test->
WSAI(
"resize_sa3", 4,
"44444444");
460 test->
RSA(
"resize_sa3", NULL,
true, 3, 5);
464 printf(
"Test array index access:\n");
472 test->
WIA(
"index_ia", ia);
473 for (
int i=0; i<5; i++) {
475 test->
RIAI(
"index_ia", i, &ivalue);
476 printf(
"index %d value %d\n", i, ivalue);
478 for (
int i=0; i<4; i++) {
480 test->
WIAI(
"index_ia", i, ivalue);
482 for (
int i=0; i<5; i++) {
484 test->
RIAI(
"index_ia", i, &ivalue);
485 printf(
"index %d value %d\n", i, ivalue);
490 printf(
"Test string array index access:\n");
494 std::vector<std::string> sa;
498 test->
WSA(
"index_sa", sa, 32);
499 for (
int i=0; i<5; i++) {
500 std::string s =
"aaa";
501 test->
RSAI(
"index_sa", i, &s);
502 printf(
"index %d value [%s]\n", i, s.c_str());
504 for (
int i=0; i<4; i++) {
505 std::string s =
"sa_qqq";
507 test->
WSAI(
"index_sa", i, s.c_str());
509 for (
int i=0; i<5; i++) {
510 std::string s =
"bbb";
511 test->
RSAI(
"index_sa", i, &s);
512 printf(
"index %d value [%s]\n", i, s.c_str());
517 printf(
"Test string truncation:\n");
521 std::vector<std::string> sa;
522 sa.push_back(
"1234567890");
523 sa.push_back(
"aaa1");
524 sa.push_back(
"aaa2");
525 test->
WSA(
"trunc_sa5", sa, 5);
526 test->
WSAI(
"trunc_sa5", 1,
"1234567890");
527 for (
int i=0; i<5; i++) {
528 std::string s =
"bbb";
529 test->
RSAI(
"trunc_sa5", i, &s);
530 printf(
"index %d value [%s]\n", i, s.c_str());
535 printf(
"Test against subdirectory:\n");
539 printf(
"Creating subdir\n");
541 printf(
"Creating subdir/i\n");
544 printf(
"RI(subdir)\n");
545 test->
RI(
"subdir", &i);
546 printf(
"WI(subdir)\n");
547 test->
WI(
"subdir", 10);
552 printf(
"WIA(subdir)\n");
553 test->
WIA(
"subdir", ia);
554 printf(
"RIA(subdir)\n");
555 test->
RIA(
"subdir", &ia);
556 printf(
"RIA() returned: ");
559 printf(
"RIA(subdir, create=true)\n");
560 test->
RIA(
"subdir", &ia,
true);
561 printf(
"RIA() returned: ");
567 printf(
"Test special cases:\n");
571 printf(
"test RI() of non existant variable:\n");
573 test->
RI(
"nonexistant", &ivalue);
574 printf(
"RI() returned ivalue %d\n", ivalue);
578 std::vector<double> da;
579 printf(
"test RDA() of integer array:\n");
581 test->
RDA(
"ia10", &da,
false, 0);
582 printf(
"RDA() returned: ");
588 printf(
"test RD() of integer array:\n");
591 test->
RD(
"ia10", &v);
592 printf(
"RD() returned %f\n", v);
597 printf(
"test RI() of array ia10:\n");
599 test->
RI(
"ia10", &ivalue);
600 printf(
"RI() returned ivalue %d\n", ivalue);
605 printf(
"test RIA() of non-array int:\n");
607 test->
RIA(
"int", &ia);
608 printf(
"RIA() returned: ");
614 printf(
"test index 0 of non-array int:\n");
616 test->
RIAI(
"int", 0, &ivalue);
617 printf(
"RIAI() returned ivalue %d\n", ivalue);
622 printf(
"test index of non-array int:\n");
624 test->
RIAI(
"int", 10, &ivalue);
625 printf(
"RIAI() returned ivalue %d\n", ivalue);
630 printf(
"test invalid index -1 of array ia10:\n");
632 test->
RIAI(
"ia10", -1, &ivalue);
633 printf(
"RIAI() returned ivalue %d\n", ivalue);
638 printf(
"test invalid index 999 of array ia10:\n");
640 test->
RIAI(
"ia10", 999, &ivalue);
641 printf(
"RIAI() returned ivalue %d\n", ivalue);
645 printf(
"test string array invalid index -1:\n");
647 test->
RSAI(
"sa10", -1, &svalue);
648 printf(
"RSAI() returned [%s]\n", svalue.c_str());
651 printf(
"test string array invalid index 999:\n");
653 test->
RSAI(
"sa10", 999, &svalue);
654 printf(
"RSAI() returned [%s]\n", svalue.c_str());
657 printf(
"test write invalid index -1:\n");
658 test->
WIAI(
"ia10", -1, 10);
661 printf(
"test string write invalid index -1:\n");
662 test->
WSAI(
"sa10", -1,
"aaa");
666 printf(
"Test Chdir():\n");
670 printf(
"test Chdir(true):\n");
671 MVOdb* dir = test->
Chdir(
"test_subdir",
true);
672 printf(
"Chdir() returned %p\n", dir);
673 if (dir == NULL)
report_fail(
"Chdir(new directory, true)");
677 printf(
"test Chdir(false):\n");
678 MVOdb* dir = test->
Chdir(
"non-existant-subdir",
false);
679 printf(
"Chdir() returned %p\n", dir);
680 if (dir != NULL)
report_fail(
"Chdir(new directory, false)");
684 printf(
"test Chdir(\"not a dir\", true):\n");
686 printf(
"Chdir() returned %p\n", dir);
687 if (dir == NULL)
report_fail(
"Chdir(not a directory, true)");
691 printf(
"test Chdir(\"not a dir\", false):\n");
693 printf(
" returned %p\n", dir);
694 if (dir != NULL)
report_fail(
"Chdir(not a directory, false)");
704 printf(
"Number of FAILED tests: %d\n",
gCountFail);
virtual void WI(const char *varname, int v, MVOdbError *error=NULL)=0
virtual void RIA(const char *varname, std::vector< int > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void WSAI(const char *varname, int index, const char *v, MVOdbError *error=NULL)=0
virtual void WIAI(const char *varname, int index, int v, MVOdbError *error=NULL)=0
virtual void WU16(const char *varname, uint16_t v, MVOdbError *error=NULL)=0
virtual void RS(const char *varname, std::string *value, bool create=false, int create_string_length=0, MVOdbError *error=NULL)=0
virtual MVOdb * Chdir(const char *subdirname, bool create=false, MVOdbError *error=NULL)=0
virtual void WF(const char *varname, float v, MVOdbError *error=NULL)=0
virtual void RU32(const char *varname, uint32_t *value, bool create=false, MVOdbError *error=NULL)=0
virtual void WSA(const char *varname, const std::vector< std::string > &v, int string_length, MVOdbError *error=NULL)=0
virtual void WU32(const char *varname, uint32_t v, MVOdbError *error=NULL)=0
virtual void RU16(const char *varname, uint16_t *value, bool create=false, MVOdbError *error=NULL)=0
virtual bool IsReadOnly() const =0
virtual void RBA(const char *varname, std::vector< bool > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void RSAI(const char *varname, int index, std::string *value, MVOdbError *error=NULL)=0
virtual void SetPrintError(bool v)=0
virtual void WIA(const char *varname, const std::vector< int > &v, MVOdbError *error=NULL)=0
virtual void RIAI(const char *varname, int index, int *value, MVOdbError *error=NULL)=0
virtual void WD(const char *varname, double v, MVOdbError *error=NULL)=0
virtual void RSA(const char *varname, std::vector< std::string > *value, bool create=false, int create_size=0, int create_string_length=0, MVOdbError *error=NULL)=0
virtual void RI(const char *varname, int *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RB(const char *varname, bool *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RDA(const char *varname, std::vector< double > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void WS(const char *varname, const char *v, int string_length=0, MVOdbError *error=NULL)=0
virtual void RF(const char *varname, float *value, bool create=false, MVOdbError *error=NULL)=0
virtual void RFA(const char *varname, std::vector< float > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
virtual void RD(const char *varname, double *value, bool create=false, MVOdbError *error=NULL)=0
virtual void WB(const char *varname, bool v, MVOdbError *error=NULL)=0
virtual void RU32A(const char *varname, std::vector< uint32_t > *value, bool create=false, int create_size=0, MVOdbError *error=NULL)=0
uint32_t GetDataSize() const
return the event size
uint16_t GetEventId() const
return the event id
char * GetData()
return pointer to the data buffer
int disconnect()
Disconnect from MIDAS.
static TMidasOnline * instance()
int connect(const char *hostname, const char *exptname, const char *progname)
Connect to MIDAS experiment.
TMEvent * TMReadEvent(TMReaderInterface *reader)
TMReaderInterface * TMNewReader(const char *source)
MVOdb * MakeMidasOdb(int hDB, MVOdbError *error=NULL)
MVOdb * MakeFileDumpOdb(const char *buf, int bufsize, MVOdbError *error=NULL)
Access ODB from a midas file dump. FOrmat could be .xml, .json or .odb.
MVOdb * MakeXmlFileOdb(const char *filename, MVOdbError *error=NULL)
MVOdb * MakeJsonFileOdb(const char *filename, MVOdbError *error=NULL)
void print_da(const std::vector< double > &da)
int main(int argc, char *argv[])
void report_fail(const char *text)
void print_ia(const std::vector< int > &ia)
std::string toString(int i)