StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DSMLayer_B001_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 "DSMAlgo_BW001_2009.hh"
8 #include "DSMAlgo_BW003_2009.hh"
9 #include "DSMAlgo_BE001_2009.hh"
10 #include "DSMAlgo_BE003_2009.hh"
11 #include "DSMLayer_B001_2009.hh"
12 
13 //DSMLayer_B001_2009::DSMLayer_B001_2009() : StDSMLayer(30) //<TriggerDataBlk>(30)
14 DSMLayer_B001_2009::DSMLayer_B001_2009() : DSMLayer<TriggerDataBlk>(30)
15 {
16  // West
17 
18  for (int dsm = 0; dsm < 15; ++dsm)
19  (*this)[dsm].setName("BW", 0, dsm);
20 
21  // East
22 
23  for (int dsm = 15; dsm < 30; ++dsm)
24  (*this)[dsm].setName("BE", 0, dsm-15);
25 }
26 
27 bool DSMLayer_B001_2009::read(const TriggerDataBlk& event)
28 {
29  // BEMC West
30 
31  bool bcw_in = event.MainX[BCW_CONF_NUM].offset && event.MainX[BCW_CONF_NUM].length;
32 
33  if (bcw_in) {
34  BWestBlock* bcw = (BWestBlock*)(((char *)&event)+event.MainX[BCW_CONF_NUM].offset);
35  // 15 DSMs * 16 channels
36  char cbuffer[15*16];
37  for (int dsm = 0; dsm < 15; ++dsm) {
38  copy_and_swap16(&cbuffer[dsm*16], &bcw->BEMCWest[dsm*16]);
39  char* cpMin = &cbuffer[dsm*16];
40  char* cpMax = cpMin+15;
41  short* sp = (*this)[dsm].channels;
42  for (char* cp = cpMin; cp < cpMax; cp += 3) {
43  int* ip = (int*)cp;
44  *sp++ = *ip & 0xfff;
45  *sp++ = *ip >> 12 & 0xfff;
46  }
47  }
48  }
49 
50  // BEMC East
51 
52  bool bce_in = event.MainX[BCE_CONF_NUM].offset && event.MainX[BCE_CONF_NUM].length;
53 
54  if (bce_in) {
55  BEastBlock* bce = (BEastBlock*)(((char *)&event)+event.MainX[BCE_CONF_NUM].offset);
56  // 15 DSMs * 16 channels
57  char cbuffer[15*16];
58  for (int dsm = 0; dsm < 15; ++dsm) {
59  copy_and_swap16(&cbuffer[dsm*16], &bce->BEMCEast[dsm*16]);
60  char* cpMin = &cbuffer[dsm*16];
61  char* cpMax = cpMin+15;
62  short* sp = (*this)[dsm+15].channels;
63  for (char* cp = cpMin; cp < cpMax; cp += 3) {
64  int* ip = (int*)cp;
65  *sp++ = *ip & 0xfff;
66  *sp++ = *ip >> 12 & 0xfff;
67  }
68  }
69  }
70 
71  return (bcw_in || bce_in);
72 }
73 
74 void DSMLayer_B001_2009::write(DSMLayer<TriggerDataBlk>& layer)
75 {
76  int dsm = 0;
77  int dsmWest = 0;
78  int dsmEast = 15;
79 
80  // Loop over BEMC layer 1 DSM's
81 
82  while (dsm < 6) {
83 
84  // BC101/103/105
85 
86  layer[dsm].channels[0] = (*this)[dsmEast++].output; // BE001/BE006/BE011
87  layer[dsm].channels[1] = (*this)[dsmWest++].output; // BW001/BW006/BW011
88  layer[dsm].channels[2] = (*this)[dsmEast++].output; // BE002/BE007/BE012
89  layer[dsm].channels[3] = (*this)[dsmWest++].output; // BW002/BW007/BW012
90  layer[dsm].channels[4] = (*this)[dsmEast].output & 0xffff; // BE003/BE008/BE013 JP1 (0-15)
91  layer[dsm].channels[5] = (*this)[dsmWest].output & 0xffff; // BW003/BW008/BW013 JP1 (0-15)
92 
93  ++dsm;
94 
95  // BC102/104/106
96 
97  layer[dsm].channels[0] = (*this)[dsmEast++].output >> 16 & 0xffff; // BE003/BE008/BE013 JP6 (16-31)
98  layer[dsm].channels[1] = (*this)[dsmWest++].output >> 16 & 0xffff; // BW003/BW008/BW013 JP6 (16-31)
99  layer[dsm].channels[2] = (*this)[dsmEast++].output; // BE004/BE009/BE014
100  layer[dsm].channels[3] = (*this)[dsmWest++].output; // BW004/BW009/BW014
101  layer[dsm].channels[4] = (*this)[dsmEast++].output; // BE005/BE010/BE015
102  layer[dsm].channels[5] = (*this)[dsmWest++].output; // BW005/BW010/BW015
103 
104  ++dsm;
105  }
106 }
107 
108 void DSMLayer_B001_2009::run()
109 {
110  // West
111 
112  int dsm = 0;
113 
114  while (dsm < 15) {
115  DSMAlgo_BW001_2009()((*this)[dsm++]); // BW001/BW006/BW011
116  DSMAlgo_BW001_2009()((*this)[dsm++]); // BW002/BW007/BW012
117  DSMAlgo_BW003_2009()((*this)[dsm++]); // BW003/BW008/BW013
118  DSMAlgo_BW001_2009()((*this)[dsm++]); // BW004/BW009/BW014
119  DSMAlgo_BW001_2009()((*this)[dsm++]); // BW005/BW010/BW015
120  }
121 
122  // East
123 
124  while (dsm < 30) {
125  DSMAlgo_BE001_2009()((*this)[dsm++]); // BE001/BE006/BE011
126  DSMAlgo_BE001_2009()((*this)[dsm++]); // BE002/BE007/BE012
127  DSMAlgo_BE003_2009()((*this)[dsm++]); // BE003/BE008/BE013
128  DSMAlgo_BE001_2009()((*this)[dsm++]); // BE004/BE009/BE014
129  DSMAlgo_BE001_2009()((*this)[dsm++]); // BE005/BE010/BE015
130  }
131 }