DT7160 2020-04-16 10:21 采纳率: 0%
浏览 79

程序找错怎么优化一下啊

这个头文件TFile.h说是root软件自带的,pack/WCDAHitPacket.h这个说是wcda自己编译的这是啥意思,有没有大神解惑
而且这段代码怎么优化一下!!!!

#define BUF_LEN (10*1024*1024)

#define HIT_LEN 16

#include < stdint.h>
#include < TFile.h>
#include < TTree.h>
#include < fstream>
#include < iostream>
#include "pack/WCDAHitPacket.h"
#include "pack/SubDetector.h"
#include "pack/Channel.h"

void decode(char datafile, char rootfile) {

TFile froot(rootfile,"recreate");
TTree t("t","tree");

uint32_t fee ; 
uint32_t channel ; 
uint32_t l1id = 0;
uint32_t flag; 
uint32_t anode_charge ; 
uint32_t dynode_charge ; 
uint32_t charge_over_range_id ; 
uint32_t second ; 
uint32_t year ; 
uint32_t coarse_time ; 
uint32_t low_threshold_fine_time ;
uint32_t high_threshold_fine_time ;
uint32_t coarse_counter_diff_id ;
uint32_t temprature_sensor_info ;
uint32_t flag_info ;
uint32_t reserved ;
uint32_t tail ;

uint64_t time;
uint32_t dt;

t.Branch("l1id", &l1id, "l1id/i");
t.Branch("fee", &fee, "fee/i");
t.Branch("ch", &channel, "ch/i");
t.Branch("anode_charge", &anode_charge, "anode_charge/i");
t.Branch("dynode_charge", &dynode_charge, "dynode_charge/i");
t.Branch("charge_over_range_id", &charge_over_range_id, "charge_over_range_id/i");
t.Branch("second", &second, "second/i");
t.Branch("year", &year, "year/i");
t.Branch("coarse_time", &coarse_time, "coarse_time/i");
t.Branch("high_th_fine_time", &high_threshold_fine_time, "high_th_fine_time/i");
t.Branch("low_th_fine_time", &low_threshold_fine_time, "low_th_fine_time/i");
t.Branch("temprature_sensor_info", &temprature_sensor_info, "temprature_sensor_info/i");

// calculated
t.Branch("time", &time, "time/l");
t.Branch("dt", &dt, "dt/i");

ifstream fdata;
fdata.open(datafile, std::ios::in | std::ios::binary);
uint8_t *buffer = new uint8_t[BUF_LEN];

uint64_t last_time;
bool is_first = true;
while (1) {
    uint8_t *ptr = buffer;
    fdata.read((char*)ptr, SubDetector::head_size);
    if(!fdata.good()) break;
    SubDetector sd(ptr);
    //std::cout << "subdetector fragment data size: " << sd.dataSize() << std::endl;
    fdata.read((char*)sd.data(), sd.dataSize());
    if(!fdata.good()) break;

    uint8_t *chPtr = sd.data();

    while(chPtr - sd.data() < sd.dataSize()) {
        Channel ch(chPtr);
        fee = ch.channelTag();

        uint8_t *hitPtr = ch.data();
        uint32_t sz = ch.dataSize();
        //std::cout << "channel fragment size: " << sz << std::endl;
        for(; hitPtr<ch.data()+sz; hitPtr+=WCDAHitPacket::element_size) {
            WCDAHitPacket hit(hitPtr);
            //hit.dump();

            flag = hit.flag();
            channel = hit.channel();
            //std::cout << "channel: " << channel << std::endl;
            anode_charge = hit.anodeCharge();
            dynode_charge = hit.dynodeCharge();
            charge_over_range_id = hit.chargeOverRangeId();
            second = hit.second();
            year = hit.year();
            coarse_time = hit.coarseTime();
            low_threshold_fine_time = hit.lowThresholdFineTime();
            high_threshold_fine_time = hit.highThresholdFineTime();
            coarse_counter_diff_id = hit.coarseCounterDiffId();
            temprature_sensor_info = hit.tempratureSensorInfo();
            flag_info = hit.flagInfo();
            tail = hit.tail();

            //if(anode_charge < 1200 || anode_charge > 2500) {
            //    continue;
            //}

            time = hit.time(); //(uint64_t)second*16000000000ULL + (uint64_t)coarse_time*16+(uint64_t)low_threshold_fine_time*333/1000;
            //time = (uint64_t)coarse_time*16;
            dt = time - last_time;
            last_time = time;
            //std::cout << "dt: " << dt << std::endl;

            if(!is_first) {
                t.Fill();
            }

            is_first = false;

            hitPtr+=WCDAHitPacket::element_size;
        }

        chPtr += ch.totalSize();
    }

    l1id ++ ;
}

fdata.close();

t.Write();
//froot.Write();
froot.Close();

}

int main(int argc, char **argv)
{
decode(argv[1], argv[2]);
return 0;
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?