StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_pmd.cxx
1 #include <sys/types.h>
2 #include <string.h>
3 
4 #include <rtsLog.h>
5 #include <rtsSystems.h>
6 
7 #include <SFS/sfs_index.h>
8 #include <DAQ_READER/daqReader.h>
9 #include <DAQ_READER/daq_dta.h>
10 
11 
12 #include "daq_pmd.h"
13 
14 extern int pmd_reader(char *m, struct pmd_t *pmd, u_int driver) ;
15 
16 const char *daq_pmd::help_string = "PMD tst\n" ;
17 
19 {
20 public:
22  daq_det_factory::det_factories[PMD_ID] = this ;
23  }
24 
25  daq_det *create() {
26  return new daq_pmd ;
27  }
28 } ;
29 
30 static daq_det_pmd_factory pmd_factory ;
31 
32 
33 
34 daq_pmd::daq_pmd(daqReader *rts_caller)
35 {
36  LOG(DBG,"PMD: rts_id %d, name %s",rts_id,name) ;
37 
38 
39  rts_id = PMD_ID ;
40  name = rts2name(rts_id) ;
41  sfs_name = "pmd" ;
42  caller = rts_caller ;
43  if(caller) caller->insert(this, rts_id) ;
44 
45  legacy = new daq_dta ;
46  raw = new daq_dta ;
47 
48  LOG(DBG,"%s: constructor: caller %p",name,caller) ;
49 }
50 
51 daq_pmd::~daq_pmd()
52 {
53  LOG(DBG,"%s: destructor",name) ;
54  if(caller) caller->de_insert(rts_id) ;
55 
56  delete legacy ;
57  delete raw ;
58 
59  return ;
60 }
61 
62 
63 daq_dta *daq_pmd::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
64 {
65  Make() ;
66  if(!present) return 0 ;
67 
68  if(strcmp(bank,"*")==0) bank = "legacy" ; // set default, if called with *
69 
70  if(strcasecmp(bank,"legacy") == 0) {
71  return handle_legacy() ;
72  }
73 
74  if(strcasecmp(bank,"raw") == 0) {
75  return handle_raw(c1) ;
76  }
77 
78  LOG(ERR,"%s: unknown bank %s",name,bank) ;
79  return 0 ;
80 
81 
82 }
83 
84 
85 daq_dta *daq_pmd::handle_legacy()
86 {
87 
88  // I need one object of pmd_t type but let the create decide on the necessary size
89  legacy->create(1,"pmd_t",rts_id,DAQ_DTA_STRUCT(pmd_t)) ;
90 
91 
92  pmd_t *pmd_p = (pmd_t *) legacy->request(1) ; // need ONE pmd_t object
93 
94  LOG(DBG,"PMD: present is %d",present) ;
95 
96  memset(pmd_p,0,sizeof(pmd_t)) ; // zap it!
97 
98  if(present & DET_PRESENT_DATAP) {
99  pmd_reader(caller->mem, pmd_p, 0) ;
100  }
101  else {
102  for(int s=1;s<=2;s++) { // need to get to both banks
103 
104  daq_dta *store = handle_raw(s) ;
105  if(store && store->iterate()) {
106  LOG(DBG,"PMD: calling reader with %p for %d",store->Void,s) ;
107  pmd_reader((char *)store->Void, pmd_p, s) ;
108  }
109  }
110  }
111 
112  legacy->finalize(1,0,0,0) ; // 1 entry; sector 0, row 0, pad 0
113  legacy->rewind() ;
114 
115  return legacy ;
116 }
117 
118 
119 daq_dta *daq_pmd::handle_raw(int sec) // counts from 1
120 {
121  char str[256] ;
122  char *full_name ;
123  char *st ;
124  int bytes ;
125 
126 
127 
128  sprintf(str,"%s/sec%02d/rb%02d/raw",sfs_name,sec,0) ;
129  full_name = caller->get_sfs_name(str) ;
130 
131  if(!full_name) return 0 ;
132 
133 
134  bytes = caller->sfs->fileSize(full_name) ;
135 
136  raw->create(bytes,"pmd_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
137  st = (char *) raw->request(bytes) ;
138 
139  int ret = caller->sfs->read(str,st,bytes) ;
140  if(ret != bytes) {
141  LOG(ERR,"PMD: ret is %d",ret) ;
142  }
143 
144  raw->finalize(bytes,sec,0,0) ;
145  raw->rewind() ;
146 
147  return raw ;
148 }
Definition: daq_pmd.h:7