StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_l3.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 #include "daq_l3.h"
12 
13 extern int l3_reader(char *m, struct l3_t *l3, u_int driver) ;
14 
15 const char *daq_l3::help_string = "L3 tst\n" ;
16 
18 {
19 public:
21  daq_det_factory::det_factories[L3_ID] = this ;
22  }
23 
24  daq_det *create() {
25  return new daq_l3 ;
26  }
27 } ;
28 
29 static daq_det_l3_factory l3_factory ;
30 
31 
32 
33 daq_l3::daq_l3(daqReader *rts_caller)
34 {
35  LOG(DBG,"L3: rts_id %d, name %s",rts_id,name) ;
36 
37  // dname is ignored
38  rts_id = L3_ID ;
39  name = rts2name(rts_id) ;
40  sfs_name = "l3" ;
41  caller = rts_caller ;
42  if(caller) caller->insert(this, rts_id) ;
43 
44  legacy = new daq_dta ;
45 
46  LOG(DBG,"%s: constructor: caller %p",name,caller) ;
47 }
48 
49 daq_l3::~daq_l3()
50 {
51  LOG(DBG,"%s: destructor",name) ;
52  if(caller) caller->de_insert(rts_id) ;
53 
54  delete legacy ;
55 
56  return ;
57 }
58 
59 
60 daq_dta *daq_l3::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
61 {
62  Make() ;
63  if(!present) return 0 ;
64 
65  if(strcmp(bank,"*")==0) bank = "legacy" ; // set default, if called with *
66 
67  if(strcasecmp(bank,"legacy") != 0) {
68  LOG(ERR,"%s: unknown bank %s",name,bank) ;
69  return 0 ;
70  }
71 
72  return handle_legacy() ;
73 
74 }
75 
76 
77 daq_dta *daq_l3::handle_legacy()
78 {
79 
80  // I need one object of l3_t type but let the create decide on the necessary size
81  legacy->create(1,"l3_t",rts_id,DAQ_DTA_STRUCT(l3_t)) ;
82 
83 
84  l3_t *l3_p = (l3_t *) legacy->request(1) ; // need ONE l3_t object
85 
86  if(present & DET_PRESENT_DATAP) {
87  l3_reader(caller->mem, l3_p, 0) ;
88  }
89  else {
90  char str[256] ;
91  char *full_name ;
92 
93  sprintf(str,"gl3/l3_gtd") ;
94  full_name = caller->get_sfs_name(str) ;
95 
96  LOG(DBG,"full_name %s",full_name) ;
97 
98  if(!full_name) {
99  sprintf(str,"l3/l3_gtd") ;
100  full_name = caller->get_sfs_name(str) ;
101 
102  LOG(DBG,"full_name %s",full_name) ;
103 
104 
105  if(!full_name) return 0 ;
106  }
107 
108  int bytes = caller->sfs->fileSize(full_name) ;
109 
110  LOG(DBG,"bytes %d",bytes) ;
111 
112  char *mem = (char *)valloc(bytes) ;
113 
114 
115  int ret = caller->sfs->read(str, mem, bytes) ;
116 
117  LOG(DBG,"ret %d",ret) ;
118 
119  l3_reader(mem, l3_p, 1) ;
120 
121  free(mem) ;
122  }
123 
124  legacy->finalize(1,0,0,0) ; // 1 entry; sector 0, row 0, pad 0
125  legacy->rewind() ;
126 
127  return legacy ;
128 }
Definition: daq_l3.h:10
Definition: daq_l3.h:26