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


#ifndef __MGUIOptionsSaverMeasurementsL0__
#define __MGUIOptionsSaverMeasurementsL0__


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


// 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 saver
class MGUIOptionsSaverMeasurementsL0 : public MGUIOptions
{
// public Session:
public:
//! Default constructor
MGUIOptionsSaverMeasurementsL0(MModule* Module);
//! Default destructor
virtual ~MGUIOptionsSaverMeasurementsL0();

//! 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 which output file to save to
MGUIEFileSelector* m_FileSelectorOutput;



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

};

#endif


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


#ifndef __MModuleSaverMeasurementsL0__
#define __MModuleSaverMeasurementsL0__


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


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

// ROOT libs:

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

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


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


//! A module to save events to L0 binary format (DD packets)
class MModuleSaverMeasurementsL0 : public MModule
{
// public interface:
public:
//! Default constructor
MModuleSaverMeasurementsL0();
//! Default destructor
virtual ~MModuleSaverMeasurementsL0();

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

//! 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 output file name
void SetFileName(const MString& FileName) { m_FileName = FileName; }
//! Get the output file name
MString GetFileName() const { return m_FileName; }

// protected methods:
protected:
//! Write CCSDS Primary Header
void WriteCCSDSPrimaryHeader(uint16_t apid, uint16_t seqCount, uint16_t dataLength);
//! Write Secondary Header (packet time)
void WriteSecondaryHeader(uint32_t seconds, uint32_t subseconds);
//! Pack bits into a continuous bit stream
void PackBitsIntoBitstream(std::vector<uint8_t>& bitstream, int& bitOffset, uint64_t bits, int numBits);
//! Encode a normal strip hit (Type 0x0) - returns 44 bits
uint64_t EncodeNormalHit(int stripID, bool fastTiming, int energy, int timing);
//! Encode a neighboring strip hit (Type 0x1) - returns 36 bits
uint64_t EncodeNeighborHit(int stripID, bool fastTiming, int energy, int timing);
//! Encode a guard ring hit (Type 0x2) - returns 24 bits
uint32_t EncodeGuardRingHit(int stripID, int energy);
//! Write 16-bit value in big-endian
void WriteUInt16BE(uint16_t value);
//! Write 32-bit value in big-endian
void WriteUInt32BE(uint32_t value);


// private methods:
private:


// protected members:
protected:


// private members:
private:
//! Output file name
MString m_FileName;

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

//! Packet sequence counter
uint16_t m_SequenceCount;

//! Total number of events written
long m_TotalEventsWritten;

//! ApID for DD packets (Compton events)
static const uint16_t APID_DD = 0x0DD;


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

};

#endif


////////////////////////////////////////////////////////////////////////////////
126 changes: 126 additions & 0 deletions src/MGUIOptionsSaverMeasurementsL0.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* MGUIOptionsSaverMeasurementsL0.cxx
*
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
*
* This code implementation is the intellectual property of
* Andreas Zoglauer.
*
* By copying, distributing or modifying the Program (or any work
* based on the Program) you indicate your acceptance of this statement,
* and all its terms.
*
*/


// Include the header:
#include "MGUIOptionsSaverMeasurementsL0.h"

// Standard libs:

// ROOT libs:
#include <TSystem.h>
#include <MString.h>
#include <TGLabel.h>
#include <TGResourcePool.h>

// MEGAlib libs:
#include "MStreams.h"
#include "MModuleSaverMeasurementsL0.h"


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


#ifdef ___CLING___
ClassImp(MGUIOptionsSaverMeasurementsL0)
#endif


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


MGUIOptionsSaverMeasurementsL0::MGUIOptionsSaverMeasurementsL0(MModule* Module)
: MGUIOptions(Module)
{
// standard constructor
}


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


MGUIOptionsSaverMeasurementsL0::~MGUIOptionsSaverMeasurementsL0()
{
// kDeepCleanup is activated
}


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


void MGUIOptionsSaverMeasurementsL0::Create()
{
PreCreate();

TGLayoutHints* LabelLayout = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 10, 10, 10, 10);

// Output file selector
m_FileSelectorOutput = new MGUIEFileSelector(m_OptionsFrame, "Please select output L0 binary file:",
dynamic_cast<MModuleSaverMeasurementsL0*>(m_Module)->GetFileName());
m_FileSelectorOutput->SetFileType("Binary file", "*.bin");
m_OptionsFrame->AddFrame(m_FileSelectorOutput, LabelLayout);

PostCreate();
}


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


bool MGUIOptionsSaverMeasurementsL0::ProcessMessage(long Message, long Parameter1, long Parameter2)
{
// Modify here if you have more buttons

bool Status = true;

switch (GET_MSG(Message)) {
case kC_COMMAND:
switch (GET_SUBMSG(Message)) {
case kCM_BUTTON:
break;
default:
break;
}
break;
default:
break;
}

if (Status == false) {
return false;
}

// Call also base class
return MGUIOptions::ProcessMessage(Message, Parameter1, Parameter2);
}


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


bool MGUIOptionsSaverMeasurementsL0::OnApply()
{
// Modify this to store the data in the module!

dynamic_cast<MModuleSaverMeasurementsL0*>(m_Module)->SetFileName(m_FileSelectorOutput->GetFileName());

return true;
}


// MGUIOptionsSaverMeasurementsL0: the end...
////////////////////////////////////////////////////////////////////////////////
Loading