00001 #ifndef RC_CONFIG_HH
00002 #define RC_CONFIG_HH
00003
00004 #include <sys/types.h>
00005 #include <rtsSystems.h>
00006 #include <netinet/in.h>
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <rts.h>
00023
00024 #define CONFIG_VERSION 2004
00025
00026 #ifdef RTS_PROJECT_PP
00027 #define RC_PARAM_FILE_BASE_PATH "/PP/conf/handler/"
00028 #define TRG_BASE_PATH "/PP/conf/handler"
00029 #define DAQ_BASE_PATH "/PP/conf/handler"
00030 #else
00031 #define RC_PARAM_FILE_BASE_PATH "/RTS/conf/handler/"
00032 #define TRG_BASE_PATH "/home/startrg/trg/handler/conf"
00033 #define DAQ_BASE_PATH "/RTS/conf/handler"
00034 #endif
00035
00036
00037 #define TRG_CONFIG_FILE_NAME ""
00038 #define DAQ_CONFIG_FILE_NAME ""
00039 #define SC_CONFIG_FILE_NAME ""
00040 #define L3_CONFIG_FILE_NAME ""
00041
00042 #define MAX_REGISTERS 1500
00043 #define CFG_MAX_LABELS 200
00044 #define MAX_TRG_DICT_ENTRIES 1500
00045
00046 #ifdef RTS_PROJECT_PP
00047 #define MAX_ID 32
00048 #else
00049 #define MAX_ID 32
00050 #endif
00051 #define MAX_SUB 4
00052 #define MAX_INST 100
00053 #define MAX_TCD 20
00054
00055 #ifdef RTS_PROJECT_PP
00056 #define MAX_NODES 20
00057 #else
00058 #define MAX_NODES 200
00059 #endif
00060
00061 #define MAX_THREADS 400
00062 #define MAX_STR_LEN 40
00063
00064 #define TRIGGERS_MAX 64
00065 #define OLD_TRIGGERS_MAX 32
00066
00067 #define EVP_GROUP_MAX 32 // Number of EVP groups...
00068 #define CONDPERTRG_MAX 4 // Conditions per Trigger
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 #define RTS_STAT_TOKENS_DONE 8
00079 #define RTS_STAT_FORCE 9
00080 #define RTS_STAT_REQUEST 10
00081
00082 #define RTS_STARTRUN_FLAG 1
00083 #define RTS_STOPRUN_FLAG 2
00084 #define RTS_SENDCONFIG_FLAG 4
00085 #define RTS_STOPRUN_SECOND_FLAG 8
00086
00087
00088 typedef unsigned int UINT32;
00089 typedef unsigned short UINT16;
00090 typedef unsigned char UINT8;
00091 typedef unsigned long long int UINT64;
00092
00093 class UINT128 {
00094 public:
00095 UINT32 x[4];
00096
00097 UINT128() {
00098 zero();
00099 }
00100
00101 void zero() {
00102 x[0] = 0;
00103 x[1] = 0;
00104 x[2] = 0;
00105 x[3] = 0;
00106 }
00107
00108 int is_set(int bit) {
00109 int byt=bit/32;
00110 bit = bit % 32;
00111
00112 return (x[byt] & (1<<bit)) ? 1 : 0;
00113 }
00114
00115 void set(int bit) {
00116 int byt=bit/32;
00117 bit = bit % 32;
00118
00119 x[byt] |= (1<<bit);
00120 }
00121
00122 void clear(int bit) {
00123 int byt=bit/32;
00124 bit = bit % 32;
00125 x[byt] &= (~(1<<bit));
00126 }
00127
00128 char *tostring(char *out = (char *)NULL) {
00129 static char _out[70];
00130
00131 if(out == NULL) out = _out;
00132 sprintf(out, "%08x-%08x-%08x-%08x", x[3], x[2], x[1], x[0]);
00133 return out;
00134 }
00135
00136 };
00137
00138
00139
00140
00141
00142 struct TASK
00143 {
00144 u_short node;
00145 u_char task;
00146 u_char inrun;
00147 u_char stoprun;
00148 u_char start_order;
00149 u_char typically_inrun;
00150 u_char res2;
00151 };
00152
00153 struct SUBSYS_TASKS
00154 {
00155 TASK nodes[MAX_NODES];
00156 };
00157
00158 struct GLB_SETUP
00159 {
00160 char DICT_name[MAX_STR_LEN];
00161
00162
00163 char TRG_SETUP_name[MAX_STR_LEN];
00164 char TRG_RUN_name[MAX_STR_LEN];
00165 char TCD_SETUP_name[MAX_STR_LEN];
00166 char DAQ_SETUP_name[MAX_STR_LEN];
00167 char DAQ_RUN_name[MAX_STR_LEN];
00168 };
00169
00170
00171 struct GLB_RUN
00172 {
00173 char GLB_SETUP_name[MAX_STR_LEN];
00174 int run_number;
00175 float bField;
00176 float base_trg_rate;
00177 int destination;
00178
00179 float drift_velocity_east;
00180 float drift_velocity_west;
00181 unsigned int rhic_clock;
00182 float reserved[10];
00183 };
00184
00185 struct TRG_DICT_ENTRY
00186 {
00187 UINT32 object;
00188 UINT32 index;
00189 UINT32 reg;
00190 char label[MAX_STR_LEN];
00191 int dfault;
00192 char comment[MAX_STR_LEN];
00193 };
00194
00195 struct TRG_DICT
00196 {
00197
00198 TRG_DICT_ENTRY entry[MAX_TRG_DICT_ENTRIES];
00199 };
00200
00201 struct TcdSetup
00202 {
00203 UINT32 tcdId;
00204 UINT32 millisec;
00205 };
00206
00207
00208
00209
00210
00211
00212 #define L1_DSM_OBJECT 1
00213 #define BC1_DSM_OBJECT 2
00214 #define MXQ_QT_OBJECT 3
00215 #define MIX_DSM_OBJECT 4
00216 #define BCW_DSM_OBJECT 5
00217 #define BCE_DSM_OBJECT 6
00218 #define FEQ_QT_OBJECT 7
00219 #define BBC_DSM_OBJECT 8
00220 #define BBQ_QT_OBJECT 9
00221 #define FMS_DSM_OBJECT 10
00222 #define QT1_FMS_OBJECT 11
00223 #define QT2_FMS_OBJECT 12
00224 #define QT3_FMS_OBJECT 13
00225 #define QT4_FMS_OBJECT 14
00226 #define TRG_OBJECT 29
00227 #define DAQ_OBJECT 30 // Reserved for DAQ use..
00228 #define PHYSICS_BIT_OBJECT 32
00229 #define DETECTOR_BIT_OBJECT 33
00230 #define TCD_OBJECT 34
00231 #define L1_OBJECT 35
00232 #define L2_OBJECT 36
00233 #define L3_OBJECT 37 // Reserved for L3 use...
00234
00235 #define BIT_OBJECT 100 // Reserved for TCU bit labels
00236
00237 struct RegValue
00238 {
00239 UINT32 object;
00240 UINT32 index;
00241 UINT32 reg;
00242 UINT32 value;
00243 };
00244
00245 struct TrgLabels
00246 {
00247 char label[MAX_STR_LEN];
00248 int object;
00249 int value;
00250 int dfault;
00251 char comment[MAX_STR_LEN];
00252 };
00253
00254 struct LxAlgorithm
00255 {
00256 UINT32 id;
00257 int userInt[5];
00258 float userFloat[5];
00259 int specialProcessing;
00260 };
00261
00262 struct TwCondition
00263 {
00264 UINT32 Pw;
00265 UINT32 detectorLiveOnBits;
00266 UINT32 detectorLiveOffBits;
00267 };
00268
00269 struct PwCondition
00270 {
00271 UINT32 used;
00272 union {
00273 UINT32 onbits;
00274 UINT32 onbits_ex[4];
00275 };
00276 union {
00277 UINT32 offbits;
00278 UINT32 offbits_ex[4];
00279 };
00280 };
00281
00282 struct AwCondition
00283 {
00284 UINT32 TW;
00285 UINT32 PS;
00286 UINT32 AW;
00287 UINT32 pre;
00288 UINT32 post;
00289 };
00290
00291 struct TriggerData
00292 {
00293 int offlineBit;
00294
00295 int desiredTrgCmd;
00296 int desiredDaqCmd;
00297 int desiredPre;
00298 int desiredPost;
00299
00300 float expected_L0_fraction;
00301 float desired_L0_rate;
00302 float expected_L1_fraction;
00303 float desired_L1_rate;
00304 float expected_L2_fraction;
00305 float desired_L2_rate;
00306 float expected_L3_fraction;
00307 float desired_L3_rate;
00308
00309 int res;
00310 int dataStream;
00311 int tokenZero;
00312 int calibration;
00313 };
00314
00315
00316 struct Trigger
00317 {
00318 int used;
00319
00320 char name[MAX_STR_LEN];
00321
00322 TriggerData userdata;
00323 PwCondition L0conditions[CONDPERTRG_MAX];
00324
00325 int detectorLiveOnBits;
00326 int detectorLiveOffBits;
00327 int detectorRequest;
00328
00329 LxAlgorithm l1;
00330 LxAlgorithm l2;
00331 LxAlgorithm l3;
00332
00333 TcdSetup tcd;
00334 };
00335
00336 struct EvpGroup
00337 {
00338 char name[MAX_STR_LEN];
00339 int id;
00340 int definition[2];
00341 float rate;
00342 };
00343
00344 struct TRG_SETUP
00345 {
00346
00347
00348 char TIER1_name[MAX_STR_LEN];
00349
00350 Trigger triggers[TRIGGERS_MAX];
00351
00352 PwCondition contaminationDef;
00353
00354 char dataStreamNames[16][MAX_STR_LEN];
00355
00356 TrgLabels labels[CFG_MAX_LABELS];
00357 RegValue registers[MAX_REGISTERS];
00358
00359
00360 EvpGroup evpGroup[EVP_GROUP_MAX];
00361 };
00362
00363 struct TRG_RUN
00364 {
00365
00366 int configOpt;
00367
00368 int QT_Ped_Offset;
00369 int res2;
00370
00371 int useFastDMA;
00372 int res4;
00373
00374 int res5;
00375 int res6;
00376
00377 int res7;
00378 int res8;
00379
00380 int tcuType;
00381 int disableTOFmask;
00382
00383 int l2Disable750;
00384 int l2MyriAcc;
00385
00386 int l2LogLevel;
00387 int l2DisableAlgos;
00388
00389 int scaler_log_level;
00390
00391 int res15;
00392 int nToken;
00393 int tokenBitsOn;
00394 int tokenBitsOff;
00395 int useSTPnetwork;
00396 int res17;
00397
00398 int clockSource;
00399 int res18;
00400 int stopRunOnError;
00401
00402 int l2DataWrite;
00403 int dataWriteTimer;
00404 int everyNEvents;
00405 int nAbort;
00406
00407 int res19;
00408 int res20;
00409 int EvpPolicy;
00410
00411 };
00412
00413 struct TCD_ENTRY
00414 {
00415 int phase;
00416 int gg_width;
00417 int daq_busy;
00418 int delay4;
00419 int delay8;
00420 int res1;
00421 int res2;
00422 int res3;
00423 int res4;
00424 };
00425
00426 struct TCD_SETUP
00427 {
00428 int tcd_log_level;
00429 int res1;
00430 int res2;
00431 int res3;
00432 int res4;
00433 int res5;
00434 TCD_ENTRY tcd[MAX_TCD];
00435 };
00436
00437
00438
00439
00440
00441 struct DAQ_DET_SETUP
00442 {
00443 int ped_mode;
00444 int gain_mode;
00445 int analysis;
00446 int default_format;
00447
00448 u_char asic_seq_hi;
00449 u_char asic_seq_lo;
00450 u_char asic_thr_hi;
00451 u_char asic_thr_lo;
00452 int time_bin_lo;
00453 int time_bin_hi;
00454 int clust_charge_lo;
00455
00456 int raw_write;
00457 int cl_write;
00458 int cl_done;
00459 };
00460
00461 struct DAQ_SUBDET
00462 {
00463 u_int rb_mask;
00464 };
00465
00466 struct DAQ_DET
00467 {
00468 int log_level;
00469 int use_l2;
00470 int use_sl3;
00471
00472 int res1;
00473 int res2;
00474 int res3;
00475 int res4;
00476 int res5;
00477 int res6;
00478 int res7;
00479 int res8;
00480 int res9;
00481 int res10;
00482
00483 DAQ_SUBDET sub[24];
00484 };
00485
00486 struct DAQ_SETUP
00487 {
00488
00489 int run_type;
00490
00491 DAQ_DET_SETUP detectors[MAX_ID];
00492 };
00493
00494 struct DAQ_DAQ
00495 {
00496 int force_reset;
00497 int evp_suppression;
00498 int event_suppression;
00499 int evb_log_level;
00500 int myri_log_level;
00501 int bb_log_level;
00502 int gb_log_level;
00503 int evp_log_level;
00504 int mon_log_level;
00505 int write_pedestals;
00506 int res1;
00507 int res2;
00508 int res3;
00509 int res4;
00510 int res5;
00511 };
00512
00513 struct DAQ_RUN
00514 {
00515 DAQ_DAQ daq;
00516 DAQ_DET detectors[MAX_ID];
00517 };
00518
00519
00520
00521
00522
00523
00524 #ifndef RTS_PROJECT_PP
00525
00526 struct STAR_CFG
00527 {
00528 SUBSYS_TASKS subsys_tasks;
00529 GLB_RUN glb_run;
00530 TRG_DICT dict;
00531
00532 GLB_SETUP glb_setup;
00533
00534 TRG_SETUP trg_setup;
00535 TRG_RUN trg_run;
00536
00537 TCD_SETUP tcd_setup;
00538
00539 DAQ_SETUP daq_setup;
00540 DAQ_RUN daq_run;
00541
00542
00543
00544
00545 };
00546
00547 #endif // !PP
00548
00549 #ifdef RTS_PROJECT_PP
00550 struct PP_SETUP {
00551
00552 char daq_setup[MAX_STR_LEN];
00553 char filename[MAX_STR_LEN];
00554 u_int enable_mask;
00555 u_int resync;
00556 u_int p3;
00557 u_int p4;
00558 u_int p5;
00559 u_int p6;
00560 };
00561
00562 struct PP_RUN {
00563 char SETUP_name[MAX_STR_LEN];
00564 int run_number;
00565 u_int p1;
00566 u_int p2;
00567 u_int p3;
00568 u_int p4;
00569 u_int p5;
00570 u_int p6;
00571 };
00572
00573 struct PP_CFG
00574 {
00575 SUBSYS_TASKS subsys_tasks;
00576
00577 PP_SETUP setup;
00578 PP_RUN run;
00579 DAQ_SETUP daq_setup;
00580 DAQ_RUN daq_run;
00581 };
00582
00583 typedef PP_CFG STAR_CFG;
00584 #endif
00585
00586 typedef STAR_CFG DAQ_CFG;
00587 typedef STAR_CFG TRG_CFG;
00588 typedef STAR_CFG SC_CFG;
00589 typedef STAR_CFG L3_CFG;
00590
00591 typedef STAR_CFG RC_Config;
00592
00593
00594 #ifdef RTS_LITTLE_ENDIAN
00595
00596 void swapTASK(TASK *);
00597 void swapSUBSYS_TASKS(SUBSYS_TASKS *);
00598 void swapGLB_SETUP(GLB_SETUP *);
00599 void swapGLB_RUN(GLB_RUN *);
00600 void swapTRG_DICT_ENTRY(TRG_DICT_ENTRY *);
00601 void swapTRG_DICT(TRG_DICT *);
00602 void swapTcdSetup(TcdSetup *);
00603 void swapRegValue(RegValue *);
00604 void swapTrgLabels(TrgLabels *);
00605 void swapLxAlgorithm(LxAlgorithm *);
00606 void swapTwCondition(TwCondition *);
00607 void swapPwCondition(PwCondition *);
00608 void swapAwCondition(AwCondition *);
00609 void swapTriggerData(TriggerData *);
00610 void swapTrigger(Trigger *);
00611 void swapTRG_SETUP(TRG_SETUP *);
00612 void swapTRG_RUN(TRG_RUN *);
00613 void swapTCD_SETUP(TCD_SETUP *);
00614 void swapTCD_ENTRY(TCD_ENTRY *);
00615 void swapDAQ_DET_SETUP(DAQ_DET_SETUP *);
00616 void swapDAQ_DET(DAQ_DET *);
00617 void swapDAQ_SETUP(DAQ_SETUP *);
00618 void swapDAQ_DAQ(DAQ_DAQ *);
00619 void swapDAQ_RUN(DAQ_RUN *);
00620 void swapSTAR_CFG(STAR_CFG *);
00621
00622 #ifdef RTS_PROJECT_PP
00623 void swapPP_SETUP(PP_SETUP *);
00624 void swapPP_RUN(PP_RUN *);
00625 void swapPP_CFG(PP_CFG *);
00626 #endif
00627
00628 #else
00629 #define swapTASK(yada)
00630 #define swapSUBSYS_TASKS(yada)
00631 #define swapGLB_SETUP(yada)
00632 #define swapGLB_RUN(yada)
00633 #define swapTRG_DICT_ENTRY(yada)
00634 #define swapTRG_DICT(yada)
00635 #define swapTcdSetup(yada)
00636 #define swapRegValue(yada)
00637 #define swapTrgLabels(yada)
00638 #define swapL1Algorithm(yada)
00639 #define swapLxAlgorithm(yada)
00640 #define swapTwCondition(yada)
00641 #define swapPwCondition(yada)
00642 #define swapAwCondition(yada)
00643 #define swapTriggerData(yada)
00644 #define swapTrigger(yada)
00645 #define swapTRG_SETUP(yada)
00646 #define swapTRG_RUN(yada)
00647 #define swapTCD_ENTRY(yada)
00648 #define swapTCD_SETUP(yada)
00649 #define swapDAQ_DET_SETUP(yada)
00650 #define swapDAQ_DET(yada)
00651 #define swapDAQ_SETUP(yada)
00652 #define swapDAQ_DAQ(yada)
00653 #define swapDAQ_RUN(yada)
00654 #define swapSTAR_CFG(yada)
00655 #define swapPP_SETUP(yada)
00656 #define swapPP_RUN(yada)
00657 #define swapPP_CFG(yada)
00658 #endif
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 struct ic_msg;
00670
00671 char *cmd2name(int cmd);
00672 char *getConfigBase(char *filename, int port, int trg);
00673 char *getConfigBase(char *filename, ic_msg *m);
00674
00675
00676 int getConfigFile(STAR_CFG *cfg, ic_msg *m);
00677 int getConfigFile(STAR_CFG *cfg, char *filename);
00678
00679
00680 int putConfigFile(STAR_CFG *cfg, char *filename);
00681
00683
00685
00686
00687 struct TrgCfg;
00688 struct TrgPS;
00689
00690 void writeRCCNF(char *fn, STAR_CFG *cfg);
00691
00692 bool node_inrun(int node, STAR_CFG *cfg);
00693 bool system_inrun(int sys, STAR_CFG *cfg);
00694 void maskDetectorsInRun(STAR_CFG *cfg);
00695
00696
00697 bool cfgBuildPS(TrgPS *ps, RC_Config *rccfg);
00698
00699
00700
00701 struct TrgPSEntry {
00702 int l0ps;
00703 float l1ps;
00704 float l2ps;
00705 float l3ps;
00706 };
00707
00708 struct TrgPS {
00709 TrgPSEntry ps[TRIGGERS_MAX];
00710 };
00711
00712 struct EthServer
00713 {
00714 UINT16 node;
00715 UINT16 task;
00716 UINT32 ip;
00717 UINT32 port;
00718 };
00719
00720 struct EthServerName
00721 {
00722 char name[40];
00723 EthServer server;
00724 };
00725
00726
00727
00728 int getEthServer(int node, int task, EthServer *eth);
00729 char *ReadAllDotConf(int node, int task, char *param, char *result=(char *)NULL, char *paramfilename="/RTS/conf/handler/all.conf");
00730 int getAllEthServers(EthServerName *list, int max);
00731
00733
00734
00735
00736
00737
00738 class EvbChooser
00739 {
00740 public:
00741 EvbChooser() {};
00742 void configure(STAR_CFG *cfg, int legacy);
00743
00744
00745
00746 EthServer *choose(int token);
00747 int chooseIdx(int token);
00748
00749
00750 int chooseIdx_proper(int token);
00751
00752 EthServer servers[50];
00753 int nservers;
00754
00755 private:
00756 int evbNodes[10][5];
00757 int nevbserv[10];
00758 int nevbs;
00759 int evb4token[4096];
00760 };
00761
00762
00763 #define RHIC_TRG "RHICTRG\0"
00764 #define TRG_UDP_PORT 8060
00765
00766 struct RHIC_Trigger {
00767 char marker[4];
00768 int tm;
00769 int evb;
00770 int count;
00771 int mask;
00772 };
00773
00774 #endif
00775
00776
00777
00778
00779