// // test_midasio.cxx --- test midasio classes // // K.Olchanski // #include #include #include #include #include #include #include // exit() #ifdef HAVE_MIDAS #include "TMidasOnline.h" #endif #ifdef HaVE_MVODB #include "mvodb.h" #endif #include "midasio.h" std::string toString(int i) { char buf[256]; sprintf(buf, "%d", i); return buf; } void print_ia(const std::vector &ia) { int size = ia.size(); printf("int[%d] has [", size); for (int i=0; i0) printf(", "); printf("%d", ia[i]); } printf("]"); } void print_da(const std::vector &da) { int size = da.size(); printf("int[%d] has [", size); for (int i=0; i0) printf(", "); printf("%f", da[i]); } printf("]"); } static int gCountFail = 0; void report_fail(const char* text) { printf("FAIL: %s\n", text); gCountFail++; } void usage() { fprintf(stderr, "Usage: test_midasio.exe [-h] [-o output_file] input_file1 [input_file2...]\n"); exit(1); // DOES NOT RETURN } // Main function int main(int argc, char *argv[]) { setbuf(stdout,NULL); setbuf(stderr,NULL); signal(SIGILL, SIG_DFL); signal(SIGBUS, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGPIPE, SIG_DFL); #ifdef HAVE_MIDAS const char* hostname = NULL; const char* exptname = NULL; #endif std::vector rfilenames; std::string wfilename; bool online = false; bool test_init = false; for (int i=1; iconnect(hostname, exptname, "test_mvodb"); if (err != 0) { fprintf(stderr,"Cannot connect to MIDAS, error %d\n", err); return -1; } odb = MakeMidasOdb(midas->fDB, &odberror); if (midas) midas->disconnect(); #else printf("MIDAS support not available, sorry! Bye.\n"); exit(1); #endif } else { int counter = 0; for (size_t ri=0; rifError) { printf("Cannot open input file \"%s\"\n", rfilenames[ri].c_str()); delete reader; continue; } while (1) { TMEvent* e = TMReadEvent(reader); if (!e) { // EOF delete e; break; } if (e->error) { // broken event printf("event with error, bye!\n"); delete e; break; } printf("Event: id 0x%04x, mask 0x%04x, serial 0x%08x, time 0x%08x, data size %d\n", e->event_id, e->trigger_mask, e->serial_number, e->time_stamp, e->data_size); if ((e->event_id & 0xFFFF) == 0x8000) { printf("Event: this is a begin of run ODB dump\n"); #ifdef HAVE_MVODB odb = MakeFileDumpOdb(event.GetData(),event.GetDataSize(), &odberror); #endif if (writer) { TMWriteEvent(writer, e); } delete e; continue; } else if ((e->event_id & 0xFFFF) == 0x8001) { printf("Event: this is an end of run ODB dump\n"); #ifdef HAVE_MVODB odb = MakeFileDumpOdb(event.GetData(),event.GetDataSize(), &odberror); #endif if (writer) { TMWriteEvent(writer, e); } delete e; continue; } if (counter == 0) { e->PrintBanks(2); } else if (counter == 1) { e->PrintBanks(1); } else { e->PrintBanks(); } if (writer) { TMWriteEvent(writer, e); } counter++; delete e; } reader->Close(); delete reader; } } if (writer) { writer->Close(); delete writer; writer = NULL; } return 0; } //end /* emacs * Local Variables: * tab-width: 8 * c-basic-offset: 3 * indent-tabs-mode: nil * End: */