Generic hardware access library
/home/cschwick/hal/generic/src/common/StaticVMEConfigurationASCIIFileReader.cc
Go to the documentation of this file.
00001 #include "hal/StaticVMEConfigurationASCIIFileReader.hh"
00002 #include <fstream>
00003 #include <sstream>
00004 #include <iomanip>
00005 
00006 HAL::StaticVMEConfigurationASCIIFileReader::StaticVMEConfigurationASCIIFileReader( std::string fileName )
00007   throw (HAL::NoSuchFileException) 
00008   : HAL::StaticVMEConfigurationReader() {
00009 
00010   // some preparation to read the file:
00011 
00012   const int MaxLength=1024;
00013   char buffer[MaxLength];
00014   std::ifstream FileStream( fileName.c_str() );
00015   if ( ! FileStream ) {
00016     std::string text = "Cannot open file : " + fileName + 
00017       "    (HAL::StaticVMEConfigurationASCIIFileReader::StaticVMEConfigurationASCIIFileReader)";
00018     throw (HAL::NoSuchFileException( text, __FILE__, __LINE__, __FUNCTION__ ));
00019   }
00020 
00021 
00022   // prepare the loop over all lines of the ascii file:
00023 
00024   std::string serialNumber;
00025   uint32_t slotId;
00026 
00027   // loop over all lines of the file:
00028   while ( ! FileStream.eof() ) {
00029     FileStream.getline(buffer, MaxLength);
00030     if ( FileStream.eof() ) break;
00031 
00032     //skip all white space at beginning of buffer:
00033     int ic = 0;
00034     while ( buffer[ic] == ' ' ||
00035             buffer[ic] == '\t' ) {
00036       ic++;
00037     }
00038 
00039     // skip comments or empty lines
00040     if (buffer[ic] == '*') continue;
00041     if (buffer[ic] == '\n') continue; // should never happen since \n is not extracted with getline
00042     if ((uint32_t)buffer[ic] == 0xd) continue; // in case of some windows edited ascii files....
00043     if (buffer[ic] == 0x00) continue;
00044     
00045     // scan a line
00046     std::istringstream Line(buffer);    
00047     Line >> serialNumber;
00048     Line >> std::dec >> slotId;
00049 
00050     // it will be destroyed in the desructor of the HAL::VME64xCrate
00051     HAL::StaticVMEItem* itemPointer = new HAL::StaticVMEItem( serialNumber, slotId ); 
00052     staticVMEItemList_.push_back(itemPointer);
00053 
00054   }
00055 
00056   FileStream.close();
00057 
00058 }