MIDAS
Loading...
Searching...
No Matches
odbinit.cxx File Reference
#include <stdio.h>
#include <string>
#include "midas.h"
#include "msystem.h"
#include "mstrlcpy.h"
Include dependency graph for odbinit.cxx:

Go to the source code of this file.

Functions

static std::string to_string (int v)
 
static std::vector< std::string > split (const char *sep, const std::string &s)
 
static std::string join (const char *sep, const std::vector< std::string > &v)
 
static std::vector< std::string > remove_dot_dot (const std::vector< std::string > &v)
 
static void usage ()
 
int DecodeSize (const char *s)
 
std::pair< double, std::string > HumanUnits (int odb_size)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ DecodeSize()

int DecodeSize ( const char s)

Definition at line 89 of file odbinit.cxx.

90{
91 // The disticntion between kB and kb is ignored...
92 // We assume the user means Bytes not bits
93
94 int size=0;
95 if (s) {
96 //strtoul ignores any no numic characters (the UNITS)
97 size = strtoul(s, NULL, 0);
98 }
99
100 const char units[] = {'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
101 int one_k=1000;
102 //Search of 'i' in string (for kiB, MiB, GiB etc)
103 for (size_t i=0; i<sizeof(s); i++)
104 {
105 if (s[i]=='i')
106 one_k=1024;
107 }
108 //Search of major unit
109 for (size_t i=0; i<sizeof(s); i++)
110 {
111 for (int j=0; j<8; j++)
112 {
113 if (s[i]==units[j])
114 {
115 //Only the first unit is used... kMB is meaningless
116 while (j>-1)
117 {
118 size*=one_k;
119 j--;
120 }
121 return size;
122 }
123 }
124 }
125 return size;
126}
INT i
Definition mdump.cxx:32
INT j
Definition odbhist.cxx:40
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HumanUnits()

std::pair< double, std::string > HumanUnits ( int  odb_size)

Definition at line 128 of file odbinit.cxx.

129{
130 int unit_index=0;
132 const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
133 while (odb_human_size > 1000) {
134 odb_human_size /= 1000;
135 unit_index++;
136 }
138}
INT odb_size
Definition analyzer.cxx:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ join()

static std::string join ( const char sep,
const std::vector< std::string > &  v 
)
static

Definition at line 44 of file odbinit.cxx.

45{
46 std::string s;
47
48 for (unsigned i=0; i<v.size(); i++) {
49 if (i>0) {
50 s += sep;
51 }
52 s += v[i];
53 }
54
55 return s;
56}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char argv[] 
)

Definition at line 142 of file odbinit.cxx.

