Skip to content
Merged
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
99 changes: 99 additions & 0 deletions include/MFITSWriterL1a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* MFITSWriterL1a.h
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
* Please see the source-file for the copyright-notice.
*
*/


#ifndef __MFITSWriterL1a__
#define __MFITSWriterL1a__


////////////////////////////////////////////////////////////////////////////////


// Standard libs:
#include <vector>
#include <valarray>
#include <string>
#include <cstdint>

// MEGAlib libs:
#include "MGlobal.h"
#include "MString.h"

// Nuclearizer libs:
#include "MReadOutAssembly.h"

// CCfits libs:
#include <CCfits/CCfits>


////////////////////////////////////////////////////////////////////////////////


class MFITSWriterL1a
{
// public interface:
public:
//! Default constructor
MFITSWriterL1a();
//! Default destructor
virtual ~MFITSWriterL1a();

//! Create the FITS file + GED_L1A extension. Returns false on error.
bool Create(const MString& FileName);
//! Append one event's strip hits as a row. Returns false on error.
bool Write(MReadOutAssembly* Event);
//! Flush buffered rows to the table. Returns false on error.
bool FlushBatch();

void Close();


private:
//! The FITS file object
CCfits::FITS* m_FITSFile;
//! The GED_L1A science table extension
CCfits::ExtHDU* m_Table;

long m_BatchStartRow;
long m_BatchEventCount;
//! Batch size
static const long m_BatchSize = 100;

bool m_HasEvents;

//! First / last event time seen, RTS (mission seconds since 2025-01-01)
double m_FirstEventTime_RTS;
double m_LastEventTime_RTS;

std::vector<double> m_BatchTIME;
std::vector<uint32_t> m_BatchEVENTID;
std::vector<uint8_t> m_BatchEVENTTYPE;
std::vector<uint16_t> m_BatchNUMSTRIPHIT;

std::vector<std::valarray<uint8_t>> m_BatchHITTYPE; // PB
std::vector<std::valarray<uint8_t>> m_BatchDETID; // PB
std::vector<std::valarray<uint8_t>> m_BatchSTRIPID; // PB
std::vector<std::valarray<uint8_t>> m_BatchSIDEID; // PX (0/1)
std::vector<std::valarray<uint8_t>> m_BatchFASTTIME; // PX (0/1)
std::vector<std::valarray<int32_t>> m_BatchPHA; // PI
std::vector<std::valarray<int32_t>> m_BatchTAC; // PI


#ifdef ___CLING___
public:
ClassDef(MFITSWriterL1a, 0) // no description
#endif

};

#endif


////////////////////////////////////////////////////////////////////////////////
90 changes: 90 additions & 0 deletions include/MGUIOptionsLoaderMeasurementsL0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* MGUIOptionsLoaderMeasurementsL0.h
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
* Please see the source-file for the copyright-notice.
*
*/


#ifndef __MGUIOptionsLoaderMeasurementsL0__
#define __MGUIOptionsLoaderMeasurementsL0__


////////////////////////////////////////////////////////////////////////////////


// ROOT libs:
#include <TROOT.h>
#include <TVirtualX.h>
#include <TGWindow.h>
#include <TObjArray.h>
#include <TGFrame.h>
#include <TGButton.h>
#include <MString.h>
#include <TGClient.h>

// MEGAlib libs:
#include "MGlobal.h"
#include "MGUIEFileSelector.h"
#include "MGUIOptions.h"

// Nuclearizer libs:
#include "MModule.h"


// Forward declarations:


////////////////////////////////////////////////////////////////////////////////


//! UI settings for the L0 measurements loader
class MGUIOptionsLoaderMeasurementsL0 : public MGUIOptions
{
// public Session:
public:
//! Default constructor
MGUIOptionsLoaderMeasurementsL0(MModule* Module);
//! Default destructor
virtual ~MGUIOptionsLoaderMeasurementsL0();

//! Process all button, etc. messages
virtual bool ProcessMessage(long Message, long Parameter1, long Parameter2);

//! The creation part which gets overwritten
virtual void Create();

// protected methods:
protected:

//! Actions after the Apply or OK button has been pressed
virtual bool OnApply();


// protected members:
protected:

// private members:
private:
//! Select the L0 binary file to load (.bin / .dat)
MGUIEFileSelector* m_FileSelectorL0;

//! Select the strip map file
MGUIEFileSelector* m_FileSelectorStripMap;



#ifdef ___CLING___
public:
ClassDef(MGUIOptionsLoaderMeasurementsL0, 1) // basic class for dialog windows
#endif

};

#endif


////////////////////////////////////////////////////////////////////////////////
2 changes: 2 additions & 0 deletions include/MGUIOptionsSaverMeasurementsL0.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class MGUIOptionsSaverMeasurementsL0 : public MGUIOptions
//! Select which output file to save to
MGUIEFileSelector* m_FileSelectorOutput;

MGUIEFileSelector* m_FileSelectorStripMap;



#ifdef ___CLING___
Expand Down
3 changes: 2 additions & 1 deletion include/MModuleLoaderMeasurementsFITS.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ class MModuleLoaderMeasurementsFITS : public MModuleLoaderMeasurements

//! Batch data storage for scalar columns
std::vector<double> m_BatchTIME;
std::vector<uint32_t> m_BatchEVENTID;
std::vector<uint8_t> m_BatchEVENTTYPE;
std::vector<uint8_t> m_BatchNUMSTRIPHIT;

