Compare commits
	
		
			3 Commits
		
	
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
								 | 
						0a9eb6e039 | |
| 
							
							
								
								 | 
						f13cb7cb51 | |
| 
							
							
								
								 | 
						9a2d26fc3b | 
| 
						 | 
				
			
			@ -27,7 +27,7 @@ set(ROOT_LIBRARIES -L${ROOT_LIBRARY_DIR} -lCore -lRIO -lNet -lHist -lGraf -lGraf
 | 
			
		|||
# Locate sources and headers for this project
 | 
			
		||||
# NB: headers are included so they will show up in IDEs
 | 
			
		||||
#
 | 
			
		||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp)
 | 
			
		||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/source/*.cpp)
 | 
			
		||||
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hpp)
 | 
			
		||||
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +36,15 @@ file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hpp)
 | 
			
		|||
add_executable(DB_Track DB_Track.cpp ${sources} ${headers})
 | 
			
		||||
target_link_libraries(DB_Track ${ROOT_LIBRARIES} )
 | 
			
		||||
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
# Locate MySQL sources and libraries
 | 
			
		||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
 | 
			
		||||
find_package(MySQL REQUIRED)
 | 
			
		||||
 | 
			
		||||
include_directories(${MYSQL_INCLUDE_DIR})
 | 
			
		||||
target_link_libraries(DB_Track ${MYSQL_LIBRARY})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#----------------------------------------------------------------------------
 | 
			
		||||
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										68
									
								
								DB_Track.cpp
								
								
								
								
							
							
						
						
									
										68
									
								
								DB_Track.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -19,20 +19,8 @@ int main(int argc, char* argv[])
 | 
			
		|||
    
 | 
			
		||||
    std::cout << "Press enter for the next track." << std::endl << "Press Ctrl + C to exit." << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    TH2D *twoDhisto = new TH2D("2Dhisto","2Dhisto", 100, 0, 32, 100, 0, 32);
 | 
			
		||||
    TH2D *twodhisto = new TH2D("twodhisto", "twodhisto", 100, 0, 32, 100, 0, 4);
 | 
			
		||||
    TCanvas *canvas = new TCanvas();
 | 
			
		||||
    std::vector<int> ch_id;
 | 
			
		||||
    std::vector<int> sec;
 | 
			
		||||
    std::vector<int> nsec;
 | 
			
		||||
    std::vector<int> amp;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<int> x_v;
 | 
			
		||||
    std::vector<int> y_v;
 | 
			
		||||
 | 
			
		||||
    int iterator = 0;
 | 
			
		||||
    int null = 0;
 | 
			
		||||
    
 | 
			
		||||
    canvas -> cd(0);
 | 
			
		||||
    
 | 
			
		||||
    TrackFinder finder;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -40,59 +28,17 @@ int main(int argc, char* argv[])
 | 
			
		|||
    {
 | 
			
		||||
        if(std::cin.get() == '\n')
 | 
			
		||||
        {
 | 
			
		||||
            twoDhisto -> Reset();
 | 
			
		||||
            x_v.clear();
 | 
			
		||||
            y_v.clear();
 | 
			
		||||
            
 | 
			
		||||
            if(finder.FindTrack())
 | 
			
		||||
            if(finder.FindAndDrawNextTrack(twodhisto, canvas))
 | 
			
		||||
            {
 | 
			
		||||
                finder.GetTrack(ch_id, sec, nsec, amp);
 | 
			
		||||
                for(int i = 0; i < ch_id.size(); i++)
 | 
			
		||||
                {
 | 
			
		||||
                    if(ch_id[i] < 32)
 | 
			
		||||
                    {
 | 
			
		||||
                        x_v.push_back(ch_id[i]);
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        y_v.push_back(ch_id[i] - 32);
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                }
 | 
			
		||||
                if(x_v.size() == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    for(int i = 0; i < y_v.size(); i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        twoDhisto -> Fill(null, y_v[i]);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if(y_v.size() == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    for(int i = 0; i < x_v.size(); i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        twoDhisto -> Fill(x_v[i], null);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if(x_v.size() > 0 && y_v.size() > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    for(int z = 0; z < x_v.size(); z++)
 | 
			
		||||
                    {
 | 
			
		||||
                        for(int j = 0; j < y_v.size(); j++)
 | 
			
		||||
                        {
 | 
			
		||||
                            twoDhisto -> Fill(x_v[z], y_v[j]);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                gSystem -> ProcessEvents();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                std::cout << "Reached the end of the database" << std::endl;
 | 
			
		||||
            }
 | 
			
		||||
            iterator++;
 | 
			
		||||
            twoDhisto -> Draw("colz");
 | 
			
		||||
            canvas -> Update();
 | 
			
		||||
            gSystem -> ProcessEvents();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    std::cout << iterator << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    App.Run();
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,74 @@
 | 
			
		|||
# Find MySQL
 | 
			
		||||
 | 
			
		||||
# Find the native MySQL includes and library
 | 
			
		||||
#
 | 
			
		||||
#  MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
 | 
			
		||||
#  MYSQL_LIBRARIES   - List of libraries when using MySQL.
 | 
			
		||||
#  MYSQL_FOUND       - True if MySQL found.
 | 
			
		||||
 | 
			
		||||
if(MYSQL_INCLUDE_DIR OR MYSQL_)
 | 
			
		||||
  # Already in cache, be silent
 | 
			
		||||
  SET(MYSQL_FIND_QUIETLY TRUE)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT WIN32)
 | 
			
		||||
  find_program(MYSQL_CONFIG_EXECUTABLE mysql_config
 | 
			
		||||
    /usr/bin/
 | 
			
		||||
    /usr/local/bin
 | 
			
		||||
    $ENV{MYSQL_DIR}/bin
 | 
			
		||||
  )
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(MYSQL_CONFIG_EXECUTABLE)
 | 
			
		||||
  execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --cflags OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
 | 
			
		||||
  separate_arguments(MYSQL_CFLAGS)
 | 
			
		||||
  string( REGEX MATCH "-I[^;]+" MYSQL_INCLUDE_DIR "${MYSQL_CFLAGS}" )
 | 
			
		||||
  string( REPLACE "-I" "" MYSQL_INCLUDE_DIR "${MYSQL_INCLUDE_DIR}")
 | 
			
		||||
  string( REGEX REPLACE "-I[^;]+;" "" MYSQL_CFLAGS "${MYSQL_CFLAGS}" )
 | 
			
		||||
  execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --libs OUTPUT_VARIABLE MYSQL_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE)
 | 
			
		||||
else()
 | 
			
		||||
  find_path(MYSQL_INCLUDE_DIR mysql.h
 | 
			
		||||
    /usr/local/mysql/include
 | 
			
		||||
    /usr/local/include/mysql
 | 
			
		||||
    /usr/local/include
 | 
			
		||||
    /usr/include/mysql
 | 
			
		||||
    /usr/include
 | 
			
		||||
    /usr/mysql/include
 | 
			
		||||
    /usr/local/mysql-8.0.12-macos10.13-x86_64/include
 | 
			
		||||
    $ENV{MYSQL_DIR}/include
 | 
			
		||||
  )
 | 
			
		||||
  set(MYSQL_NAMES mysqlclient mysqlclient_r)
 | 
			
		||||
  find_library(MYSQL_LIBRARY NAMES ${MYSQL_NAMES}
 | 
			
		||||
    PATHS /usr/local/mysql/lib /usr/local/lib /usr/lib /usr/local/mysql-8.0.12-macos10.13-x86_64/lib $ENV{MYSQL_DIR}/lib $ENV{MYSQL_DIR}/lib/opt
 | 
			
		||||
  )
 | 
			
		||||
  set(MYSQL_LIBRARIES ${MYSQL_LIBRARY})
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
 | 
			
		||||
  set(MYSQL_FOUND TRUE)
 | 
			
		||||
  if(WIN32)
 | 
			
		||||
    string(REPLACE mysqlclient libmysql libmysql ${MYSQL_LIBRARY})
 | 
			
		||||
    set(MYSQL_LIBRARIES ${libmysql} ${MYSQL_LIBRARIES})
 | 
			
		||||
  endif()
 | 
			
		||||
else()
 | 
			
		||||
  set(MYSQL_FOUND FALSE)
 | 
			
		||||
  set(MYSQL_LIBRARIES )
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(MYSQL_FOUND)
 | 
			
		||||
  if(NOT MYSQL_FIND_QUIETLY)
 | 
			
		||||
    message(STATUS "Found MySQL libraries: ${MYSQL_LIBRARIES}")
 | 
			
		||||
    message(STATUS "Found MySQL includes: ${MYSQL_INCLUDE_DIR}")
 | 
			
		||||
  endif()
 | 
			
		||||
else()
 | 
			
		||||
  if(MYSQL_FIND_REQUIRED)
 | 
			
		||||
    message(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
 | 
			
		||||
    message(FATAL_ERROR "Could NOT find MySQL library")
 | 
			
		||||
  endif()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
mark_as_advanced(
 | 
			
		||||
  MYSQL_CONFIG_EXECUTABLE
 | 
			
		||||
  MYSQL_LIBRARY
 | 
			
		||||
  MYSQL_INCLUDE_DIR
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
//
 | 
			
		||||
//  SQLHandler.hpp
 | 
			
		||||
//  DB_Track
 | 
			
		||||
//
 | 
			
		||||
//  Created by Baranyai David on 2018. 10. 13..
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef SQLHandler_hpp
 | 
			
		||||
#define SQLHandler_hpp
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <mysql.h>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
struct Hit
 | 
			
		||||
{
 | 
			
		||||
    unsigned int channel_id;
 | 
			
		||||
    unsigned int elapsed_time;
 | 
			
		||||
    unsigned int amplitude_peak;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SQLHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SQLHandler();
 | 
			
		||||
    ~SQLHandler();
 | 
			
		||||
    
 | 
			
		||||
    std::vector<Hit> QueryNext();
 | 
			
		||||
    void SetRange(unsigned int);
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int range;
 | 
			
		||||
    uint64_t latest_value;
 | 
			
		||||
    MYSQL *server;
 | 
			
		||||
    
 | 
			
		||||
    unsigned int min_hits;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* SQLHandler_hpp */
 | 
			
		||||
