StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_tpc.cxx
1 #include <sys/types.h>
2 #include <errno.h>
3 #include <assert.h>
4 
5 #include <rtsLog.h>
6 #include <rtsSystems.h>
7 
8 
9 
10 
11 #include <SFS/sfs_index.h>
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_dta.h>
14 
15 
16 #include "daq_tpc.h"
17 
18 extern int tpc_reader(char *m, tpc_t *tpc, int sec, int flag) ;
19 
20 
22 {
23 public:
25  daq_det_factory::det_factories[TPC_ID] = this ;
26  }
27 
28  daq_det *create() {
29  return new daq_tpc ;
30  }
31 } ;
32 
33 static daq_det_tpc_factory tpc_factory ;
34 
35 
36 
37 
38 daq_tpc::daq_tpc(daqReader *rts_caller)
39 {
40  rts_id = TPC_ID ;
41  name = sfs_name = rts2name(rts_id) ;
42 
43  caller = rts_caller ;
44  if(caller) caller->insert(this, rts_id) ;
45 
46  legacy = new daq_dta ;
47 
48  LOG(DBG,"%s: constructor: caller %p",name,rts_caller) ;
49  return ;
50 }
51 
52 daq_tpc::~daq_tpc()
53 {
54  LOG(DBG,"%s: DEstructor",name) ;
55 
56  delete legacy ;
57 
58  return ;
59 }
60 
61 
62 
63 daq_dta *daq_tpc::get(const char *bank, int sec, int row, int pad, void *p1, void *p2)
64 {
65  Make() ;
66  if(!present) return 0 ;
67 
68 
69  if(!bank || (strcasecmp(bank,"legacy")==0)) bank = "legacy" ;
70 
71 
72  if(strcasecmp(bank,"legacy")==0) {
73  return handle_legacy(sec,row) ;
74  }
75 
76 
77 
78  LOG(ERR,"%s: unknown bank type \"%s\"",name,bank) ;
79  return 0 ;
80 }
81 
82 daq_dta *daq_tpc::handle_legacy(int sec, int rdo)
83 {
84  int min_s, max_s ;
85  int found_something = 0 ;
86 
87  if(sec <= 0) {
88  min_s = 1 ;
89  max_s = 24 ;
90  }
91  else {
92  min_s = max_s = sec ;
93  }
94 
95  legacy->create((max_s-min_s+1)*sizeof(tpc_t),"tpc_t",rts_id,DAQ_DTA_STRUCT(tpc_t)) ;
96 
97  for(int s=min_s;s<=max_s;s++) {
98  int have ;
99 
100  tpc_t *tpc_p = (tpc_t *) legacy->request(1) ;
101 
102  // old tpc_reader wanted sectors counting from 0!!!
103  have = tpc_reader(caller->mem, tpc_p, s-1, m_Debug) ;
104 
105  if(have) {
106  found_something = 1 ;
107  legacy->finalize(1,s,0,0) ; // accept
108  }
109  else {
110  LOG(NOTE,"%s: sector %d: not found",name,s) ;
111  }
112 
113  }
114 
115  legacy->rewind() ;
116 
117  LOG(NOTE,"%s: done",name) ;
118 
119  if(found_something) return legacy ;
120  else return 0 ;
121 }
122 
123 
124 int daq_tpc::get_l2(char *buff, int buff_bytes, struct daq_trg_word *trg, int prompt)
125 {
126  trg[0].t = 1234 ;
127  trg[0].daq = 0 ;
128  trg[0].trg = 4 ; // TPC does not give the correct L0, only L2
129  trg[0].rhic = 0 ;
130 
131  return 1 ;
132 }
Definition: daq_tpc.h:22