#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include "OnlineUtil/msgLogLib/msgLog.h"#include "OnlineUtil/rototalk.h"#include "OnlineUtil/rotoMessages.h"Go to the source code of this file.
Defines | |
| #define | MAXBUFFER 8388608 |
Functions | |
| int | send_whole_file (const char *fname, long *buffer, int bsize, int mxrec) |
| int | config_autosave (const char *config) |
| int | config_compress (const char *config) |
| int | config_basketsize (const char *config) |
| int | main (int argc, char **argv) |
|
|
Definition at line 20 of file daq_bin2roto.c. |
|
|
Referenced by main(). |
|
|
Referenced by main(). |
|
|
Referenced by main(). |
|
||||||||||||
|
COMMAND LINE CALIB CONSTANTS BEAM RUN KEY Cerenkov ADC cuts: ATTENUATION PARAMS FILE + TREE Definition at line 55 of file daq_bin2roto.c. References config_autosave(), config_basketsize(), config_compress(), logDebugLevelSet(), logNotice(), msgLogCleanup(), msgLogInit(), msgLogLocalEchoSet(), msgLogNodeIdSet(), port, producer(), roto_close_connection(), roto_open_connection(), roto_open_DCP_connection(), roto_set_connection_nodelay(), roto_verbose, and send_whole_file(). 00056 {
00057
00058 /* this is C ... all declarations must come first */
00059 const char* iphost = "localhost";
00060 const char* default_producer = "DCP"; /* default producer */
00061 const int default_port = 9011; /* default port */
00062 const char* producer = default_producer;
00063 const char* autosave_config = 0;
00064 const char* compress_config = 0;
00065 const char* basketsize_config = 0;
00066 int port = default_port;
00067 int whoami = MINOS_ROOTER_DCP;
00068 int bsize = MAXBUFFER;
00069 long* buffer = 0;
00070 int nerr = 0;
00071 int mxrec = 0;
00072 int nodelay_flag = 1; /* on by default */
00073 int echoMsgLog = 0;
00074 int copt;
00075
00076 /*
00077 * parse the options and filenames
00078 * -i and -p take args
00079 */
00080 while ((copt = getopt(argc, argv, "i:b:c:C:B:w:p:ev:n:D:h")) != EOF) {
00081 switch (copt) {
00082 case 'i': /* internet host */
00083 iphost = optarg;
00084 break;
00085 case 'b': /* buffer size */
00086 bsize = atoi(optarg);
00087 break;
00088 case 'c': /* autosave config string */
00089 autosave_config = optarg;
00090 break;
00091 case 'C': /* compression config string */
00092 compress_config = optarg;
00093 break;
00094 case 'B': /* basketsize config string */
00095 basketsize_config = optarg;
00096 break;
00097 case 'w': /* whoami: DCP, DCS, other */
00098 producer = optarg;
00099 break;
00100 case 'p': /* port # */
00101 port = atoi(optarg);
00102 break;
00103 case 'e': /* msgLog messages to stdout as well */
00104 echoMsgLog = 1;
00105 break;
00106 case 'v': /* verbosity */
00107 roto_verbose = atoi(optarg);
00108 break;
00109 case 'n': /* maximum number of records */
00110 mxrec = atoi(optarg);
00111 break;
00112 case 'D': /* set nodelay_flag? */
00113 nodelay_flag = atoi(optarg);
00114 break;
00115 case 'h': /* help */
00116 printf(" usage: %s -i<hostname> -b<buffer size> -w<whoami> -p<port #> <filenames..>\n", argv[0]);
00117 printf(" -i: hostname where rotorooter is running\n");
00118 printf(" -b: buffer size to use\n");
00119 printf(" -w: DCP or DCS\n");
00120 printf(" -p: port number rotorooter is listening on\n");
00121 printf(" -v: how verbose to be\n");
00122 printf(" -c: autosave config \"streamName,nrec,nsec[;streamName,nrec,nsec]\"\n");
00123 printf(" -C: compression config \"streamName,level[;streamName,level]\"\n");
00124 printf(" -B: basketsize config \"streamName,size[;streamName,size]\"\n");
00125
00126 printf(" -n: maximum number of records from each file\n");
00127
00128 printf(" -h: print this message\n");
00129 exit(1);
00130 default:
00131 printf(" unrecognized option '%c' ignored\n",(char)optopt);
00132 break;
00133 }
00134 }
00135
00136 msgLogInit(argv[0]);
00137 msgLogNodeIdSet(whoami);
00138 msgLogLocalEchoSet(echoMsgLog);
00139 logDebugLevelSet(3);
00140 logNotice("starting %s",argv[0]);
00141
00142 /* allocate a buffer to use */
00143 buffer = (long*) malloc(bsize);
00144 if (!buffer) {
00145 printf("failed to allocate buffer of size %d\n",bsize);
00146 exit(1);
00147 }
00148 if (roto_verbose>1) printf("allocated buffer of size %d\n",bsize);
00149
00150 /* open a connection to the Rotorooter */
00151 if (0 == strcmp(producer,default_producer) &&
00152 port == default_port) {
00153 /* standard connection */
00154 if (roto_verbose>1)
00155 printf("connect via roto_open_DCP_connection\n");
00156 nerr += roto_open_DCP_connection(iphost);
00157 } else {
00158 /* non-standard connection requested (either producer or port) */
00159 if (0 == strcmp(producer,"DCP")) {
00160 whoami = MINOS_ROOTER_DCP;
00161 }
00162 else if (0 == strcmp(producer,"DCS")) {
00163 whoami = MINOS_ROOTER_DCS;
00164 }
00165 else if (0 == strcmp(producer,"BEAMMON")) {
00166 whoami = MINOS_ROOTER_BEAMMON;
00167 }
00168 else
00169 whoami = MINOS_ROOTER_UNIDENTIFIED_CLIENT;
00170
00171 if (roto_verbose>1)
00172 printf("connect via roto_open_connection: port %d, whoami %s (0x%2.2x)\n",port,producer,whoami);
00173 nerr += roto_open_connection(iphost,port,whoami);
00174 }
00175 if (nerr) exit(nerr);
00176
00177 nerr += roto_set_connection_nodelay(nodelay_flag);
00178
00179 if (autosave_config) nerr += config_autosave(autosave_config);
00180 if (compress_config) nerr += config_compress(compress_config);
00181 if (basketsize_config) nerr += config_basketsize(basketsize_config);
00182
00183 /* process each file in turn */
00184 while (optind < argc) {
00185 nerr += send_whole_file(argv[optind++],buffer,bsize,mxrec);
00186 }
00187
00188 /* close the connection */
00189 nerr += roto_close_connection();
00190
00191 /* set my buffer free */
00192 free(buffer);
00193
00194 logNotice("stopping %s",argv[0]);
00195 msgLogCleanup();
00196
00197 exit(nerr);
00198 }
|
|
||||||||||||||||||||
|
Definition at line 217 of file daq_bin2roto.c. References roto_close_named_file(), roto_open_named_file(), and roto_send_record(). Referenced by main(). 00218 {
00219
00220 FILE* file;
00221 long size;
00222 int nRecords=0;
00223 int nbytes;
00224 const char* lastslash;
00225 #ifdef DUMPALL
00226 int i;
00227 #endif
00228
00229
00230 char rootfname[1024];
00231 int nerr = 0;
00232
00233 nerr = 0;
00234
00235 /*
00236 * strip off any leading path
00237 */
00238 lastslash = strrchr(fname,'/');
00239 if (lastslash) ++lastslash;
00240 else lastslash = fname;
00241 sprintf(rootfname,"%s",lastslash);
00242
00243 file=fopen(fname,"rb");
00244 if (file==NULL) {
00245 printf("Failed to open input file: '%s'\n",fname);
00246 return 1;
00247 }
00248
00249 /*
00250 * WARNING, WARNING, WARNING!
00251 * this should be the ONLY place roto_open_file() is ever used
00252 * code in the DCP one should use
00253 * roto_open_daqfile(int detector, int run, int subrun);
00254 * in order that multi-file capabilities are enabled
00255 */
00256 nerr += roto_open_named_file(rootfname);
00257 if (nerr) {
00258 printf("Rotorooter failed to open output file: '%s'\n",rootfname);
00259 return 1;
00260 }
00261
00262 /*
00263 * NB These binary files are a temporary measure
00264 * ROOT files will replace them soon
00265 *
00266 * Format is
00267 * [#bytes in record] [record data]
00268 * [#bytes in record] [record data]
00269 * and so on
00270 *
00271 * The record data contains the 'data' DAQ blocks
00272 * : TP singles summary
00273 * : Snarl header
00274 * : Crate Readout
00275 * - identify them by their block ID.
00276 *
00277 * You may find others that are of no interest so branch on block ID
00278 *
00279 * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/tp-singles.html
00280 * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/snarl-header.html
00281 * See http://hepunx.rl.ac.uk/minos/daq/data-format/blocks/crate-readout.html
00282 *
00283 */
00284
00285 while(!feof(file)){
00286 if (mxrec>0 && nRecords==mxrec) break;
00287 if (fread(&size,sizeof(long),1,file)==1) {
00288 nRecords++;
00289 nbytes = size-sizeof(long); /* byte count is inclusive */
00290 if (nbytes>bsize) {
00291 printf("Record %d Size %d bytes too large for buffer (%d)\n",
00292 nRecords,nbytes,bsize);
00293 printf("Skip the rest of '%s'\n",fname);
00294 break;
00295 }
00296 #ifdef DUMPALL
00297 printf("Record %d Size = %d bytes (0x%03x words follow)\n",
00298 nRecords,size,(size-sizeof(long))/sizeof(long));
00299 #endif
00300 if (fread(buffer,nbytes,1,file)==1) {
00301 #ifdef DUMPALL
00302 /* this is the old "dump" code */
00303 for (i=0;i<(size-4)/sizeof(int);i++) {
00304 printf("0x%03x: 0x%08x\n",i,buffer[i]);
00305 }
00306 #endif
00307 /* send the record */
00308 nerr += roto_send_record(buffer,nbytes);
00309 }
00310 }
00311 }
00312
00313 fclose(file);
00314
00315 /*
00316 * WARNING, WARNING, WARNING!
00317 * this should be the ONLY place roto_close_file() is ever used
00318 * code in the DCP one should use
00319 * roto_close_daqfile(int detector, int run, int subrun);
00320 * in order that multi-file capabilities are enabled
00321 */
00322 nerr += roto_close_named_file(rootfname);
00323 return nerr;
00324 }
|
1.3.9.1