StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2VirtualAlgo2009.h
1 #ifndef L2VirtualAlgo2009_h
2 #define L2VirtualAlgo2009_h
3 
4 
5 /*************************************************************
6  * $Id: L2VirtualAlgo2009.h,v 1.6 2011/03/20 02:14:50 pibero Exp $
7  * \author Jan Balewski, IUCF, 2006
8  *************************************************************
9  * Descripion:
10  * all actual L2 algos should inherit from it the 4 methods
11  *************************************************************
12  */
13 
14 // A great suggestion from Pibero, to use ASM macro directly
15 #define rdtscl_macro(low) \
16  __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
17 
18 #define rdtsc_macro(low,high) \
19  __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
20 
21 
22 #include <string>
23 #include "L2eventStream2009.h"
24 
25 class L2EmcDb;
26 class L2Histo;
28  public:
29  enum EmcSwitch { kIsBad=0, kIsBtow, kIsEtow, kIsB_Etow }; // changes action of some methods
30  protected:
31  bool algoIsOkay; //master 'this algorithm is working' flag.
32  //Flipped false if it fails consistency checks or is missing anything it needs
33 
34  enum {kMaximumNumberOfDsmMasks=4}; //needed for running with old TCU only.
35  bool useDsmMask; //needed for running with old TCU only.
36  int nmasks; //needed for running with old TCU only.
37  unsigned short DsmMask[kMaximumNumberOfDsmMasks][8]; //needed for running with old TCU only.
38 
39  //..... main Barrel/Endcap/Both switch
40  EmcSwitch mSwitch; // use enum above
41 
42  std::string mOutDir1, mName1;
43  L2EmcDb *mDb;
44  FILE *mLogFile, *mHistFile;
45  L2Histo *mhN; /* Neve(case),
46  bins: [0-4],[10-14], reserved for virtual09 algo
47  0 - # of input events
48  1 - # of calls computeUser()
49  2 - # of calls decisionUser()
50  3,4 - free
51  5...9 - user algo
52  10 - # of accepted events
53  11..14 - free
54  15...19 - user algo
55  */
56  L2Histo *mhTc,*mhTd,*mhTcd;/* time/eve : compute, decision, compute+decision */
57  L2Histo *mhRc, *mhRd, *mhRa ; /* rate/sec: compute, decision, accepted */
58  int oflTrigId; // important only for off-line analysis /w Makers
59  bool mAccept, mRandomAccept;
60  int mEventsInRun;
61  int mSecondsInRun;
62  int mRunNumber;
63  int mResultOffset; // tells us where in L2Result we are allowed to write.
64 
65  int mRndAcceptCounter; //counter for random accept.
66  int par_RndAcceptPrescale;//accept when counter%prescale=0, hence accept 1/prescale events. prescale=0==>don't rndaccept.
67 
68  bool mNeeds_barrel;
69  bool mNeeds_endcap;
70  const L2BtowCalibData09 *mEveStream_btow;
71  const L2EtowCalibData09 *mEveStream_etow;
72 
73  enum {par_cpuTicksPerSecond=1600000000};
74  unsigned long mComputeTimeStart, mComputeTimeStop, mComputeTimeDiff[L2eventStream2009::mxToken];
75  unsigned long mDecisionTimeStart, mDecisionTimeStop, mDecisionTimeDiff;
76  unsigned long long mRunStartTicks;
77 
78  L2Histo **hA; // my private HBOOK@L2
79  int mxHA; // set by user
80  void setMaxHist(int k) {
81  if (!(k>0)) {
82  criticalError("setMaxHist called with negative argument.");
83  k=0;
84  }
85  mxHA=k; hA=new L2Histo*[mxHA];
86  memset(hA,0,mxHA*sizeof(L2Histo*));
87  }
88  int finishCommonHistos();
89 
90  void computeStart();
91  void computeStop(int token);
92  unsigned short swap_bytes(unsigned short in);
93 
94  public:
95  L2VirtualAlgo2009(const char* name, L2EmcDb* db, char*outDir, bool needsbarrel, bool needsendcap, int resOff);
96  virtual ~L2VirtualAlgo2009(); //memory leak NOT taken care off
97  void setOflTrigID(int x) {oflTrigId=x;} //only for Maker-analysis
98  int getOflTrigID() {return oflTrigId;} //only for Maker-analysis
99  bool isAccepted(){ return mAccept; } // only for Maker-analysis
100  static int readParams(const char *fileN, int mxPar, int *iPar, float *fPar);
101  const char *getName() { return mName1.c_str();}
102 
103  int initRun(int runNo, int *rc_ints, float *rc_floats);
104  void compute (int token);
105  bool decision(int token, bool barrel_is_in, bool endcap_is_in, int *myL2Result);
106  void finishRun();
107  bool checkDsmMask(unsigned short *lastDSM);
108  int readDsmMask(const char *fileN);
109 
110  // implement algo specific operations in the virtual functions
111  virtual int initRunUser(int runNo, int *rc_ints, float *rc_floats){ return 0;}
112  virtual void computeUser(int token){};
113  virtual bool decisionUser(int token, int *myL2Result){return true;}
114  virtual void finishRunUser(){}// at the end of each run
115 
116  // read-only access to current 'global' event, updated in compute
117  void printCalibratedData(int token);
118 
119  void criticalError(const char* message);
120 };
121 
122 
123 #endif