<commit_before>/*
 * Copyright 2006-2010 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

package net.sf.mzmine.project.impl;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Vector;
import java.util.logging.Logger;

import net.sf.mzmine.data.DataPoint;
import net.sf.mzmine.data.RawDataFile;
import net.sf.mzmine.data.Scan;
import net.sf.mzmine.data.impl.SimpleDataPoint;
import net.sf.mzmine.util.Range;
import net.sf.mzmine.util.ScanUtils;

/**
 * Implementation of the Scan interface which stores raw data points in a
 * temporary file, accessed by RawDataFileImpl.readFromFloatBufferFile()
 */
public class StorableScan implements Scan {

	private Logger logger = Logger.getLogger(this.getClass().getName());

	private int scanNumber, msLevel, parentScan, fragmentScans[];
	private double precursorMZ;
	private int precursorCharge;
	private double retentionTime;
	private Range mzRange;
	private DataPoint basePeak;
	private double totalIonCurrent;
	private boolean centroided;
	private long scanFileOffset;
	private int numberOfDataPoints;
	private RawDataFileImpl rawDataFile;

	/**
	 * Constructor for creating a storable scan from a given scan
	 */
	public StorableScan(Scan originalScan, RawDataFileImpl rawDataFile,
			long scanFileOffset, int numberOfDataPoints) {

		// save scan data
		this.rawDataFile = rawDataFile;
		this.scanFileOffset = scanFileOffset;
		this.numberOfDataPoints = numberOfDataPoints;

		this.scanNumber = originalScan.getScanNumber();
		this.msLevel = originalScan.getMSLevel();
		this.retentionTime = originalScan.getRetentionTime();
		this.parentScan = originalScan.getParentScanNumber();
		this.precursorMZ = originalScan.getPrecursorMZ();
		this.precursorCharge = originalScan.getPrecursorCharge();
		this.fragmentScans = originalScan.getFragmentScanNumbers();
		this.centroided = originalScan.isCentroided();
		this.mzRange = originalScan.getMZRange();
		this.basePeak = originalScan.getBasePeak();
		this.totalIonCurrent = originalScan.getTIC();

	}

	public StorableScan(RawDataFileImpl rawDataFile, long scanFileOffset,
			int numberOfDataPoints, int scanNumber, int msLevel,
			double retentionTime, int parentScan, double precursorMZ,
			int precursorCharge, int fragmentScans[], boolean centroided) {

		this.rawDataFile = rawDataFile;
		this.scanFileOffset = scanFileOffset;
		this.numberOfDataPoints = numberOfDataPoints;

		this.scanNumber = scanNumber;
		this.msLevel = msLevel;
		this.retentionTime = retentionTime;
		this.parentScan = parentScan;
		this.precursorMZ = precursorMZ;
		this.precursorCharge = precursorCharge;
		this.fragmentScans = fragmentScans;
		this.centroided = centroided;

		DataPoint dataPoints[] = getDataPoints();

		// find m/z range and base peak
		if (dataPoints.length > 0) {

			basePeak = dataPoints[0];
			mzRange = new Range(dataPoints[0].getMZ(), dataPoints[0].getMZ());

			for (DataPoint dp : dataPoints) {

				if (dp.getIntensity() > basePeak.getIntensity())
					basePeak = dp;

				mzRange.extendRange(dp.getMZ());

				totalIonCurrent += dp.getIntensity();

			}

		} else {
			// Empty scan, so no m/z range or base peak
			mzRange = new Range(0, 0);
			basePeak = null;
			totalIonCurrent = 0;
		}

	}<commit_msg>Fixed a bug ID 3116370 reported by Chris<commit_after>/*
 * Copyright 2006-2010 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * MZmine 2; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 */

package net.sf.mzmine.project.impl;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Vector;
import java.util.logging.Logger;

import net.sf.mzmine.data.DataPoint;
import net.sf.mzmine.data.RawDataFile;
import net.sf.mzmine.data.Scan;
import net.sf.mzmine.data.impl.SimpleDataPoint;
import net.sf.mzmine.util.Range;
import net.sf.mzmine.util.ScanUtils;

/**
 * Implementation of the Scan interface which stores raw data points in a
 * temporary file, accessed by RawDataFileImpl.readFromFloatBufferFile()
 */
public class StorableScan implements Scan {

	private Logger logger = Logger.getLogger(this.getClass().getName());

	private int scanNumber, msLevel, parentScan, fragmentScans[];
	private double precursorMZ;
	private int precursorCharge;
	private double retentionTime;
	private Range mzRange;
	private DataPoint basePeak;
	private double totalIonCurrent;
	private boolean centroided;
	private long scanFileOffset;
	private int numberOfDataPoints;
	private RawDataFileImpl rawDataFile;

	/**
	 * Constructor for creating a storable scan from a given scan
	 */
	public StorableScan(Scan originalScan, RawDataFileImpl rawDataFile,
			long scanFileOffset, int numberOfDataPoints) {

		// save scan data
		this.rawDataFile = rawDataFile;
		this.scanFileOffset = scanFileOffset;
		this.numberOfDataPoints = numberOfDataPoints;

		this.scanNumber = originalScan.getScanNumber();
		this.msLevel = originalScan.getMSLevel();
		this.retentionTime = originalScan.getRetentionTime();
		this.parentScan = originalScan.getParentScanNumber();
		this.precursorMZ = originalScan.getPrecursorMZ();
		this.precursorCharge = originalScan.getPrecursorCharge();
		this.fragmentScans = originalScan.getFragmentScanNumbers();
		this.centroided = originalScan.isCentroided();
		this.mzRange = originalScan.getMZRange();
		this.basePeak = originalScan.getBasePeak();
		this.totalIonCurrent = originalScan.getTIC();

	}

	public StorableScan(RawDataFileImpl rawDataFile, long scanFileOffset,
			int numberOfDataPoints, int scanNumber, int msLevel,
			double retentionTime, int parentScan, double precursorMZ,
			int precursorCharge, int fragmentScans[], boolean centroided) {

		this.rawDataFile = rawDataFile;
		this.scanFileOffset = scanFileOffset;
		this.numberOfDataPoints = numberOfDataPoints;

		this.scanNumber = scanNumber;
		this.msLevel = msLevel;
		this.retentionTime = retentionTime;
		this.parentScan = parentScan;
		this.precursorMZ = precursorMZ;
		this.precursorCharge = precursorCharge;
		this.fragmentScans = fragmentScans;
		this.centroided = centroided;

		mzRange = new Range(0, 0);
		basePeak = null;
		totalIonCurrent = 0;
		
		DataPoint dataPoints[] = getDataPoints();

		// find m/z range and base peak
		if (dataPoints.length > 0) {

			basePeak = dataPoints[0];
			mzRange = new Range(dataPoints[0].getMZ(), dataPoints[0].getMZ());

			for (DataPoint dp : dataPoints) {

				if (dp.getIntensity() > basePeak.getIntensity())
					basePeak = dp;

				mzRange.extendRange(dp.getMZ());

				totalIonCurrent += dp.getIntensity();

			}

		}

	}
{'fraction_non_alphanumeric': 0.0881057268722467, 'fraction_numerical': 0.00893643801132788, 'mean_word_length': 4.5372822299651565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5037579', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2382, 'n_words': 711}