4 #ifdef IS_REAL_L2 //in l2-ana environment
5 #include "trgStructures.h"
6 #include "../L2algoUtil/L2Histo.h"
7 #include "../L2algoUtil/L2EmcDb.h"
9 #include "StDaqLib/TRG/trgStructures.h"
10 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2Histo.h"
11 #include "StTriggerUtilities/L2Emulator/L2algoUtil/L2EmcDb.h"
16 #include "L2VirtualAlgo2008.h"
18 L2VirtualAlgo2008::L2VirtualAlgo2008(
const char* name,
L2EmcDb* db,
char* outDir) : mDb(db) {
24 mEveStream_btow=globL2eventStream2008.get_btow();
25 mEveStream_etow=globL2eventStream2008.get_etow();
28 mhN =
new L2Histo(900,
"total events 0=anyInput, 10=anyAccept; x=cases",19);
29 mhTc=
new L2Histo(901,
"L2 COMPUTE time per input event; x: COMPUTE time (CPU kTics); y: events ",180);
30 mhTd=
new L2Histo(902,
"L2 DECISION time per input event; x: DECISION time (CPU kTics); y: events ",36);
31 mhTcd=
new L2Histo(903,
"L2 COMP+DECI time per input event; x: COMP+DECIS time (CPU kTics); y: events ",180);
34 mhRc=
new L2Histo(905,
"rate of COMPUTE; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
35 mhRd=
new L2Histo(906,
"rate of DECISION; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
36 mhRa=
new L2Histo(907,
"rate of ACCEPT; x: time in this run (seconds); y: rate (Hz)", mxRunDration);
37 printf(
"L2-%s instantiated, logPath='%s'\n",getName(),mOutDir1.c_str());
40 assert(L2eventStream2008::mxToken == L2eventStream2008::tokenMask+1);
46 L2VirtualAlgo2008::initRun(
int runNo,
int *rc_ints,
float *rc_floats) {
47 if(mDb->getRun()!=runNo)
return -700;
49 if(mRunNumber==runNo) {
50 if (mLogFile) fprintf(mLogFile,
"L2-%s::initRun(%d)=ghost already initilized, Abort run\n",getName(), runNo);
54 unsigned int high,low;
55 rdtsc_macro(low,high);
56 mRunStartTicks=high; mRunStartTicks <<= 32; mRunStartTicks += low;
61 sprintf(Fname,
"%s/run%d.l2%s.log",mOutDir1.c_str(),mRunNumber,getName());
62 printf(
"L2-%s::initRun('%s') ...\n",getName(),Fname);
64 mLogFile = fopen(Fname,
"w");
65 if( mLogFile==0) printf(
" L2-%s() UNABLE to open run summary log file, continue anyhow\n",getName());
67 int kBad=initRunUser( runNo, rc_ints, rc_floats);
70 fprintf(mLogFile,
"L2-%s initRun() params checked for consistency, Error flag=0x%04x\n",getName(),kBad);
75 fprintf(mLogFile,
"L2-%s initRun() ABORT due to internal logic\n",getName());
81 fprintf(mLogFile,
"L2-%s initRun succesfull\n",getName());
83 #ifdef ADD_HARDCODED_DELAY
84 fprintf(mLogFile,
"WARN: HARDCODED_DELAY in compute() & decision() is ON\n");
97 L2VirtualAlgo2008::finishRun() {
99 if(mRunNumber<0)
return;
100 if(mLogFile)fprintf(mLogFile,
"L2-%s: finishRun(%d) called after %d seconds\n",getName(),mRunNumber ,mSecondsInRun);
105 sprintf(Fname,
"%s/run%d.l2%s.hist.bin",mOutDir1.c_str(),mRunNumber,getName());
106 printf(
"\nL2:%s::finishRun('%s') , save histo ...\n",getName(),Fname);
107 mHistFile = fopen(Fname,
"w");
111 printf(
" L2-%s: finishRun() UNABLE to open run summary log file, continue anyhow\n",getName());
113 fprintf(mLogFile,
"L2-%s histos NOT saved, I/O error\n",getName());
117 int nh=finishCommonHistos();
120 fprintf(mLogFile,
"L2-%s: %d histos saved to '%s'\n",getName(),nh,Fname);
141 L2VirtualAlgo2008::finishCommonHistos() {
144 for(j=0;j<mxHA;j++) {
145 if(hA[j]==0)
continue;
146 hA[j]->write(mHistFile);
151 L2Histo *hT[nHt]={mhTc,mhTd,mhTcd};
152 const char *text[nHt]={
"Compute ",
"Decision ",
"Deci+Comp"};
154 for(ih=0;ih<nHt;ih++) {
155 int iMax=-3, iFWHM=-4;
156 hT[ih]->findMax( &iMax, &iFWHM);
157 printf(
"L2-%s %s CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",getName(),text[ih],iMax, iFWHM,mEventsInRun);
160 fprintf(mLogFile,
"L2:%s %s CPU/eve MPV %d kTicks, FWHM=%d, seen eve=%d\n",getName(),text[ih],iMax, iFWHM,mEventsInRun);
163 if (mHistFile) {hT[ih]->write(mHistFile); nh++;}
167 mhN->write(mHistFile); nh++;
168 mhRc->write(mHistFile);nh++;
169 mhRd->write(mHistFile);nh++;
170 mhRa->write(mHistFile);nh++;
177 L2VirtualAlgo2008::~L2VirtualAlgo2008(){};
181 L2VirtualAlgo2008::readParams(
const char *fileN,
int mxPar,
int *iPar,
float *fPar) {
187 memset(iPar,0,mxPar*
sizeof(
int));
188 memset(fPar,0,mxPar*
sizeof(
int));
189 FILE *fd=fopen(fileN,
"r");
190 if(fd==0) { printf(
" L2VirtualAlgo2008::readParams failed to open =%s=\n",fileN);
return -2222;}
193 int nInt=0, nFloat=0;
200 char * ret=fgets(buf,mx,fd);
203 if(buf[0]==0)
continue;
204 if(buf[0]==
'#')
continue;
205 if(buf[0]==
'\n')
continue;
207 if (mode==0 && strstr(buf,
"INTS")) { mode=1;
continue; }
208 if (mode==1 && strstr(buf,
"FLOATS")) { mode=2;
continue; }
211 if(nInt>=mxPar) {nVal=-501;
break;}
212 int ret1=sscanf(buf,
"%i",iPar+nInt);
213 if(ret1!=1) {nVal=-100*mode -nInt;
break;}
217 if(nFloat>=mxPar) {nVal=-502;
break;}
218 int ret1=sscanf(buf,
"%f",fPar+nFloat);
219 if(ret1!=1) {nVal= -100*mode -nFloat;
break;}
226 printf(
" L2VirtualAlgo2008::readParams %d from '%s'\n",nVal,fileN);
233 L2VirtualAlgo2008::compute(
int token){
237 token&=L2eventStream2008::tokenMask;
239 #ifdef ADD_HARDCODED_DELAY
243 for(
int i=0;i<3*100;i++) {
float x=i*i; x=x;}
246 computeUser( token );
253 L2VirtualAlgo2008::computeStart(){
256 unsigned int high,low;
257 rdtsc_macro(low,high);
259 mComputeTimeStart=low;
260 unsigned long long ticks = high;
265 mSecondsInRun=(ticks- mRunStartTicks)/par_cpuTicksPerSecond;
267 mhRc->fill(mSecondsInRun);
277 L2VirtualAlgo2008::computeStop(
int token){
279 rdtscl_macro(mComputeTimeStop);
280 unsigned long xxx=mComputeTimeStop-mComputeTimeStart;
281 mComputeTimeDiff[token]=xxx;
290 L2VirtualAlgo2008::decision(
int token,
void **myL2Result){
297 rdtscl_macro(mDecisionTimeStart);
298 token&=L2eventStream2008::tokenMask;
301 mhRd->fill(mSecondsInRun);
303 #ifdef ADD_HARDCODED_DELAY
307 for(
int i=0;i<3*100;i++) {
float x=i*i; x=x;}
311 mAccept=decisionUser(token, myL2Result);
316 mhRa->fill(mSecondsInRun);
318 rdtscl_macro(mDecisionTimeStop);
319 mDecisionTimeDiff=mDecisionTimeStop-mDecisionTimeStart;
320 int kTick=mDecisionTimeDiff/1000;
324 kTick=(mDecisionTimeDiff+mComputeTimeDiff[token])/1000;
334 L2VirtualAlgo2008::printCalibratedData(
int token){
337 const int hitSize=mEveStream_btow[token].get_hitSize();
338 printf(
"printCalibratedData-%s: ---BTOW ADC list--- size=%d\n",getName(),hitSize);
340 for(i=0;i< hitSize;i++,hit++) {
345 printf(
" btow: i=%2d rdo=%4d adc=%d et=%.3f ene=%.3f\n",i,rdo,adc,et,ene);