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

Last change on this file since 7166 was 7166, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 6.7 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, 05/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.Contains("Y"))
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 query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
103 source.Data(), startdate.Data(), stopdate.Data());
104 if (cal)
105 query +=" and not IsNull(fStar) ";
106 query +=" order by Sequences.fSequenceFirst ";
107
108 cout << "Q: " << query << endl;
109
110 TSQLResult *res = serv.Query(query);
111 if (!res)
112 {
113 cout << "Error - no sequence found" << endl;
114 return 0;
115 }
116
117 fout << "SequencesOn: " << flush;
118 TSQLRow *row=0;
119 while ((row = res->Next()))
120 fout << " " << (*row)[0] << " " << flush;
121 fout << endl << endl;
122
123 delete res;
124
125 if (wobble.Contains("N"))
126 {
127 if (off.Contains("none"))
128 {
129 off ="Off";
130 off +=source;
131 off.Remove(10,15);
132 }
133
134 cout << "off: " << off << endl;
135 query ="Select Sequences.fSequenceFirst from Sequences left join Source on ";
136 query +="Sequences.fSourceKEY=Source.fSourceKEY ";
137 if (cal)
138 query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
139 query +=Form("where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
140 off.Data(), offstartdate.Data(), offstopdate.Data());
141 if (cal)
142 query +=" and not IsNull(fStar) ";
143 query +=" order by Sequences.fSequenceFirst ";
144
145 cout << "Q: " << query << endl;
146
147 res = serv.Query(query);
148 if (!res)
149 {
150 cout << "Error - no sequence found" << endl;
151 return 0;
152 }
153
154 fout << "SequencesOff: " << flush;
155 row=0;
156 while ((row = res->Next()))
157 fout << " " << (*row)[0] << " " << flush;
158 fout << endl << endl;
159
160 delete res;
161 }
162
163 if (wobble.Contains("N"))
164 fout << "#" << flush;
165 fout << "SourceName: " << source << endl;
166 fout << "Catalog: /magic/datacenter/setup/magic_favorites.edb" << endl;
167 if (wobble.Contains("N"))
168 fout << "#" << flush;
169 fout << "WobbleMode: On" << endl << endl;
170
171
172 return 1;
173}
174
175int createdataset(TString filename)
176{
177 ifstream fin(filename);
178 if (!fin)
179 {
180 cout << "Could not open file " << filename << endl;
181 return 0;
182 }
183 cout << "reading file " << filename << endl;
184
185 while (1)
186 {
187 TString strng;
188 strng.ReadToDelim(fin, ',');
189 if (!fin)
190 break;
191
192 if (strng.BeginsWith("#"))
193 {
194 cout << "comment line: " << strng << endl;
195 strng.ReadToDelim(fin, '\n');
196 continue;
197 }
198
199 Int_t dataset=atoi(strng.Data());
200 if (dataset==0)
201 continue;
202 cout << "creating dataset # " << dataset << endl;
203
204 TString source;
205 source.ReadToDelim(fin, ',');
206 TString wobble;
207 wobble.ReadToDelim(fin, ',');
208 strng.ReadToDelim(fin, ',');
209 Bool_t cal=kFALSE;
210 if (strng=="kTRUE")
211 cal=kTRUE;
212 TString startdate;
213 startdate.ReadToDelim(fin, ',');
214 TString stopdate;
215 stopdate.ReadToDelim(fin, ',');
216 TString off;
217 off.ReadToDelim(fin, ',');
218 TString offstartdate;
219 offstartdate.ReadToDelim(fin, ',');
220 TString offstopdate;
221 offstopdate.ReadToDelim(fin, '\n');
222
223 cout << createdataset(dataset, source, wobble, cal, startdate, stopdate, off, offstartdate, offstopdate) << endl;
224 }
225
226 return 1;
227}
Note: See TracBrowser for help on using the repository browser.