Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mc2coda.h
Go to the documentation of this file.
1 /* mc2coda.h - Header File for mc2coda library */
2 
3 
4 
5 /* defines */
6 #define OK 0
7 #define ERROR -1
8 
9 #define MAX_PARAM 10
10 
11 /* Module Types (0-15) and modes */
12 /* (Updated 6/24/2013 by DL to be consistent with document: */
13 /* "VME Data Format Standards for JLAB Modules" */
14 enum type_id_t {
15  TID, // =0
16  FADC250, // =1
17  FADC125, // =2
18  F1TDC32, // =3
19  F1TDC48, // =4
20  JLAB_TS, // =5
21  TD, // =6
22  SSP, // =7
23  JLAB_DISC, // =8
31 
32  // The following are not defined by the DAQ group (i.e.
33  // they don't control the data format so can't encode
34  // the module type in it)
35  UNKNOWN, // =16
36  VMECPU, // =17
37  CAEN1190, // =18
38  CAEN1290, // =19
39 
40  N_MODULE_TYPES // Make sure this is the last thing in the enum!
41 };
42 //#define NOMOD 0
43 //#define VMECPU 1
44 //#define TID 2
45 //#define FADC250 3
46 #define FADC250_MODE_RW 1 /* Raw Window */
47 #define FADC250_MODE_WI 2 /* Window Integrated */
48 #define FADC250_MODE_RP 3 /* Raw Pulse */
49 #define FADC250_MODE_IP 4 /* Integrated Pulse */
50 //#define FADC125 4
51 #define FADC125_MODE_RW 1
52 #define FADC125_MODE_WI 2
53 #define FADC125_MODE_RP 3
54 #define FADC125_MODE_IP 4
55 
56 //#define F1TDC32 5
57 //#define F1TDC48 6
58 //#define CAEN1190 7
59 #define CAEN1190_MODE_TM 1 /* Trigger Matching mode */
60 //#define CAEN1290 8
61 #define CAEN1290_MODE_TM 1 /* Trigger Matching mode */
62 //#define JLDISC 10
63 //#define USERMOD 14
64 
65 
66 /* Define limits for CODA DAQ Systems */
67 #define MAX_EXP 10
68 #define MAX_CRATES 128
69 #define MAX_SLOTS 21
70 #define MIN_SLOT 2
71 #define MAX_SLOT 21
72 
73 #define MIN_TRIG_TIME 2048 /* minimum 8 microseconds for trigger time */
74 
75 #define MAX_EVENT_SIZE 1048576 /* 1 Megabyte Default Event buffer size */
76 #define MAX_HIT_SIZE 256 /* Max Bytes for 1 Hit - eg RAW window mode for FADC250 */
77 #define MAX_TOTAL_HITS 50000 /* Define maximum number of hits that can be stored */
78 #define MAX_HITS_PER_SLOT 500 /* Max hits stored per slot (module) */
79 #define MAX_HITS_PER_CHAN 50 /* Max hits allowed per channel - most modules will less than this */
80 
81 #define MC2CINIT_NULL 0
82 #define MC2CINIT_DEFINED 1
83 #define MC2CINIT_COMPLETE 2
84 
85 
86 typedef struct coda_crate_map {
87  int crate_id;
88  int nModules;
89  unsigned int moduleMask;
93 
94 typedef struct coda_exp_info {
95  char expname[64];
96  int ncrates;
97  int inited;
99  unsigned short rocid[MAX_CRATES];
101 } CODA_EXP_INFO;
102 
103 
104 typedef struct coda_event_info {
105  uint64_t eventid;
106  uint64_t trigtime;
107  uint32_t evtype;
109  int nhits;
112  int maxBytes;
113  unsigned int *evbuf;
115 
116 
117 typedef struct coda_hit_info {
118  int hit_id; /* Unique identifier for each "hit" */
119  int det_id; /* Detector ID 0<=val<=4095 */
120  int crate_id; /* Crate ID 0<=val<=127 */
121  int slot_id; /* Slot ID 2<=val<=21 */
122  int chan_id; /* Channel number - dependent on module type */
123  int module_id; /* User defined module type */
124  int module_mode; /* Module Operational Mode */
125  int module_param[MAX_PARAM]; /* Module specific program parameters - times - windows latencies etc...*/
126  uint32_t nwords; /* Number of words in the hdata array */
127  uint32_t *hdata; /* Hit data - dependent on module type and mode */
128 } CODA_HIT_INFO;
129 
130 
131 
132 /* Macros */
133 
134 #define ROC_BANK_OPEN(status, id, nevents) { \
135 StartOfRocBank = dabufp; \
136 *(++dabufp) = (((status) << 28) | (id) << 16) | 0x1000 | (nevents);\
137 (dabufp)++;
138 
139 #define ROC_BANK_CLOSE \
140 *StartOfRocBank = (uint32_t) (dabufp - StartOfRocBank -1); \
141 } \
142 
143 
144 #define DATA_BANK_OPEN(status, detid, nevents) { \
145 uint32_t *StartOfBank; \
146 StartOfBank = dabufp; \
147 *(++dabufp) = (((status) << 28) | (detid) << 16) | 0x0100 | (nevents);\
148 (dabufp)++;
149 
150 #define DATA_BANK_CLOSE \
151 *StartOfBank = (uint32_t) (dabufp - StartOfBank - 1); \
152 } \
153 
154 
155 
156 
157 
158 
159 /* Prototypes */
160 void mc2codaSetRunNumber(unsigned int run_number);
161 CODA_EXP_INFO *mc2codaInitExp(int nCrates, const char *name);
162 int mc2codaSetCrate(CODA_EXP_INFO *expID, int crateid, int nmod, int *modules, int *detid);
163 CODA_EVENT_INFO *mc2codaOpenEvent(CODA_EXP_INFO *expID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType, int maxSize);
164 int mc2codaWrite(CODA_EVENT_INFO *eventID, int nHits, struct coda_hit_info *codaHits);
165 void mc2codaStats(CODA_EVENT_INFO *eventID, int sflag);
166 unsigned int mc2codaCloseEvent(CODA_EVENT_INFO *eventID);
167 int mc2codaResetEvent(CODA_EVENT_INFO *eventID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType);
168 int mc2codaFreeEvent(CODA_EVENT_INFO *eventID);
169 void mc2codaFree(CODA_EXP_INFO *expID);
170 
uint32_t evtype
Definition: mc2coda.h:107
struct coda_hit_info * hits[MAX_CRATES][MAX_SLOTS]
Definition: mc2coda.h:111
char expname[64]
Definition: mc2coda.h:95
CODA_EXP_INFO * mc2codaInitExp(int nCrates, const char *name)
Definition: mc2coda.c:45
void mc2codaSetRunNumber(unsigned int run_number)
Definition: mc2coda.c:34
#define MAX_SLOTS
Definition: mc2coda.h:69
unsigned int mc2codaCloseEvent(CODA_EVENT_INFO *event)
Definition: mc2coda.c:347
int crate_id
Definition: mc2coda.h:120
struct coda_exp_info * expid
Definition: mc2coda.h:108
CODA_CRATE_MAP * crate[MAX_CRATES]
Definition: mc2coda.h:100
uint64_t eventid
Definition: mc2coda.h:105
int nModules
Definition: mc2coda.h:88
uint64_t trigtime
Definition: mc2coda.h:106
int hcount[MAX_CRATES][MAX_SLOTS]
Definition: mc2coda.h:110
unsigned int * evbuf
Definition: mc2coda.h:113
Definition: mc2coda.h:21
Definition: mc2coda.h:22
int module_map[MAX_SLOTS]
Definition: mc2coda.h:90
struct coda_event_info CODA_EVENT_INFO
int crate_id
Definition: mc2coda.h:87
Definition: mc2coda.h:36
int det_map[MAX_SLOTS]
Definition: mc2coda.h:91
int mc2codaSetCrate(CODA_EXP_INFO *expID, int crateid, int nmod, int *modules, int *detid)
Definition: mc2coda.c:102
int inited
Definition: mc2coda.h:97
int module_id
Definition: mc2coda.h:123
int module_mode
Definition: mc2coda.h:124
int openevents
Definition: mc2coda.h:98
unsigned short rocid[MAX_CRATES]
Definition: mc2coda.h:99
#define MAX_CRATES
Definition: mc2coda.h:68
int mc2codaFreeEvent(CODA_EVENT_INFO *eventID)
Definition: mc2coda.c:577
type_id_t
Definition: mc2coda.h:14
Definition: mc2coda.h:15
int module_param[MAX_PARAM]
Definition: mc2coda.h:125
struct coda_hit_info CODA_HIT_INFO
int ncrates
Definition: mc2coda.h:96
struct coda_crate_map CODA_CRATE_MAP
unsigned int moduleMask
Definition: mc2coda.h:89
#define MAX_PARAM
Definition: mc2coda.h:9
void mc2codaStats(CODA_EVENT_INFO *eventID, int sflag)
Definition: mc2coda.c:669
uint32_t nwords
Definition: mc2coda.h:126
struct coda_exp_info CODA_EXP_INFO
int mc2codaWrite(CODA_EVENT_INFO *event, int nHits, struct coda_hit_info *codaHits)
Definition: mc2coda.c:273
void mc2codaFree(CODA_EXP_INFO *expID)
Definition: mc2coda.c:639
int mc2codaResetEvent(CODA_EVENT_INFO *eventID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType)
Definition: mc2coda.c:483
uint32_t * hdata
Definition: mc2coda.h:127
CODA_EVENT_INFO * mc2codaOpenEvent(CODA_EXP_INFO *expID, uint64_t eventNum, uint64_t trigTime, unsigned short eventType, int maxSize)
Definition: mc2coda.c:155