XrdMonDecMainApp.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                            XrdMonDecMainApp.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: XrdMonDecMainApp.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 #include "XrdMon/XrdMonCommon.hh"
00014 #include "XrdMon/XrdMonDecArgParser.hh"
00015 #include "XrdMon/XrdMonDecOnePacket.hh"
00016 #include "XrdMon/XrdMonDecPacketDecoder.hh"
00017 #include "XrdMon/XrdMonDecPreProcess.hh"
00018 #include "XrdMon/XrdMonErrors.hh"
00019 #include "XrdMon/XrdMonException.hh"
00020 #include "XrdMon/XrdMonHeader.hh"
00021 #include "XrdMon/XrdMonTimer.hh"
00022 #include "XrdSys/XrdSysHeaders.hh"
00023 
00024 #include <unistd.h>   /* access */
00025 #include <fstream>
00026 #include <iomanip>
00027 using std::cout;
00028 using std::ios;
00029 using std::setw;
00030 
00031 // use this switch if you want to brute-close all files in the active dir.
00032 // Useful to run after the very last log file
00033 
00034 void
00035 closeFiles()
00036 {
00037     cout << "brute close file not implemented FIXME" << endl;
00038     ::abort();
00039 }
00040 
00041 void
00042 doDecoding()
00043 {
00044     const char* fName = XrdMonDecArgParser::_fPath.c_str();
00045     
00046     if ( 0 != access(fName, F_OK) ) {
00047         string s("Invalid log file name ");
00048         s += fName;
00049         throw XrdMonException(ERR_INVALIDARG, s);
00050     }
00051 
00052     // here decoder should read all last seqno and unique id from jnl file
00053     XrdMonDecPacketDecoder decoder(XrdMonDecArgParser::_baseDir.c_str(),
00054                                    XrdMonDecArgParser::_saveTraces,
00055                                    XrdMonDecArgParser::_maxTraceLogSize,
00056                                    XrdMonDecArgParser::_upToTime);
00057 
00058     sequen_t lastSeq = decoder.lastSeq();
00059         
00060     // open file, find length and prepare for reading
00061     fstream _file;
00062     _file.open(fName, ios::in|ios::binary);
00063     _file.seekg(0, ios::end);
00064     kXR_int64 fSize = _file.tellg();
00065     _file.seekg(0, ios::beg);
00066 
00067     // preprocess: includes catching out of order packets
00068     vector< pair<packetlen_t, kXR_int64> > allPackets;
00069     XrdMonDecPreProcess pp(_file, 
00070                            fSize, 
00071                            lastSeq, 
00072                            XrdMonDecArgParser::_ignoreIfBefore,
00073                            allPackets);
00074     pp();
00075 
00076     // here it shoudl read all active dicts...
00077     decoder.init(XrdMonDecOnePacket::minDictId(), 
00078                  XrdMonDecOnePacket::maxDictId(),
00079                  XrdMonDecArgParser::_hostPort);         
00080 
00081     XrdMonHeader header;
00082     char packet[MAXPACKETSIZE];
00083     int noPackets = allPackets.size();
00084     for ( int packetNo = 0 ; packetNo<noPackets ; ++ packetNo ) {
00085         packetlen_t len = allPackets[packetNo].first;
00086         kXR_int64 pos     = allPackets[packetNo].second;
00087         if ( pos == -1 && len == 0 ) {
00088             cout << "Lost #" << packetNo << endl;
00089             continue;
00090         }
00091         cout << "Decoding #" << packetNo 
00092              << ", tellg " << setw(10) << pos << endl;
00093         _file.seekg(pos);
00094         memset(packet, 0, MAXPACKETSIZE);
00095         _file.read(packet, len);
00096         header.decode(packet);
00097         decoder(header, packet+HDRLEN);
00098 
00099         if ( decoder.stopNow() ) {
00100             break;
00101         }   
00102     }
00103 
00104     _file.close();
00105     //LogMgr::storeLastSeqNo(decoder.lastSeqNo());
00106 }
00107 
00108 int main(int argc, char* argv[])
00109 {
00110     XrdMonTimer t;
00111     t.start();
00112     try {
00113         XrdMonDecArgParser::parseArguments(argc, argv);
00114     } catch (XrdMonException& e) {
00115         e.printIt();
00116         cout << "Expected arguments: <logName> [-isActive <host>:<port> YYYY MM DD HH MM SS] [-ignoreIfBefore <unix_timestamp>] [-forceCloseOnly]\n"
00117              << "Use \"-isActive\" only when the logfile is active.rcv\n"
00118              << "up-till-date means that decoding will be stoped when given date is reached\n"
00119              << "-ignoreIfBefore can be used to ignore packets that arrived before certain date/time (e.g. from \"previous\" xrootd). Useful during xrootd/collector restarts\n"
00120              << "Use -forceCloseOnly to force closing all active files that are in active dir\n"
00121              << "\n"
00122              << "Examples:\n"
00123              << "  decoder logs/receiver/kan025/61145/20041102_11:57:51.073_kan025:61145.rcv\n"
00124              << "  decoder logs/receiver/kan025/61145/20041102_11:57:51.073_kan025:61145.rcv -forceCloseOnly\n"
00125              << "  decoder logs/receiver/kan025/61145/active.rcv -isActive kan025:61145 2004 11 02 12 45 12\n"
00126              << endl;
00127         return 1;
00128     }
00129     
00130     try{
00131         if ( XrdMonDecArgParser::_forceCloseOnly ) {
00132             closeFiles();
00133         } else {
00134             doDecoding();
00135         }
00136     } catch (XrdMonException& e) {
00137         e.printIt();
00138         return 1;
00139     }
00140     
00141     cout << "Total time: " << t.stop() << endl;
00142     //cout << "Publishing: " << LogMgr::_t1.getElapsed() << endl;
00143     //cout << "Flushing:   " << LogMgr::_t2.getElapsed() << endl;
00144     
00145     return 0;
00146 }

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