Segmentation violation when accesing vector

Hi all,

I hope somebody can help me. I am reading a two dimensional vector of unsigned int into a tree but when I read it out again it seems that it doesn’t work as I get this error, which looks like the object wasn’t actuallay read out. I am using an external compiler so I generated a dictionary, which works because at least I can read in an empty vector of this type. Here is the error message:

[code] *** Break *** segmentation violation

===========================================================
There was a crash (#7 0x010a0eed in SigHandler(ESignals) () from /libs/root_5.27_6/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0x00ea6422 in __kernel_vsyscall ()
#1 0x01a6f7d3 in __waitpid_nocancel () at …/sysdeps/unix/syscall-template.S:82
#2 0x01a10de3 in do_system (line=) at …/sysdeps/posix/system.c:149
#3 0x076db27d in system (line=0xdbc5050 “/libs/root_5.27_6/etc/gdb-backtrace.sh 4010 1>&2”) at pt-system.c:29
#4 0x010992fd in TUnixSystem::Exec(char const*) () from /libs/root_5.27_6/lib/libCore.so
#5 0x0109fa15 in TUnixSystem::StackTrace() () from /libs/root_5.27_6/lib/libCore.so
#6 0x010a0ddf in TUnixSystem::DispatchSignals(ESignals) () from /libs/root_5.27_6/lib/libCore.so
#7 0x010a0eed in SigHandler(ESignals) () from /libs/root_5.27_6/lib/libCore.so
#8 0x010964f2 in sighandler(int) () from /libs/root_5.27_6/lib/libCore.so
#9
#10 0x081017b0 in std::vector<unsigned int, std::allocator >::operator[] (this=0x0, __n=0)
at /usr/include/c++/4.4/bits/stl_vector.h:611
#11 0x08129a2a in TRawDataConverter::fillFifo1Data (this=0xbff9a928)
at /home/adonai/projects/HAT/TRawDataConverter.cpp:226
#12 0x0812a585 in TRawDataConverter::analyse (this=0xbff9a928, data=…)
at /home/adonai/projects/HAT/TRawDataConverter.cpp:396
#13 0x081c868c in main (argc=1, argv=0xbffab0a4) at /home/adonai/projects/HAT/main.cpp:53

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#10 0x081017b0 in std::vector<unsigned int, std::allocator >::operator[] (this=0x0, __n=0)
at /usr/include/c++/4.4/bits/stl_vector.h:611
#11 0x08129a2a in TRawDataConverter::fillFifo1Data (this=0xbff9a928)
at /home/adonai/projects/HAT/TRawDataConverter.cpp:226
#12 0x0812a585 in TRawDataConverter::analyse (this=0xbff9a928, data=…)
at /home/adonai/projects/HAT/TRawDataConverter.cpp:396
#13 0x081c868c in main (argc=1, argv=0xbffab0a4) at /home/adonai/projects/HAT/main.cpp:53
[/code]

Thanks for any information.

Hi,

What is the code around TRawDataConverter.cpp:226 ?

Philippe.

[code]int TRawDataConverter::fillFifo1Data()
/* reads the fifos of all installed APV */
{
int i,j;
double tdcval;

memset (adcRawdata_, 0, sizeof(adcRawdata_));
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;;
   }
}[/code]

Hi,

What is the type of adcRawdata_? Can you check the value of calling .size() on adcRawdata_ and adcRawdata_[i] (in particular compared to numberApv_ and adcSamples_).

Cheers,
Philippe.

Hi,

adcRawdata_ is a std::vector<std::vector > initialised in the constructor to have this size =>

dcRawdata_.size() 32 adcRawdata_[0].size() 1024
the other sizes you requested are =>

numberApv_ 10 adcSamples_ 1024

