, trb(trb)
, sensor(subid-0xa000)
, sensoraddress(subid)
- {}
+ {
+ }
//Hit data - decode pixel address and save
} else {
- DecodePixel(data >> 16, column, row);
- hitcount++;
- Columns->Fill(column);
- Matrix->Fill(column, row);
- MatrixCurrent->Fill(column, row);
- RegionCounts->Fill(column/16);
+
+ unsigned int dataWord = data >> 16;
+ int code = dataWord & 0b111;
+
+ while (code >= 0) {
+
+ DecodePixel(dataWord, column, row);
+ hitcount++;
+ Columns->Fill(column);
+ Matrix->Fill(column, row);
+ MatrixCurrent->Fill(column, row);
+ RegionCounts->Fill(column/16);
+
+ code >> 1;
+ if (code == 0) {code = -1;}
+ dataWord = dataWord += 8;
+
+ }
+
}
//Second Hit data - decode pixel address and save
if ((data & 0x0000FF00) != 0x0000FC00) {
- DecodePixel(data & 0xFFFF, column, row);
- hitcount++;
- Columns->Fill(column);
- Matrix->Fill(column, row);
- MatrixCurrent->Fill(column, row);
- RegionCounts->Fill(column/16);
+
+ unsigned int dataWord = data & 0xFFFF;
+ int code = dataWord & 0b111;
+
+ while (code >= 0) {
+
+ DecodePixel(dataWord, column, row);
+ hitcount++;
+ Columns->Fill(column);
+ Matrix->Fill(column, row);
+ MatrixCurrent->Fill(column, row);
+ RegionCounts->Fill(column/16);
+
+ code >> 1;
+ if (code == 0) {code = -1;}
+ dataWord = dataWord += 8;
+
+ }
}
}
}
--- /dev/null
+#ifndef MimosisProcessor_h
+#define MimosisProcessor_h
+
+
+#include "hadaq/SubProcessor.h"
+
+
+
+namespace hadaq
+{
+ class TrbProcessor;
+
+ /** This is specialized sub-processor for custom data.
+ * It should be used together with TrbProcessor,
+ * which the only can provide data
+ **/
+ class MimosisProcessor : public SubProcessor
+ {
+ friend class TrbProcessor;
+
+ protected:
+ const base::H1handle HandleFrameLength = MakeH1("FrameSize", "32bit words", 3000, 0, 3000, "ch");
+ TH1* FrameLength = static_cast<TH1*>(HandleFrameLength);
+ const base::H1handle HandleNumHeaders = MakeH1("NumHeaders", "", 2000, 0, 2000, "#");
+ TH1* NumHeaders = static_cast<TH1*>(HandleNumHeaders);
+ const base::H1handle HandleNumTrailers = MakeH1("NumTrailers", "Consecutive Frames", 500, 0, 500, "#");
+ TH1* NumTrailers = static_cast<TH1*>(HandleNumTrailers);
+ const base::H1handle HandleRegionHeaders = MakeH1("RegionHeaders", "", 64, 0, 63, "#");
+ TH1* RegionHeaders = static_cast<TH1*>(HandleRegionHeaders);
+ const base::H1handle HandleRegionCounts = MakeH1("RegionCounts", "", 64, 0, 63, "#");
+ TH1* RegionCounts = static_cast<TH1*>(HandleRegionCounts);
+ const base::H1handle HandleColumns = MakeH1("Columns", "Hits per Column", 1024, 0, 1024, "#");
+ TH1* Columns = static_cast<TH1*>(HandleColumns);
+ const base::H1handle HandleErrorFlags = MakeH1("ErrorFlags", "", 9, 0, 9, "Bit");
+ TH1* ErrorFlags = static_cast<TH1*>(HandleErrorFlags);
+ const base::H2handle HandleFrameLengthDist = MakeH2("FrameLengthDist", "", 1024,0,1024,1024,0,1024,"this frame ; last frame");
+ TH2* FrameLengthDist = static_cast<TH2*>(HandleFrameLengthDist);
+ const base::H2handle HandleMatrix = MakeH2("Matrix", "", 1024,0,1024,508,0,508);
+ TH2* Matrix = static_cast<TH2*>(HandleMatrix);
+ const base::H2handle HandleMatrixCurrent = MakeH2("MatrixCurrent", "", 1024,0,1024,508,0,508);
+ TH2* MatrixCurrent = static_cast<TH2*>(HandleMatrixCurrent);
+ const base::H2handle HandleMatrixLast = MakeH2("MatrixLast", "", 1024,0,1024,508,0,508);
+ TH2* MatrixLast = static_cast<TH2*>(HandleMatrixLast);
+ const base::H1handle HandleLast4096 = MakeH1("Last 4096 Content", "", 4095, 0, 4095, "Last 4096 Content");
+ TH1* Last4096 = static_cast<TH1*>(HandleLast4096);
+
+ unsigned int sensoraddress;
+ unsigned int sensor;
+ unsigned int length = 0;
+ unsigned int region = 0;
+ unsigned int frameCounter = 0;
+ unsigned int frameNumber = 0;
+ unsigned int lastRegion = 0;
+ TrbProcessor * const trb;
+
+
+
+ virtual bool DecodePixel(const unsigned int& word, unsigned int& column, unsigned int& row) const noexcept
+ {
+ unsigned int pixelcode = (word >> 6) & 0x3ff;
+ unsigned int side = 0, topdown = 0;
+ if((pixelcode&3) == 0x1 || (pixelcode&3) == 0x2) side = 1;
+ if((pixelcode&3) == 0x3 || (pixelcode&3) == 0x2) topdown = 1;
+ row = (pixelcode>>2)*2 + topdown;
+ column = (((word>>3)&0x7) + region*8)*2 + side;
+ return true;
+ }
+
+
+
+ public:
+ MimosisProcessor(TrbProcessor * const trb, const unsigned subid) noexcept
+ : hadaq::SubProcessor(trb, "%04X", subid)
+ , trb(trb)
+ , sensor(subid-0xa000)
+ , sensoraddress(subid)
+ {
+ }
+
+
+
+ virtual ~MimosisProcessor() noexcept override = default;
+
+
+ /** Scan all messages, find reference signals if returned false, buffer has error and must be discarded */
+ virtual bool FirstBufferScan(const base::Buffer&) noexcept override;
+
+
+ /** Scan buffer for selecting messages inside trigger window */
+ virtual bool SecondBufferScan(const base::Buffer&) const noexcept { return true; }
+ };
+}
+
+
+
+bool hadaq::MimosisProcessor::FirstBufferScan(const base::Buffer& buf) noexcept
+{
+ const uint32_t len = buf.datalen()/4;
+ const uint32_t* arr = static_cast<uint32_t *>(buf.ptr());
+ unsigned int n = 0;
+ unsigned int column, row, lastcolumn = -1, lastrow = -1;
+ unsigned int headers = 0, trailers = 0;
+ unsigned int headersnow = 0;
+ unsigned int lastlength = -1;
+ unsigned int hitcount = 0;
+ uint32_t data;
+
+ if(((arr[0]&0xFF000000) != 0xFE000000) ||
+ ((arr[0]&0xFF00) != 0xFE00) )
+ n = 1;
+
+ for (; n < len; n++) {
+ data = arr[n];
+ length++;
+
+//Begin of frame - store frame header
+ if ((data & 0xFF000000) == 0xFE000000) {
+ headers++;
+ headersnow++;
+ length = 0;
+
+ if (headersnow == 1) {
+ frameNumber = (data & 0xFF0000) >> 16;
+ frameNumber += (data & 0xFF) << 8;
+ }
+
+ else if (headersnow == 2) {
+ frameNumber += data & 0xFF0000;
+ frameNumber += (data & 0xFF) << 24;
+ }
+ }
+
+//End of frame - process frame results and error flags
+ else if ((data & 0xFF000000) == 0xFF000000) {
+ length--;
+ trailers++;
+ frameCounter++;
+ MatrixCurrent->Fill(-1, -1);
+
+ Last4096->SetBinContent(frameNumber % 4096, hitcount);
+ hitcount = 0;
+
+ if (frameCounter == 10000) {
+ MatrixCurrent->Copy(*MatrixLast);
+ MatrixLast->SetName("MatrixLast10000");
+ MatrixCurrent->Reset();
+ RegionCounts->Reset();
+ frameCounter = 0;
+ }
+
+ headersnow = 0;
+ FrameLength->Fill(length);
+
+ if (lastlength != -1) {
+ FrameLengthDist->Fill(length, lastlength);
+ }
+
+ lastlength = length;
+ if (data & 0x00010000) ErrorFlags->Fill(0);
+ if (data & 0x00020000) ErrorFlags->Fill(1);
+ if (data & 0x00040000) ErrorFlags->Fill(2);
+ if (data & 0x00080000) ErrorFlags->Fill(3);
+ if (data & 0x00100000) ErrorFlags->Fill(4);
+ if (data & 0x00200000) ErrorFlags->Fill(5);
+ if (data & 0x00400000) ErrorFlags->Fill(6);
+ if (data & 0x00800000) ErrorFlags->Fill(7);
+ if (!(data & 0x00FF0000)) ErrorFlags->Fill(8);
+ }
+
+ else {
+ headersnow = 0;
+
+//New region starts - save region number
+ if ((data & 0xFF000000) == 0xFD000000) {
+ lastRegion = region;
+ int tmp = (data >> 16) & 0xFF;
+ if (tmp > 63)
+ continue;
+ region = tmp;
+ RegionHeaders->Fill(region);
+
+//Hit data - decode pixel address and save
+ } else {
+ DecodePixel(data >> 16, column, row);
+ hitcount++;
+ Columns->Fill(column);
+ Matrix->Fill(column, row);
+ MatrixCurrent->Fill(column, row);
+ RegionCounts->Fill(column/16);
+ }
+
+//Second Hit data - decode pixel address and save
+ if ((data & 0x0000FF00) != 0x0000FC00) {
+ DecodePixel(data & 0xFFFF, column, row);
+ hitcount++;
+ Columns->Fill(column);
+ Matrix->Fill(column, row);
+ MatrixCurrent->Fill(column, row);
+ RegionCounts->Fill(column/16);
+ }
+ }
+ }
+
+NumHeaders->Fill(headers);
+NumTrailers->Fill(trailers);
+
+return true;
+}
+
+#endif