]> jspc29.x-matter.uni-frankfurt.de Git - mvd_soft.git/commitdiff
Modified unpacker to read s-curve .hld files
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 25 Sep 2014 18:37:51 +0000 (20:37 +0200)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Thu, 25 Sep 2014 18:37:51 +0000 (20:37 +0200)
s-curves/cpp_based-on-dabc-lib/Makefile
s-curves/cpp_based-on-dabc-lib/unpacker.cxx

index d1eaf3c075003253313a8736977aa7a2a6669e60..37da33435ee17caa0911a31d5d9e4944cc25635d 100644 (file)
@@ -1,28 +1,11 @@
-DABCSYS = /d/jspc22/dabc
+CC=g++
+CLDFLAGS=-std=c++11 `root-config --cflags --glibs`
 
-include $(DABCSYS)/config/Makefile.config
+all: unpacker
 
-ifdef DABCMAINMAKE
-HADAQEXAMPLEDIR   = applications/hadaq/
-else
-HADAQEXAMPLEDIR   = ./
-endif
-
-HADAQEXAMPLE_EXE  = $(HADAQEXAMPLEDIR)unpacker
-
-HADAQEXAMPLE_S    = $(HADAQEXAMPLEDIR)unpacker.$(SrcSuf)
-HADAQEXAMPLE_O    = $(patsubst %.$(SrcSuf), $(BLD_DIR)/%.$(ObjSuf), $(HADAQEXAMPLE_S))
-HADAQEXAMPLE_D    = $(patsubst %.$(SrcSuf), $(BLD_DIR)/%.$(DepSuf), $(HADAQEXAMPLE_S))
-
-ALLDEPENDENC += $(HADAQEXAMPLE_D)
-
-exes::  $(HADAQEXAMPLE_EXE)
-
-clean::
-       rm -f $(HADAQEXAMPLE_EXE)
-
-$(HADAQEXAMPLE_EXE) : $(HADAQEXAMPLE_O) $(DABCBASE_LIB)
-       $(LD) -Wl,--no-as-needed -O $(HADAQEXAMPLE_O) -L$(DABCSYS)/lib -lDabcBase -lDabcMbs -lDabcHadaq -o $(HADAQEXAMPLE_EXE)
-
-include $(DABCSYS)/config/Makefile.rules
+unpacker: unpacker.cxx
+       g++ $(CLDFLAGS) -c unpacker.cxx -O2 -Wall -fPIC -m64 -I/d/jspc22/dabc/include -o unpacker.o 
+       g++ $(CLDFLAGS) -Wl,--no-as-needed -O unpacker.o -L/d/jspc22/dabc/lib -lDabcBase -lDabcMbs -lDabcHadaq -o unpacker
 
+clean:
+       rm -f unpacker
index 6b0c0534de216a3e7114598929917f3fa3c548fd..9024b0894dfac003e9c1b0731324d21036d59090 100644 (file)
@@ -1,10 +1,16 @@
 #include "hadaq/api.h"
 #include <time.h>
 
+#include <TTree.h>
+#include <TFile.h>
+#include "TROOT.h"
+#include "TApplication.h"
+
 void     readSubEvents(hadaq::RawEvent* evnt);
 signed   analyzeData(hadaq::RawSubevent* sub, unsigned ix, unsigned datalen, unsigned source);
 unsigned getSensor(unsigned sensorId);
 void     writeResults();
+void     save_tree();
 
 #define DEBUG 0
 #define MAX_SENSORS 12
@@ -24,13 +30,37 @@ unsigned sensors[MAX_SENSORS];
 const char* filename = "file.hld";
 const char* picPath = "./png";
 const char* mySystem = "NONE";
+const char* rootOutfile = "./output.root";
 
+Float_t*  pixelprob;
+UShort_t* rowcount;
+unsigned prev_threshold = 0xFFFF;
+UShort_t  tree_threshold;
+TTree*  scurveTree;
+TFile*  outFile;
+Int_t   rowcurr;
+bool    firstout = false;
 
 int main(int argc, char** argv) {
 
   if (argc>1) filename = argv[1];
   if (argc>2) picPath = argv[2];
   if (argc>3) mySystem = argv[3];  
+  if (argc>4) rootOutfile = argv[4];
+
+//----------------------------------
+  TApplication theApp("Analysis", &argc, argv);
+
+  pixelprob = new Float_t[1152*576];  for(int i=0;i<1152*576;i++) {pixelprob[i]=0;}
+  rowcount = new UShort_t[576];  for(int i=0;i<576;i++) {rowcount[i]=0;}
+
+  outFile = new TFile (rootOutfile,"RECREATE");
+  scurveTree = new TTree("scurvesall", "scurvesall");
+  scurveTree -> Branch("threshold", &tree_threshold, "threshold/s",         32000);
+  scurveTree -> Branch("pixelprob",  pixelprob, "pixelprob[663552]/F", 32000);
+  scurveTree -> Branch("frames",     rowcount,  "frames[576]/s",       32000);
+//----------------------------------
+
 
   hadaq::ReadoutHandle ref = hadaq::ReadoutHandle::Connect(filename);
   hadaq::RawEvent* evnt = 0;
@@ -41,6 +71,18 @@ int main(int argc, char** argv) {
 #endif     
     }
   writeResults();
+
+  save_tree();
+
+  outFile->Write();
+  outFile->Save();
+  outFile->Close();
+
+  delete[] pixelprob;
+  delete[] rowcount;
+
+  gApplication->Terminate();
+
   return 0;
 
 }