It seems for me that not adcRawdata_ is the problem but
((*fadc_rawdata_)[apv_[i].fadc_module][apv_[i].fadc_data_offset+j]
this object of type std::vector<std::vector > is read from TTree. Interestingly it is not a problem if there is only one entry in the TTree (at least if it is initialised with zeros), but if there are two or more entries in the TTree the object seems not to be able to be read into a pointer of the same type. I compared pointer addresses and they also dont fit.

I have one class where I fill the TTree like this =>

TTree* rawDataReader = new TTree("Test","Test"); hat::UIntVector2D fadc_rawdata_; rawDataReader->Branch("fadcRawData", &fadc_rawdata_); rawDataReader->Fill();
UIntVector2D is a typdef std::vector<std::vector > in namespace hat which I included in the dictionary

and another class where I read in the data from the TTree =>

hat::UIntVector2D *fadc_rawdata_ = new UIntVector2D; rawDataReader->SetBranchAddress("fadcRawData", &fadc_rawdata_); rawDataReader->GetEntry(rawDataReader->GetEntries()-1);

The interesting thing is, if I access the TTree in the same class then there is no problem. It is only not working if I access the entry in the other class.

I don’t know what I do wrong. I even coded a small dummy program which does the same, but without any errors. I don’t see the error.

Thank you for any help. I am going crazy.

BR

Hi,

Did you generate a dictionary for the std::vector<std::vector > (see faq)?

Philippe.

Yes I did. My HatLinkDef.h looks like this=>

[code]//HatLinkDef.h
#ifdef MAKECINT

#pragma link C++ class std::vector<std::vector >+;
#pragma link C++ class std::vector+;
#pragma link C++ class std::vector+;
#pragma link C++ class std::vector<std::vector >+;
#pragma link C++ class std::vector<std::vector<std::vector > >+;
#pragma link C++ class std::vector<std::vector<std::vector<std::vector > > >+;
#pragma link C++ class std::vector<std::vector<std::vector > >+;
#pragma link C++ class std::vector<std::vector >+;
#pragma link C++ class hat::SaveEventHeader+;
#pragma link C++ class hat::Data+;
#pragma link C++ class std::vector<std::vectorhat::Data >+;
#pragma link C++ class hat::Module+;
#pragma link C++ class std::vectorhat::Module+;
#pragma link C++ class hat::Pos+;
#pragma link C++ class std::vectorhat::Pos+;
#pragma link C++ class hat::Event+;
#pragma link C++ class std::vector<std::vectorhat::Event >+;
#pragma link C++ class hat::Psums+;
#pragma link C++ class std::vectorhat::Psums+;
#pragma link C++ class hat::Prop+;
#pragma link C++ class std::vectorhat::Prop+;
#pragma link C++ class hat::ModProp+;
#pragma link C++ class std::vector<std::vectorhat::ModProp >+;
#pragma link C++ class hat::SenPos+;
#pragma link C++ class std::vector<std::vectorhat::SenPos >+;
#pragma link C++ class hat::Zones+;
#pragma link C++ class std::vector<std::vectorhat::Zones >+;
//#pragma link C++ class hat::T_CLUMP_PROP+;
#pragma link C++ class hat::HitAreas+;
#pragma link C++ class std::vector<std::vectorhat::HitAreas >+;
#pragma link C++ class hat::Sensor+;
#pragma link C++ class std::vectorhat::Sensor+;
#pragma link C++ class hat::ClumpProperty+;
#pragma link C++ class std::vector<std::vector<std::vector<std::vector > > >+;

#pragma link C++ class std::vector<std::vector >+;

#endif[/code]

I use

to generate it. /datastructure/ is the folder where my header files for the types reside. I put the generated HatDict.cpp in my make file and there are no errors. I am also able to fill these types into TTrees.

At least I can fill them without any error message. The only thing at the moment is that it seems that I cant get an entry which is not the only one in the Tree when getting it in any other class besides the one where I filled the TTree. Its really crazy.

BR

[quote=“rikmer”]Hi,

adcRawdata_ is a std::vector<std::vector > …
[/code]
BR[/quote]

If it’s a vector, you can not call memset on it (memset’s first parameter is void *). And your code sample is

memset (adcRawdata_, 0, sizeof(adcRawdata_));

And if you pass &adcRawdata_ - this is already a serious error - you will zero out vector’s object, not the memory it points to, but its internal data-members, like first_, last_ etc - which are pointers to allocated memory. So, it’s clear, that attempt to call adcRawdata_[index] fill break.

What’s the actual code?

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

Ohhh, that’s already too much code :slight_smile:

What are you doing here:


...
  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]));//how do you use 'j'?
    }
  }

...

Are you sure, number_fadcs and fadcdatalength are <= fadc_rawdata_ dimensions?

Hi,

i will investigate the sizes but thats actually not what seems to be the problem. At least the program runs over this point without any problems. The interesting thing is that when filled into a TTree the element is accessible when read out of the TTree in the same class (TRawDataReader) but not when I try to read it out in the next class (TRawDataConverter). It seems that there is a memory problem at some point. It kind a looks like as if some pointer is disallocated at some point.

BR

[quote=“rikmer”]Hi,

i will investigate the sizes but thats actually not what seems to be the problem. At least the program runs over this point without any problems. The interesting thing is that when filled into a TTree the element is accessible when read out of the TTree in the same class (TRawDataReader) but not when I try to read it out in the next class (TRawDataConverter). It seems that there is a memory problem at some point. It kind a looks like as if some pointer is disallocated at some point.

BR[/quote]

In fact even your read operation looks strange: instead of reading all values for i-th adc, you read them 1 by 1 and place them in element with index 0, overwriting the previous value. Is it what you really want?

Would this be more correct?

fread(&save_event_header_,sizeof(save_event_header_),1,DataFile_);
  for (int i=0; i<save_event_header_.number_fadcs; i++)
  {
    fread(&fadc_rawdata_[i][0],sizeof(fadc_rawdata_[0][0]),save_event_header_.fadcdatalength[i],DataFile_);
  }

or can I emulate this functionality with

BR

[quote=“rikmer”]Would this be more correct?

fread(&save_event_header_,sizeof(save_event_header_),1,DataFile_);
  for (int i=0; i<save_event_header_.number_fadcs; i++)
  {
    fread(&fadc_rawdata_[i][0],sizeof(fadc_rawdata_[0][0]),save_event_header_.fadcdatalength[i],DataFile_);
  }

or can I emulate this functionality with

BR[/quote]

Well, there was nothing bad with your binary_.read(…), you only have to fix arguments. Something like

binary_.read((char *)&fadc_rawdata[i][0], and here correct size to read.

I do not mean this is the real reason you have seg-fault, this just looks strange.
Did you check the dimensions of array and number of iterations in loops ?

True. The readin is not working the way I like it too. Thanks for the tip.

see tree->SetBranchAddress() modifies tree? for the seg fault problem.

BR