Changeset 2286


Ignore:
Timestamp:
09/02/11 19:05:11 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: No (performance tuning)

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: a parameter "filename" is added to Scantable::summary. scantable.summary doesn't return a string anymore

Test Programs: sdlist unittest/ scantable.summary("summary.txt")

Put in Release Notes: Yes

Module(s): sdlist, asap.summary

Description:

scantable.summary is very slow for large data sets (in row number) often outputted
by modern telescopes. It takes > 1.5 hours to list OTF raster scan with 350,000 rows.

This was because, the methods accumulates the whole text string (~700,000 lines) and
returns it as a string. Once the summary string exceed several tens thousands lines,
elapse time increases non-linearly, may be because very massive output string starts
to overweigh the memory.

I updated scantable.summary so that it flushes the summary string more often to file/logger.
After the modification, scantable.summary could list the data mentioned above in ~ 7 minutes.
The side effect of it is that scantable.summary doesn't return summary string anymore.
(But people may not happy with sub-million lines of string anyway.)


Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2277 r2286  
    445445
    446446        """
    447         info = Scantable._summary(self)
     447#         info = Scantable._summary(self)
    448448        if filename is not None:
    449449            if filename is "":
     
    451451            from os.path import expandvars, isdir
    452452            filename = expandvars(filename)
    453             if not isdir(filename):
    454                 data = open(filename, 'w')
    455                 data.write(info)
    456                 data.close()
    457             else:
     453#             if not isdir(filename):
     454#                 data = open(filename, 'w')
     455#                 data.write(info)
     456#                 data.close()
     457#             else:
     458            if isdir(filename):
    458459                msg = "Illegal file name '%s'." % (filename)
    459460                raise IOError(msg)
    460         return page(info)
     461        else:
     462            filename = ""
     463        Scantable._summary(self, filename)
     464#         return page(info)
    461465
    462466    def get_spectrum(self, rowno):
  • trunk/src/Scantable.cpp

    r2277 r2286  
    10401040}
    10411041
    1042 std::string Scantable::summary()
     1042  //std::string Scantable::summary( const std::string& filename )
     1043void Scantable::summary( const std::string& filename )
    10431044{
    10441045  ostringstream oss;
     1046  ofstream ofs;
     1047  LogIO ols(LogOrigin("Scantable", "summary", WHERE));
     1048
     1049  if (filename != "")
     1050    ofs.open( filename.c_str(),  ios::out );
     1051
    10451052  oss << endl;
    10461053  oss << asap::SEPERATOR << endl;
     
    10671074      << endl;
    10681075  oss << asap::SEPERATOR << endl;
     1076
     1077  // Flush summary and clear up the string
     1078  ols << String(oss) << LogIO::POST;
     1079  if (ofs) ofs << String(oss) << flush;
     1080  oss.str("");
     1081  oss.clear();
     1082
     1083//   TableIterator iter(table_, "SCANNO");
     1084//   while (!iter.pastEnd()) {
     1085//     Table subt = iter.table();
     1086//     ROTableRow row(subt);
     1087//     MEpoch::ROScalarColumn timeCol(subt,"TIME");
     1088//     const TableRecord& rec = row.get(0);
     1089//     oss << setw(4) << std::right << rec.asuInt("SCANNO")
     1090//         << std::left << setw(1) << ""
     1091//         << setw(15) << rec.asString("SRCNAME")
     1092//         << setw(10) << formatTime(timeCol(0), false);
     1093//     // count the cycles in the scan
     1094//     TableIterator cyciter(subt, "CYCLENO");
     1095//     int nint = 0;
     1096//     while (!cyciter.pastEnd()) {
     1097//       ++nint;
     1098//       ++cyciter;
     1099//     }
     1100//     oss << setw(3) << std::right << nint  << setw(3) << " x " << std::left
     1101//         << setw(11) <<  formatSec(rec.asFloat("INTERVAL")) << setw(1) << ""
     1102//      << setw(15) << SrcType::getName(rec.asInt("SRCTYPE")) << endl;
     1103
     1104//     TableIterator biter(subt, "BEAMNO");
     1105//     while (!biter.pastEnd()) {
     1106//       Table bsubt = biter.table();
     1107//       ROTableRow brow(bsubt);
     1108//       const TableRecord& brec = brow.get(0);
     1109//       uInt row0 = bsubt.rowNumbers(table_)[0];
     1110//       oss << setw(5) << "" <<  setw(4) << std::right << brec.asuInt("BEAMNO")<< std::left;
     1111//       oss  << setw(4) << ""  << formatDirection(getDirection(row0)) << endl;
     1112//       TableIterator iiter(bsubt, "IFNO");
     1113//       while (!iiter.pastEnd()) {
     1114//         Table isubt = iiter.table();
     1115//         ROTableRow irow(isubt);
     1116//         const TableRecord& irec = irow.get(0);
     1117//         oss << setw(9) << "";
     1118//         oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left
     1119//             << setw(1) << "" << frequencies().print(irec.asuInt("FREQ_ID"))
     1120//             << setw(3) << "" << nchan(irec.asuInt("IFNO"))
     1121//             << endl;
     1122
     1123//         ++iiter;
     1124//       }
     1125//       ++biter;
     1126//     }
     1127//     ++iter;
     1128//   }
    10691129  TableIterator iter(table_, "SCANNO");
    10701130  while (!iter.pastEnd()) {
     
    11111171      ++biter;
    11121172    }
     1173    // Flush summary every scan and clear up the string
     1174    ols << String(oss) << LogIO::POST;
     1175    if (ofs) ofs << String(oss) << flush;
     1176    oss.str("");
     1177    oss.clear();
     1178
    11131179    ++iter;
    11141180  }
    1115   return String(oss);
     1181  oss << asap::SEPERATOR << endl;
     1182  ols << String(oss) << LogIO::POST;
     1183  if (ofs) {
     1184    //ofs << String(oss) << flush;
     1185    ofs.close();
     1186  }
     1187  //  return String(oss);
    11161188}
    11171189
  • trunk/src/Scantable.h

    r2193 r2286  
    375375
    376376  std::string headerSummary();
    377   std::string summary();
     377  //  std::string summary();
     378  void summary(const std::string& filename="");
    378379  //std::string getTime(int whichrow=-1, bool showdate=true) const;
    379380  std::string getTime(int whichrow=-1, bool showdate=true, casa::uInt prec=0) const;
  • trunk/src/ScantableWrapper.h

    r2193 r2286  
    217217  Scantable* getPtr() {return &(*table_);}
    218218
    219   std::string summary() const {
    220     return table_->summary();
     219  //  std::string summary() const {
     220  //  return table_->summary();
     221  //  }
     222  void summary(const std::string& filename="") {
     223    return table_->summary(filename);
    221224  }
    222225
  • trunk/src/python_Scantable.cpp

    r2186 r2286  
    118118          boost::python::arg("unflag")=false) )
    119119    .def("_save",  &ScantableWrapper::makePersistent)
    120     .def("_summary",  &ScantableWrapper::summary)
     120    //.def("_summary",  &ScantableWrapper::summary)
     121    .def("_summary",  &ScantableWrapper::summary,
     122         (boost::python::arg("filename")=""))
    121123    .def("_list_header",  &ScantableWrapper::listHeader)
    122124    //.def("_getrestfreqs",  &ScantableWrapper::getRestFrequencies)
Note: See TracChangeset for help on using the changeset viewer.