Error handling

This commit is contained in:
Paolo Andreetto
2023-02-22 11:20:56 +01:00
parent 7bc4932d09
commit 1507ee4e7c
2 changed files with 9 additions and 3 deletions

View File

@@ -5,13 +5,16 @@
SkinDetectorWriter::SkinDetectorWriter(string filename) : SkinDetectorWriter::SkinDetectorWriter(string filename) :
t_file(nullptr), t_file(nullptr),
t_tree(nullptr), t_tree(nullptr),
t_buffer(nullptr) t_buffer(nullptr),
i_status(0)
{ {
t_file = new TFile(filename.c_str(), "RECREATE"); t_file = new TFile(filename.c_str(), "RECREATE");
t_tree = new TTree("muCastorMC", "muCastorMC"); t_tree = new TTree("muCastorMC", "muCastorMC");
t_buffer = new TClonesArray("muCastorSkinHit"); t_buffer = new TClonesArray("muCastorSkinHit");
t_tree->Branch("CastorSkinHits", "TClonesArray", t_buffer, 32000, 99); t_tree->Branch("CastorSkinHits", "TClonesArray", t_buffer, 32000, 99);
if (t_file->IsZombie()) i_status = 1;
} }
SkinDetectorWriter::~SkinDetectorWriter() SkinDetectorWriter::~SkinDetectorWriter()
@@ -30,14 +33,15 @@ void SkinDetectorWriter::add(int detID, float p_x, float p_y, float p_z,
new_hit->SetPos (TVector3(p_x, p_y, p_z)); new_hit->SetPos (TVector3(p_x, p_y, p_z));
new_hit->SetMom (TVector3(m_x, m_y, m_z)); new_hit->SetMom (TVector3(m_x, m_y, m_z));
} }
void SkinDetectorWriter::write() void SkinDetectorWriter::write()
{ {
t_tree->Fill(); if (t_tree->Fill() < 0) i_status = 2;
t_buffer->Delete(); // or t_buffer->Clear() ?? t_buffer->Delete(); // or t_buffer->Clear() ??
} }
void SkinDetectorWriter::close() void SkinDetectorWriter::close()
{ {
t_tree->Write(); if (t_tree->Write() == 0) i_status = 3;
t_file->Close(); t_file->Close();
} }

View File

@@ -16,6 +16,7 @@ public:
virtual ~SkinDetectorWriter(); virtual ~SkinDetectorWriter();
void add(int detID, float p_x, float p_y, float p_z, float m_x, float m_y, float m_z); void add(int detID, float p_x, float p_y, float p_z, float m_x, float m_y, float m_z);
int status() { return i_status; }
void write(); void write();
void close(); void close();
@@ -23,6 +24,7 @@ private:
TFile* t_file; TFile* t_file;
TTree* t_tree; TTree* t_tree;
TClonesArray* t_buffer; TClonesArray* t_buffer;
int i_status;
}; };