Mass++ mzML IO Plugin v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::io::mzml::MzmlDataHandler Class Reference

XML data handler to get spectrum data points. More...

#include <MzmlDataHandler.h>

Inheritance diagram for kome::io::mzml::MzmlDataHandler:
Inheritance graph
[legend]
Collaboration diagram for kome::io::mzml::MzmlDataHandler:
Collaboration graph
[legend]

Public Member Functions

 MzmlDataHandler (MzmlSample &sample, const char *id, kome::core::XYData &xyData)
 constructor More...
 
virtual ~MzmlDataHandler ()
 destructor
 

Protected Member Functions

void setPoints ()
 set data points
 
virtual void onStartDocument ()
 This method is called by startDocument method. (override method)
 
virtual void onEndDocument ()
 This method is called by endDocument method. (override method)
 
virtual void onStartElement (const char *name, kome::core::Properties &attrs)
 This method is called by startElement method. (override method) More...
 
virtual void onEndElement (const char *name, const char *text)
 This method is called by end element method. (override method) More...
 

Protected Attributes

MzmlSamplem_sample
 
std::string m_id
 
kome::core::XYData & m_xyData
 
int m_dataLength
 
bool m_reverseFlg
 
MzmlSample::ArrayInfo m_arrayInfo
 
bool m_available
 
double * m_xArray
 
double * m_yArray
 
bool m_reading
 

Detailed Description

XML data handler to get spectrum data points.

Definition at line 29 of file MzmlDataHandler.h.

Constructor & Destructor Documentation

kome::io::mzml::MzmlDataHandler::MzmlDataHandler ( MzmlSample sample,
const char *  id,
kome::core::XYData &  xyData 
)

constructor

Parameters
samplesample
iddata ID
xyDataxy data object to store data points

Definition at line 48 of file MzmlDataHandler.cpp.

49  : m_sample( sample ), m_id( NVL( id, "" ) ), m_xyData( xyData ) {
50  m_reverseFlg = isbigendian();
52 }
kome::core::XYData & m_xyData
virtual void onStartDocument()
This method is called by startDocument method. (override method)

Here is the call graph for this function:

Member Function Documentation

void kome::io::mzml::MzmlDataHandler::onEndElement ( const char *  name,
const char *  text 
)
protectedvirtual

This method is called by end element method. (override method)

Parameters
nametag name
textbody text

Definition at line 194 of file MzmlDataHandler.cpp.

194  {
195  // each tags
196  if( strcmp( name, SPEC_TAG_NAME ) == 0 ) { // </spectrum>
197  if( m_reading ) {
198  setPoints();
199  }
200  }
201  else if( strcmp( name, CHROM_TAG_NAME ) == 0 ) { // </chromatogram>
202  if( m_reading ) {
203  setPoints();
204  }
205  }
206  else if( strcmp( name, BINARY_TAG_NAME ) == 0 ) { // </binary>
207  if( m_reading && m_available && m_dataLength > 0 ) {
208  // create array
209  double* arr = NULL;
210  if( m_arrayInfo.isY ) {
211  if( m_yArray == NULL ) {
212  m_yArray = new double[ m_dataLength ];
213  }
214  arr = m_yArray;
215  }
216  else {
217  if( m_xArray == NULL ) {
218  m_xArray = new double[ m_dataLength ];
219  }
220  arr = m_xArray;
221  }
222 
223  // get data
224  char* data0 = new char[ strlen( text ) ];
225  unsigned long size0 = kome::core::Base64::decode( (char*)text, strlen( text ), data0, strlen( text ) );
226 
227  unsigned long size1 = m_dataLength * m_arrayInfo.bits / 8;
228  char* data1 = new char[ size1 ];
229 
230  if( m_arrayInfo.compressed ) {
231  uncompress( (Bytef*)data1, &size1, (Bytef*)data0, size0 );
232  }
233  else {
234  memcpy( data1, data0, size1 );
235  }
236 
237  // add to array
238  if( m_arrayInfo.bits == 64 ) { // double
239  double* dArr = (double*)data1;
240  for( int i = 0; i < m_dataLength; i++ ) {
241  arr[ i ] = dArr[ i ] * m_arrayInfo.scale;
242  if( m_reverseFlg ) {
243  memreverse( arr + i, sizeof( double ) );
244  }
245  }
246  }
247  else { // float
248  float* fArr = (float*)data1;
249  for( int i = 0; i < m_dataLength; i++ ) {
250  arr[ i ] = (double)fArr[ i ] * m_arrayInfo.scale;
251  if( m_reverseFlg ) {
252  memreverse( arr + i, sizeof( double ) );
253  }
254  }
255  }
256 
257  // delete
258  delete[] data0;
259  delete[] data1;
260  }
261  m_available = false;
262  }
263 }
MzmlSample::ArrayInfo m_arrayInfo
void setPoints()
set data points

Here is the call graph for this function:

void kome::io::mzml::MzmlDataHandler::onStartElement ( const char *  name,
kome::core::Properties &  attrs 
)
protectedvirtual

This method is called by startElement method. (override method)

Parameters
nametag name
attrsattributes

Definition at line 109 of file MzmlDataHandler.cpp.