143{
144 // set unbuffered output
147
149 char exp_name[NAME_LENGTH];
150
151 /* get default from environment */
153
154 printf("Checking environment... experiment name is \"%s\", remote hostname is \"%s\"\n", exp_name, host_name);
155
156 if (strlen(host_name) > 0) {
157 printf("Error: trying to use a remote connection to host \"%s\". odbinit must run locally. Sorry.\n", host_name);
158 exit(1);
159 }
160
161 bool cleanup = false;
162 bool dry_run = false;
163 bool create_exptab = false;
164 bool create_env = false;
165 int odb_size = 0; // DEFAULT_ODB_SIZE;
166
167 /* parse command line parameters */
168 for (int i = 1; i < argc; i++) {
169 if (strcmp(argv[i], "-g") == 0) {
170 //debug = TRUE;
171 } else if (strcmp(argv[i], "-n") == 0) {
172 dry_run = true;
173 } else if (strcmp(argv[i], "--exptab") == 0) {
174 create_exptab = true;
175 } else if (strcmp(argv[i], "--env") == 0) {
176 create_env = true;
177 } else if (strcmp(argv[i], "--cleanup") == 0) {
178 cleanup = true;
179 } else if (strcmp(argv[i], "-e") == 0) {
180 i++;
181 mstrlcpy(exp_name, argv[i], sizeof(exp_name));
182 } else if (strcmp(argv[i], "-s") == 0) {
183 i++;
185 } else {
186 usage(); // DOES NOT RETURN
187 }
188 }
189
190 printf("Checking command line... experiment \"%s\", cleanup %d, dry_run %d, create_exptab %d, create_env %d\n", exp_name, cleanup, dry_run, create_exptab, create_env);
191
192#ifndef NO_LOCAL_ROUTINES
193
194 if (create_exptab) {
195 printf("Creating a new exptab file in the current directory...\n");
196
197 FILE *fpr = fopen("exptab", "r");
198 if (fpr) {
199 fclose(fpr);
200 printf("Error: exptab already exists in the current directory. Sorry...\n");
201 exit(1);
202 }
203
204 if (strlen(exp_name) < 1) {
205 mstrlcpy(exp_name, "Default", sizeof(exp_name));
206 }
207 if (strchr(exp_name, ' ')) {
208 printf("Error: experiment name \"%s\" should not contain a space character. Sorry...\n", exp_name);
209 exit(1);
210 }
211 const char* pwd = getenv("PWD");
212 if (!pwd || strlen(pwd)<1) {
213 printf("Error: env.variable PWD is not defined or is empty. Sorry...\n");
214 exit(1);
215 }
216 if (strchr(pwd, ' ')) {
217 printf("Error: env.variable PWD value \"%s\" should not contain a space character. Sorry...\n", pwd);
218 exit(1);
219 }
220 const char* user = getenv("USER");
221 if (!user || strlen(user)<1) {
222 printf("Error: env.variable USER is not defined or is empty. Sorry...\n");
223 exit(1);
224 }
225 if (strchr(user, ' ')) {
226 printf("Error: env.variable USER value \"%s\" should not contain a space character. Sorry...\n", user);
227 exit(1);
228 }
229 printf("Experiment name [%s], experiment directory [%s], username [%s]\n", exp_name, pwd, user);
230
231 FILE* fp = fopen("exptab", "w");
232 if (!fp) {
233 printf("Error: Cannot write exptab file, fopen() errno %d (%s). Sorry...\n", errno, strerror(errno));
234 exit(1);
235 }
236
237 fprintf(fp, "%s %s %s\n", exp_name, pwd, user);
238 fclose(fp);
239
240 printf("\n");
241 printf("Please define env.variable MIDAS_EXPTAB=%s/%s\n", pwd, "exptab");
242 printf("\n");
243 printf("Done\n");
244 exit(0);
245 }
246
247 if (create_env) {
248 printf("Creating a new environment settings file in the current directory...\n");
249
250 // check if files already exist
251
252 FILE *fpr = fopen("env.sh", "r");
253 if (fpr) {
254 fclose(fpr);
255 printf("Error: env.sh already exists in the current directory. Sorry...\n");
256 exit(1);
257 }
258
259 fpr = fopen("env.csh", "r");
260 if (fpr) {
261 fclose(fpr);
262 printf("Error: env.csh already exists in the current directory. Sorry...\n");
263 exit(1);
264 }
265
266 // construct MIDAS_EXPTAB
267
268 const char* pwd = getenv("PWD");
269 if (!pwd || strlen(pwd)<1) {
270 printf("Error: env.variable PWD is not defined or is empty. Sorry...\n");
271 exit(1);
272 }
273
274 std::string midas_exptab;
275 midas_exptab += pwd;
277 midas_exptab += "exptab";
278
279 // try to extract midas location from argv[0]
280
281 std::string argv0 = argv[0];
282
283 if (argv0[0] != '/') {
284 printf("\n");
285 printf("Please run odbinit using the full path, i.e. run $HOME/packages/midas/linux/bin/odbinit\n");
286 printf("\n");
287 printf("Bye\n");
288 exit(1);
289 }
290
291 // construct MIDASSYS
292
293 std::string midassys;
294
295 if (argv0[0] == '/') { // absolute path
296 midassys += argv0;
297 } else {
298 midassys += pwd;
299 midassys += "/";
300 midassys += argv0;
301 }
302
303 std::vector<std::string> aa = split("/", midassys);
304 if (aa.size() > 0) { // remove "odbinit"
305 aa.pop_back();
306 }
307 if (aa.size() > 0) { // remove "bin"
308 aa.pop_back();
309 }
310 if (aa.size() > 0) { // remove "darwin" or "linux"
311 aa.pop_back();
312 }
313
315
316 // construct MIDAS path
317
318 std::string path;
319
320 {
321 if (argv0[0] == '/') { // absolute path
322 path += argv0;
323 } else {
324 path += pwd;
325 path += "/";
326 path += argv0;
327 }
328
329 std::vector<std::string> aa = split("/", path);
330 if (aa.size() > 0) { // remove "odbinit"
331 aa.pop_back();
332 }
333
334 path = join("/", remove_dot_dot(aa));
335 }
336
337 std::string hostname = ss_gethostname();
338
339 // start writing
340
341 FILE *fpb = fopen("env.sh", "w");
342 if (!fpb) {
343 printf("Error: Cannot write env.sh file, fopen() errno %d (%s). Sorry...\n", errno, strerror(errno));
344 exit(1);
345 }
346
347 FILE *fpc = fopen("env.csh", "w");
348 if (!fpc) {
349 printf("Error: Cannot write env.csh file, fopen() errno %d (%s). Sorry...\n", errno, strerror(errno));
350 exit(1);
351 }
352
353 fprintf(fpb, "#!echo You must source\n");
354 fprintf(fpc, "#!echo You must source\n");
355
356 fprintf(fpb, "export MIDASSYS=\"%s\"\n", midassys.c_str());
357 fprintf(fpc, "setenv MIDASSYS \"%s\"\n", midassys.c_str());
358
359 fprintf(fpb, "export MIDAS_EXPTAB=\"%s\"\n", midas_exptab.c_str());
360 fprintf(fpc, "setenv MIDAS_EXPTAB \"%s\"\n", midas_exptab.c_str());
361
362 fprintf(fpb, "export PATH=$PATH:\"%s\"\n", path.c_str());
363 fprintf(fpc, "setenv PATH $PATH\\:\"%s\"\n", path.c_str());
364
365 fprintf(fpb, "# define mserver connection\n");
366 fprintf(fpb, "case `hostname` in\n");
367 fprintf(fpb, "%s) unset MIDAS_SERVER_HOST ;;\n", hostname.c_str());
368 fprintf(fpb, "*) export MIDAS_SERVER_HOST=%s ;;\n", hostname.c_str());
369 fprintf(fpb, "esac\n");
370
371 fprintf(fpc, "# define mserver connection\n");
372 fprintf(fpc, "switch (`hostname`)\n");
373 fprintf(fpc, "case %s:\n", hostname.c_str());
374 fprintf(fpc, "unsetenv MIDAS_SERVER_HOST\n");
375 fprintf(fpc, "breaksw\n");
376 fprintf(fpc, "default:\n");
377 fprintf(fpc, "setenv MIDAS_SERVER_HOST %s\n", hostname.c_str());
378 fprintf(fpc, "endsw\n");
379
380 fprintf(fpb, "#end\n");
381 fprintf(fpc, "#end\n");
382
383 fclose(fpb);
384 fclose(fpc);
385
386 printf("\n");
387 printf("Please source env.sh or env.csh\n");
388 printf("\n");
389 printf("Done\n");
390 exit(0);
391 }
392
393 // check MIDASSYS
394
395 printf("Checking MIDASSYS...");
396 const char* midassys = getenv("MIDASSYS");
397
398 if (!midassys) {
399 printf("\n");
400 printf("Error: Env.variable MIDASSYS is not defined.\n");
401 printf("odbinit path [%s]\n", argv[0]);
402 printf("\n");
403 printf("Please run odbinit --env\n");
404 printf("\n");
405 printf("Bye.\n");
406 exit(1);
407 }
408
409 printf("...%s\n", midassys);
410
412 INT status;
413
415
416 if (status != CM_SUCCESS) {
417 printf("Error: cm_list_experiments() status %d\n", status);
418 printf("\n");
419 printf("Cannot get the list of experiments, maybe the exptab file is missing.\n");
420 printf("\n");
421 printf("To create a new exptab file in the current directory, run odbinit --exptab -e new_experiment_name\n");
422 printf("\n");
423 printf("Bye...\n");
424 exit(1);
425 }
426
428
429 if (exptab_filename.empty()) {
430 printf("Cannot get the name of the exptab file. Sorry...\n");
431 exit(1);
432 }
433
434 printf("Checking exptab... experiments defined in exptab file \"%s\":\n", exptab_filename.c_str());
435
436 bool found_exp = false;
437 for (unsigned i=0; i<exp_names.size(); i++) {
438 printf("%d: \"%s\"", i, exp_names[i].c_str());
439 if (exp_name[0] == 0)
440 mstrlcpy(exp_name, exp_names[i].c_str(), sizeof (exp_name));
442 printf(" <-- selected experiment");
443 mstrlcpy(exp_name, exp_names[i].c_str(), sizeof (exp_name));
444 found_exp = true;
445 }
446 printf("\n");
447 }
448
449 if (!found_exp) {
450 printf("Specified experiment \"%s\" not found in exptab. Sorry...\n", exp_name);
451 exit(1);
452 }
453
454 std::string exp_dir;
455 std::string exp_user;
456
458
459 if (status != CM_SUCCESS) {
460 printf("Specified experiment \"%s\" not found in exptab, cm_get_exptab() returned %d. Sorry...\n", exp_name, status);
461 exit(1);
462 }
463
464 printf("\n");
465 printf("Checking exptab... selected experiment \"%s\", experiment directory \"%s\"\n", exp_name, exp_dir.c_str());
466
468 cm_set_path(exp_dir.c_str());
470
471 printf("\n");
472
473 {
474 printf("Checking experiment directory \"%s\"\n", exp_dir.c_str());
475
476#ifdef S_ISDIR
477 struct stat stat_buf;
478 int v = stat(exp_dir.c_str(), &stat_buf);
479
480 if (v != 0) {
481 printf("Invalid experiment directory \"%s\" does not seem to exist, stat() returned %d, errno %d (%s)\n", exp_dir.c_str(), v, errno, strerror(errno));
482 printf("Sorry.\n");
483 exit(1);
484 }
485
486 if (!S_ISDIR(stat_buf.st_mode)) {
487 printf("Invalid experiment directory \"%s\" is not a directory\n", exp_dir.c_str());
488 printf("Sorry.\n");
489 exit(1);
490 }
491#else
492#error No support for stat() and S_ISDIR on this system!
493#endif
494 }
495
496 std::string odb_path;
497
498 {
499 std::string path;
500 path += exp_dir;
501 path += ".ODB.SHM";
502
503 FILE *fp = fopen(path.c_str(), "r");
504 if (fp) {
505 fclose(fp);
506 printf("Found existing ODB save file: \"%s\"\n", path.c_str());
507 if (cleanup) {
508 // cannot get rid of ODB save file yet - it is used as SysV semaphore key
509 // so delete semaphore first, delete .ODB.SHM next.
510 // hope deleting the semaphore and crashing all MIDAS programs does not corrupt the ODB save file.
511 odb_path = path;
512 } else {
513 printf("Looks like this experiment ODB is already initialized.\n");
514 printf("To create new empty ODB, please rerun odbinit with the \"--cleanup\" option.\n");
515 exit(1);
516 }
517 } else {
518 printf("Good: no ODB save file\n");
519 }
520 }
521
522 printf("\n");
523 printf("Checking shared memory...\n");
524
525 {
526 printf("Deleting old ODB shared memory...\n");
527 if (!dry_run) {
528 status = ss_shm_delete("ODB");
529 if (status == SS_NO_MEMORY) {
530 printf("Good: no ODB shared memory\n");
531 } else if (status == SS_SUCCESS) {
532 printf("Deleted existing ODB shared memory, please check that all MIDAS programs are stopped and try again.\n");
533 exit(1);
534 } else {
535 printf("ss_shm_delete(ODB) status %d\n", status);
536 printf("Please check that all MIDAS programs are stopped and try again.\n");
537 exit(1);
538 }
539 }
540 }
541
542 {
543 printf("Deleting old ODB semaphore...\n");
544 if (!dry_run) {
545 HNDLE sem;
546 int cstatus = ss_semaphore_create("ODB", &sem);
548 printf("Deleting old ODB semaphore... create status %d, delete status %d\n", cstatus, dstatus);
549 }
550 }
551
552 if (odb_path.length() > 0 && cleanup) {
553 time_t now = time(NULL);
554 std::string path1;
555 path1 += odb_path;
556 path1 += ".";
557 path1 += to_string(now);
558 printf("Preserving old ODB save file \"%s\" to \"%s\"\n", odb_path.c_str(), path1.c_str());
559 if (!dry_run) {
560 status = rename(odb_path.c_str(), path1.c_str());
561 if (status != 0) {
562 printf("rename(%s, %s) returned %d, errno %d (%s)\n", odb_path.c_str(), path1.c_str(), status, errno, strerror(errno));
563 printf("Sorry.\n");
564 exit(1);
565 }
566 }
567 }
568
569 printf("\n");
570
571 {
572 printf("Checking ODB size...\n");
573
574 std::pair<double,std::string> odb_size_human=HumanUnits(odb_size);
575
576 printf("Requested ODB size is %d bytes (%.2f%s)\n", odb_size,odb_size_human.first,odb_size_human.second.c_str());
577
578 std::string path1;
579 path1 += exp_dir;
580 path1 += "/";
581 path1 += ".ODB_SIZE.TXT";
582
583 printf("ODB size file is \"%s\"\n", path1.c_str());
584
585 FILE *fp = fopen(path1.c_str(), "r");
586 if (!fp) {
587 printf("ODB size file \"%s\" does not exist, creating it...\n", path1.c_str());
588 fp = fopen(path1.c_str(), "w");
589 if (!fp) {
590 printf("Cannot create ODB size file \"%s\", fopen() errno %d (%s)\n", path1.c_str(), errno, strerror(errno));
591 printf("Sorry.\n");
592 exit(1);
593 }
594 if (odb_size == 0)
595 {
596 std::pair<double,std::string> default_odb_size_human=HumanUnits(DEFAULT_ODB_SIZE);
597 fprintf(fp, "%d (%.2f%s)\n", DEFAULT_ODB_SIZE,default_odb_size_human.first,default_odb_size_human.second.c_str());
598 }
599 else
600 {
601 fprintf(fp, "%d (%.2f%s)\n", odb_size,odb_size_human.first,odb_size_human.second.c_str());
602 }
603 fclose(fp);
604
605 fp = fopen(path1.c_str(), "r");
606 if (!fp) {
607 printf("Creation of ODB size file \"%s\" somehow failed.\n", path1.c_str());
608 printf("Sorry.\n");
609 exit(1);
610 }
611 }
612
613 int file_odb_size = 0;
614 std::pair<double,std::string> file_odb_size_human;
615 {
616 char buf[256];
617 char *s = fgets(buf, sizeof(buf), fp);
618 if (s) {
621 }
622 }
623 fclose(fp);
624
625 printf("Saved ODB size from \"%s\" is %d bytes (%.2f%s)\n", path1.c_str(), file_odb_size,file_odb_size_human.first,file_odb_size_human.second.c_str());
626
627 if (odb_size == 0)
629
630 if (file_odb_size != odb_size) {
631 printf("Requested ODB size %d is different from previous ODB size %d. You have 2 choices:\n", odb_size, file_odb_size);
632 printf("1) to create ODB with old size, please try again without the \"-s\" switch.\n");
633 printf("2) to create ODB with new size, please delete the file \"%s\" and try again.\n", path1.c_str());
634 exit(1);
635 }
636 }
637 std::pair<double,std::string> odb_size_human=HumanUnits(odb_size);
638 printf("We will initialize ODB for experiment \"%s\" on host \"%s\" with size %d bytes (%.2f%s)\n", exp_name, host_name, odb_size, odb_size_human.first, odb_size_human.second.c_str());
639 printf("\n");
640
641
642 {
643 HNDLE hDB;
644 printf("Creating ODB...\n");
645 status = db_open_database("ODB", odb_size, &hDB, "odbinit");
646 printf("Creating ODB... db_open_database() status %d\n", status);
647 if ((status != DB_SUCCESS) && (status != DB_CREATED)) {
648 printf("Something went wrong... continuing...\n");
649 }
650 printf("Saving ODB...\n");
652 printf("Saving ODB... db_close_database() status %d\n", status);
653 if (status != DB_SUCCESS) {
654 printf("Something went wrong... continuing...\n");
655 }
656 }
657
658 printf("Connecting to experiment...\n");
659
661
662 if (status != CM_SUCCESS) {
663 printf("Error: cm_connect_experiment() status %d\n", status);
664 printf("Sorry...\n");
665 exit(1);
666 }
667
668 printf("\n");
669 printf("Connected to ODB for experiment \"%s\" on host \"%s\" with size %d bytes (%.2f%s)\n", exp_name, host_name, odb_size,odb_size_human.first,odb_size_human.second.c_str());
670
672
673 {
674 HNDLE hDB;
676 int size = NAME_LENGTH;
677 char buf[NAME_LENGTH];
678 status = db_get_value(hDB, 0, "/Experiment/Name", buf, &size, TID_STRING, FALSE);
679 printf("Checking experiment name... status %d, found \"%s\"\n", status, buf);
680 //status = db_save_json(hDB, 0, "odbinit.json");
681 //printf("Saving odbinit.json... status %d\n", status);
682 }
683
684 printf("Disconnecting from experiment...\n");
686
687 printf("\n");
688 printf("Done\n");
689
690#else
691 printf("this version of odbinit is built with NO_LOCAL_ROUTINES and it will not work. odbinit only works locally!\n");
692#endif // NO_LOCAL_ROUTINES
693
694 return 0;
695}
#define FALSE
Definition cfortran.h:309
INT cm_set_path(const char *path)
Definition midas.cxx:1497
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
INT cm_list_experiments_local(STRING_LIST *exp_names)
Definition midas.cxx:2586
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
Definition midas.cxx:2297
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
int cm_get_exptab(const char *expname, std::string *dir, std::string *user)
Definition midas.cxx:1799
std::string cm_get_exptab_filename()
Definition midas.cxx:1788
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
Definition midas.cxx:2134
INT cm_set_experiment_name(const char *name)
Definition midas.cxx:1558
#define CM_SUCCESS
Definition midas.h:582
#define DB_SUCCESS
Definition midas.h:631
#define DB_CREATED
Definition midas.h:632
#define SS_SUCCESS
Definition midas.h:663
#define SS_NO_MEMORY
Definition midas.h:665
#define TID_STRING
Definition midas.h:346
std::string ss_gethostname()
Definition system.cxx:5706
INT ss_suspend_init_odb_port()
Definition system.cxx:4305
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
Definition system.cxx:2460
INT ss_shm_delete(const char *name)
Definition system.cxx:909
INT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag)
Definition system.cxx:2869
INT cm_msg_flush_buffer()
Definition midas.cxx:865
BOOL equal_ustring(const char *str1, const char *str2)
Definition odb.cxx:3201
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5415
INT db_open_database(const char *xdatabase_name, INT database_size, HNDLE *hDB, const char *client_name)
Definition odb.cxx:1787
INT db_close_database(HNDLE hDB)
Definition odb.cxx:2152
char exp_name[NAME_LENGTH]
Definition mana.cxx:243
HNDLE hDB
main ODB handle
Definition mana.cxx:207
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
#define DIR_SEPARATOR
Definition midas.h:193
INT HNDLE
Definition midas.h:132
#define HOST_NAME_LENGTH
Definition midas.h:273
#define DEFAULT_WATCHDOG_TIMEOUT
Definition midas.h:290
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
#define DEFAULT_ODB_SIZE
Definition midas.h:270
std::vector< std::string > STRING_LIST
Definition midas.h:246
#define NAME_LENGTH
Definition midas.h:272
static FILE * fp
char pwd[256]
Definition odbedit.cxx:24
DWORD status
Definition odbhist.cxx:39
static std::string join(const char *sep, const std::vector< std::string > &v)
Definition odbinit.cxx:44
static void usage()
Definition odbinit.cxx:75
static std::string to_string(int v)
Definition odbinit.cxx:19
static std::vector< std::string > remove_dot_dot(const std::vector< std::string > &v)
Definition odbinit.cxx:58
int DecodeSize(const char *s)
Definition odbinit.cxx:89
std::pair< double, std::string > HumanUnits(int odb_size)
Definition odbinit.cxx:128
static std::vector< std::string > split(const char *sep, const std::string &s)
Definition odbinit.cxx:26
Here is the call graph for this function:

