Sorry. Yes thats true. I changed the type to vector and removed memset. Here is the whole code.
main.cpp:
[code]#include
//#include “TConfigurator.h”
#include “TRawDataReader.h”
#include “TRawDataConverter.h”
#include “TData.h”
#include “TCfgFileHandler.h”
#include “THatFileHandler.h”
#include “TDataToEvent.h”
#include “TEvalPedestal.h”
#include “TCMCPassOne.h”
#include “TCMCPassTwo.h”
#include “TEvalNoisePassOne.h”
#include “TEvalNoisePassTwo.h”
#include “TCalFileHandler.h”
#include “TEvalHits.h”
#include “TCluster1D.h”
#include “TCluster2D.h”
int main(int argc, char **argv) {
THatFileHandler hat(“config_erik.hat”);
TCfgFileHandler cfg(“cal001.cfg”);
TCalFileHandler cal(“cal007.cal”);
TData data;
TRawDataReader rdr;
TRawDataConverter cvr;
TDataToEvent dte;
TEvalPedestal epd;
TCMCPassOne cpo;
TCMCPassTwo cpt;
TEvalNoisePassOne eno;
TEvalNoisePassTwo ent;
TEvalHits eht;
TCluster1D c1d;
TCluster2D c2d;
cal.configure(hat,cfg,data);
rdr.configure(hat,cfg,data);
cvr.configure(hat, cfg, data);
dte.configure(hat, cfg, data);
epd.configure(hat, cfg, data);
cpo.configure(hat, cfg, data);
cpt.configure(hat, cfg, data);
eno.configure(hat, cfg, data);
ent.configure(hat, cfg, data);
eht.configure(hat, cfg, data);
c1d.configure(hat, cfg, data);
c2d.configure(hat, cfg, data);
cal.analyse(data);
//for (int i(0); i<4; i++) {
rdr.analyse(data);
cvr.analyse(data);
dte.analyse(data);
epd.analyse(data);
cpo.analyse(data);
cpt.analyse(data);
eno.analyse(data);
ent.analyse(data);
eht.analyse(data);
c1d.analyse(data);
c2d.analyse(data);
//}
return 0;
}
[/code]
the problems start right after rdr.analyse(data).
TRawDataReader.h:
#ifndef TRAWDATAREADER_H
#define TRAWDATAREADER_H
#pragma pack(4)
/** own classes **/
#include "IAnalyser.h"
#include "THatFileHandler.h"
/** data structures **/
#include "./datastructure/SaveEventHeader.h"
#include "./datastructure/UIntVector2D.h"
#include "./datastructure/ULongVector2D.h"
/** std classes **/
#include <vector>
/** ROOT classes **/
#include "TTree.h"
#include "Rtypes.h"
class TRawDataReader : public IAnalyser
{
protected:
enum Config_ {fadc_modules = 2, fadc_fifo1_s1 = 1024, altera_per_fadc = 4, channel_per_altera = 4, channel_per_fadc = altera_per_fadc*channel_per_altera, fadc_max_data = fadc_fifo1_s1*channel_per_fadc};
string id_;
TTree* outputTree_;
string binaryFilename_;
ifstream binary_;
FILE *DataFile_;
hat::SaveEventHeader save_event_header_;
unsigned long fadc_rawdata_array_[fadc_modules][fadc_max_data];
hat::UIntVector2D fadc_rawdata_;
void openDatFile();
ifstream readEventHeader();
public:
void configure(THatFileHandler &hat, TCfgFileHandler &cfg, TData &data);
void analyse(TData &data);
TTree *getTree();
TRawDataReader();
};
#endif // TRAWDATAREADER_H
there are some types that are not needed in the code. They were for testing.
TRawDataReader.cpp:
/** own classes **/
#include "TRawDataReader.h"
/** std classes **/
#include <fstream>
#include <string>
#include <iostream>
#include <cstdio>
/** ROOT classes **/
#include "TFile.h"
using namespace std;
void TRawDataReader::configure(THatFileHandler& hat, TCfgFileHandler& cfg, TData& data)
{
SectionCollection::iterator itSectionFind = hat.sections_.find("files");
if (itSectionFind==hat.sections_.end()) {
cout << "Section [files] not found. Did you read in the .hat file?" << endl;
}
else {
binaryFilename_ = itSectionFind->second.find("binaryfile")->second.front();
}
openDatFile();
outputTree_ = new TTree(id_.c_str(),"Raw Data Tree");
data.addTree(id_,outputTree_, true, false);
outputTree_->Branch("save_event_header_ttree",&save_event_header_);
outputTree_->Branch("fadcRawdata",&fadc_rawdata_);
std::cout << "fadc_rawdata_.size() zero " << fadc_rawdata_.size() << std::endl;
std::cout << "fadc_rawdata_.capacity() zero" << fadc_rawdata_.capacity() << std::endl;
outputTree_->Fill();
std::cout << "configure() &(*outputTree_) " << &(*outputTree_) << endl;
std::cout << "configure() &fadc_rawdata_ " << &fadc_rawdata_ << endl;
}
void TRawDataReader::openDatFile()
{
binary_.open(binaryFilename_.c_str(), ios::binary | ios::in);
}
void TRawDataReader::analyse(TData &data)
{
binary_.read((char*)&save_event_header_,sizeof(save_event_header_));
for (int i(0); i<save_event_header_.number_fadcs; i++)
{
for (int j(0); j<save_event_header_.fadcdatalength[i]; j++)
{
binary_.read((char*)&fadc_rawdata_[i][0],sizeof(fadc_rawdata_[0][0]));
}
}
outputTree_->Fill();
}
TTree* TRawDataReader::getTree()
{
return outputTree_;
}
TRawDataReader::TRawDataReader() : outputTree_(0), id_("TRawDataReader"),fadc_rawdata_(fadc_modules, vector<unsigned int>(fadc_max_data))
{
}
TRawDataConverter.h:
#ifndef TRAWDATACONVERTER_H
#define TRAWDATACONVERTER_H
/** own classes**/
#include "IAnalyser.h"
#include "TRawDataReader.h"
/** data structures **/
#include "./datastructure/SaveEventHeader.h"
#include "./datastructure/UIntVector2D.h"
#include "./datastructure/DataVector2D.h"
#include "./datastructure/PosVector1D.h"
#include "./datastructure/ModuleVector1D.h"
#include "./datastructure/ApvVector1D.h"
#include "./datastructure/ULongVector2D.h"
#include "./datastructure/UShortVector2D.h"
/** std classes **/
#include <string>
/** ROOT classes **/
#include "TTree.h"
class TRawDataConverter : public IAnalyser
{
private:
enum Config_ {max_subevents = 6, max_hybrids = 8, max_apv = 4*max_hybrids, max_apv_per_mod = 8, apv_channels = 128, adc_samples = 1024, adc_channels = 16,
fadc_modules = 2, fadc_fifo1_s1 = 1024, altera_per_fadc = 4, channel_per_altera = 4,
channel_per_fadc = altera_per_fadc*channel_per_altera, fadc_max_data = fadc_fifo1_s1*channel_per_fadc,
HS_STOPSEARCH = 7900, HS_LIVESCAN = 50, HS_STARTSEARCH = 50, HS_MINTICKAMP = 40};
string id_;
TTree* outputTree_;
TTree* rawDataTree_;
string hardwarecfgFilename_;
string binaryFilename_;
ifstream hardwarecfg_;
ifstream binary_;
unsigned int fadcApvLl_[fadc_modules][channel_per_fadc]; // changed to ULong_t64 by Erik 1011101640
unsigned char numberapvFadc_[fadc_modules];
hat::UShortVector2D adcRawdata_;
const static unsigned short adcSamples_=1024; /* # of samples to take (must be <= ADC_SAMPLES-SAMPLES_SKIP_BEG-SAMPLES_SKIP_END) */
unsigned char dataMaxsubevents_;
unsigned int eventcnt_;
double tdcCurrent_;
unsigned int initevents_;
int sysclk_;
hat::DataVector2D data_;
hat::ApvVector1D apv_;
hat::ModuleVector1D module_;
hat::SaveEventHeader *save_event_header_;
hat::PosVector1D pos_;
int fillFifo1Data();
void processRawAdc(unsigned char maxsubevents);
double necoTrgtime2ns(unsigned char trg_time);
void getApvs(TCfgFileHandler& cfg);
void getSysclk(TCfgFileHandler& cfg);
void getModules(TCfgFileHandler& cfg);
hat::UIntVector2D *fadc_rawdata_;
unsigned char number_hybrids_;
public:
int numberApv_;
void configure(THatFileHandler &hat, TCfgFileHandler &cfg, TData &data, TRawDataReader &rdr);
void analyse(TData &data);
TRawDataConverter();
};
#endif // TRAWDATACONVERTER_H
TRawDataConveter.cpp:
/** own classes **/
#include "TRawDataConverter.h"
/** std classes **/
#include <string>
#include <fstream>
#include <iostream>
#include <cstdio>
/** ROOT classes **/
#include "TFile.h"
using namespace std;
void TRawDataConverter::configure(THatFileHandler& hat, TCfgFileHandler& cfg, TData& data, TRawDataReader &rdr)
{
memset(fadcApvLl_,0,sizeof(fadcApvLl_));
memset(numberapvFadc_,0,sizeof(numberapvFadc_));
fadc_rawdata_ = new hat::UIntVector2D;
save_event_header_ = new hat::SaveEventHeader;
outputTree_ = new TTree(id_.c_str(),"Raw Data Converter Tree");
data.addTree(id_,outputTree_,true,false);
outputTree_->Branch("ConvertedData",&data_);
outputTree_->Branch("pos",&pos_);
outputTree_->Branch("dataMaxsubevents", &dataMaxsubevents_, "dataMaxsubevents/b");
outputTree_->Branch("module", &module_);
outputTree_->Branch("numberHybrids", &number_hybrids_, "number_hybrids_/b");
outputTree_->Branch("tdcCurrent", &tdcCurrent_, "tdcCurrent_/D");
outputTree_->Fill();
if (data.treeIsAvailable("TRawDataReader")) {
rawDataTree_ = data.getTree("TRawDataReader");
rawDataTree_->SetBranchAddress("fadcRawdata",&fadc_rawdata_);
}
numberApv_ = cfg.getNumberApv();
cout << "numberApv_ " << numberApv_ << endl;
tdcCurrent_=0.0;
initevents_=300;
sysclk_ = cfg.getSysclk();
apv_ = cfg.getApvs();
module_ = cfg.getModules();
}
double TRawDataConverter::necoTrgtime2ns(unsigned char trg_time)
/* converts the raw trg_time value into nanoseconds, ignoring a possible ambiguity.
(in that case, the first occurence of a trigger signal counts.)
The unit for time measurement is sysclk/6 [ns], or 4.2ns in case of 40MHz.
If trg_time does not contain a valid measurement, this function returns -999.9.
Otherwise, the result is >=0.0 */
{
unsigned char coarse;
unsigned char fine;
double ns=0;
coarse=(trg_time&0x38)>>3;
fine=trg_time&7;
if (coarse && fine)
{
ns=sysclk_*(coarse-1)+((double)sysclk_)/6.0*(fine-1);
}
else
{
ns=-999.9;
}
return (ns);
}
int TRawDataConverter::fillFifo1Data()
/* reads the fifos of all installed APV */
{
int i,j;
double tdcval;
for (i=0; i<numberApv_; i++)
{
for (j=0; j<adcSamples_; j++)
{
adcRawdata_[i][j] = ((*fadc_rawdata_)[apv_[i].fadc_module][apv_[i].fadc_data_offset+j]>>23) & 0x1ff;;
}
}
// TDC values have to be calculated for both raw and hit mode and thus has to be done in function UI_daqtimer!!
// convert TDC
if ((*save_event_header_).eventcnt>=(2*initevents_))
{
// read trigger time (TDC)
tdcval=necoTrgtime2ns(save_event_header_->trg_time);
if (tdcval==-999.9)
{
tdcCurrent_=0.0;
}
else
{
tdcCurrent_=tdcval+sysclk_;
}
}
else
{
tdcCurrent_ = 0.0;
}
return 0;
}
void TRawDataConverter::processRawAdc(unsigned char maxsubevents)
{
/* Perform header search and fill events/subevents into data structure */
unsigned char i;
unsigned short j,k;
unsigned short liveticks_min;
unsigned short liveticks_max;
unsigned short liveticks_mean;
unsigned short s;
unsigned char subevent;
unsigned char hwsubevent;
unsigned short hs_stopsearch;
dataMaxsubevents_=0;
hs_stopsearch=adc_samples-apv_channels;
if (HS_STOPSEARCH<hs_stopsearch)
{
hs_stopsearch=HS_STOPSEARCH;
}
for (i=0; i<numberApv_; i++)
{
liveticks_min=65535;
liveticks_max=0;
subevent=0;
for (j=0; j<HS_LIVESCAN; j++)
{
//cout << "j<HS_LIVESCAN;" << endl;
if (adcRawdata_[i][j]>liveticks_max)
{
cout << "test liveticks_max" << endl;
liveticks_max=adcRawdata_[i][j];
}
if (adcRawdata_[i][j]<liveticks_min)
{
cout << "test liveticks_min" << endl;
liveticks_min=adcRawdata_[i][j];
}
}
liveticks_mean=(liveticks_min+liveticks_max)/2;
s=HS_STARTSEARCH;
while ((subevent<maxsubevents) && (s<hs_stopsearch) && ((liveticks_max-liveticks_min)>=HS_MINTICKAMP))
{
while ((s<hs_stopsearch) && ((adcRawdata_[i][s]<liveticks_mean) || (adcRawdata_[i][s+1]<liveticks_mean) || (adcRawdata_[i][s+2]<liveticks_mean)))
{
s++;
}
data_[subevent][i].sof=s;
if (s>=hs_stopsearch)
{
data_[subevent][i].header=0;
data_[subevent][i].address=0;
data_[subevent][i].eof=s;
}
else
{
data_[subevent][i].header=0;
for (j=0;j<3;j++)
{
if (adcRawdata_[i][s+j]>liveticks_mean)
{
data_[subevent][i].header|=(1<<j);
}
}
s+=3;
data_[subevent][i].address=0;
for (j=0;j<8;j++)
{
if (adcRawdata_[i][s+j]>liveticks_mean)
{
data_[subevent][i].address|=(1<<j);
}
}
s+=8;
if (adcRawdata_[i][s]>liveticks_mean)
{
data_[subevent][i].header|=8;
}
s+=1;
/* Reorder and fill analog data */
for (j=0;j<apv_channels;j++)
{
//data[subevent][i].adc[channel_lookup[j]]=adc_rawdata[i][s+j];
// k = (apv_[i].readout_order && FADC_CHK_MODE(fadc_mode,FADC_MODE_TRP_2K)) ? channel_lookup_inv[j] : channel_lookup[j];
cout << "in subevents" << endl;
data_[subevent][i].adc[k]=adcRawdata_[i][s+j];
}
s+=apv_channels;
data_[subevent][i].eof=s;
subevent++;
}
}
for (j=0; j<subevent; j++)
{
data_[j][i].event=(*save_event_header_).eventcnt; //when parallelysing be carefull
data_[j][i].numberofsubevents=subevent; //when parallelysing be carefull
data_[j][i].subevent=j;
data_[j][i].module=module_[apv_[i].modnumber].modposition;
data_[j][i].apv=apv_[i].apvposition;
data_[j][i].maxapv=numberApv_;
data_[j][i].adcnumber=i;
data_[j][i].liveticks_baseline=liveticks_min;
data_[j][i].liveticks_peak=liveticks_max;
data_[j][i].tdc=tdcCurrent_;
}
if (subevent>dataMaxsubevents_)
{
dataMaxsubevents_=subevent;
cout << "test if subevent" << endl;
}
//startdist[i][data[0][i].sof]++;
}
}
void TRawDataConverter::analyse(TData& data)
{
rawDataTree_->GetEntry(rawDataTree_->GetEntries()-1);
fillFifo1Data();
processRawAdc(save_event_header_->subevents);
outputTree_->Branch("ConvertedData",&data_);
outputTree_->Branch("pos",&pos_);
outputTree_->Branch("dataMaxsubevents", &dataMaxsubevents_, "dataMaxsubevents/b");
outputTree_->Branch("numberApv", &numberApv_, "numberApv/I");
outputTree_->Branch("module", &module_);
outputTree_->Branch("numberHybrids", &number_hybrids_, "number_hybrids_/b");
outputTree_->Branch("tdcCurrent", &tdcCurrent_, "tdcCurrent_/D");
outputTree_->Fill();
}
TRawDataConverter::TRawDataConverter() : outputTree_(0),
id_("TRawDataConverter"),
data_(max_subevents, std::vector<hat::Data>(max_apv)),pos_(max_hybrids),
adcRawdata_(max_apv, std::vector<unsigned short>(adc_samples, 0))
{
}
Please tell me if you need more.
BR