109  {
110  // each tags
111  if( strcmp( name, SPEC_TAG_NAME ) == 0 ) { // <spectrum>
112  // ID
113  const char* id = attrs.getStringValue( SPEC_ID_ATTR_NAME, "" );
114  if( m_id.compare( id ) == 0 ) {
115  m_reading = true;
116  m_dataLength = attrs.getIntValue( SPEC_LENGTH_ATTR_NAME, 0 );
117  }
118  }
119  else if( strcmp( name, CHROM_TAG_NAME ) == 0 ) { // <chromatogram>
120  // ID
121  const char* id = attrs.getStringValue( CHROM_ID_ATTR_NAME, "" );
122  if( m_id.compare( id ) == 0 ) {
123  m_reading = true;
124  m_dataLength = attrs.getIntValue( CHROM_LENGTH_ATTR_NAME, 0 );
125  }
126  }
127  else if( strcmp( name, ARRAY_TAG_NAME ) == 0 ) { // <binaryDataArray>
128  if( m_reading ) {
129  m_dataLength = attrs.getIntValue( ARRAY_LENGTH_ATTR_NAME, m_dataLength );
130 
131  m_arrayInfo.name.clear();
132  m_arrayInfo.bits = 32;
133  m_arrayInfo.compressed = false;
134  m_arrayInfo.scale = 1.0;
135  m_arrayInfo.isY = false;
136 
137  m_available = false;
138  }
139  }
140  else if( strcmp( name, PARAM_GROUP_TAG_NAME ) == 0 ) { // <referenceableParamGroupRef>
141  if( m_reading ) {
142  const char* id = attrs.getStringValue( PARAM_GROUP_ID_ATTR_NAME, "" );
144  if( info != NULL ) {
145  m_arrayInfo = *info;
146  m_available = true;
147  }
148  }
149  }
150  else if( strcmp( name, CV_TAG_NAME ) == 0 ) { // <cvParam>
151  if( m_reading ) {
152  // accession
153  const char* accession = attrs.getStringValue( CV_ACCESSION_ATTR_NAME, "" );
154 
155  // each accessions
156  if( strcmp( accession, "MS:1000514" ) == 0 ) { // m/z array
157  m_arrayInfo.isY = false;
158  m_arrayInfo.scale = 1.0;
159 
160  m_available = true;
161  }
162  else if( strcmp( accession, "MS:1000595" ) == 0 ) { // RT array
163  m_arrayInfo.isY = false;
164  m_arrayInfo.scale = 1.0;
165 
166  m_available = true;
167 
168  const char* unit = attrs.getStringValue( CV_UNIT_ATTR_NAME, "" );
169  if( strcmp( unit, "UO:0000031" ) != 0 ) { // second
170  m_arrayInfo.scale = 1.0 / 60.0;
171  }
172  }
173  else if( strcmp( accession, "MS:1000515" ) == 0 ) { // intensity array
174  m_arrayInfo.isY = true;
175  m_available = true;
176  }
177  else if( strcmp( accession, "MS:1000521" ) == 0 ) { // 32-bit float
178  m_arrayInfo.bits = 32;
179  }
180  else if( strcmp( accession, "MS:1000523" ) == 0 ) { // 64-bit float
181  m_arrayInfo.bits = 64;
182  }
183  else if( strcmp( accession, "MS:1000576" ) == 0 ) { // no compression
184  m_arrayInfo.compressed = false;
185  }
186  else if( strcmp( accession, "MS:1000574" ) == 0 ) { // zlib compression
187  m_arrayInfo.compressed = true;
188  }
189  }
190  }
191 }
ArrayInfo * getArrayInfo(const char *name)
gets array information
Definition: MzmlSample.cpp:111
MzmlSample::ArrayInfo m_arrayInfo

Here is the call graph for this function:

Member Data Documentation

MzmlSample::ArrayInfo kome::io::mzml::MzmlDataHandler::m_arrayInfo
protected

array information

Definition at line 64 of file MzmlDataHandler.h.

bool kome::io::mzml::MzmlDataHandler::m_available
protected

available array flag

Definition at line 67 of file MzmlDataHandler.h.

int kome::io::mzml::MzmlDataHandler::m_dataLength
protected

data length

Definition at line 57 of file MzmlDataHandler.h.

std::string kome::io::mzml::MzmlDataHandler::m_id
protected

ID

Definition at line 51 of file MzmlDataHandler.h.

bool kome::io::mzml::MzmlDataHandler::m_reading
protected

reading flag

Definition at line 77 of file MzmlDataHandler.h.

bool kome::io::mzml::MzmlDataHandler::m_reverseFlg
protected

reverse flag

Definition at line 60 of file MzmlDataHandler.h.

MzmlSample& kome::io::mzml::MzmlDataHandler::m_sample
protected

sample

Definition at line 48 of file MzmlDataHandler.h.

double* kome::io::mzml::MzmlDataHandler::m_xArray
protected

x array

Definition at line 70 of file MzmlDataHandler.h.

kome::core::XYData& kome::io::mzml::MzmlDataHandler::m_xyData
protected

xy data

Definition at line 54 of file MzmlDataHandler.h.

double* kome::io::mzml::MzmlDataHandler::m_yArray
protected

y array

Definition at line 73 of file MzmlDataHandler.h.


The documentation for this class was generated from the following files: