47{
   48  
   49  std::string str(adf_waveform_line);
   50 
   51  std::string::iterator new_end = std::unique(str.begin(), str.end(), [](char a, char b)
   52                                              { return a == b && a == ' '; });
   53 
   54  str.erase(new_end, str.end());
   55 
   56  
   57  std::istringstream ins(str);
   58  std::string        line;
   59 
   61  int            waveform_id{};
   62 
   63  std::getline(ins, line, ' ');
   64  try {
   65    waveform_id = std::stoi(line);
   66  }
   67  catch (std::exception const& ex) {
   68    std::cerr << "could not parse the waveform_id:" << ex.what() << "\n";
   69    return std::nullopt;
   70  }
   71 
   72  size_t nsamples{};
   73 
   74  std::getline(ins, line, ' ');
   75  try {
   76    nsamples = std::stoi(line);
   77    std::cout << "line=" << line << " nsamples=" << nsamples << "\n";
   78  }
   79  catch (std::exception const& ex) {
   80    std::cerr << "could not parse the waveform_id:" << ex.what() << "\n";
   81    return std::nullopt;
   82  }
   83 
   84  waveform_samples.reserve(nsamples);
   85 
   86  while (std::getline(ins, line, ' ')) {
   87    T sample = atof(line.c_str());
   88    waveform_samples.push_back(sample);
   89  }
   90  if (waveform_samples.size() != nsamples) {
   91    std::cerr << "mismatched number of samples : expecting " << nsamples << " but got " << waveform_samples.size() << "\n";
   92    return std::nullopt;
   93  }
   94 
   96}