mirror of
https://github.com/sesps/SPS_SABRE_EventBuilder.git
synced 2024-11-22 18:18:52 -05:00
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:
parent
1dc9a47a11
commit
0850f9a5e5
|
@ -14,26 +14,22 @@
|
|||
namespace EventBuilder {
|
||||
|
||||
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) :
|
||||
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);
|
||||
}
|
||||
|
||||
CompassFile::CompassFile(const std::string& filename, int bsize) :
|
||||
m_filename(""), bufferIter(nullptr), bufferEnd(nullptr), m_smap(nullptr), hitUsedFlag(true),
|
||||
bufsize(bsize), m_file(std::make_shared<std::ifstream>()), eofFlag(false)
|
||||
m_filename(""), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_smap(nullptr), m_hitUsedFlag(true), m_bufsize(bsize), 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);
|
||||
}
|
||||
|
||||
|
@ -44,21 +40,24 @@ namespace EventBuilder {
|
|||
|
||||
void CompassFile::Open(const std::string& filename)
|
||||
{
|
||||
eofFlag = false;
|
||||
hitUsedFlag = true;
|
||||
m_eofFlag = false;
|
||||
m_hitUsedFlag = true;
|
||||
m_filename = filename;
|
||||
m_file->open(m_filename, std::ios::binary | std::ios::in);
|
||||
|
||||
m_file->seekg(0, std::ios_base::end);
|
||||
m_size = m_file->tellg();
|
||||
m_nHits = m_size/24;
|
||||
if(m_size == 0)
|
||||
{
|
||||
eofFlag = true;
|
||||
m_eofFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
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())
|
||||
{
|
||||
EVB_WARN("Unable to get hit size from file {0}, sending invalid value.", m_filename);
|
||||
return 0;
|
||||
EVB_WARN("Unable to read header from file. State not validated", m_filename);
|
||||
return;
|
||||
}
|
||||
|
||||
char* firstHit = new char[24]; //A compass hit by default has 24 bytes (at least in our setup)
|
||||
|
||||
m_file->read(firstHit, 24);
|
||||
|
||||
firstHit += 16;
|
||||
int nsamples = *((uint32_t*) firstHit);
|
||||
|
||||
m_file->seekg(0, std::ios_base::beg);
|
||||
|
||||
delete[] firstHit;
|
||||
|
||||
return 24 + nsamples*16;
|
||||
|
||||
|
||||
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)
|
||||
m_file->read(firstHit, 24);
|
||||
firstHit += m_hitsize - 4;
|
||||
uint32_t 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->read(header, 2);
|
||||
delete[] firstHit;
|
||||
}
|
||||
|
||||
delete[] header;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -105,7 +116,7 @@ namespace EventBuilder {
|
|||
{
|
||||
if(!IsOpen()) return true;
|
||||
|
||||
if((bufferIter == nullptr || bufferIter == bufferEnd) && !IsEOF())
|
||||
if((m_bufferIter == nullptr || m_bufferIter == m_bufferEnd) && !IsEOF())
|
||||
{
|
||||
GetNextBuffer();
|
||||
}
|
||||
|
@ -113,10 +124,10 @@ namespace EventBuilder {
|
|||
if(!IsEOF())
|
||||
{
|
||||
ParseNextHit();
|
||||
hitUsedFlag = false;
|
||||
m_hitUsedFlag = false;
|
||||
}
|
||||
|
||||
return eofFlag;
|
||||
return m_eofFlag;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -131,34 +142,51 @@ namespace EventBuilder {
|
|||
|
||||
if(m_file->eof())
|
||||
{
|
||||
eofFlag = true;
|
||||
m_eofFlag = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_file->read(hitBuffer.data(), hitBuffer.size());
|
||||
m_file->read(m_hitBuffer.data(), m_hitBuffer.size());
|
||||
|
||||
bufferIter = hitBuffer.data();
|
||||
bufferEnd = bufferIter + m_file->gcount(); //one past the last datum
|
||||
m_bufferIter = m_hitBuffer.data();
|
||||
m_bufferEnd = m_bufferIter + m_file->gcount(); //one past the last datum
|
||||
|
||||
}
|
||||
|
||||
void CompassFile::ParseNextHit()
|
||||
{
|
||||
|
||||
m_currentHit.board = *((uint16_t*)bufferIter);
|
||||
bufferIter += 2;
|
||||
m_currentHit.channel = *((uint16_t*)bufferIter);
|
||||
bufferIter += 2;
|
||||
m_currentHit.timestamp = *((uint64_t*)bufferIter);
|
||||
bufferIter += 8;
|
||||
m_currentHit.lgate = *((uint16_t*)bufferIter);
|
||||
bufferIter += 2;
|
||||
m_currentHit.sgate = *((uint16_t*)bufferIter);
|
||||
bufferIter += 2;
|
||||
m_currentHit.flags = *((uint32_t*)bufferIter);
|
||||
bufferIter += 4;
|
||||
m_currentHit.Ns = *((uint32_t*)bufferIter);
|
||||
bufferIter += 4;
|
||||
m_currentHit.board = *((uint16_t*)m_bufferIter);
|
||||
m_bufferIter += 2;
|
||||
m_currentHit.channel = *((uint16_t*)m_bufferIter);
|
||||
m_bufferIter += 2;
|
||||
m_currentHit.timestamp = *((uint64_t*)m_bufferIter);
|
||||
m_bufferIter += 8;
|
||||
if(IsEnergy())
|
||||
{
|
||||
m_currentHit.energy = *((uint16_t*)m_bufferIter);
|
||||
m_bufferIter += 2;
|
||||
}
|
||||
if(IsEnergyCalibrated())
|
||||
{
|
||||
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)
|
||||
{ //memory safety
|
||||
|
|
|
@ -32,40 +32,54 @@ namespace EventBuilder {
|
|||
inline bool IsOpen() const { return m_file->is_open(); };
|
||||
inline CompassHit GetCurrentHit() const { return m_currentHit; }
|
||||
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 void SetHitHasBeenUsed() { 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* GetUsedFlagPtr() { return &hitUsedFlag; }
|
||||
inline bool CheckHitHasBeenUsed() const { return m_hitUsedFlag; } //query to find out if we've used the current hit
|
||||
inline void SetHitHasBeenUsed() { m_hitUsedFlag = true; } //flip the flag to indicate the current hit has been used
|
||||
inline bool IsEOF() const { return m_eofFlag; } //see if we've read all available data
|
||||
inline bool* GetUsedFlagPtr() { return &m_hitUsedFlag; }
|
||||
inline void AttachShiftMap(ShiftMap* map) { m_smap = map; }
|
||||
inline unsigned int GetSize() const { return m_size; }
|
||||
inline unsigned int GetNumberOfHits() const { return m_nHits; }
|
||||
|
||||
|
||||
private:
|
||||
int GetHitSize();
|
||||
void ReadHeader();
|
||||
void ParseNextHit();
|
||||
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 FilePointer = std::shared_ptr<std::ifstream>; //to make this class copy/movable
|
||||
|
||||
std::string m_filename;
|
||||
Buffer hitBuffer;
|
||||
char* bufferIter;
|
||||
char* bufferEnd;
|
||||
Buffer m_hitBuffer;
|
||||
char* m_bufferIter;
|
||||
char* m_bufferEnd;
|
||||
ShiftMap* m_smap; //NOT owned by CompassFile. DO NOT delete
|
||||
|
||||
bool hitUsedFlag;
|
||||
int bufsize = 200000; //size of the buffer in hits
|
||||
int hitsize = 24; //size of a CompassHit in bytes (without alignment padding)
|
||||
bool m_hitUsedFlag;
|
||||
int m_bufsize = 200000; //size of the buffer in hits
|
||||
int m_hitsize; //size of a CompassHit in bytes (without alignment padding)
|
||||
uint16_t m_header;
|
||||
int m_buffersize;
|
||||
|
||||
CompassHit m_currentHit;
|
||||
FilePointer m_file;
|
||||
bool eofFlag;
|
||||
bool m_eofFlag;
|
||||
unsigned int m_size; //size of the file in bytes
|
||||
unsigned int m_nHits; //number of hits in the file (m_size/24)
|
||||
|
||||
enum CoMPASSHeaders
|
||||
{
|
||||
Energy = 0x0001,
|
||||
EnergyCalibrated = 0x0002,
|
||||
EnergyShort = 0x0004,
|
||||
Waves = 0x0008,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
|
||||
namespace EventBuilder {
|
||||
|
||||
struct CompassHit
|
||||
{
|
||||
uint16_t board = 400;
|
||||
uint16_t channel = 400;
|
||||
uint64_t timestamp = 0;
|
||||
uint16_t lgate = 0;
|
||||
uint16_t sgate = 0;
|
||||
uint32_t flags = 0;
|
||||
uint32_t Ns = 0;
|
||||
};
|
||||
struct CompassHit
|
||||
{
|
||||
uint16_t board = 400;
|
||||
uint16_t channel = 400;
|
||||
uint64_t timestamp = 0;
|
||||
uint16_t energy = 0;
|
||||
uint64_t energyCalibrated = 0;
|
||||
uint16_t energyShort = 0;
|
||||
uint32_t flags = 0;
|
||||
uint8_t waveCode = 0;
|
||||
uint32_t Ns = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace EventBuilder {
|
|||
while(input>>filename)
|
||||
{
|
||||
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);
|
||||
}
|
||||
input.close();
|
||||
|
@ -58,7 +58,7 @@ namespace EventBuilder {
|
|||
bool CompassRun::GetBinaryFiles()
|
||||
{
|
||||
std::string prefix = "";
|
||||
std::string suffix = ".bin"; //binaries
|
||||
std::string suffix = ".BIN"; //binaries
|
||||
RunCollector grabber(m_directory, prefix, suffix);
|
||||
grabber.GrabAllFiles();
|
||||
|
||||
|
@ -168,8 +168,8 @@ namespace EventBuilder {
|
|||
|
||||
outtree->Branch("Board", &hit.board);
|
||||
outtree->Branch("Channel", &hit.channel);
|
||||
outtree->Branch("Energy", &hit.lgate);
|
||||
outtree->Branch("EnergyShort", &hit.sgate);
|
||||
outtree->Branch("Energy", &hit.energy);
|
||||
outtree->Branch("EnergyShort", &hit.energyShort);
|
||||
outtree->Branch("Timestamp", &hit.timestamp);
|
||||
outtree->Branch("Flags", &hit.flags);
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace EventBuilder {
|
|||
EVB_INFO("Converting file {0}...", binfile);
|
||||
rawfile = rawroot_dir + "compass_run_"+ std::to_string(i) + ".root";
|
||||
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());
|
||||
converter.Convert2RawRoot(rawfile);
|
||||
|
@ -238,7 +238,7 @@ namespace EventBuilder {
|
|||
|
||||
sortfile = sortroot_dir +"run_"+std::to_string(i)+ ".root";
|
||||
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());
|
||||
converter.Convert2SortedRoot(sortfile, m_mapfile, m_SlowWindow);
|
||||
|
@ -281,7 +281,7 @@ namespace EventBuilder {
|
|||
|
||||
sortfile = sortroot_dir + "run_" + std::to_string(i) + ".root";
|
||||
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());
|
||||
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";
|
||||
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());
|
||||
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";
|
||||
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());
|
||||
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);
|
||||
|
|
|
@ -140,9 +140,9 @@ namespace EventBuilder {
|
|||
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,"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,"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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,4 +277,4 @@ namespace EventBuilder {
|
|||
delete outfile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ namespace EventBuilder {
|
|||
{
|
||||
DPPChannel curHit;
|
||||
curHit.Timestamp = mhit.timestamp;
|
||||
curHit.Energy = mhit.lgate;
|
||||
curHit.EnergyShort = mhit.sgate;
|
||||
curHit.Energy = mhit.energy;
|
||||
curHit.EnergyShort = mhit.energyShort;
|
||||
curHit.Channel = mhit.channel;
|
||||
curHit.Board = mhit.board;
|
||||
curHit.Flags = mhit.flags;
|
||||
|
|
Loading…
Reference in New Issue
Block a user