Preparing for changes with new CoMPASS version. Binary data format has changed, with headers now included to indicate exsitance of optional data members (i.e. short energy, cal energy, waves). Tested with small data from CoMPASS 2.01.0

This commit is contained in:
Gordon McCann 2022-05-19 14:32:58 -04:00
parent 1dc9a47a11
commit 0850f9a5e5
7 changed files with 132 additions and 88 deletions

View File

@ -14,26 +14,22 @@
namespace EventBuilder { namespace EventBuilder {
CompassFile::CompassFile() : CompassFile::CompassFile() :
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), eofFlag(false) m_filename(""), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_smap(nullptr), m_hitUsedFlag(true), m_hitsize(0), m_buffersize(0),
m_file(std::make_shared<std::ifstream>()), m_eofFlag(false)
{ {
m_buffersize = bufsize*hitsize;
hitBuffer.resize(m_buffersize);
} }
CompassFile::CompassFile(const std::string& filename) : CompassFile::CompassFile(const std::string& filename) :
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_file(std::make_shared<std::ifstream>()), eofFlag(false) m_filename(""), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_smap(nullptr), m_hitUsedFlag(true), m_hitsize(0), m_buffersize(0),
m_file(std::make_shared<std::ifstream>()), m_eofFlag(false)
{ {
m_buffersize = bufsize*hitsize;
hitBuffer.resize(m_buffersize);
Open(filename); Open(filename);
} }
CompassFile::CompassFile(const std::string& filename, int bsize) : CompassFile::CompassFile(const std::string& filename, int bsize) :
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true), m_filename(""), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_smap(nullptr), m_hitUsedFlag(true), m_bufsize(bsize), m_hitsize(0),
bufsize(bsize), m_file(std::make_shared<std::ifstream>()), eofFlag(false) m_buffersize(0), m_file(std::make_shared<std::ifstream>()), m_eofFlag(false)
{ {
m_buffersize = bufsize*hitsize;
hitBuffer.resize(m_buffersize);
Open(filename); Open(filename);
} }
@ -44,21 +40,24 @@ namespace EventBuilder {
void CompassFile::Open(const std::string& filename) void CompassFile::Open(const std::string& filename)
{ {
eofFlag = false; m_eofFlag = false;
hitUsedFlag = true; m_hitUsedFlag = true;
m_filename = filename; m_filename = filename;
m_file->open(m_filename, std::ios::binary | std::ios::in); m_file->open(m_filename, std::ios::binary | std::ios::in);
m_file->seekg(0, std::ios_base::end); m_file->seekg(0, std::ios_base::end);
m_size = m_file->tellg(); m_size = m_file->tellg();
m_nHits = m_size/24;
if(m_size == 0) if(m_size == 0)
{ {
eofFlag = true; m_eofFlag = true;
} }
else else
{ {
m_file->seekg(0, std::ios_base::beg); m_file->seekg(0, std::ios_base::beg);
ReadHeader();
m_nHits = m_size/m_hitsize;
m_buffersize = m_hitsize*m_bufsize;
m_hitBuffer.resize(m_buffersize);
} }
} }
@ -70,27 +69,39 @@ namespace EventBuilder {
} }
} }
int CompassFile::GetHitSize() void CompassFile::ReadHeader()
{ {
if(!IsOpen()) if(!IsOpen())
{ {
EVB_WARN("Unable to get hit size from file {0}, sending invalid value.", m_filename); EVB_WARN("Unable to read header from file. State not validated", m_filename);
return 0; return;
} }
char* header = new char[2];
m_file->read(header, 2);
m_header = *((uint16_t*)header);
m_hitsize = 16; //default hitsize of 16 bytes
if(IsEnergy())
m_hitsize += 2;
if(IsEnergyCalibrated())
m_hitsize += 8;
if(IsEnergyShort())
m_hitsize += 2;
if(IsWaves())
{
EVB_ERROR("Waveforms are not supported by the SPS_SABRE_EventBuilder. The wave data will be skipped.");
m_hitsize += 5;
char* firstHit = new char[24]; //A compass hit by default has 24 bytes (at least in our setup) char* firstHit = new char[24]; //A compass hit by default has 24 bytes (at least in our setup)
m_file->read(firstHit, 24); m_file->read(firstHit, 24);
firstHit += m_hitsize - 4;
firstHit += 16; uint32_t nsamples = *((uint32_t*) firstHit);
int nsamples = *((uint32_t*) firstHit); m_hitsize += nsamples * 2; //Each sample is a 2 byte data value
m_file->seekg(0, std::ios_base::beg); m_file->seekg(0, std::ios_base::beg);
m_file->read(header, 2);
delete[] firstHit; delete[] firstHit;
}
return 24 + nsamples*16; delete[] header;
} }
/* /*
@ -105,7 +116,7 @@ namespace EventBuilder {
{ {
if(!IsOpen()) return true; if(!IsOpen()) return true;
if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF()) if((m_bufferIter == nullptr || m_bufferIter == m_bufferEnd) && !IsEOF())
{ {
GetNextBuffer(); GetNextBuffer();
} }
@ -113,10 +124,10 @@ namespace EventBuilder {
if(!IsEOF()) if(!IsEOF())
{ {
ParseNextHit(); ParseNextHit();
hitUsedFlag = false; m_hitUsedFlag = false;
} }
return eofFlag; return m_eofFlag;
} }
/* /*
@ -131,34 +142,51 @@ namespace EventBuilder {
if(m_file->eof()) if(m_file->eof())
{ {
eofFlag = true; m_eofFlag = true;
return; return;
} }
m_file->read(hitBuffer.data(), hitBuffer.size()); m_file->read(m_hitBuffer.data(), m_hitBuffer.size());
bufferIter = hitBuffer.data(); m_bufferIter = m_hitBuffer.data();
bufferEnd = bufferIter + m_file->gcount(); //one past the last datum m_bufferEnd = m_bufferIter + m_file->gcount(); //one past the last datum
} }
void CompassFile::ParseNextHit() void CompassFile::ParseNextHit()
{ {
m_currentHit.board = *((uint16_t*)bufferIter); m_currentHit.board = *((uint16_t*)m_bufferIter);
bufferIter += 2; m_bufferIter += 2;
m_currentHit.channel = *((uint16_t*)bufferIter); m_currentHit.channel = *((uint16_t*)m_bufferIter);
bufferIter += 2; m_bufferIter += 2;
m_currentHit.timestamp = *((uint64_t*)bufferIter); m_currentHit.timestamp = *((uint64_t*)m_bufferIter);
bufferIter += 8; m_bufferIter += 8;
m_currentHit.lgate = *((uint16_t*)bufferIter); if(IsEnergy())
bufferIter += 2; {
m_currentHit.sgate = *((uint16_t*)bufferIter); m_currentHit.energy = *((uint16_t*)m_bufferIter);
bufferIter += 2; m_bufferIter += 2;
m_currentHit.flags = *((uint32_t*)bufferIter); }
bufferIter += 4; if(IsEnergyCalibrated())
m_currentHit.Ns = *((uint32_t*)bufferIter); {
bufferIter += 4; m_currentHit.energyCalibrated = *((uint64_t*)m_bufferIter);
m_bufferIter += 8;
}
if(IsEnergyShort())
{
m_currentHit.energyShort = *((uint16_t*)m_bufferIter);
m_bufferIter += 2;
}
m_currentHit.flags = *((uint32_t*)m_bufferIter);
m_bufferIter += 4;
if(IsWaves())
{
m_currentHit.waveCode = *((uint8_t*)m_bufferIter);
m_bufferIter += 1;
m_currentHit.Ns = *((uint32_t*)m_bufferIter);
m_bufferIter += 4;
m_bufferIter += 2*m_currentHit.Ns;
}
if(m_smap != nullptr) if(m_smap != nullptr)
{ //memory safety { //memory safety

View File

@ -32,41 +32,55 @@ namespace EventBuilder {
inline bool IsOpen() const { return m_file->is_open(); }; inline bool IsOpen() const { return m_file->is_open(); };
inline CompassHit GetCurrentHit() const { return m_currentHit; } inline CompassHit GetCurrentHit() const { return m_currentHit; }
inline std::string GetName() const { return m_filename; } inline std::string GetName() const { return m_filename; }
inline bool CheckHitHasBeenUsed() const { return hitUsedFlag; } //query to find out if we've used the current hit inline bool CheckHitHasBeenUsed() const { return m_hitUsedFlag; } //query to find out if we've used the current hit
inline void SetHitHasBeenUsed() { hitUsedFlag = true; } //flip the flag to indicate the current hit has been used inline void SetHitHasBeenUsed() { m_hitUsedFlag = true; } //flip the flag to indicate the current hit has been used
inline bool IsEOF() const { return eofFlag; } //see if we've read all available data inline bool IsEOF() const { return m_eofFlag; } //see if we've read all available data
inline bool* GetUsedFlagPtr() { return &hitUsedFlag; } inline bool* GetUsedFlagPtr() { return &m_hitUsedFlag; }
inline void AttachShiftMap(ShiftMap* map) { m_smap = map; } inline void AttachShiftMap(ShiftMap* map) { m_smap = map; }
inline unsigned int GetSize() const { return m_size; } inline unsigned int GetSize() const { return m_size; }
inline unsigned int GetNumberOfHits() const { return m_nHits; } inline unsigned int GetNumberOfHits() const { return m_nHits; }
private: private:
int GetHitSize(); void ReadHeader();
void ParseNextHit(); void ParseNextHit();
void GetNextBuffer(); void GetNextBuffer();
inline bool IsEnergy() { return (m_header & CoMPASSHeaders::Energy) != 0; }
inline bool IsEnergyCalibrated() { return (m_header & CoMPASSHeaders::EnergyCalibrated) != 0; }
inline bool IsEnergyShort() { return (m_header & CoMPASSHeaders::EnergyShort) != 0; }
inline bool IsWaves() { return (m_header & CoMPASSHeaders::Waves) != 0; }
using Buffer = std::vector<char>; using Buffer = std::vector<char>;
using FilePointer = std::shared_ptr<std::ifstream>; //to make this class copy/movable using FilePointer = std::shared_ptr<std::ifstream>; //to make this class copy/movable
std::string m_filename; std::string m_filename;
Buffer hitBuffer; Buffer m_hitBuffer;
char* bufferIter; char* m_bufferIter;
char* bufferEnd; char* m_bufferEnd;
ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete
bool hitUsedFlag; bool m_hitUsedFlag;
int bufsize = 200000; //size of the buffer in hits int m_bufsize = 200000; //size of the buffer in hits
int hitsize = 24; //size of a CompassHit in bytes (without alignment padding) int m_hitsize; //size of a CompassHit in bytes (without alignment padding)
uint16_t m_header;
int m_buffersize; int m_buffersize;
CompassHit m_currentHit; CompassHit m_currentHit;
FilePointer m_file; FilePointer m_file;
bool eofFlag; bool m_eofFlag;
unsigned int m_size; //size of the file in bytes unsigned int m_size; //size of the file in bytes
unsigned int m_nHits; //number of hits in the file (m_size/24) unsigned int m_nHits; //number of hits in the file (m_size/24)
enum CoMPASSHeaders
{
Energy = 0x0001,
EnergyCalibrated = 0x0002,
EnergyShort = 0x0004,
Waves = 0x0008,
};
}; };
} }

View File

@ -8,9 +8,11 @@ namespace EventBuilder {
uint16_t board = 400; uint16_t board = 400;
uint16_t channel = 400; uint16_t channel = 400;
uint64_t timestamp = 0; uint64_t timestamp = 0;
uint16_t lgate = 0; uint16_t energy = 0;
uint16_t sgate = 0; uint64_t energyCalibrated = 0;
uint16_t energyShort = 0;
uint32_t flags = 0; uint32_t flags = 0;
uint8_t waveCode = 0;
uint32_t Ns = 0; uint32_t Ns = 0;
}; };

View File

@ -49,7 +49,7 @@ namespace EventBuilder {
while(input>>filename) while(input>>filename)
{ {
input>>varname; input>>varname;
filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".bin"; filename = m_directory+filename+"_run_"+std::to_string(m_runNum)+".BIN";
m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init); m_scaler_map[filename] = TParameter<Long64_t>(varname.c_str(), init);
} }
input.close(); input.close();
@ -58,7 +58,7 @@ namespace EventBuilder {
bool CompassRun::GetBinaryFiles() bool CompassRun::GetBinaryFiles()
{ {
std::string prefix = ""; std::string prefix = "";
std::string suffix = ".bin"; //binaries std::string suffix = ".BIN"; //binaries
RunCollector grabber(m_directory, prefix, suffix); RunCollector grabber(m_directory, prefix, suffix);
grabber.GrabAllFiles(); grabber.GrabAllFiles();
@ -168,8 +168,8 @@ namespace EventBuilder {
outtree->Branch("Board", &hit.board); outtree->Branch("Board", &hit.board);
outtree->Branch("Channel", &hit.channel); outtree->Branch("Channel", &hit.channel);
outtree->Branch("Energy", &hit.lgate); outtree->Branch("Energy", &hit.energy);
outtree->Branch("EnergyShort", &hit.sgate); outtree->Branch("EnergyShort", &hit.energyShort);
outtree->Branch("Timestamp", &hit.timestamp); outtree->Branch("Timestamp", &hit.timestamp);
outtree->Branch("Flags", &hit.flags); outtree->Branch("Flags", &hit.flags);

View File

@ -178,7 +178,7 @@ namespace EventBuilder {
EVB_INFO("Converting file {0}...", binfile); EVB_INFO("Converting file {0}...", binfile);
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root"; rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin"; wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str()); sys_return = system(unpack_command.c_str());
converter.Convert2RawRoot(rawfile); converter.Convert2RawRoot(rawfile);
@ -238,7 +238,7 @@ namespace EventBuilder {
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root"; sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin"; wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str()); sys_return = system(unpack_command.c_str());
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow); converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
@ -281,7 +281,7 @@ namespace EventBuilder {
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin"; wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str()); sys_return = system(unpack_command.c_str());
converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh); converter.Convert2FastSortedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh);
@ -324,7 +324,7 @@ namespace EventBuilder {
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin"; wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str()); sys_return = system(unpack_command.c_str());
converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta); converter.Convert2SlowAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);
@ -368,7 +368,7 @@ namespace EventBuilder {
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root"; sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir; unpack_command = "tar -xzf "+binfile+" --directory "+unpack_dir;
wipe_command = "rm -r "+unpack_dir+"*.bin"; wipe_command = "rm -r "+unpack_dir+"*.BIN";
sys_return = system(unpack_command.c_str()); sys_return = system(unpack_command.c_str());
converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta); converter.Convert2FastAnalyzedRoot(sortfile, m_mapfile, m_SlowWindow, m_FastWindowSABRE, m_FastWindowIonCh, m_ZT, m_AT, m_ZP, m_AP, m_ZE, m_AE, m_BKE, m_B, m_Theta);

View File

@ -140,9 +140,9 @@ namespace EventBuilder {
if(ev.sabreRingE[i] != -1) //Again, at this point front&back are required if(ev.sabreRingE[i] != -1) //Again, at this point front&back are required
{ {
MyFill(table,"sabreRingE_NoCuts",2000,0,20,ev.sabreRingE[i]); MyFill(table,"sabreRingE_NoCuts",2000,0,20,ev.sabreRingE[i]);
MyFill(table,"sabreRingChannel_sabreRingE_NoCuts",144,0,144,ev.sabreRingChannel[i],200,0,20,ev.sabreRingE[i]); MyFill(table,"sabreRingChannel_sabreRingE_NoCuts",144,0,144,ev.sabreRingChannel[i],4096,0,16384,ev.sabreRingE[i]);
MyFill(table,"sabreWedgeE_NoCuts",2000,0,20,ev.sabreWedgeE[i]); MyFill(table,"sabreWedgeE_NoCuts",2000,0,20,ev.sabreWedgeE[i]);
MyFill(table,"sabreWedgeChannel_sabreWedgeE_NoCuts",144,0,144,ev.sabreWedgeChannel[i],200,0,20,ev.sabreWedgeE[i]); MyFill(table,"sabreWedgeChannel_sabreWedgeE_NoCuts",144,0,144,ev.sabreWedgeChannel[i],4096,0,16384,ev.sabreWedgeE[i]);
} }
} }

View File

@ -76,8 +76,8 @@ namespace EventBuilder {
{ {
DPPChannel curHit; DPPChannel curHit;
curHit.Timestamp = mhit.timestamp; curHit.Timestamp = mhit.timestamp;
curHit.Energy = mhit.lgate; curHit.Energy = mhit.energy;
curHit.EnergyShort = mhit.sgate; curHit.EnergyShort = mhit.energyShort;
curHit.Channel = mhit.channel; curHit.Channel = mhit.channel;
curHit.Board = mhit.board; curHit.Board = mhit.board;
curHit.Flags = mhit.flags; curHit.Flags = mhit.flags;