CFEL - ASG Software Suite  2.5.0
CASS
lma_parser.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file lma_parser.cpp contains class to parse a lma file
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <fstream>
10 #include <sstream>
11 #include <iostream>
12 #include <stdexcept>
13 
14 #include "lma_parser.h"
15 #include "agattypes.hpp"
16 #include "log.h"
17 #include "input_base.h"
18 
19 using namespace cass;
20 using namespace ACQIRIS;
21 using namespace std;
22 using Streaming::operator >>;
23 
25 {
26  ifstream &file(*(_readerpointerpair.second._filestream));
27 
28  lmaHeader::General header;
29  file >> header;
30 
31  if (header.nbrBits != 16)
32  throw runtime_error("LMAParser():run: The lma file seems to contain 8-bit wavefroms '"
33  + toString(header.nbrBits) + "'. Currently this is not supported.");
34 
35  Log::add(Log::VERBOSEINFO,"LMAParser(): File contains instrument with '" +
36  toString(header.nbrChannels) + "' channels:");
37 
38  for (int16_t i(0) ; i < header.nbrChannels ;++i)
39  {
40  Log::add(Log::VERBOSEINFO,"LMAParser(): Channel '" + toString(i) + "' is " +
41  ((header.usedChannelBitmask & (0x1<<i))?"":"not") + " recorded!");
42  if (header.usedChannelBitmask & (0x1<<i))
43  file.seekg(sizeof(lmaHeader::Channel),ios_base::cur);
44  }
45 
46  lmaHeader::Event evtHead;
47  while((!InputBase::reference().shouldQuit()) && (!file.eof()))
48  {
49  const streampos eventStartPos(file.tellg());
50  file >> evtHead;
51  savePos(eventStartPos,evtHead.id);
52 
53  for (int16_t i=0; i<header.nbrChannels;++i)
54  {
55  if (header.usedChannelBitmask & (0x1<<i))
56  {
57  int16_t nbrPulses(Streaming::retrieve<int16_t>(file));
58  for (int16_t i(0); i < nbrPulses; ++i)
59  {
60  lmaHeader::Puls pulsHead;
61  file >> pulsHead;
62  const size_t dataSize(pulsHead.length * 2);
63  file.seekg(dataSize,ios_base::cur);
64  }
65  }
66  }
67  }
68 
69 }
contains the layout of the lma file headers.
void runthis()
parse the lma file
Definition: lma_parser.cpp:24
STL namespace.
the header for each event
Definition: agattypes.hpp:67
the general header of an lma file
Definition: agattypes.hpp:24
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
the header of a puls
Definition: agattypes.hpp:126
contains the base class for all input modules
contains class to parse a lma file
the header of each channel as part of the file header
Definition: agattypes.hpp:80
static shared_pointer::element_type & reference()
get reference to the singelton instance
Definition: input_base.cpp:28
contains a logger for cass