]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
PK: changes to the eventbuilder by Paweł Staszel
authorMaps <maps@ikf>
Thu, 11 May 2017 13:15:14 +0000 (15:15 +0200)
committerMaps <maps@ikf>
Thu, 11 May 2017 13:16:13 +0000 (15:16 +0200)
hadaq/evtbuild.c

index cd3e091d72b4cf0a05a71114e864a6076d999b97..a4bc52d7ebaa6d482b2ea56687d1be928004baed 100644 (file)
@@ -79,6 +79,8 @@ static FILE *outFile;
 static FILE *outLustreFile;
 static FILE *outSecondFile;
 
+static FILE* logfile;
+
 static AnsiTape *outTape;
 static uint32_t seqNr;
 static uint32_t runNr;
@@ -95,6 +97,11 @@ static char msglog[300];
 
 static jmp_buf terminateJmp;
 
+static int frameCounter = 100;
+static int triggerCounter = 0;
+static int triggerCounter2 = 0;
+static int trbCounterOffset = 0;
+
 void sigHandler(int sig)
 {
        longjmp(terminateJmp, sig);
@@ -611,8 +618,10 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                        }
                }
 
+               fprintf(logfile,"  attempting to open file:  %s \n",theArgs->outPath);
                if (NULL == (outFile = fopen(theArgs->outPath, "wb"))) {
                        sprintf(msglog, "<E> %s, %d: fopen: failed to open file %s: %s", __FILE__, __LINE__, theArgs->outPath, strerror(errno));
+                       fprintf(logfile,"<E> %s, %d: fopen: failed to open file %s: %s", __FILE__, __LINE__, theArgs->outPath, strerror(errno));
                        storeLogInfo(theArgs, msglog);
                        syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
                        outFile = NULL;
@@ -626,8 +635,12 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                                unlink(theArgs->outPath);
 
                                sprintf(msglog, "<E>  %s, %d: no space left to open new file %s: %s", __FILE__, __LINE__, theArgs->outPath,
-                                               strerror(errno));
-                               storeLogInfo(theArgs, msglog);
+                                       strerror(errno));
+
+                               fprintf(logfile," <E>  %s, %d: no space left to open new file %s: %s", __FILE__, __LINE__, theArgs->outPath,
+                                       strerror(errno));
+
+                                       storeLogInfo(theArgs, msglog);
                                syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
                                return -1;
                        }