◆ remove_dot_dot()

static std::vector< std::string > remove_dot_dot ( const std::vector< std::string > &  v)
static

Definition at line 58 of file odbinit.cxx.

59{
60 std::vector<std::string> out;
61 for (unsigned i=0; i<v.size(); i++) {
62 if (v[i] == "..") {
63 if (out.size() > 0) {
64 out.pop_back();
65 }
66 } else {
67 out.push_back(v[i]);
68 }
69 }
70 return out;
71}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ split()

static std::vector< std::string > split ( const char sep,
const std::string &  s 
)
static

Definition at line 26 of file odbinit.cxx.

27{
28 unsigned sep_len = strlen(sep);
29 std::vector<std::string> v;
30 std::string::size_type pos = 0;
31 while (1) {
32 std::string::size_type next = s.find(sep, pos);
33 //printf("pos %d, next %d\n", (int)pos, (int)next);
34 if (next == std::string::npos) {
35 v.push_back(s.substr(pos));
36 break;
37 }
38 v.push_back(s.substr(pos, next-pos));
39 pos = next+sep_len;
40 }
41 return v;
42}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string()

static std::string to_string ( int  v)
static

Definition at line 19 of file odbinit.cxx.

20{
21 char buf[1024];
22 sprintf(buf, "%d", v);
23 return buf;
24}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ usage()

static void usage ( )
static

Definition at line 75 of file odbinit.cxx.

76{
77 printf("usage: odbinit [options...]\n");
78 printf("options:\n");
79 printf(" [-e Experiment] --- specify experiment name\n");
80 printf(" [-s size] --- specify new size of ODB in bytes, default is %d (optional units: B, kB, MB, kiB, MiB)\n", DEFAULT_ODB_SIZE);
81 printf(" [--env] --- create new env.sh and env.csh files in the current directory\n");
82 printf(" [--exptab] --- create new exptab file in the current directory\n");
83 printf(" [--cleanup] --- cleanup (preserve) old (existing) ODB files\n");
84 printf(" [-n] --- dry run, report everything that will be done, but do not actually do anything\n");
85 //printf(" [-g] --- debug\n");
86 exit(1);
87}
Here is the call graph for this function:
Here is the caller graph for this function: