char * parse_name (char const *s, int strip_leading, char const **endp) { char *ret; while (ISSPACE ((unsigned char) *s)) s++; if (*s == '"') ret = parse_c_string (s, endp); else { char const *t; for (t = s; *t && ! ISSPACE ((unsigned char) *t); t++) /* do nothing*/ ; ret = savebuf (s, t - s + 1); ret[t - s] = 0; if (endp) *endp = t; } if (! strip_leading_slashes (ret, strip_leading)) { free (ret); ret = NULL; } return ret; }
char * savestr (char const *s) { return savebuf (s, strlen (s) + 1); }
void fetchname (char const *at, int strip_leading, char **pname, char **ptimestr, struct timespec *pstamp) { char *name; const char *t; char *timestr = NULL; struct timespec stamp; stamp.tv_sec = -1; stamp.tv_nsec = 0; while (ISSPACE ((unsigned char) *at)) at++; if (debug & 128) say ("fetchname %s %d\n", at, strip_leading); if (*at == '"') { name = parse_c_string (at, &t); if (! name) { if (debug & 128) say ("ignoring malformed filename %s\n", quotearg (at)); return; } } else { for (t = at; *t; t++) { if (ISSPACE ((unsigned char) *t)) { /* Allow file names with internal spaces, but only if a tab separates the file name from the date. */ char const *u = t; while (*u != '\t' && ISSPACE ((unsigned char) u[1])) u++; if (*u != '\t' && (strchr (u + 1, pstamp ? '\t' : '\n'))) continue; break; } } name = savebuf (at, t - at + 1); name[t - at] = 0; } /* If the name is "/dev/null", ignore the name and mark the file as being nonexistent. The name "/dev/null" appears in patches regardless of how NULL_DEVICE is spelled. */ if (strcmp (name, "/dev/null") == 0) { free (name); if (pstamp) { pstamp->tv_sec = 0; pstamp->tv_nsec = 0; } return; } /* Ignore the name if it doesn't have enough slashes to strip off. */ if (! strip_leading_slashes (name, strip_leading)) { free (name); return; } if (ptimestr) { char const *u = t + strlen (t); if (u != t && *(u-1) == '\n') u--; if (u != t && *(u-1) == '\r') u--; timestr = savebuf (t, u - t + 1); timestr[u - t] = 0; } if (*t != '\n') { if (! pstamp) { free (name); free (timestr); return; } if (set_time | set_utc) get_date (&stamp, t, &initial_time); else { /* The head says the file is nonexistent if the timestamp is the epoch; but the listed time is local time, not UTC, and POSIX.1 allows local time offset anywhere in the range -25:00 < offset < +26:00. Match any time in that range. */ const struct timespec lower = { -25L * 60 * 60 }, upper = { 26L * 60 * 60 }; if (get_date (&stamp, t, &initial_time) && timespec_cmp (stamp, lower) > 0 && timespec_cmp (stamp, upper) < 0) { stamp.tv_sec = 0; stamp.tv_nsec = 0; } } } free (*pname); *pname = name; if (ptimestr) { free (*ptimestr); *ptimestr = timestr; } if (pstamp) *pstamp = stamp; }
//========================================================================== void readfile(std::string filename, std::string outfile) { int num_events(0); int num_badevents(0); int num_baduncompress(0); int num_badchksum(0); int num_goodevents(0); int num_duplevents(0); uint32 hltcount(0); std::vector<uint32> hltStats(0); std::vector<unsigned char> compress_buffer(7000000); std::map<uint32, uint32> seenEventMap; bool output(false); if(outfile != "/dev/null") { output = true; } StreamerOutputFile stream_output(outfile); try{ // ----------- init edm::StreamerInputFile stream_reader(filename); //if(output) StreamerOutputFile stream_output(outfile); std::cout << "Trying to Read The Init message from Streamer File: " << std::endl << filename << std::endl; InitMsgView const* init = stream_reader.startMessage(); std::cout << "\n\n-------------INIT Message---------------------" << std::endl; std::cout << "Dump the Init Message from Streamer:-" << std::endl; dumpInitView(init); if(output) { stream_output.write(*init); hltcount = init->get_hlt_bit_cnt(); //Initialize the HLT Stat vector with all ZEROs for(uint32 i = 0; i != hltcount; ++i) hltStats.push_back(0); } // ------- event std::cout << "\n\n-------------EVENT Messages-------------------" << std::endl; bool first_event(true); std::auto_ptr<EventMsgView> firstEvtView(0); std::vector<unsigned char> savebuf(0); EventMsgView const* eview(0); seenEventMap.clear(); while(stream_reader.next()) { eview = stream_reader.currentRecord(); ++num_events; bool good_event(true); if(seenEventMap.find(eview->event()) == seenEventMap.end()) { seenEventMap.insert(std::make_pair(eview->event(), 1)); } else { ++seenEventMap[eview->event()]; ++num_duplevents; std::cout << "??????? duplicate event Id for count " << num_events << " event number " << eview->event() << " seen " << seenEventMap[eview->event()] << " times" << std::endl; } if(first_event) { std::cout << "----------dumping first EVENT-----------" << std::endl; dumpEventView(eview); first_event = false; unsigned char* src = (unsigned char*)eview->startAddress(); unsigned int srcSize = eview->size(); savebuf.resize(srcSize); std::copy(src, src+srcSize, &(savebuf)[0]); firstEvtView.reset(new EventMsgView(&(savebuf)[0])); //firstEvtView, reset(new EventMsgView((void*)eview->startAddress())); if(!test_chksum(firstEvtView.get())) { std::cout << "checksum error for count " << num_events << " event number " << eview->event() << " from host name " << eview->hostName() << std::endl; ++num_badchksum; std::cout << "----------dumping bad checksum EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } if(!test_uncompress(firstEvtView.get(), compress_buffer)) { std::cout << "uncompress error for count " << num_events << " event number " << firstEvtView->event() << std::endl; ++num_baduncompress; std::cout << "----------dumping bad uncompress EVENT-----------" << std::endl; dumpEventView(firstEvtView.get()); good_event = false; } } else { if(compares_bad(firstEvtView.get(), eview)) { std::cout << "Bad event at count " << num_events << " dumping event " << std::endl << "----------dumping bad EVENT-----------" << std::endl; dumpEventView(eview); ++num_badevents; good_event = false; } if(!test_chksum(eview)) { std::cout << "checksum error for count " << num_events << " event number " << eview->event() << " from host name " << eview->hostName() << std::endl; ++num_badchksum; std::cout << "----------dumping bad checksum EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } if(!test_uncompress(eview, compress_buffer)) { std::cout << "uncompress error for count " << num_events << " event number " << eview->event() << std::endl; ++num_baduncompress; std::cout << "----------dumping bad uncompress EVENT-----------" << std::endl; dumpEventView(eview); good_event = false; } } if(output && good_event) { ++num_goodevents; stream_output.write(*eview); //get the HLT Packed bytes std::vector<uint8> packedHlt; uint32 hlt_sz = 0; if(hltcount != 0) hlt_sz = 1 + ((hltcount - 1)/4); packedHlt.resize(hlt_sz); firstEvtView->hltTriggerBits(&packedHlt[0]); updateHLTStats(packedHlt, hltcount, hltStats); } if((num_events % 50) == 0) { std::cout << "Read " << num_events << " events, and " << num_badevents << " events with bad headers, and " << num_badchksum << " events with bad check sum, and " << num_baduncompress << " events with bad uncompress" << std::endl; if(output) std::cout << "Wrote " << num_goodevents << " good events " << std::endl; } } std::cout << std::endl << "------------END--------------" << std::endl << "read " << num_events << " events" << std::endl << "and " << num_badevents << " events with bad headers" << std::endl << "and " << num_badchksum << " events with bad check sum" << std::endl << "and " << num_baduncompress << " events with bad uncompress" << std::endl << "and " << num_duplevents << " duplicated event Id" << std::endl; if(output) { uint32 dummyStatusCode = 1234; stream_output.writeEOF(dummyStatusCode, hltStats); std::cout << "Wrote " << num_goodevents << " good events " << std::endl; } }catch(cms::Exception& e){ std::cerr << "Exception caught: " << e.what() << std::endl << "After reading " << num_events << " events, and " << num_badevents << " events with bad headers" << std::endl << "and " << num_badchksum << " events with bad check sum" << std::endl << "and " << num_baduncompress << " events with bad uncompress" << std::endl << "and " << num_duplevents << " duplicated event Id" << std::endl; } }