XrdMonDumpPacketsApp.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                          XrdMonDumpPacketsApp.cc                          */
00004 /*                                                                           */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonDumpPacketsApp.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 #include "XrdMon/XrdMonHeader.hh"
00014 #include "XrdMon/XrdMonException.hh"
00015 #include "XrdMon/XrdMonDecArgParser.hh"
00016 #include <fstream>
00017 #include <iomanip>
00018 #include "XrdSys/XrdSysHeaders.hh"
00019 #include <sstream>
00020 using std::cout;
00021 using std::endl;
00022 using std::fstream;
00023 using std::ios;
00024 using std::setfill;
00025 using std::setw;
00026 using std::stringstream;
00027 
00028 void 
00029 dumpOnePacket(kXR_int64 uniqueId, fstream& _file)
00030 {
00031     // prepare file for writing
00032     stringstream ss(stringstream::out);
00033     ss << "/tmp/ap.dump." << setw(6) << setfill('0') << uniqueId;
00034     string filePath = ss.str();
00035     fstream ofs(filePath.c_str(), ios::out|ios::binary);
00036 
00037     // read header, dump to file
00038     char hBuffer[HDRLEN];
00039     _file.read(hBuffer, HDRLEN);
00040     ofs.write(hBuffer, HDRLEN);
00041 
00042     //decode header
00043     XrdMonHeader header;
00044     header.decode(hBuffer);
00045     cout << "Dumping packet " << uniqueId << " to " << filePath.c_str() << ", "
00046          << "inputfile tellg: " << setw(10) << (kXR_int64) _file.tellg()-HDRLEN 
00047          << ", header: " << header << endl;
00048     
00049     // read packet, dump to file
00050     char packet[MAXPACKETSIZE];
00051     _file.read(packet, header.packetLen()-HDRLEN);
00052     ofs.write(packet, header.packetLen()-HDRLEN);
00053 
00054     // close output file
00055     ofs.close();
00056 }
00057 
00058 int main(int argc, char* argv[])
00059 {
00060     try {
00061         XrdMonDecArgParser::parseArguments(argc, argv);
00062         const char* fName = XrdMonDecArgParser::_fPath.c_str();
00063 
00064         fstream _file;
00065         _file.open(fName, ios::in|ios::binary);
00066         _file.seekg(0, ios::end);
00067         kXR_int64 fSize = _file.tellg();
00068         _file.seekg(XrdMonDecArgParser::_offset2Dump, ios::beg);
00069     
00070         if (XrdMonDecArgParser::_offset2Dump != 0 ) {
00071             dumpOnePacket(XrdMonDecArgParser::_offset2Dump, _file);
00072         } else {
00073             kXR_int64 packetNo = 0;
00074             while ( fSize > _file.tellg() ) {
00075                 dumpOnePacket(++packetNo, _file);
00076             }
00077         }
00078         } catch (XrdMonException& e) {
00079         e.printIt();
00080         return 1;
00081     }
00082 
00083     return 0;
00084 }

Generated on Tue Jul 5 14:46:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1