@@ -96,9 +138,12 @@ signed analyzeData(hadaq::RawSubevent* sub, unsigned ix, unsigned datalen, unsig
     }
   while(1) {
     unsigned sensorHead   = sub->Data(ix++);
+    unsigned testmode = 0x0;
     unsigned sensorId = 0x0;
     unsigned sensorStatus = 0x0;
     unsigned external = 0x0;
+    unsigned threshold = 0x0;
+    unsigned run = 0x0;
     unsigned internal_fr_num = 0x0;
     unsigned mySensor = 0x0;
     unsigned sensorError = 0x0;
@@ -106,11 +151,14 @@ signed analyzeData(hadaq::RawSubevent* sub, unsigned ix, unsigned datalen, unsig
     
     if (sub->Data(ix)>>16 == 0xf002){
       // Version 2
+      testmode = sub->Data(ix) & 0xffff;
       ix++;
       sensorId     = (source << 16)|(sub->Data(ix++)>>16);
       sensorStatus = sub->Data(ix++);
       ix += 2;  // skip reserved words
-      external          = sub->Data(ix++);
+      external     = sub->Data(ix++);
+      threshold    = external >> 16;
+      run          = external & 0xFF;
       internal_fr_num   = sub->Data(ix++);
       sensorError  = 0x0;
       sensorDebug  = 0x0;
@@ -132,7 +180,7 @@ signed analyzeData(hadaq::RawSubevent* sub, unsigned ix, unsigned datalen, unsig
                 sensorHead, sensorId, sensorStatus, sensorError, sensorDebug);
     #endif    
 
-    if(sensorHead != 0xffffffff) {
+    if( (testmode != 0x01) && (sensorHead != 0xffffffff) ) {
         //Something is really wrong with data. Skip SubEvent!
         printf("Broken Sensor Header\n");
         statistics[mySensor][FRREALBROKEN]++;
@@ -218,6 +266,28 @@ signed analyzeData(hadaq::RawSubevent* sub, unsigned ix, unsigned datalen, unsig
       //Read end of frame marker without check
       ix += 1;  
       }  
+    else if (testmode == 0x01) {
+      if (prev_threshold == 0xFFFF) prev_threshold = 0xFFFE; // prevent first save_tree() call
+      else if (threshold != prev_threshold) {
+        save_tree();
+        prev_threshold = threshold;
+        }
+      unsigned d = 0;
+      unsigned pos = 0;
+      unsigned row = internal_fr_num - 1;
+      rowcount[row]++;
+      while(1) {
+        d = sub->Data(ix++);
+        //printf("%08x", d);
+        for(int i = 0; i < 0x20; i++) {
+          pixelprob[1152 * row + pos*0x20 + i] += d & 0x1;
+          d = d >> 1;
+          }
+        pos++;
+        ix++;
+        if(ix >= RocEnd) break;
+        }
+      }
     else {
       return -2;
       }
@@ -323,4 +393,30 @@ void writeResults() {
     }
   }  
 
-  
+ void save_tree() {
+  if(firstout) {
+    tree_threshold = prev_threshold;
+    for(int i=0;i<1152*576;i++) {
+      rowcurr = (int)(i/1152);
+      if( rowcount[rowcurr] != 0 ) {
+        // printf("%5i %5i %10.6f %10.1i ",i, threshold, pixelprob[i], rowcount[rowcurr]);
+        pixelprob[i] = 1.*pixelprob[i]/rowcount[rowcurr];
+        // printf("%10.6f \n",pixelprob[i]);
+        }
+      else
+        {
+        pixelprob[i] = 0;
+        }
+      }
+    scurveTree->Fill();
+
+    for(int i=0;i<1152*576;i++) {pixelprob[i]=0;}
+    for(int i=0;i<576;i++) {rowcount[i]=0;}
+    }
+  else {
+    firstout = true;
+    }
+  // printf("Entries: %i \n", scurveTree->GetEntries());
+  }
+
+