Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,380 changes: 4,380 additions & 0 deletions configs/standard_run_diagnostic_water_fill.json

Large diffs are not rendered by default.

4,380 changes: 4,380 additions & 0 deletions configs/standard_run_fiber_water_fill.json

Large diffs are not rendered by default.

4,380 changes: 4,380 additions & 0 deletions configs/standard_run_laserball_water_fill.json

Large diffs are not rendered by default.

4,384 changes: 4,384 additions & 0 deletions configs/standard_run_muons_water_fill.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/Decode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void *decode_thread(void *_data) {
Exception::dontPrint();

string fname = data->runtype->fname() + ".h5";
cout << "Saving data to " << fname << endl;

H5File file(fname, H5F_ACC_TRUNC);
data->runtype->write(file);
Expand Down
8 changes: 4 additions & 4 deletions src/Dispatch.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void *dispatch_thread(void *_data) {

vector<size_t> evtsReady(data->buffers->size());
data->runtype->begin();
bool print = false;
try {
dispatch_running = true;
while (dispatch_running) {
Expand All @@ -56,15 +57,14 @@ void *dispatch_thread(void *_data) {
if (found) break;
pthread_cond_wait(data->newdata,data->iomutex);
}

size_t total = data->dispatcher->Digest(*data->buffers);
string path = data->dispatcher->NextPath();
if (stop && total == 0) {
dispatch_running = false;
} else if (stop || data->dispatcher->Ready()) {
} else if (stop || data->dispatcher->Ready(print, path)) {
Exception::dontPrint();

string path = data->dispatcher->NextPath();
cout << "Streaming data to " << path << endl;
data->dispatcher->Dispatch(*data->buffers);
dispatch_running = data->runtype->keepgoing();
}
Expand Down
22 changes: 13 additions & 9 deletions src/Dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ Dispatcher::~Dispatcher(){
/* */
}

bool Dispatcher::Ready(){
bool Dispatcher::Ready(bool &print, string path){
double rate = 0.0;
bool rv = this->nEvents > 0;
for (size_t i = 0; i < this->evtsReady.size(); i++) {
rate += this->evtsReady[i];
//if (this->evtsReady[i] < nEvents) rv = false;
std::cout << "evtsReady[" << i << "] " << evtsReady[i] << std::endl;
}
if (rate < nEvents) rv = false;
rate /= evtsReady.size();

cout << "Cycle " << curCycle+1 << endl;


clock_gettime(CLOCK_MONOTONIC,&cur_time);
double time_int = (cur_time.tv_sec - last_time.tv_sec)+1e-9*(cur_time.tv_nsec - last_time.tv_nsec);
rate /= time_int;
cout << "Avg rate " << rate << " Hz" << endl;

std::cout << "nEvents " << this->nEvents << ", rv " << rv << std::endl;

if(curCycle > 0){
print = true;
}
if(print && path != previous_path){
cout << "Cycle " << curCycle << ", Trig. Rate: " << rate << ", nEV: " << this->nEvents << endl;
print = false;
}

previous_path = path;

return rv;
}
3 changes: 2 additions & 1 deletion src/Dispatcher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class Dispatcher{
virtual string NextPath() = 0;
virtual size_t Digest(vector<Buffer*>& buffers) = 0;
virtual void Dispatch(vector<Buffer*>& buffers) = 0;
virtual bool Ready();
virtual bool Ready(bool &print, string path);
protected:
size_t curCycle;
size_t nEvents;
string previous_path;
vector<size_t> evtsReady;
struct timespec cur_time, last_time;
};
Expand Down
2 changes: 1 addition & 1 deletion src/LegacyHDF5Dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ size_t LegacyHDF5Dispatcher::Digest(vector<Buffer*>& buffers){

void LegacyHDF5Dispatcher::Dispatch(vector<Buffer*>& buffers){
string fname = this->NextPath();
cout << "Saving data to " << fname << endl;
// cout << "Saving data to " << fname << endl;

H5File file(fname, H5F_ACC_TRUNC);
this->Initialize(file);
Expand Down
19 changes: 14 additions & 5 deletions src/Readout.hh
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,23 @@ void *readout(void *_data){
if (cur_time.tv_sec-last_temp_time.tv_sec > temptime) {
pthread_mutex_lock(&iomutex);
last_temp_time = cur_time;
cout << "Temperature check..." << endl;
cout << "Temperature check...";
bool overtemp = false;
for (size_t i = 0; i < digitizers.size() && !stop; i++) {
int warning_count = 0;
for (size_t i = 0; i < digitizers.size() && !stop; i++) {
overtemp |= digitizers[i]->checkTemps(temps,84);
cout << settings[i]->getIndex() << " temp: [ " << temps[0];
for (size_t t = 1; t < temps.size(); t++) cout << ", " << temps[t];
cout << " ]" << endl;
for (size_t t = 1; t < temps.size(); t++){
if(temps[t] > 65){
warning_count += 1;
}
}
}
if(warning_count > 0){
cout << "WARNING: " << warning_count << " temps above 65 deg." << endl;
}
else{
cout << "All below 65 deg." << endl;
}
if (overtemp) {
cout << "Overtemp! Aborting readout." << endl;
stop = true;
Expand Down
126 changes: 23 additions & 103 deletions src/V1730.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,33 +384,22 @@ void V1730Decoder::decode(Buffer &buf) {
vector<size_t> lastgrabbed(grabbed);

decode_size = buf.fill();
cout << settings.getIndex() << " decoding " << decode_size << " bytes." << endl;
//cout << settings.getIndex() << " decoding " << decode_size << " bytes." << endl;
uint32_t *next = (uint32_t*)buf.rptr(), *start = (uint32_t*)buf.rptr();
while ((size_t)((next = decode_board_agg(next)) - start + 1)*4 < decode_size);
buf.dec(decode_size);
decode_counter++;

struct timespec cur_time;
clock_gettime(CLOCK_MONOTONIC,&cur_time);
double time_int = (cur_time.tv_sec - last_decode_time.tv_sec)+1e-9*(cur_time.tv_nsec - last_decode_time.tv_nsec);
last_decode_time = cur_time;

// for (size_t i = 0; i < idx2chan.size(); i++) {
// size_t nev = grabbed[i] - lastgrabbed[i];
// double trate = nev / time_int;
// cout << "\tch" << idx2chan[i]
// << "\tev: " << nev
// << " / "
// << trate << " Hz "
// << "/ "
// << grabbed[i] << " total"
// << endl;
// }
double nmb = decode_size / pow(1024, 2);
double drate = nmb / time_int;
cout << "\t\t data rate: "
<< drate << " MB/s"
<< endl;
//double time_int = (cur_time.tv_sec - last_decode_time.tv_sec)+1e-9*(cur_time.tv_nsec - last_decode_time.tv_nsec);
//last_decode_time = cur_time;

// double nmb = decode_size / pow(1024, 2);
// double drate = nmb / time_int;
// cout << "\t\t data rate: "
// << drate << " MB/s"
// << endl;
}

size_t V1730Decoder::eventsReady() {
Expand All @@ -426,8 +415,6 @@ using namespace H5;
//MBS: Revert to Ed's writeOut function due to issues with DigitizerData struct
void V1730Decoder::writeOut(H5File &file, size_t nEvents) {

// cout << "\t/" << settings.getIndex() << endl;

Group cardgroup = file.createGroup("/"+settings.getIndex());

DataSpace scalar(0,NULL);
Expand All @@ -450,21 +437,22 @@ void V1730Decoder::writeOut(H5File &file, size_t nEvents) {
hsize_t dims[1];
dims[0] = nEvents;
DataSpace space(1, dims);

DataSet counters_ds = cardgroup.createDataSet("counters", PredType::NATIVE_UINT32, space);
counters_ds.write(counters.data(), PredType::NATIVE_UINT32);
DataSet timetags_ds = cardgroup.createDataSet("timetags", PredType::NATIVE_UINT32, space);
timetags_ds.write(timetags.data(), PredType::NATIVE_UINT32);
DataSet exttimetags_ds = cardgroup.createDataSet("exttimetags", PredType::NATIVE_UINT16, space);
exttimetags_ds.write(exttimetags.data(), PredType::NATIVE_UINT16);

std::cout << "Event count: " << counters.size() << std::endl;

for (size_t i = 0; i < nsamples.size(); i++) {

string chname = "ch" + to_string(idx2chan[i]);
Group group = cardgroup.createGroup(chname);
string groupname = "/"+settings.getIndex()+"/"+chname;

// cout << "\t" << groupname << endl;

Attribute offset = group.createAttribute("offset",PredType::NATIVE_UINT32,scalar);
ival = settings.getDCOffset(idx2chan[i]);
offset.write(PredType::NATIVE_UINT32,&ival);
Expand All @@ -484,12 +472,10 @@ void V1730Decoder::writeOut(H5File &file, size_t nEvents) {
DataSpace samplespace(2, dimensions);
DataSpace metaspace(1, dimensions);

// cout << "\t" << groupname << "/samples" << endl;
DataSet samples_ds = file.createDataSet(groupname+"/samples", PredType::NATIVE_UINT16, samplespace);
samples_ds.write(grabs[i], PredType::NATIVE_UINT16);
memmove(grabs[i],grabs[i]+nEvents*nsamples[i],nsamples[i]*sizeof(uint16_t)*(grabbed[i]-nEvents));

// cout << "\t" << groupname << "/patterns" << endl;
DataSet patterns_ds = file.createDataSet(groupname+"/patterns", PredType::NATIVE_UINT16, metaspace);
patterns_ds.write(patterns[i], PredType::NATIVE_UINT16);
memmove(patterns[i],patterns[i]+nEvents,sizeof(uint16_t)*(grabbed[i]-nEvents));
Expand All @@ -503,74 +489,14 @@ void V1730Decoder::writeOut(H5File &file, size_t nEvents) {
grabbed[i] -= nEvents;
}

timetags.clear();
exttimetags.clear();
counters.clear();

dispatch_index -= nEvents;
if (dispatch_index < 0) dispatch_index = 0;
}

//// ATM: move this to the H5 dispatcher, calls decoder's pack.
//void V1730Decoder::writeOut(H5File &file, size_t nEvents) {
// DigitizerData data;
// pack(&data, nEvents);
//
// Group cardgroup = file.createGroup("/"+settings.getIndex());
//
// DataSpace scalar(0,NULL);
//
// Attribute bits = cardgroup.createAttribute("bits",PredType::NATIVE_UINT32,scalar);
// bits.write(PredType::NATIVE_INT32, &data.bits);
//
// Attribute ns_sample = cardgroup.createAttribute("ns_sample",PredType::NATIVE_DOUBLE,scalar);
// ns_sample.write(PredType::NATIVE_DOUBLE, &data.ns_sample);
//
// Attribute samples = cardgroup.createAttribute("samples",PredType::NATIVE_UINT32,scalar);
// samples.write(PredType::NATIVE_UINT32, &data.samples);
//
// hsize_t dims[1];
// dims[0] = nEvents;
// DataSpace space(1, dims);
// DataSet counters_ds = cardgroup.createDataSet("counters", PredType::NATIVE_UINT32, space);
// counters_ds.write(&data.counters, PredType::NATIVE_UINT32);
// DataSet timetags_ds = cardgroup.createDataSet("timetags", PredType::NATIVE_UINT32, space);
// timetags_ds.write(&data.timetags, PredType::NATIVE_UINT32);
// DataSet exttimetags_ds = cardgroup.createDataSet("exttimetags", PredType::NATIVE_UINT16, space);
// exttimetags_ds.write(&data.exttimetags, PredType::NATIVE_UINT16);
//
// for (size_t i = 0; i < nsamples.size(); i++) {
// DigitizerData::ChannelData& ch = data.channels[i];
//
// string chname = "ch" + to_string(ch.chID);
// Group group = cardgroup.createGroup(chname);
// string groupname = "/"+settings.getIndex()+"/"+chname;
//
// Attribute offset = group.createAttribute("offset",PredType::NATIVE_UINT32,scalar);
// offset.write(PredType::NATIVE_UINT32, &ch.offset);
//
// Attribute threshold = group.createAttribute("threshold",PredType::NATIVE_UINT32,scalar);
// threshold.write(PredType::NATIVE_UINT32, &ch.threshold);
//
// Attribute dynamic_range = group.createAttribute("dynamic_range",PredType::NATIVE_DOUBLE,scalar);
// dynamic_range.write(PredType::NATIVE_DOUBLE, &ch.dynamic_range);
//
// hsize_t dimensions[2];
// dimensions[0] = data.nEvents;
// dimensions[1] = nsamples[i];
//
// DataSpace samplespace(2, dimensions);
// DataSpace metaspace(1, dimensions);
//
// DataSet samples_ds = file.createDataSet(groupname+"/samples", PredType::NATIVE_UINT16, samplespace);
// samples_ds.write(&ch.samples[i], PredType::NATIVE_UINT16);
//
// DataSet patterns_ds = file.createDataSet(groupname+"/patterns", PredType::NATIVE_UINT16, metaspace);
// patterns_ds.write(&ch.patterns[i], PredType::NATIVE_UINT16);
// }
//
// //dispatch_index -= nEvents;
//
// //if (dispatch_index < 0)
// // dispatch_index = 0;
//}

uint32_t* V1730Decoder::decode_chan_agg(uint32_t *chanagg, uint32_t chn, uint16_t pattern) {

// TODO a quality check for every 32-bit sample word would be:
Expand Down Expand Up @@ -622,17 +548,17 @@ uint32_t* V1730Decoder::decode_board_agg(uint32_t *boardagg) {
if (boardagg[0] == 0xFFFFFFFF) {
boardagg++; //sometimes padded
}
if ((boardagg[0] & 0xF0000000) != 0xA0000000)
if ((boardagg[0] & 0xF0000000) != 0xA0000000){
throw runtime_error("Board aggregate missing tag");

}
boardagg_counter++;

uint32_t size = boardagg[0] & 0x0FFFFFFF;

//const uint32_t board = (boardagg[1] >> 28) & 0xF;
const bool fail = boardagg[1] & (1 << 26);
if (fail){
throw runtime_error("board fail flag set. check with an expert.");
throw runtime_error("board fail flag set " + to_string(boardagg_counter));
}
//const uint16_t pattern = (boardagg[1] >> 8) & 0x7FFF;
const uint16_t pattern = settings.getETTTEnabled() ? 0 : ((boardagg[1] >> 8) & 0xFFFF); // this has been changed; 0 if ETTT mode, else LVDS I/O pattern
Expand All @@ -641,16 +567,10 @@ uint32_t* V1730Decoder::decode_board_agg(uint32_t *boardagg) {

const uint32_t counter = static_cast<uint32_t>(boardagg[2] & 0x00FFFFFF);
const uint32_t timetag = boardagg[3];
std::cout << "Time Tag: " << timetag << std::endl;
const uint16_t exttimetag = settings.getETTTEnabled() ? ((boardagg[1] >> 8) & 0xFFFF) : 0 ; // ETTT bits if ETTT mode, else 0
std::cout << "Ext Time Tag: " << exttimetag << std::endl;
counters.push_back(counter);
timetags.push_back(timetag);
exttimetags.push_back(exttimetag);
// cout << "\t(LVDS & 0xFF): " << (pattern & 0xFF) << endl;

//const uint32_t count = boardagg[2] & 0x7FFFFF;
//const uint32_t timetag = boardagg[3];

uint32_t *chans = boardagg+4;

Expand All @@ -666,7 +586,7 @@ uint32_t* V1730Decoder::decode_board_agg(uint32_t *boardagg) {
return boardagg+size;
}


// Not used? TBK
void V1730Decoder::pack(DigitizerData* ddd, size_t nEvents) {
DigitizerData& data = *ddd;
data.nEvents = nEvents;
Expand All @@ -679,9 +599,9 @@ void V1730Decoder::pack(DigitizerData* ddd, size_t nEvents) {
memcpy(&data.timetags, timetags.data(), nEvents*sizeof(uint32_t));
memcpy(&data.exttimetags, exttimetags.data(), nEvents*sizeof(uint16_t));

exttimetags.erase(exttimetags.begin(), exttimetags.begin() + nEvents);
timetags.erase(timetags.begin(), timetags.begin() + nEvents);
counters.erase(counters.begin(), counters.begin() + nEvents);
exttimetags.clear();
timetags.clear();
counters.clear();

for (size_t i = 0; i < nsamples.size(); i++) {
DigitizerData::ChannelData& ch = data.channels[i];
Expand Down