//! Batch data storage for variable-length array columns
std::vector<std::valarray<uint8_t>> m_BatchTYPEHIT;
std::vector<std::valarray<uint8_t>> m_BatchHITTYPE;
std::vector<std::valarray<int>> m_BatchDETID;
std::vector<std::valarray<int>> m_BatchSTRIPID;
std::vector<std::valarray<int>> m_BatchSIDEID;
Expand Down
122 changes: 122 additions & 0 deletions include/MModuleLoaderMeasurementsL0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* MModuleLoaderMeasurementsL0.h
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
* Please see the source-file for the copyright-notice.
*
*/


#ifndef __MModuleLoaderMeasurementsL0__
#define __MModuleLoaderMeasurementsL0__


////////////////////////////////////////////////////////////////////////////////


// Standard libs:
#include <fstream>
#include <vector>
#include <cstdint>

// MEGAlib libs:
#include "MGlobal.h"
#include "MString.h"

// Nuclearizer libs:
#include "MModuleLoaderMeasurements.h"
#include "MStripMap.h"


////////////////////////////////////////////////////////////////////////////////


//! A module to load L0 binary files (CCSDS DD packets) into MReadOutAssembly events.
class MModuleLoaderMeasurementsL0 : public MModuleLoaderMeasurements
{
// public interface:
public:
//! Default constructor
MModuleLoaderMeasurementsL0();
//! Default destructor
virtual ~MModuleLoaderMeasurementsL0();

//! Create a new object of this class
virtual MModuleLoaderMeasurementsL0* Clone() { return new MModuleLoaderMeasurementsL0(); }

//! Initialize the module
virtual bool Initialize();

//! Finalize the module
virtual void Finalize();

//! Main data analysis routine, which updates the event to a new level
virtual bool AnalyzeEvent(MReadOutAssembly* Event);

//! Show the options GUI
virtual void ShowOptionsGUI();

//! Read the configuration data from an XML node
virtual bool ReadXmlConfiguration(MXmlNode* Node);
//! Create an XML node tree from the configuration
virtual MXmlNode* CreateXmlConfiguration();

//! Set the L0 binary file name
void SetFileName(const MString& FileName) { m_FileName = FileName; }
//! Get the L0 binary file name
MString GetFileName() const { return m_FileName; }

//! Set the strip map file name
void SetFileNameStripMap(const MString& FileName) { m_FileNameStripMap = FileName; }
//! Get the strip map file name
MString GetFileNameStripMap() const { return m_FileNameStripMap; }


// protected methods:
protected:
//! Open the L0 file. Auto-detects whether it has a 20-byte L0 header (from MOC simulator) or is raw CCSDS packets.
bool OpenL0File(MString FileName);

//! Read the next CCSDS packet from the file and populate Event.
//! Returns false on EOF or unrecoverable read error.
bool ReadNextPacket(MReadOutAssembly* Event);

//! Decode the bit-packed HIT_DATA payload into MStripHit objects on Event.
//! Returns false on parsing error.
bool DecodeHitData(const std::vector<uint8_t>& hitData, unsigned int expectedHits, MReadOutAssembly* Event);


// private members:
private:
//! Input L0 binary file name (.dat or .bin)
MString m_FileName;

//! Strip map file name for read-out ID -> (detector, side, strip) lookup
MString m_FileNameStripMap;

//! Strip map (loaded at Initialize)
MStripMap m_StripMap;

//! Whether the strip map was successfully loaded
bool m_StripMapLoaded;

//! The opened input file stream
std::ifstream m_InFile;

//! Total number of packets read so far
unsigned long m_PacketsRead;


#ifdef ___CLING___
public:
ClassDef(MModuleLoaderMeasurementsL0, 0) // no description
#endif

};

#endif


////////////////////////////////////////////////////////////////////////////////
6 changes: 5 additions & 1 deletion include/MModuleSaverMeasurementsFITS.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

// Nuclearizer libs:
#include "MModule.h"
#include "MFITSWriterL1a.h"

// CCfits libs
#include <CCfits/CCfits>
Expand Down Expand Up @@ -101,9 +102,12 @@ class MModuleSaverMeasurementsFITS : public MModule
//! Output file name
MString m_FileName;

//! Output data level: 1 = L1b (all events, with QUALITY_FLAG), 2 = L2 (screened, no QUALITY_FLAG)
//! Output data level: 0 = L1a (raw hits), 1 = L1b (all events, with QUALITY_FLAG), 2 = L2 (screened, no QUALITY_FLAG)
int m_OutputDataLevel;

//! L1a writer, used only when m_OutputDataLevel == 0
MFITSWriterL1a m_L1aWriter;

//! The FITS file object pointer
FITS* m_FITSFile;

Expand Down
14 changes: 14 additions & 0 deletions include/MModuleSaverMeasurementsL0.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// Nuclearizer libs:
#include "MModule.h"
#include "MReadOutAssembly.h"
#include "MStripMap.h"


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -69,6 +70,11 @@ class MModuleSaverMeasurementsL0 : public MModule
//! Get the output file name
MString GetFileName() const { return m_FileName; }

//! Set the strip map file name (used for reverse (det,side,strip) → ReadOutID lookup)
void SetFileNameStripMap(const MString& FileName) { m_FileNameStripMap = FileName; }
//! Get the strip map file name
MString GetFileNameStripMap() const { return m_FileNameStripMap; }

// protected methods:
protected:
//! Write CCSDS Primary Header
Expand Down Expand Up @@ -104,6 +110,14 @@ class MModuleSaverMeasurementsL0 : public MModule
//! Output file name
MString m_FileName;

//! Strip map file name. Used for reverse lookup (det,side,strip) → read-out ID
MString m_FileNameStripMap;

//! The loaded strip map
MStripMap m_StripMap;

bool m_StripMapLoaded;

//! Output file stream
std::ofstream m_OutFile;

Expand Down
Loading