StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
L2VirtualAlgo2012.h
1 #ifndef L2VirtualAlgo2012_h
2 #define L2VirtualAlgo2012_h
3 
4 
5 /*************************************************************
6  * $Id: L2VirtualAlgo2012.h,v 1.3 2011/10/19 15:58:06 jml 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 "L2eventStream2012.h"
24 
25 class L2EmcDb2012;
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, muid;
43  L2EmcDb2012 *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 L2BtowCalibData12 *mEveStream_btow;
71  const L2EtowCalibData12 *mEveStream_etow;
72 
73  enum {par_cpuTicksPerSecond=1600000000};
74  unsigned long mComputeTimeStart, mComputeTimeStop, mComputeTimeDiff[L2eventStream2012::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  L2VirtualAlgo2012(const char* name, const char *uid, L2EmcDb2012* db, char*outDir, bool needsbarrel, bool needsendcap, int resOff);
96  virtual ~L2VirtualAlgo2012(); //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() {
102  return mName1.c_str();
103  }
104 
105  int initRun(int runNo, int *rc_ints, float *rc_floats);
106  void compute (int token);
107  bool decision(int token, bool barrel_is_in, bool endcap_is_in, int *myL2Result);
108  void finishRun();
109  bool checkDsmMask(unsigned short *lastDSM);
110  int readDsmMask(const char *fileN);
111 
112  // implement algo specific operations in the virtual functions
113  virtual int initRunUser(int runNo, int *rc_ints, float *rc_floats){ return 0;}
114  virtual void computeUser(int token){};
115  virtual bool decisionUser(int token, int *myL2Result){return true;}
116  virtual void finishRunUser(){}// at the end of each run
117 
118  // read-only access to current 'global' event, updated in compute
119  void printCalibratedData(int token);
120 
121  void criticalError(const char* message);
122 };
123 
124 
125 #endif