Hi,
I’m trying to read large data files with many individual measurements, storing each individual measurement in a TH1F. The TH1F are arranged in a TClonesArray.
I would like to store the data in memory because I have to first determine quantities from the combined dataset before I can analyse the individual measurements and I would like to avoid reading the data (<1 gb) in several times. I’m am not sure if my approach is at all suitable to achieve this goal.
Currently I use a class for reading which looks like this:
ReadData::ReadData(string path) {
rundata = new TClonesArray("TH1F", 100000);
FILE* pFILE = fopen(path.c_str(), "rb");
for (int i = 0; i < 100000; i++) {
TH1F* hCh = (TH1F*)rundata.ConstructedAt(i);
hCh->SetBins(1024, 0, 1);
float values = 0.;
int nitem;
for (int j = 0; j < 1024; j++) {
nitem = fread(&values, sizeof(float), 1, pFILE);
hCh->SetBinContent(j + 1, val);
}
}
fclose(pFILE);
}
ReadData::~ReadData() {
rundata->Clear();
}
TH1F* ReadData::Getmeasurement(int eventnr) {
TH1F* his;
his = (TH1F*)rundata->At(eventnr);
return his;
}
In reality it loops over many smaller files with a total of currently 100,000 individual measurements with 1024 values each. It works fine for up to a few 10,000s of measurements but crashes for more. I assume the memory usage gets too high (crashes when memory usage is ~1.7 gb). If I add errors to the histograms the maximum number of measurements is significantly reduced.
My questions:
-
Am I making some stupid mistakes here?
-
Is there a better way to do this?
Thanks!
ROOT Version: 6.20/02
Platform: windows 10