StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2VirtualAlgo2006.cxx
1 #include <string.h>
2 #include <stdio.h>
3 
4 #ifdef IS_REAL_L2 //in l2-ana environment
5  #include "../L2algoUtil/L2Histo.h"
6  #include "trgStructures.h"
7  #else
8  #include "StDaqLib/TRG/trgStructures.h"
9  #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
10 #endif
11 
12 #include "L2VirtualAlgo2006.h"
13 //=============================================
14 L2VirtualAlgo2006::L2VirtualAlgo2006(const char* name, L2EmcDb* db, char* outDir, int resOff) : mDb(db), mResultOffset(resOff) {
15  strncpy(mName, name,sizeof(mName));
16  strncpy(mOutDir,outDir,sizeof(mOutDir));
17  setOflTrigID(0);
18  mhT=new L2Histo(901,"L2 time used per input event; x: time (CPU kTics); y: events ",400);
19 }
20 
21 //=============================================
22 void
23 L2VirtualAlgo2006::finishCommonHistos() {
24 
25  int iMax=-3, iFWHM=-4;
26  mhT->findMax( &iMax, &iFWHM);
27  printf("L2:%s CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",mName,iMax, iFWHM,mEventsInRun);
28 
29  if (mLogFile==0) return; // failed open log file, skip
30  fprintf(mLogFile,"L2:%s CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",mName,iMax, iFWHM,mEventsInRun);
31  mhT->print(0,mLogFile);
32  // mhT->printCSV(mLogFile);
33 
34  if (mHistFile) mhT->write(mHistFile);
35 }
36 
37 //=============================================
38 
39 L2VirtualAlgo2006::~L2VirtualAlgo2006(){};
40 
41 //=============================================
42 int
43 L2VirtualAlgo2006::readParams(const char *fileN, int mxPar, int *iPar, float *fPar) {
44  /* return:
45  <0 : error in input
46  >=0 : # of valid params : int+float
47  */
48 
49  memset(iPar,0,mxPar*sizeof(int));
50  memset(fPar,0,mxPar*sizeof(int));
51  FILE *fd=fopen(fileN,"r");
52  if(fd==0) { printf(" L2VirtualAlgo2006::readParams failed to open =%s=\n",fileN); return -2222;}
53 
54  int nVal=0; // sum of read in ints & floats
55  int nInt=0, nFloat=0; // # of read in values
56 
57  const int mx=1000;
58  char buf[mx];
59  int mode=0; // 1=int, 2=float
60 
61  for(;;) {
62  char * ret=fgets(buf,mx,fd);
63  //printf("xx1=%p\n",ret);
64  if(ret==0) break;
65  if(buf[0]==0) continue;
66  if(buf[0]=='#') continue;
67  if(buf[0]=='\n') continue;
68 
69  if (mode==0 && strstr(buf,"INTS")) { mode=1; continue; }
70  if (mode==1 && strstr(buf,"FLOATS")) { mode=2; continue; }
71  // printf("AA %d =%s= %p %p \n",mode,buf,strstr(buf,"INTS"),strstr("FLOATS",buf));
72  if(mode==1) { // ints[]
73  if(nInt>=mxPar) {nVal=-501; break;} // too many int-params
74  int ret1=sscanf(buf,"%i",iPar+nInt);
75  if(ret1!=1) {nVal=-100*mode -nInt; break;} // wrong input file for this int-par
76  nInt++; nVal++;
77  }
78  else if(mode==2) { // floats[]
79  if(nFloat>=mxPar) {nVal=-502; break;} // too many float-params
80  int ret1=sscanf(buf,"%f",fPar+nFloat);
81  if(ret1!=1) {nVal= -100*mode -nFloat; break;} // wrong input file for this float-par
82  nFloat++; nVal++;
83  }
84 
85  }
86 
87  fclose(fd);
88  printf(" L2VirtualAlgo2006::readParams %d from '%s'\n",nVal,fileN);
89  return nVal;
90 }