source: branches/MarsGapdTimeJitter/datacenter/macros/createdataset.C@ 18315

Last change on this file since 18315 was 7460, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 7.1 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-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// createdataset.C
28// ===============
29//
30// this script is not run automatically
31// the purpose of this script is to make it easier for people to write
32// datasetfiles
33//
34// be careful with the path in this macro, if you use it for test-reasons!
35//
36/////////////////////////////////////////////////////////////////////////////
37
38#include <iostream>
39#include <iomanip>
40#include <fstream>
41
42#include <TEnv.h>
43
44#include <MSQLServer.h>
45#include <TSQLRow.h>
46#include <TSQLResult.h>
47#include <TSystem.h>
48
49using namespace std;
50
51
52
53int createdataset(Int_t dataset, TString source, TString wobble,
54 Bool_t cal=kFALSE,
55 TString startdate="0000-00-00 00:00:00",
56 TString stopdate="3000-00-00 00:00:00",
57 TString off="none",
58 TString offstartdate="0000-00-00 00:00:00",
59 TString offstopdate="3000-00-00 00:00:00")
60{
61 TEnv env("sql.rc");
62
63 MSQLServer serv(env);
64 if (!serv.IsConnected())
65 {
66 cout << "ERROR - Connection to database failed." << endl;
67 return 0;
68 }
69 cout << "createdataset" << endl;
70 cout << "-------------" << endl;
71 cout << endl;
72 cout << "Connected to " << serv.GetName() << endl;
73 cout << endl;
74
75 TString fname(Form("/magic/datasets/%05d/dataset%08d.txt", dataset/1000, dataset));
76 TString fhtml="/home/operator/html";
77 Bool_t exist=gSystem->AccessPathName(fname,kFileExists);
78 if (exist==0)
79 {
80 cout << fname << " already exists, please choose different dataset#" << endl;
81 return 0;
82 }
83
84 ofstream fouthtml(fhtml, ios::app);
85 fouthtml << "<tr><td>" << endl;
86 fouthtml << dataset << endl;
87 fouthtml << "</td><td>" << endl;
88 fouthtml << source << endl;
89 fouthtml << "</td><td>" << endl;
90 if (wobble!="N")
91 fouthtml << "wobble," << endl;
92 if (startdate=="0000-00-00 00:00:00")
93 fouthtml << "all" << endl;
94 else
95 fouthtml << "from " << startdate << " to " << stopdate << endl;
96 if (cal)
97 fouthtml << ", only data processed to the imgpar is taken into account" << endl;
98 fouthtml << "</td></tr>" << endl;
99
100 ofstream fout(fname, ios::app);
101 cout << "writing to file " << fname << endl;
102 fout << "AnalysisNumber: " << dataset << endl << endl;
103
104 TString query="Select Sequences.fSequenceFirst from Sequences left join Source on ";
105 query +="Sequences.fSourceKEY=Source.fSourceKEY ";
106 if (cal)
107 query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
108 if (wobble=="N")
109 query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
110 source.Data(), startdate.Data(), stopdate.Data());
111 else
112 query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
113 wobble.Data(), startdate.Data(), stopdate.Data());
114 if (cal)
115 query +=" and not IsNull(fStar) ";
116 query +=" order by Sequences.fSequenceFirst ";
117
118 cout << "Q: " << query << endl;
119
120 TSQLResult *res = serv.Query(query);
121 if (!res)
122 {
123 cout << "Error - no sequence found" << endl;
124 return 0;
125 }
126
127 fout << "SequencesOn: " << flush;
128 TSQLRow *row=0;
129 while ((row = res->Next()))
130 fout << " " << (*row)[0] << " " << flush;
131 fout << endl << endl;
132
133 delete res;
134
135 if (wobble=="N")
136 {
137 if (off=="none")
138 {
139 off ="Off";
140 off +=source;
141 off.Remove(10,15);
142 }
143
144 cout << "off: " << off << endl;
145 query ="Select Sequences.fSequenceFirst from Sequences left join Source on ";
146 query +="Sequences.fSourceKEY=Source.fSourceKEY ";
147 if (cal)
148 query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
149 query +=Form("where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
150 off.Data(), offstartdate.Data(), offstopdate.Data());
151 if (cal)
152 query +=" and not IsNull(fStar) ";
153 query +=" order by Sequences.fSequenceFirst ";
154
155 cout << "Q: " << query << endl;
156
157 res = serv.Query(query);
158 if (!res)
159 {
160 cout << "Error - no sequence found" << endl;
161 return 0;
162 }
163
164 fout << "SequencesOff: " << flush;
165 row=0;
166 while ((row = res->Next()))
167 fout << " " << (*row)[0] << " " << flush;
168 fout << endl << endl;
169
170 delete res;
171 }
172
173 if (wobble=="N")
174 fout << "#" << flush;
175 fout << "SourceName: " << source << endl;
176 fout << "Catalog: /magic/datacenter/setup/magic_favorites.edb" << endl;
177 if (wobble=="N")
178 fout << "#" << flush;
179 fout << "WobbleMode: On" << endl << endl;
180
181
182 return 1;
183}
184
185int createdataset(TString filename)
186{
187 ifstream fin(filename);
188 if (!fin)
189 {
190 cout << "Could not open file " << filename << endl;
191 return 0;
192 }
193 cout << "reading file " << filename << endl;
194
195 while (1)
196 {
197 TString strng;
198 strng.ReadToDelim(fin, ',');
199 if (!fin)
200 break;
201
202 if (strng.BeginsWith("#"))
203 {
204 cout << "comment line: " << strng << endl;
205 strng.ReadToDelim(fin, '\n');
206 continue;
207 }
208
209 Int_t dataset=atoi(strng.Data());
210 if (dataset==0)
211 continue;
212 cout << "creating dataset # " << dataset << endl;
213
214 TString source;
215 source.ReadToDelim(fin, ',');
216 TString wobble;
217 wobble.ReadToDelim(fin, ',');
218 strng.ReadToDelim(fin, ',');
219 Bool_t cal=kFALSE;
220 if (strng=="kTRUE")
221 cal=kTRUE;
222 TString startdate;
223 startdate.ReadToDelim(fin, ',');
224 TString stopdate;
225 stopdate.ReadToDelim(fin, ',');
226 TString off;
227 off.ReadToDelim(fin, ',');
228 TString offstartdate;
229 offstartdate.ReadToDelim(fin, ',');
230 TString offstopdate;
231 offstopdate.ReadToDelim(fin, '\n');
232
233 cout << createdataset(dataset, source, wobble, cal, startdate, stopdate, off, offstartdate, offstopdate) << endl;
234 }
235
236 return 1;
237}
Note: See TracBrowser for help on using the repository browser.