Skip to content

Commit

Permalink
A fresh start
Browse files Browse the repository at this point in the history
  • Loading branch information
tblum committed May 18, 2017
1 parent c7fbb0b commit b99ffa6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
55 changes: 32 additions & 23 deletions HDF5File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,33 @@


HDF5File::HDF5File (std::string fileName)
: pedestal(NULL)
, events(0)
: events(0)
{
file = new H5::H5File(fileName, H5F_ACC_TRUNC);
imagegroup = file->createGroup("/images");

imageGroup = file->createGroup("/images");
}

HDF5File::~HDF5File ()
{
file->close();
}
HDF5File::~HDF5File ()
{
try
{
H5::Attribute nevents = imageGroup.createAttribute("nevents",H5::PredType::NATIVE_UINT, H5::DataSpace(H5S_SCALAR));
nevents.write(H5::PredType::NATIVE_UINT,&events);
nevents.close();
}
catch(H5::Exception e)
{
std::cerr << e.getDetailMsg() << std::endl;
throw e;
}
file->close();
}

void HDF5File::addPedestal (Pedestal *pedestal_, Histogram *histogram)
void HDF5File::addAggregate (Pedestal *pedestal, Histogram *histogram, std::string name)
{
pedestal = pedestal_;
try
{
H5::Group pedgroup(file->createGroup( "/pedestal"));
H5::Group pedgroup(file->createGroup(name));
if (histogram)
{
const hsize_t dims[2] = {DAQ_CHANNELS*APV_CHANNELS, APV_MAX_VALUE};
Expand All @@ -40,14 +48,17 @@ void HDF5File::addPedestal (Pedestal *pedestal_, Histogram *histogram)
H5::DataSet dataset = pedgroup.createDataSet("histogram", datatype, dataspace );
dataset.write(histogram->data, H5::PredType::NATIVE_UINT);
}
const hsize_t dims[2] = {2, IMG_WIDTH};
H5::DataSpace dataspace( 2, dims);
H5::IntType datatype( H5::PredType::NATIVE_UINT16 );
datatype.setOrder( H5T_ORDER_LE );
H5::DataSet dataset_avg = pedgroup.createDataSet("average", datatype, dataspace );
dataset_avg.write(pedestal->avg, H5::PredType::NATIVE_UINT16);
H5::DataSet dataset_cut = pedgroup.createDataSet("cut-off", datatype, dataspace );
dataset_cut.write(pedestal->cut, H5::PredType::NATIVE_UINT16);
if (pedestal)
{
const hsize_t dims[2] = {2, IMG_WIDTH};
H5::DataSpace dataspace(2, dims);
H5::IntType datatype(H5::PredType::NATIVE_UINT16);
datatype.setOrder(H5T_ORDER_LE);
H5::DataSet dataset_avg = pedgroup.createDataSet("average", datatype, dataspace);
dataset_avg.write(pedestal->avg, H5::PredType::NATIVE_UINT16);
H5::DataSet dataset_cut = pedgroup.createDataSet("cut-off", datatype, dataspace);
dataset_cut.write(pedestal->cut, H5::PredType::NATIVE_UINT16);
}

}
catch(H5::Exception e)
Expand All @@ -61,18 +72,16 @@ void HDF5File::addPedestal (Pedestal *pedestal_, Histogram *histogram)
void HDF5File::addEvent(const FECEvent& event)
{
EventImage image = event.generateImage();
//if (pedestal)
// image.applyPedestal(pedestal);
std::stringstream evs;
evs << std::setw(7) << std::setfill('0') << events++;
evs << std::setw(6) << std::setfill('0') << events++;
try
{
const hsize_t dims[3] = {2, IMG_HEIGHT, IMG_WIDTH};
H5::DataSpace dataspace( 3, dims);
H5::IntType datatype( H5::PredType::NATIVE_UINT16 );
datatype.setOrder( H5T_ORDER_LE );

H5::DataSet dataset = imagegroup.createDataSet(evs.str(), datatype, dataspace );
H5::DataSet dataset = imageGroup.createDataSet(evs.str(), datatype, dataspace );
dataset.write(image.images(), H5::PredType::NATIVE_UINT16 );
}
catch(H5::Exception e)
Expand Down
5 changes: 2 additions & 3 deletions HDF5File.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class HDF5File
{
private:
H5::H5File* file;
Pedestal* pedestal;
uint events;
H5::Group imagegroup;
H5::Group imageGroup;
public:
HDF5File(std::string fileName);
void addPedestal(Pedestal* pedestal, Histogram *histogram=NULL);
void addAggregate(Pedestal* pedestal, Histogram *histogram, std::string name);
void addEvent(const FECEvent& event);
void addEvents(SRSRawFile& file, int n);
~HDF5File ();
Expand Down
2 changes: 1 addition & 1 deletion Histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Histogram
{return findCutoff(channel(strip_id), o, n, v);}
double average(size_t strip_id) const;
friend void FECEvent::addToHistogram (Histogram *histogram) const;
friend void HDF5File::addPedestal(Pedestal* pedestal, Histogram *histogram);
friend void HDF5File::addAggregate(Pedestal* pedestal, Histogram *histogram, std::string name);
};


Expand Down
2 changes: 1 addition & 1 deletion Pedestal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Pedestal
public:
Pedestal(const Histogram& histogram);
uint16_t cutOff(size_t img, size_t column) const {return cut[img][column];}
friend void HDF5File::addPedestal(Pedestal* pedestal, Histogram* histogram);
friend void HDF5File::addAggregate(Pedestal* pedestal, Histogram* histogram, std::string name);
};


Expand Down
13 changes: 12 additions & 1 deletion vmmef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main(int argc, char** argv)
TCLAP::ValueArg<int> numEvents_("n","nevent","Number of events to read from file",false,-1,"int",cmd);
TCLAP::ValueArg<int> numPedEvents_("N","nped","Number of events to read from pedestal file",false,-1,"int",cmd);
TCLAP::ValueArg<std::string> pedFile_("p","pedestal","Name of file containing pedestal data", false,"","filename",cmd);
TCLAP::ValueArg<std::string> aggFile_("a","aggregate","Aggregate the data in file in the same manner as the pedestal", false,"","filename",cmd);
TCLAP::ValueArg<std::string> hdf5File_("o","hdf5","Write output to HDF5 file <filename>", false,"","filename",cmd);
TCLAP::ValueArg<std::string> x_("x","Xmap","Comma separated list of DAQ indexes mapping to the X projection", false,"1,0","int,int",cmd);
TCLAP::ValueArg<std::string> y_("y","Ymap","Comma separated list of DAQ indexes mapping to the Y projection", false,"3,2","int,int",cmd);
Expand All @@ -45,6 +46,7 @@ int main(int argc, char** argv)
cmd.parse(argc, argv);
std::string dataFileName = dataFile_.getValue();
std::string pedestalFileName = pedFile_.getValue();
std::string aggregateFileName = aggFile_.getValue();
std::string hdf5FileName = hdf5File_.getValue();
int numEvents = numEvents_.getValue();
int numPedEvents = numPedEvents_.getValue();
Expand Down Expand Up @@ -74,7 +76,16 @@ int main(int argc, char** argv)
histogram = new Histogram(pedFile, numPedEvents);
pedestal = new Pedestal(*histogram);
if (hdf5File)
hdf5File->addPedestal(pedestal,histogram);
hdf5File->addAggregate(pedestal,histogram, "/pedestal");
}

if (!aggregateFileName.empty())
{
SRSRawFile aggFile(aggregateFileName,daqMap);
histogram = new Histogram(aggFile, numPedEvents);
pedestal = new Pedestal(*histogram);
if (hdf5File)
hdf5File->addAggregate(pedestal,histogram,"/aggregate");
}

if (!dataFileName.empty())
Expand Down

0 comments on commit b99ffa6

Please sign in to comment.