| 
						 | 
				
			
			@ -13,33 +13,21 @@
 | 
			
		|||
#include <vector>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include "SQLHandler.hpp"
 | 
			
		||||
#include "TH2D.h"
 | 
			
		||||
#include "TCanvas.h"
 | 
			
		||||
 | 
			
		||||
class TrackFinder
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    TrackFinder();
 | 
			
		||||
    ~TrackFinder();
 | 
			
		||||
    bool FindTrack();
 | 
			
		||||
    void GetTrack(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&);
 | 
			
		||||
    bool FindAndDrawNextTrack(TH2D*, TCanvas*);
 | 
			
		||||
    
 | 
			
		||||
private:
 | 
			
		||||
    std::ifstream file;
 | 
			
		||||
    std::string line;
 | 
			
		||||
    int interval = 900000; //nanosec
 | 
			
		||||
    std::vector<Hit> track_data[4]; //4 chambers
 | 
			
		||||
    
 | 
			
		||||
    int ch_id_1 = 0;
 | 
			
		||||
    int sec_1 = 0;
 | 
			
		||||
    int nsec_1 = 0;
 | 
			
		||||
    int amp_1 = 0;
 | 
			
		||||
    
 | 
			
		||||
    int line_data[4];
 | 
			
		||||
    
 | 
			
		||||
    std::vector<int> ch_id;
 | 
			
		||||
    std::vector<int> amp;
 | 
			
		||||
    std::vector<int> sec;
 | 
			
		||||
    std::vector<int> nsec;
 | 
			
		||||
    
 | 
			
		||||
    bool istrackavailable = false;
 | 
			
		||||
    SQLHandler sqlHandler;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* TrackFinder_hpp */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,127 @@
 | 
			
		|||
