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 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 | int 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 (startdate=="0000-00-00 00:00:00")
|
---|
85 | fouthtml << "all" << endl;
|
---|
86 | else
|
---|
87 | fouthtml << "from " << startdate << " to " << stopdate << endl;
|
---|
88 | if (cal)
|
---|
89 | fouthtml << "only data processed to the imgpar is taken into account" << endl;
|
---|
90 | fouthtml << "</td></tr>" << endl;
|
---|
91 |
|
---|
92 | ofstream fout(fname, ios::app);
|
---|
93 | cout << "writing to file " << fname << endl;
|
---|
94 | fout << "AnalysisNumber: " << dataset << endl << endl;
|
---|
95 |
|
---|
96 | TString query="Select Sequences.fSequenceFirst from Sequences left join Source on ";
|
---|
97 | query +="Sequences.fSourceKEY=Source.fSourceKEY ";
|
---|
98 | if (cal)
|
---|
99 | query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
|
---|
100 | query +=Form(" where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
|
---|
101 | source.Data(), startdate.Data(), stopdate.Data());
|
---|
102 | if (cal)
|
---|
103 | query +=" and not IsNull(fStar) ";
|
---|
104 | query +=" order by Sequences.fSequenceFirst ";
|
---|
105 |
|
---|
106 | cout << "Q: " << query << endl;
|
---|
107 |
|
---|
108 | TSQLResult *res = serv.Query(query);
|
---|
109 | if (!res)
|
---|
110 | {
|
---|
111 | cout << "Error - no sequence found" << endl;
|
---|
112 | return 0;
|
---|
113 | }
|
---|
114 |
|
---|
115 | fout << "SequencesOn: " << flush;
|
---|
116 | TSQLRow *row=0;
|
---|
117 | while ((row = res->Next()))
|
---|
118 | fout << " " << (*row)[0] << " " << flush;
|
---|
119 | fout << endl << endl;
|
---|
120 |
|
---|
121 | delete res;
|
---|
122 |
|
---|
123 | if (off.Contains("none"))
|
---|
124 | {
|
---|
125 | cout << "no off chosen" << endl;
|
---|
126 | if (wobble.Contains("Y"))
|
---|
127 | {
|
---|
128 | cout << "wobble mode -> finished" << endl;
|
---|
129 | return 1;
|
---|
130 | }
|
---|
131 | off ="Off";
|
---|
132 | off +=source.Remove(7,12);
|
---|
133 | }
|
---|
134 |
|
---|
135 | cout << "off: " << off << endl;
|
---|
136 | query ="Select Sequences.fSequenceFirst from Sequences left join Source on ";
|
---|
137 | query +="Sequences.fSourceKEY=Source.fSourceKEY ";
|
---|
138 | if (cal)
|
---|
139 | query +=" left join SequenceProcessStatus on Sequences.fSequenceFirst=SequenceProcessStatus.fSequenceFirst ";
|
---|
140 | query +=Form("where fSourceName like '%s%%' and fRunStart between '%s' and '%s'",
|
---|
141 | off.Data(), offstartdate.Data(), offstopdate.Data());
|
---|
142 | if (cal)
|
---|
143 | query +=" and not IsNull(fStar) ";
|
---|
144 | query +=" order by Sequences.fSequenceFirst ";
|
---|
145 |
|
---|
146 | cout << "Q: " << query << endl;
|
---|
147 |
|
---|
148 | res = serv.Query(query);
|
---|
149 | if (!res)
|
---|
150 | {
|
---|
151 | cout << "Error - no sequence found" << endl;
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 |
|
---|
155 | fout << "SequencesOff: " << flush;
|
---|
156 | row=0;
|
---|
157 | while ((row = res->Next()))
|
---|
158 | fout << " " << (*row)[0] << " " << flush;
|
---|
159 | fout << endl << endl;
|
---|
160 |
|
---|
161 | fout << "#SourceName: " << source << endl;
|
---|
162 | fout << "Catalog: /magic/datacenter/setup/magic_favorites.edb" << endl;
|
---|
163 | if (wobble.Contains("N"))
|
---|
164 | fout << "#" << flush;
|
---|
165 | fout << "WobbleMode: On" << endl << endl;
|
---|
166 |
|
---|
167 | delete res;
|
---|
168 |
|
---|
169 | return 1;
|
---|
170 | }
|
---|
171 |
|
---|