Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

IONameArchiveFile.cpp

00001 #include "IONameArchiveFile.h"
00002 #include "../SctNames.h"
00003 
00004 #include <fstream>
00005 
00006 namespace Sct {
00007 namespace Archive {
00008 
00009 IONameArchiveFile::IONameArchiveFile(const string& fileName) throw(InvalidArgument) : IOName(fileName) {
00010     IONameArchiveFile::parse();
00011 }
00012 
00013 IONameArchiveFile::IONameArchiveFile(const string& uniqueID, const string& className) throw() : IOName(uniqueID, className) {
00014     IONameArchiveFile::construct();
00015 }
00016 
00017 IONameArchiveFile::~IONameArchiveFile() throw() {
00018 }
00019 
00020 IONameArchiveFile::IONameArchiveFile() {
00021 }
00022 
00023 bool IONameArchiveFile::wildcard()const{
00024   if (nameIO.find("*")!=string::npos){
00025     std::cout << nameIO << " has a wildcard " << std::endl;
00026   }
00027   std::cout << std::endl;
00028   return (nameIO.find("*")!=string::npos);
00029 }
00030 
00031 void IONameArchiveFile::expandWildcards(){
00032   if (m_wildcardsExpanded || !wildcard() ) return;
00033   m_wildcardsExpanded=true;
00034   std::ostringstream oss;  oss << SctNames::getTempDir() << "/ArchivingList.XXXXXX";
00035   char tempfile_template[oss.str().size()];
00036   char* tempfile= tempfile_template;
00037   strcpy(tempfile, oss.str().c_str());
00038   mkstemp(tempfile);
00039   string fullcmd="ls "; fullcmd += nameIO;
00040   fullcmd += " > "; fullcmd += tempfile;
00041   if (system (fullcmd.c_str() ) !=0 ) {
00042     throw Sct::IoError(string("Error executing command :") + fullcmd, __FILE__, __LINE__);
00043   }
00044   std::ifstream f(tempfile);
00045   while (f.good()){
00046     string name; f>> name; if(!f.good()) break;
00047     shared_ptr<IONameArchiveFile> item (new IONameArchiveFile(name) );
00048     std::cout << "adding " << name << std::endl;
00049     m_list.push_back(item);
00050   }
00051 }
00052 
00053 void IONameArchiveFile::parse() throw(InvalidArgument) {
00054     int ldot = nameIO.rfind(".gz");
00055     int slash = nameIO.rfind('/');      //We want last /
00056     int dot2 = nameIO.find('.', ++slash);
00057 
00058     if (ldot==string::npos || slash==string::npos || dot2==string::npos){
00059       throw InvalidArgument(string("Error parsing IONameArchiveFile ") + nameIO,
00060                 __FILE__, __LINE__);
00061     }
00062     className = nameIO.substr(slash, dot2-slash);
00063     uniqueID = nameIO.substr(dot2+1, ldot-dot2-1);
00064 }
00065 
00066 void IONameArchiveFile::construct() throw() {
00067     nameIO = SctNames::getPersistentDir();
00068     nameIO += "/" + className;
00069     nameIO += "." + uniqueID;
00070     nameIO += ".gz";
00071 }
00072 
00073 }
00074 }

Generated on Thu Jul 15 09:50:47 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5