StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
eemcDbFunctions.C
1 // $Id: eemcDbFunctions.C,v 1.1 2013/01/25 16:46:49 stevens4 Exp $
2 // Description: EEMC DB functions
3 // Author: Piotr A. Zolnierczuk
4 // Contributions Jan Balewski
5 //
6 // $Log: eemcDbFunctions.C,v $
7 // Revision 1.1 2013/01/25 16:46:49 stevens4
8 // Scripts used to upload EEMC tables to the DB
9 //
10 // Revision 1.6 2003/09/12 16:38:36 zolnie
11 // *** empty log message ***
12 //
13 // Revision 1.5 2003/08/29 17:07:22 zolnie
14 // added: flavor and expiration time flag
15 //
16 // Revision 1.4 2003/08/07 16:33:23 zolnie
17 // replaced confusing --noWrite/-w option with a clearer one: --dataonly/-d
18 //
19 // Revision 1.3 2003/06/03 06:29:15 zolnie
20 // fixed time zone problem
21 //
22 // Revision 1.2 2003/04/11 18:27:58 balewski
23 // add -w option to prohibit writing of the '#node/table' string to the output
24 //
25 // Revision 1.1 2003/01/28 23:22:18 balewski
26 // start
27 //
28 // Revision 1.24 2003/01/13 18:20:49 zolnie
29 // modified history time to be local rather than GMT
30 //
31 // Revision 1.23 2003/01/10 04:52:05 zolnie
32 // updates to Tcl/Tk interface (czyli Zadana Pana Jana)
33 //
34 // Revision 1.22 2003/01/08 21:58:27 zolnie
35 // history clean-up
36 // tk interface updates
37 //
38 // Revision 1.21 2003/01/03 16:40:16 zolnie
39 // added comment field
40 //
41 // Revision 1.20 2003/01/02 16:31:06 zolnie
42 // added comment field to all the c-structs
43 //
44 // Revision 1.19 2002/12/03 19:30:46 zolnie
45 // polished stuff
46 //
47 // Revision 1.18 2002/12/03 17:58:44 balewski
48 // added PMTped , VerC
49 //
50 // Revision 1.17 2002/11/14 19:22:27 zolnie
51 // working version of mkHVDB
52 //
53 // Revision 1.16 2002/11/13 20:12:35 zolnie
54 // towards (semi)(stable?) final solution
55 //
56 // Revision 1.15 2002/11/11 22:54:02 zolnie
57 // fixed a number of bugs in perl scripts (mainly in digestPmtConf.pl)
58 // patchy version of mkHVDB
59 // updated *.hh files
60 //
61 // Revision 1.14 2002/11/05 17:51:04 zolnie
62 // "characterization" updates
63 //
64 // Revision 1.13 2002/11/01 23:29:34 zolnie
65 // *** empty log message ***
66 //
67 // Revision 1.12 2002/11/01 20:47:39 zolnie
68 // added: file parameter added
69 // help updated
70 //
71 // Revision 1.11 2002/11/01 19:47:45 zolnie
72 // fixed bug: logical conditions in read/write_db were reversed
73 //
74 // Revision 1.10 2002/11/01 19:23:19 zolnie
75 // use templates in eemcDbOp
76 //
77 // Revision 1.9 2002/11/01 14:49:48 balewski
78 //
79 // ADCconf works
80 //
81 // Revision 1.8 2002/11/01 14:34:06 zolnie
82 // shorten EEMCDbMaxName from 32 to 16
83 //
84 // Revision 1.7 2002/11/01 14:18:13 balewski
85 // walka z ADC conf
86 //
87 // Revision 1.6 2002/10/31 22:13:25 zolnie
88 // bug fixed in eemcConstDB.hh (algebra problem)
89 //
90 // Revision 1.5 2002/10/31 20:44:31 zolnie
91 // for Jas
92 //
93 // Revision 1.4 2002/10/31 15:58:28 zolnie
94 // structure field naming bug fixed in eemcDbPMTcal
95 //
96 // Revision 1.3 2002/10/30 22:48:33 zolnie
97 // new dbase manipulation updates
98 //
99 // Revision 1.2 2002/10/30 15:39:44 zolnie
100 // updated eemcDb and Readme files
101 //
102 // Revision 1.1 2002/10/29 23:00:50 zolnie
103 // chyba dziala (ze sciezkami)
104 //
105 
106 
107 
108 #include <stdio.h>
109 #include <assert.h>
110 #include <string.h>
111 #include <getopt.h>
112 
113 #ifndef __USE_XOPEN
114 #define __USE_XOPEN
115 #endif
116 #include <time.h>
117 
118 #include "eemcDb.h"
119 
120 
121 
122 //extern "C" char *strptime (const char *s, const char *fmt, struct tm *tp);
123 int verboseMode = false;
124 int quietMode = false;
125 
126 
127 // ===============================================================
128 // time stamp function
129 // ===============================================================
130 time_t
131 getTimeStamp(const char *timeformat[] , const char *timestr)
132 {
133  time_t ts=0;
134  struct tm tm;
135 
136  ts = time(NULL);
137  localtime(&ts);
138 
139  if(strncmp(timestr,"now",3)) {
140  memset(&tm,0x0,sizeof(struct tm));
141  for(int i=0; timeformat[i]!=NULL ; i++ ) {
142  //dprintf("trying %s\n",timeformat[i]);
143  if(strptime(timestr,timeformat[i], &tm)!=NULL) {
144  //dprintf("using date/time format: %s\n",timeformat[i]);
145  break;
146  }
147  }
148  ts = mktime(&tm);
149  }
150  if(ts<0) {
151  fprintf(stderr,"time stamp %s not understood\n",timestr);
152  fprintf(stderr,"\tvalid formats are:\n");
153  for(int i=0; timeformat[i]!=NULL ; i++ )
154  fprintf(stderr,"\t%s\n",timeformat[i]);
155  return(-1);
156  }
157 
158  // now print the "decoded" times
159  char *tstr=NULL,*nline=NULL;
160 
161  dprintf("TIME STAMP: ");
162  tstr=asctime(localtime(&ts));
163  nline=strrchr(tstr,'\n');
164  if(nline!=NULL) *nline=0x00; // get rid of '\n' returned by asctime
165  dprintf("%s (%s)\t",tstr,tzname[daylight]);
166 
167  tstr=asctime(gmtime(&ts));
168  nline=strrchr(tstr,'\n');
169  if(nline!=NULL) *nline=0x00; // get rid of '\n' returned by asctime
170  dprintf("%s (GMT)\n",tstr);
171  return ts;
172 }
173 
174 
175 // ===============================================================
176 // CONVERT TIME FROM <-> SQL
177 // ===============================================================
178 static void
179 timeStringConv1(const char *a, char *b) {
180  memcpy(b+0,a+0,4); // yyyy
181  b[4]='-';
182  memcpy(b+5,a+4,2); // mm
183  b[7]='-';
184  memcpy(b+8,a+6,2); // dd
185  b[10]=' ';
186  memcpy(b+11,a+8,2); // hh
187  b[13]=':';
188  memcpy(b+14,a+10,2); // mm
189  b[16]=':';
190  memcpy(b+17,a+12,2); // ss
191  b[19]=0;
192  //fprintf(out,"=%s=%s=\n",a,b);
193 }
194 
195 
196 char *
197 fmtSqlTime(const char* sqltime) {
198  static char stringTime[1024];
199  timeStringConv1(sqltime,stringTime);
200  return stringTime;
201 }
202 
203 
204 
205 
206 // ===============================================================
207 // format function
208 // ===============================================================
209 static inline char*
210 fmt(const char *s, const int len) {
211  static char fmtstr[EEmcDbMaxDbPathLen];
212  sprintf(fmtstr,"%s %%%d[A-z0-9 \\t]\n",s,len-1);
213  return fmtstr;
214 }
215 
216 
217 
218