@@ -744,13 +757,20 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
 
 static int writeFile(TheArgs *theArgs, void *evt)
 {
+
        int writeFileR;
 
        Evt_setSeqNr(evt, seqNr++);
        Evt_setRunNr(evt, runNr);
 
        if (outFile != NULL) {
+
+         /*fprintf(stderr,"  writing event: event size = %d  paddedSize = %d \n",Evt_size(evt),Evt_paddedSize(evt));*/
+         /*fprintf(stderr,"  outFile = %s \n",outFile);*/
+
                writeFileR = fwrite(evt, 1, Evt_paddedSize(evt), outFile);
+               writeFileR = fflush(outFile);
+
        } else if (outTape != NULL) {
                writeFileR = writeAnsiTape(outTape, evt, Evt_paddedSize(evt));
        }
@@ -792,8 +812,14 @@ static int closeFile(TheArgs *theArgs)
        }
 
        if (outFile != NULL) {
-               closeFileR = fclose(outFile);
-               if (0 != closeFileR) {
+
+         fprintf(stderr,"  Closing the outFile \n");
+         
+         closeFileR = fclose(outFile);
+
+         fprintf(stderr,"  outFile Closed \n");
+       
+         if (0 != closeFileR) {
                        sprintf(msglog, "<E> %s, %d: closeFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
                        storeLogInfo(theArgs, msglog);
                        syslog(LOG_ERR, "%s, %d: failed to fclose 'outFile': %s", __FILE__, __LINE__, strerror(errno));
@@ -855,7 +881,7 @@ static int rfio_openConnection(TheArgs *theArgs, TheStats *theStats)
 
                fRemote = rfio_fopen_gsidaq_dm(rfioBase, theArgs->rfio_pcOption,
                                                                           pcDataMover, &piDataMover,
-                                                                          theArgs->rfio_iCopyMode, theArgs->rfioLustrePath,
+Fi                                                                        theArgs->rfio_iCopyMode, theArgs->rfioLustrePath,
                                                                           theArgs->rfio_iCopyFrac, theArgs->rfio_iMaxFile, theArgs->rfio_iPathConv);
 
 
@@ -917,13 +943,26 @@ int main(int argc, char *argv[])
        uint32_t lastTrigNr = 0;
        int firstFile = 1;
 
+         /* PAWEL */
+         void *OLDevt;
+         int OLDevtSet=0;
+         /* PAWEL */
 
+       
 
+       logfile = fopen("/local.1/log/evtbuild.log","w");
+       
+       fprintf(stderr,"Entered Pawel evt builder\n");
+       fprintf(logfile,"----------> entered main in pawel  \n");
+       fflush(logfile);
 
        signal(SIGINT, sigHandler);
        signal(SIGTERM, sigHandler);
        signal(SIGHUP, sigHandler);
 
+       fprintf(logfile,"----------> line 1  \n");
+       fflush(logfile);
+
        openlog(argv[0], LOG_PID | LOG_PERROR, LOG_LOCAL0);
        setlogmask(LOG_UPTO(LOG_INFO));
 
@@ -931,11 +970,18 @@ int main(int argc, char *argv[])
 
        Args_fromParam(theArgs, argc, argv);
 
+       fprintf(logfile,"----------> line 2  \n");
+       fflush(logfile);
+
        if (0 > Args_fromCL(theArgs, argc, argv)) {
                usage(argv[0]);
                exit(EXIT_FAILURE);
        }
 
+       
+       fprintf(logfile,"----------> line 3  \n");
+       fflush(logfile);
+
        storeLogInfo(theArgs, "<I> started.");
 
        if (0 > makeQueues(theArgs)) {
@@ -943,10 +989,19 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
+      
+       fprintf(logfile,"----------> line 4  \n");
+
+       fflush(logfile);
+
        if (Args_check(theArgs)) {
                exit(EXIT_FAILURE);
        }
 
+      
+       fprintf(logfile,"----------> line 5  \n");
+       fflush(logfile);
+
        /* Init debugging structure */
        if (theArgs->debugOptsCnt)
                Debug_init(theDebug);
@@ -984,7 +1039,7 @@ int main(int argc, char *argv[])
                sprintf(msglog, "<E> %s, %d: initOnline: failed to init online service: %s", __FILE__, __LINE__, strerror(errno));
                storeLogInfo(theArgs, msglog);
        }
-
+syslog(LOG_WARNING, "Entered Pawel evt builder");
        if (theArgs->nrOfMsgs == 0) {
                /*
                   no '-m' option was on command line, we assume that the
@@ -1146,7 +1201,11 @@ int main(int argc, char *argv[])
 
        currId = 0;
 
+
        while (setjmp(terminateJmp) == 0) {
+
+
+
                void *evt;
                void *subEvt;
                int step;
@@ -1180,12 +1239,17 @@ int main(int argc, char *argv[])
                        strftime(s, 20, "%Y-%m-%dT%H:%M:%S", localtime(&ourTime));
                        printf("ioc time: %s\n", s);
                        printf("ioc runid: %d\n", runNr);
-
+       
+                       fprintf(logfile,"  in main: attempt to open new file  \n");
+       
                        if (-1 == openFile(theArgs, theStats)) {
                                syslog(LOG_ERR, "error opening output file, exiting");
+                               fprintf(logfile,"error opening output file, exiting \n");
                                exit(EXIT_FAILURE);
                        }
 
+                       fflush(logfile);
+
                        storeInfoStart(argv[0], ourTime, theArgs);
 
                        /* store simple start run info */
@@ -1198,6 +1262,9 @@ int main(int argc, char *argv[])
                        }
 
                        (*theStats->bytesWritten) += Evt_size(evt);
+
+                       fprintf(stderr,"  calling write 1 \n");
+
                        writeFile(theArgs, evt);
                        deleteEvt(evt);
                }
@@ -1495,6 +1562,13 @@ int main(int argc, char *argv[])
                        }
                }
 
+
+               void *subEvt2 = Evt_data(evt);
+               uint32_t headerWord1_2 = SubEvt_dataValue(subEvt2, 2);
+               
+               const uint32_t trigFlag_2 = 0x80000000;
+               if((headerWord1_2 & trigFlag_2))triggerCounter2++;
+
                if (!evtIsBroken) {
 
                        if (theArgs->debugOptsCnt) {
@@ -1527,8 +1601,98 @@ int main(int argc, char *argv[])
                                        goto bailOut1;
                                }
                        }
-                       (*theStats->bytesWritten) += Evt_size(evt);
-                       writeFile(theArgs, evt);
+               
+
+                       /*fprintf(stderr,"  calling write 2 \n");*/
+                       /* --------------  checking trigger flag by PS */
+
+
+
+
+                       frameCounter = frameCounter+1;
+                       void *subEvt = Evt_data(evt);                   
+                       
+                       uint32_t headerWord1 = SubEvt_dataValue(subEvt, 3);
+                       
+                       /*
+                         fprintf(stderr, "@@@ Header word 0x%x\n", headerWord1); 
+                       */
+
+                       const uint32_t trigFlag = 0x80000000;
+                       if((headerWord1 & trigFlag)){
+                        
+                         frameCounter=0;
+                         triggerCounter++;
+                         
+                         uint32_t trbCounter = headerWord1 & 0x00ffffff;
+                         if(triggerCounter==1) trbCounterOffset = trbCounter -1;
+
+                         /*
+                           trbCounter = trbCounter - trbCounterOffset;
+                         */
+
+                         fprintf(stderr,"  collected VD events: = %d \n",
+                                 trbCounter);
+                         fprintf(logfile," ->$#$#$# got trigger!!!!!!!! triggerCounter = %d  triggerCounter2 = %d  trbCounter = %d \n",
+                                 triggerCounter,triggerCounter2,trbCounter);
+                         fflush(logfile);
+                        
+                       }
+
+                       
+                       /*if((frameCounter>5) && (frameCounter<11)){*/ 
+                       if((frameCounter<9)){ 
+                      
+                         
+                         (*theStats->bytesWritten) += Evt_size(evt);
+                         
+                         /*
+                         fprintf(stderr,"  fC = %d, event size = %d  \n",frameCounter,Evt_size(evt));
+                         fprintf(logfile,"  fC = %d, event size = %d  \n",frameCounter,Evt_size(evt));
+                         fflush(logfile);
+                         */                      
+
+                         /* --------------- end of trigger checking block */
+                         /*fprintf(stderr, "Pawel!\n");*/
+                 
+                           writeFile(theArgs, evt);
+
+                         /* PAWEL */
+                         /*
+                         if(OLDevtSet != 0){
+                        
+                           fwrite(OLDevt, 1, Evt_paddedSize(OLDevt),outFile);
+                           fflush(outFile);
+                           fflush(stderr);
+                    
+                         }
+                         */
+                         /* PAWEL */
+
+                       }else{
+                         /*
+                           fprintf(logfile,"  fC = %d, event size = %d  \n",frameCounter,Evt_size(evt));
+                           fflush(logfile);
+                         */
+                         /*fprintf(stderr,"  fC = %d, event size = %d  \n",frameCounter,Evt_size(evt));*/
+                           
+                         /* Uncomment consecutive line in order to run without external trigger */
+                         /*
+                         (*theStats->bytesWritten) += Evt_size(evt);                     
+                         writeFile(theArgs, evt);     
+                         */                        
+                         /* End line to be uncommented to run without external trigger */
+                         
+                       }
+                       
+                       /* PAWEL */
+                       if (OLDevtSet != 0){
+                         free(OLDevt);
+                       }
+                         OLDevt = malloc(Evt_paddedSize(evt));
+                         memcpy(OLDevt,evt, Evt_paddedSize(evt));
+                         OLDevtSet = 1; 
+                       /* PAWEL */
 
                        if (theArgs->resdownscale) {
 
@@ -1639,16 +1803,27 @@ int main(int argc, char *argv[])
                 *           Something went wrong with sinchronization of Event Builders,
                 *           close the file.
                 */
+
                if ((!(theArgs->epicsCtrl) && (*theStats->bytesWritten) >= theArgs->maxFileSz) ||
                        (theArgs->epicsCtrl && runNr < newRunId) ||
                        /* (theArgs->epicsCtrl && (*theStats->bytesWritten) >= 1900000000) JAM disable closing run ourselfs if we are slave */
                        (theArgs->epicsCtrl && newRunId == 0)) {
+
+
+               fprintf(logfile,"  check runID (passed if), runNr=%d, newRunId=%d , maxFileSz=%d , epicsCtrl=%d \n",runNr,newRunId,theArgs->maxFileSz,theArgs->epicsCtrl);
+                 fflush(logfile);
+               fprintf(logfile,"  bytesWritten=%d \n",(*theStats->bytesWritten));
+                 fflush(logfile);
+
                        evt = newEvt(EvtDecoding_64bitAligned, EvtId_runStop);
 
                        for (i = 0; i < theArgs->slowCtrlFileCnt; i++)
                                evt = appendFile(evt, theArgs->slowCtrlFiles[i]);
 
                        (*theStats->bytesWritten) += Evt_size(evt);
+
+                       fprintf(stderr,"  calling write 3 \n");
+
                        writeFile(theArgs, evt);
                        deleteEvt(evt);
 
@@ -1712,8 +1887,13 @@ int main(int argc, char *argv[])
                                Res_closeFile(theArgs);
                                (*theStats->evtsRes) = 0;
                        }
-               }
-       }
+               } 
+       } /* end of while loop*/
+
+
+
+       fprintf(stderr,"  T2  I'm here  \n");
+
 
   bailOut1:
 
@@ -1735,6 +1915,10 @@ int main(int argc, char *argv[])
                        /******/
                Res_closeFile(theArgs);
        }
+
+       fprintf(stderr,"  T1  I'm here  \n");
+       
+
        storeInfoStop(argv[0], ourTime, worker, theArgs);
 
        /* store simple stop run info */