//
 | 
			
		||||
//  SQLHandler.cpp
 | 
			
		||||
//  DB_Track
 | 
			
		||||
//
 | 
			
		||||
//  Created by Baranyai David on 2018. 10. 13..
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include "SQLHandler.hpp"
 | 
			
		||||
 | 
			
		||||
SQLHandler::SQLHandler()
 | 
			
		||||
{
 | 
			
		||||
    latest_value = 0;
 | 
			
		||||
    range = 9000000000;
 | 
			
		||||
    min_hits = 4; //need at least 4 hits
 | 
			
		||||
    server = mysql_init(server);
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        if (!mysql_real_connect(server, "localhost", "root", "raspberry", "adatok", 0, NULL, 0))
 | 
			
		||||
        {
 | 
			
		||||
            throw "Can't connect to the server";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            std::cout << "-----------------------------" << std::endl;
 | 
			
		||||
            std::cout << "Successfully connected" << std::endl;
 | 
			
		||||
            std::cout << "Host info: " << mysql_get_host_info(server) << std::endl;
 | 
			
		||||
            std::cout << "Client info: " << mysql_get_client_info() << std::endl;
 | 
			
		||||
            std::cout << "-----------------------------" << std::endl << std::endl;
 | 
			
		||||
            
 | 
			
		||||
            std::cout << "Getting the first value..." << std::endl;
 | 
			
		||||
            std::string query = "SELECT min(time_sum) FROM (SELECT *, (time_sec * (power(10, 7)) + time_ns) time_sum FROM fb55) sum";
 | 
			
		||||
            
 | 
			
		||||
            if (!mysql_query(server, query.c_str()))
 | 
			
		||||
            {
 | 
			
		||||
                MYSQL_RES *result = mysql_store_result(server);
 | 
			
		||||
                if (mysql_num_fields(result) == 1) //1 oszlop
 | 
			
		||||
                {
 | 
			
		||||
                    MYSQL_ROW row;
 | 
			
		||||
                    if(mysql_num_rows(result) == 1) //1 érték
 | 
			
		||||
                    {
 | 
			
		||||
                        row = mysql_fetch_row(result);
 | 
			
		||||
                        latest_value = std::stoll(row[0]);
 | 
			
		||||
                        std::cout << "Min value = " << latest_value <<std::endl;
 | 
			
		||||
                    }
 | 
			
		||||
                    else throw "More than one row error";
 | 
			
		||||
                }
 | 
			
		||||
                else throw "More than one column error";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } catch (char const* s)
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << s <<std::endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SQLHandler::~SQLHandler()
 | 
			
		||||
{
 | 
			
		||||
    mysql_close(server);
 | 
			
		||||
    delete server;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//MAIN QUERY:
 | 
			
		||||
//SELECT * FROM (SELECT ch_id, time_sec, time_ns, (time_sec * (power(10, 7)) + time_ns) time_sum FROM fb55) s WHERE time_sum BETWEEN 2521025900 AND 2570247800 ORDER BY time_sum ASC
 | 
			
		||||
 | 
			
		||||
std::vector<Hit> SQLHandler::QueryNext()
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << "Getting next between " << latest_value << " and " << latest_value + range << std::endl;
 | 
			
		||||
        std::stringstream query;
 | 
			
		||||
        unsigned int nRow = 0;
 | 
			
		||||
        std::vector<Hit> hit_vector;
 | 
			
		||||
        while(nRow < min_hits)
 | 
			
		||||
        {
 | 
			
		||||
            hit_vector.clear();
 | 
			
		||||
            double max = latest_value + range;
 | 
			
		||||
            query << "SELECT * FROM (SELECT ch_id, peak_amp, (time_sec * (power(10, 7)) + time_ns) time_sum FROM fb55) s WHERE time_sum BETWEEN " << latest_value << " AND " << max << " ORDER BY time_sum ASC";
 | 
			
		||||
            
 | 
			
		||||
            if (!mysql_query(server, query.str().c_str())) //Start query
 | 
			
		||||
            {
 | 
			
		||||
                MYSQL_RES *result = mysql_store_result(server); //store result
 | 
			
		||||
                unsigned int nColumn = mysql_num_fields(result); //store column number
 | 
			
		||||
                if (nColumn == 3) //3 oszlop, se több, se kevesebb
 | 
			
		||||
                {
 | 
			
		||||
                    MYSQL_ROW row;
 | 
			
		||||
                    nRow = mysql_num_rows(result);
 | 
			
		||||
                    if(nRow > min_hits) //at least
 | 
			
		||||
                    {
 | 
			
		||||
                        Hit hit_helper;
 | 
			
		||||
                        
 | 
			
		||||
                        for(int i = 0; i < nRow; i++)
 | 
			
		||||
                        {
 | 
			
		||||
                            row = mysql_fetch_row(result);
 | 
			
		||||
                            hit_helper.channel_id = atoi(row[0]);
 | 
			
		||||
                            hit_helper.amplitude_peak = atoi(row[1]);
 | 
			
		||||
                            hit_helper.elapsed_time = std::stoll(row[2]);
 | 
			
		||||
                            hit_vector.push_back(hit_helper);
 | 
			
		||||
                        }
 | 
			
		||||
                        latest_value = atof(row[2]);
 | 
			
		||||
                        //std::cout << "Min value = " << latest_value <<std::endl;
 | 
			
		||||
                        return hit_vector;
 | 
			
		||||
                    }
 | 
			
		||||
                    else if(nRow != 0)
 | 
			
		||||
                    {
 | 
			
		||||
                        for(int i = 0; i < nRow; i++) //seek to the end
 | 
			
		||||
                        {
 | 
			
		||||
                            row = mysql_fetch_row(result);
 | 
			
		||||
                        }
 | 
			
		||||
                        latest_value = atoi(row[2]); //store the latest value
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else throw "More than three column error";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return hit_vector;
 | 
			
		||||
    }
 | 
			
		||||
    catch (char const* s)
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << s << std::endl;
 | 
			
		||||
        return std::vector<Hit>();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SQLHandler::SetRange(unsigned int n_range)
 | 
			
		||||
{
 | 
			
		||||
    range = n_range;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -10,101 +10,56 @@
 | 
			
		|||
 | 
			
		||||
TrackFinder::TrackFinder()
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        file.open("data.txt");
 | 
			
		||||
        if(!file.is_open())
 | 
			
		||||
        {
 | 
			
		||||
            throw "File opening error";
 | 
			
		||||
        }
 | 
			
		||||
        getline(file, line);
 | 
			
		||||
        std::istringstream is(line);
 | 
			
		||||
        for(int i = 0; i < 4; i++)
 | 
			
		||||
        {
 | 
			
		||||
            is >> line_data[i];
 | 
			
		||||
        }
 | 
			
		||||
        ch_id_1 = line_data[0];
 | 
			
		||||
        sec_1 = line_data[1];
 | 
			
		||||
        nsec_1 = line_data[2];
 | 
			
		||||
        amp_1 = line_data[3];
 | 
			
		||||
        
 | 
			
		||||
        ch_id.push_back(ch_id_1);
 | 
			
		||||
        sec.push_back(sec_1);
 | 
			
		||||
        nsec.push_back(nsec_1);
 | 
			
		||||
        amp.push_back(amp_1);
 | 
			
		||||
    }
 | 
			
		||||
    catch(char param)
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << param << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TrackFinder::~TrackFinder()
 | 
			
		||||
{
 | 
			
		||||
    file.close();
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TrackFinder::FindTrack()
 | 
			
		||||
bool TrackFinder::FindAndDrawNextTrack(TH2D* histo, TCanvas *canvas)
 | 
			
		||||
{
 | 
			
		||||
    ch_id.erase(ch_id.begin(), ch_id.end());
 | 
			
		||||
    sec.erase(sec.begin(), sec.end());
 | 
			
		||||
    nsec.erase(nsec.begin(), nsec.end());
 | 
			
		||||
    amp.erase(amp.begin(), amp.end());
 | 
			
		||||
    while(!file.eof())
 | 
			
		||||
    std::vector<Hit> track;
 | 
			
		||||
    track.clear();
 | 
			
		||||
    
 | 
			
		||||
    for(int i = 0; i < 4; i++)
 | 
			
		||||
    {
 | 
			
		||||
        getline(file, line);
 | 
			
		||||
        std::istringstream is(line);
 | 
			
		||||
        track_data[i].clear();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    track = sqlHandler.QueryNext();
 | 
			
		||||
    
 | 
			
		||||
    histo -> Reset();
 | 
			
		||||
    canvas -> cd(0);
 | 
			
		||||
    
 | 
			
		||||
    if (track.size() == 0)
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << "End of database" << std::endl;
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        for(int i = 0; i < track.size(); i++)
 | 
			
		||||
        {
 | 
			
		||||
            Hit helper;
 | 
			
		||||
            helper.amplitude_peak = track[i].amplitude_peak;
 | 
			
		||||
            helper.elapsed_time = track[i].elapsed_time;
 | 
			
		||||
            helper.channel_id = track[i].channel_id % 16;
 | 
			
		||||
            track_data[track[i].channel_id / 16].push_back(helper);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        for(int i = 0; i < 4; i++)
 | 
			
		||||
        {
 | 
			
		||||
            is >> line_data[i];
 | 
			
		||||
        }
 | 
			
		||||
        long old = ((line_data[1]*1000000)+line_data[2]);
 | 
			
		||||
        long nw = ((sec_1*1000000)+nsec_1);
 | 
			
		||||
        if( old - nw < interval)
 | 
			
		||||
        {
 | 
			
		||||
            ch_id_1 = line_data[0];
 | 
			
		||||
            sec_1 = line_data[1];
 | 
			
		||||
            nsec_1 = line_data[2];
 | 
			
		||||
            amp_1 = line_data[3];
 | 
			
		||||
            
 | 
			
		||||
            ch_id.push_back(ch_id_1);
 | 
			
		||||
            sec.push_back(sec_1);
 | 
			
		||||
            nsec.push_back(nsec_1);
 | 
			
		||||
            amp.push_back(amp_1);
 | 
			
		||||
        }
 | 
			
		||||
        else if(ch_id.size() < 4) //ha négynél kevesebb szál szólalt meg
 | 
			
		||||
        {
 | 
			
		||||
            ch_id_1 = line_data[0];
 | 
			
		||||
            sec_1 = line_data[1];
 | 
			
		||||
            nsec_1 = line_data[2];
 | 
			
		||||
            amp_1 = line_data[3];
 | 
			
		||||
            
 | 
			
		||||
            ch_id.erase(ch_id.begin(), ch_id.end());
 | 
			
		||||
            sec.erase(sec.begin(), sec.end());
 | 
			
		||||
            nsec.erase(nsec.begin(), nsec.end());
 | 
			
		||||
            amp.erase(amp.begin(), amp.end());
 | 
			
		||||
            
 | 
			
		||||
            ch_id.push_back(ch_id_1);
 | 
			
		||||
            sec.push_back(sec_1);
 | 
			
		||||
            nsec.push_back(nsec_1);
 | 
			
		||||
            amp.push_back(amp_1);
 | 
			
		||||
        }
 | 
			
		||||
        else if(ch_id.size() >= 4) //ha négynél több
 | 
			
		||||
        {
 | 
			
		||||
            istrackavailable = true;
 | 
			
		||||
            return true;
 | 
			
		||||
            for(int j = 0; j < track_data[i].size(); j++)
 | 
			
		||||
            {
 | 
			
		||||
                histo -> Fill(track_data[i][j].channel_id, i, track_data[i][j].amplitude_peak);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        histo -> Draw("colz");
 | 
			
		||||
        histo -> Fit("pol1");
 | 
			
		||||
        canvas -> Update();
 | 
			
		||||
        
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TrackFinder::GetTrack(std::vector<int> &ch, std::vector<int> &s, std::vector<int> &ns, std::vector<int> &a)
 | 
			
		||||
{
 | 
			
		||||
    if(istrackavailable)
 | 
			
		||||
    {
 | 
			
		||||
        ch = ch_id;
 | 
			
		||||
        s = sec;
 | 
			
		||||
        ns = nsec;
 | 
			
		||||
        a = amp;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue