StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TCU_2009.cc
1 //
2 // Pibero Djawotho <pibero@comp.tamu.edu>
3 // Texas A&M University Cyclotron Institute
4 // 7 Jan 2009
5 //
6 
7 #include "DSMLayer_LD301_2009.hh"
8 #include "TCU_2009.hh"
9 
10 TCU_2009::TCU_2009() : mDSMInput(0), mTCUInput(0)
11 {
12  defineTrigger("bemc-jp1-mb", 137222, 0x4020);
13  defineTrigger("eemc-jp1-mb", 137273, 0x4080);
14  defineTrigger("bemc-jp0-mb", 137501, 0x4010);
15  defineTrigger("bemc-jp0-mb", 137501, 0x4020);
16  defineTrigger("eemc-jp0-mb", 137551, 0x4040);
17  defineTrigger("eemc-jp0-mb", 137551, 0x4080);
18  defineTrigger("bemc-jp2", 137585, 0x0030);
19  defineTrigger("eemc-jp2", 137635, 0x00c0);
20  defineTrigger("jpsi-mb", 137705, 0x4008);
21  defineTrigger("ajp-mb", 999996, 0x4400);
22  defineTrigger("emc2-jp0-mb", 999997, 0x4100);
23  defineTrigger("emc2-jp0-mb", 999997, 0x4200);
24  defineTrigger("emc2-jp1-mb", 999998, 0x4200);
25  defineTrigger("emc2-jp2", 999999, 0x0300);
26 }
27 
28 void TCU_2009::read(const TriggerDataBlk& event)
29 {
30  EvtDescData* evtDesc = (EvtDescData*)((char*)&event+event.EventDesc_ofl.offset);
31  mDSMInput = evtDesc->DSMInput;
32 }
33 
34 void TCU_2009::read(const DSMLayer_LD301_2009& layer)
35 {
36  mTCUInput = layer[0].output & 0xffff;
37 }
38 
39 void TCU_2009::update()
40 {
41  mTCUInput = mDSMInput;
42 }
43 
44 void TCU_2009::defineTrigger(const char* name, int id, int mask)
45 {
46  mTriggers.insert(make_pair(id, make_pair(name, mask)));
47 }
48 
49 int TCU_2009::numberOfTriggers() const { return mTriggers.size(); }
50 
51 bool TCU_2009::isTrigger(int triggerId) const
52 {
53  pair<MapIterator, MapIterator> p = mTriggers.equal_range(triggerId);
54  for (MapIterator i = p.first; i != p.second; ++i)
55  if (isTrigger(i)) return true;
56  return false;
57 }
58 
59 string TCU_2009::triggerName(int triggerId) const
60 {
61  MapIterator i = mTriggers.find(triggerId);
62  return (i == mTriggers.end()) ? "" : triggerName(i);
63 }
64 
65 void TCU_2009::getTriggerMasks(int triggerId, vector<int>& masks) const
66 {
67  pair<MapIterator, MapIterator> p = mTriggers.equal_range(triggerId);
68  for (MapIterator i = p.first; i != p.second; ++i)
69  masks.push_back(triggerMask(i));
70 }
71 
72 int TCU_2009::barrelJetPatchBits(int triggerId) const
73 {
74  vector<int> masks;
75  getTriggerMasks(triggerId, masks);
76  return masks.empty() ? 0 : *min_element(masks.begin(), masks.end()) >> 4 & 0x3;
77 }
78 
79 int TCU_2009::endcapJetPatchBits(int triggerId) const
80 {
81  vector<int> masks;
82  getTriggerMasks(triggerId, masks);
83  return masks.empty() ? 0 : *min_element(masks.begin(), masks.end()) >> 6 & 0x3;
84 }
85 
86 int TCU_2009::emcJetPatchBits(int triggerId) const
87 {
88  vector<int> masks;
89  getTriggerMasks(triggerId, masks);
90  return masks.empty() ? 0 : *min_element(masks.begin(), masks.end()) >> 8 & 0x3;
91 }
92 
93 void TCU_2009::dump() const
94 {
95  //printf("TCU: 0x%04x\n", mTCUInput);
96  for (MapIterator i = mTriggers.begin(); i != mTriggers.end(); ++i)
97  printf("%s\t%d\t0x%04x\t%d\n", triggerName(i).c_str(), triggerId(i), triggerMask(i), isTrigger(i));
98 }