source: trunk/MagicSoft/Mars/datacenter/macros/createdataset.C@ 7228

Last change on this file since 7228 was 7167, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 6.9 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Daniela Dorner, 06/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// createdataset.C
28// ===============
29//
30/////////////////////////////////////////////////////////////////////////////
31
32#include <iostream>
33#include <iomanip>
34#include <fstream>
35
36#include <TEnv.h>
37
38#include <MSQLServer.h>
39#include <TSQLRow.h>
40#include <TSQLResult.h>
41#include <TSystem.h>
42
43using namespace std;
44
45
46
47int createdataset(Int_t dataset, TString source, TString wobble,
48 Bool_t cal=kFALSE,
49 TString startdate="0000-00-00 00:00:00",
50 TString stopdate="3000-00-00 00:00:00",
51 TString off="none",
52 TString offstartdate="0000-00-00 00:00:00",
53 TString offstopdate="3000-00-00 00:00:00")
54{
55 TEnv env("sql.rc");
56
57 MSQLServer serv(env);
58 if (!serv.IsConnected())
59 {
60 cout << "ERROR - Connection to database failed." << endl;
61 return 0;
62 }
63 cout << "createdataset" << endl;
64 cout << "-------------" << endl;
65 cout << endl;
66 cout << "Connected to " << serv.GetName() << endl;
67 cout << endl;
68
69 TString fname(Form("/magic/datasets/%05d/dataset%08d.txt", dataset/1000, dataset));
70 TString fhtml="/home/operator/html";
71 Bool_t exist=gSystem->AccessPathName(fname,kFileExists);
72 if (exist==0)
73 {
74 cout << fname << " already exists, please choose different dataset#" << endl;
75 return 0;
76 }
77
78 ofstream fouthtml(fhtml, ios::app);
79 fouthtml << "<tr><td>" << endl;
80 fouthtml << dataset << endl;
81 fouthtml << "</td><td>" << endl;
82 fouthtml << source << endl;
83 fouthtml << "</td><td>" << endl;
84 if (wobble!="N")
85 fouthtml << "wobble," << endl;
86 if (startdate=="0000-00-00 00:00:00")
87 fouthtml << "all" << endl;
88 else
89 fouthtml << "from " << startdate << " to " << stopdate << endl;
90 if (cal)
91 fouthtml << ", only data processed to the imgpar is taken into account" << endl;
92 fouthtml << "</td></tr>" << endl;
93
94 ofstream fout(fname, ios::app);
95 cout << "writing to file " << fname << endl;
96 fout << "AnalysisNumber: " << dataset << endl << endl;
97
98 TString query="Select Sequences.fSequenceFirst from Sequences left join Source on ";
99 query +="Sequences.fSourceKEY=Source.fSourceKEY ";
100 if (cal)
101 query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
102 if (wobble=="N")
103 query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
104 source.Data(), startdate.Data(), stopdate.Data());
105 else
106 query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
107 wobble.Data(), startdate.Data(), stopdate.Data());
108 if (cal)
109 query +=" and not IsNull(fStar) ";
110 query +=" order by Sequences.fSequenceFirst ";
111
112 cout << "Q: " << query << endl;
113
114 TSQLResult *res = serv.Query(query);
115 if (!res)
116 {
117 cout << "Error - no sequence found" << endl;
118 return 0;
119 }
120
121 fout << "SequencesOn: " << flush;
122 TSQLRow *row=0;
123 while ((row = res->Next()))
124 fout << " " << (*row)[0] << " " << flush;
125 fout << endl << endl;
126
127 delete res;
128
129 if (wobble=="N")
130 {
131 if (off=="none")
132 {
133 off ="Off";
134 off +=source;
135 off.Remove(10,15);
136 }
137
138 cout << "off: " << off << endl;
139 query ="Select Sequences.fSequenceFirst from Sequences left join Source on ";
140 query +="Sequences.fSourceKEY=Source.fSourceKEY ";
141 if (cal)
142 query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
143 query +=Form("where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
144 off.Data(), offstartdate.Data(), offstopdate.Data());
145 if (cal)
146 query +=" and not IsNull(fStar) ";
147 query +=" order by Sequences.fSequenceFirst ";
148
149 cout << "Q: " << query << endl;
150
151 res = serv.Query(query);
152 if (!res)
153 {
154 cout << "Error - no sequence found" << endl;
155 return 0;
156 }
157
158 fout << "SequencesOff: " << flush;
159 row=0;
160 while ((row = res->Next()))
161 fout << " " << (*row)[0] << " " << flush;
162 fout << endl << endl;
163
164 delete res;
165 }
166
167 if (wobble=="N")
168 fout << "#" << flush;
169 fout << "SourceName: " << source << endl;
170 fout << "Catalog: /magic/datacenter/setup/magic_favorites.edb" << endl;
171 if (wobble=="N")
172 fout << "#" << flush;
173 fout << "WobbleMode: On" << endl << endl;
174
175
176 return 1;
177}
178
179int createdataset(TString filename)
180{
181 ifstream fin(filename);
182 if (!fin)
183 {
184 cout << "Could not open file " << filename << endl;
185 return 0;
186 }
187 cout << "reading file " << filename << endl;
188
189 while (1)
190 {
191 TString strng;
192 strng.ReadToDelim(fin, ',');
193 if (!fin)
194 break;
195
196 if (strng.BeginsWith("#"))
197 {
198 cout << "comment line: " << strng << endl;
199 strng.ReadToDelim(fin, '\n');
200 continue;
201 }
202
203 Int_t dataset=atoi(strng.Data());
204 if (dataset==0)
205 continue;
206 cout << "creating dataset # " << dataset << endl;
207
208 TString source;
209 source.ReadToDelim(fin, ',');
210 TString wobble;
211 wobble.ReadToDelim(fin, ',');
212 strng.ReadToDelim(fin, ',');
213 Bool_t cal=kFALSE;
214 if (strng=="kTRUE")
215 cal=kTRUE;
216 TString startdate;
217 startdate.ReadToDelim(fin, ',');
218 TString stopdate;
219 stopdate.ReadToDelim(fin, ',');
220 TString off;
221 off.ReadToDelim(fin, ',');
222 TString offstartdate;
223 offstartdate.ReadToDelim(fin, ',');
224 TString offstopdate;
225 offstopdate.ReadToDelim(fin, '\n');
226
227 cout << createdataset(dataset, source, wobble, cal, startdate, stopdate, off, offstartdate, offstopdate) << endl;
228 }
229
230 return 1;
231}
Note: See TracBrowser for help on using the repository browser.