00001 #ifndef L2VirtualAlgo2009_h
00002 #define L2VirtualAlgo2009_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #define rdtscl_macro(low) \
00016 __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
00017
00018 #define rdtsc_macro(low,high) \
00019 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
00020
00021
00022 #include <string>
00023 #include "L2eventStream2009.h"
00024
00025 class L2EmcDb;
00026 class L2Histo;
00027 class L2VirtualAlgo2009 {
00028 public:
00029 enum EmcSwitch { kIsBad=0, kIsBtow, kIsEtow, kIsB_Etow };
00030 protected:
00031 bool algoIsOkay;
00032
00033
00034 enum {kMaximumNumberOfDsmMasks=4};
00035 bool useDsmMask;
00036 int nmasks;
00037 unsigned short DsmMask[kMaximumNumberOfDsmMasks][8];
00038
00039
00040 EmcSwitch mSwitch;
00041
00042 std::string mOutDir1, mName1;
00043 L2EmcDb *mDb;
00044 FILE *mLogFile, *mHistFile;
00045 L2Histo *mhN;
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 L2Histo *mhTc,*mhTd,*mhTcd;
00057 L2Histo *mhRc, *mhRd, *mhRa ;
00058 int oflTrigId;
00059 bool mAccept, mRandomAccept;
00060 int mEventsInRun;
00061 int mSecondsInRun;
00062 int mRunNumber;
00063 int mResultOffset;
00064
00065 int mRndAcceptCounter;
00066 int par_RndAcceptPrescale;
00067
00068 bool mNeeds_barrel;
00069 bool mNeeds_endcap;
00070 const L2BtowCalibData09 *mEveStream_btow;
00071 const L2EtowCalibData09 *mEveStream_etow;
00072
00073 enum {par_cpuTicksPerSecond=1600000000};
00074 unsigned long mComputeTimeStart, mComputeTimeStop, mComputeTimeDiff[L2eventStream2009::mxToken];
00075 unsigned long mDecisionTimeStart, mDecisionTimeStop, mDecisionTimeDiff;
00076 unsigned long long mRunStartTicks;
00077
00078 L2Histo **hA;
00079 int mxHA;
00080 void setMaxHist(int k) {
00081 if (!(k>0)) {
00082 criticalError("setMaxHist called with negative argument.");
00083 k=0;
00084 }
00085 mxHA=k; hA=new L2Histo*[mxHA];
00086 memset(hA,0,mxHA*sizeof(L2Histo*));
00087 }
00088 int finishCommonHistos();
00089
00090 void computeStart();
00091 void computeStop(int token);
00092 unsigned short swap_bytes(unsigned short in);
00093
00094 public:
00095 L2VirtualAlgo2009(const char* name, L2EmcDb* db, char*outDir, bool needsbarrel, bool needsendcap, int resOff);
00096 virtual ~L2VirtualAlgo2009();
00097 void setOflTrigID(int x) {oflTrigId=x;}
00098 int getOflTrigID() {return oflTrigId;}
00099 bool isAccepted(){ return mAccept; }
00100 static int readParams(const char *fileN, int mxPar, int *iPar, float *fPar);
00101 const char *getName() { return mName1.c_str();}
00102
00103 int initRun(int runNo, int *rc_ints, float *rc_floats);
00104 void compute (int token);
00105 bool decision(int token, bool barrel_is_in, bool endcap_is_in, int *myL2Result);
00106 void finishRun();
00107 bool checkDsmMask(unsigned short *lastDSM);
00108 int readDsmMask(const char *fileN);
00109
00110
00111 virtual int initRunUser(int runNo, int *rc_ints, float *rc_floats){ return 0;}
00112 virtual void computeUser(int token){};
00113 virtual bool decisionUser(int token, int *myL2Result){return true;}
00114 virtual void finishRunUser(){}
00115
00116
00117 void printCalibratedData(int token);
00118
00119 void criticalError(const char* message);
00120 };
00121
00122
00123 #endif