source: trunk/Mars/datacenter/macros/insertsequence.C@ 16130

Last change on this file since 16130 was 9308, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.6 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, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// insertsequence.C
28// ================
29//
30// This macro inserts a sequence into the database. It extracts the
31// information from a sequence file.
32// This macro is not used by the automatic analysis. It is needed to insert
33// manually built sequences into the database.
34//
35// Usage:
36// .x insertsequence.C+("filename", kTRUE)
37// The first argument is the filename of the manual written sequencefile.
38// The second argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
39// switched on and nothing will be written into the database. This is usefull
40// for tests.
41//
42// Make sure, that database and password are corretly set in a resource
43// file called sql.rc and the resource file is found.
44//
45// Returns 0 in case of failure and 1 in case of success.
46//
47/////////////////////////////////////////////////////////////////////////////
48
49#include <iostream>
50#include <iomanip>
51
52#include <TEnv.h>
53
54#include <MSQLMagic.h>
55#include <TSQLRow.h>
56#include <TSQLResult.h>
57
58using namespace std;
59
60int insertsequence(TString filename, Bool_t dummy=kTRUE)
61{
62 cout << "ERROR - TelescopeNumber and FileNumber not implemeted." << endl;
63 return 2;
64/*
65 TEnv env("sql.rc");
66 TEnv sequ(filename);
67
68 MSQLMagic serv(env);
69 if (!serv.IsConnected())
70 {
71 cout << "ERROR - Connection to database failed." << endl;
72 return 0;
73 }
74
75 serv.SetIsDummy(dummy);
76
77 cout << "insertsequence" << endl;
78 cout << "--------------" << endl;
79 cout << endl;
80 cout << "Connected to " << serv.GetName() << endl;
81 cout << endl;
82
83 //get sequence number from file
84 TString sequnum;
85 sequnum=sequ.GetValue("Sequence", "");
86 Int_t seq=atoi(sequnum.Data());
87
88 //get runs from sequence file
89 TString runs;
90 runs = sequ.GetValue("Runs", "");
91 runs.ReplaceAll(" ", ",");
92 if (runs.IsNull())
93 {
94 cout << "ERROR - No runs in file " << filename << " found." << endl;
95 return 0;
96 }
97
98 //get source key
99 TString sourcename = sequ.GetValue("Source", "");
100 Int_t sourcekey = serv.QueryKeyOfName("Source", sourcename.Data(), kFALSE);
101 if (sourcekey<0)
102 {
103 cout << "Error - could not get sourcename from DB -> " << flush;
104 cout << "maybe you have the wrong sourcename in your datasetfile" << endl;
105 return 2;
106 }
107
108 //get values for the sequence
109 TString query="SELECT max(fRunNumber), min(fRunStart), ";
110 query +="sum(time_to_sec(fRunStop)-time_to_sec(fRunStart)), ";
111 query +="min(fZenithDistance), max(fZenithDistance), ";
112 query +="min(fAzimuth), max(fAzimuth), sum(fNumEvents) from RunData ";
113 query +=Form("WHERE fRunNumber IN (%s)",runs.Data());
114
115 cout << "runs: " << runs << endl;
116 cout << "q1: " << query << endl;
117
118 TSQLResult *res = serv.Query(query);
119 if (!res)
120 return 0;
121
122 TSQLRow *row=res->Next();
123 TString lastrun=(*row)[0];
124 TString starttime=(*row)[1];
125 TString uptime=(*row)[2];
126 TString zdmin=(*row)[3];
127 TString zdmax=(*row)[4];
128 TString azmin=(*row)[5];
129 TString azmax=(*row)[6];
130 TString numevts=(*row)[7];
131
132 delete res;
133
134 query ="SELECT fProjectKEY, fSourceKEY, fHvSettingsKEY, ";
135 query +="fTriggerDelayTableKEY, fDiscriminatorThresholdTableKEY, ";
136 query +="fTestFlagKEY, fLightConditionsKEY, fL1TriggerTableKEY, ";
137 query +=Form("fL2TriggerTableKEY FROM RunData WHERE fRunNumber=%d", seq);
138
139 cout << "q2: " << query << endl;
140
141 res = serv.Query(query);
142 if (!res)
143 return 0;
144
145 row=res->Next();
146 TString project=(*row)[0];
147 TString source=(*row)[1];
148 TString hv=(*row)[2];
149 TString delay=(*row)[3];
150 TString dt=(*row)[4];
151 TString testflag=(*row)[5];
152 TString lightcond=(*row)[6];
153 TString l1tt=(*row)[7];
154 TString l2tt=(*row)[8];
155
156 delete res;
157
158 cout << "seq: " << seq << endl;
159 cout << " lastrun " << lastrun << endl;
160 cout << " startime " << starttime << endl;
161 cout << " uptime " << uptime << endl;
162 cout << " zdmin " << zdmin << endl;
163 cout << " zdmax " << zdmax << endl;
164 cout << " azmin " << azmin << endl;
165 cout << " azmax " << azmax << endl;
166 cout << " numevts " << numevts << endl;
167 cout << " keys:" << endl;
168 cout << " project " << project << endl;
169 cout << " source1 " << source << " (from db -> run " << seq << ") " << endl;
170 cout << " source2 " << sourcekey << " (from sequ file) " << endl;
171 if (!(atoi(source.Data())==sourcekey))
172 {
173 cout << "new source name: " << sourcename << " -> inserting..." << endl;
174 sourcekey = serv.QueryKeyOfName("Source", sourcename.Data(), kFALSE);
175 if (sourcekey<0)
176 {
177 cout << "Error - could not get sourcename from DB -> " << flush;
178 cout << "maybe you have the wrong sourcename in your datasetfile" << endl;
179 return 2;
180 }
181 source=Form("%d",sourcekey);
182 }
183 cout << " source " << source << endl;
184 cout << " hv " << hv << endl;
185 cout << " delay " << delay << endl;
186 cout << " dt " << dt << endl;
187 cout << " testflag " << testflag << endl;
188 cout << " lightcond " << lightcond << endl;
189 cout << " l1tt " << l1tt << endl;
190 cout << " l2tt " << l2tt << endl;
191
192 //build queries
193 TString vals=
194 Form("fManuallyChangedKEY=2, "
195 "fSequenceFirst=%d, fSequenceLast=%s, "
196 "fProjectKEY=%s, fSourceKEY=%s, fNumEvents=%s, "
197 "fRunStart='%s', fHvSettingsKEY=%s, fRunTime=%s, "
198 "fTriggerDelayTableKEY=%s, fDiscriminatorThresholdTableKEY=%s, "
199 "fTestFlagKEY=%s, fLightConditionsKEY=%s, fAzimuthMin=%s, "
200 "fAzimuthMax=%s, fZenithDistanceMin=%s, fZenithDistanceMax=%s, "
201 "fL1TriggerTableKEY=%s, fL2TriggerTableKEY=%s ",
202 seq, lastrun.Data(), project.Data(), source.Data(),
203 numevts.Data(), starttime.Data(), hv.Data(), uptime.Data(),
204 delay.Data(), dt.Data(), testflag.Data(), lightcond.Data(),
205 azmin.Data(), azmax.Data(), zdmin.Data(), zdmax.Data(),
206 l1tt.Data(), l2tt.Data());
207
208 const Int_t rc1 = serv.Insert("Sequences", vals);
209 if (rc1<0) // dummy
210 return 1;
211 if (rc1==kFALSE) // insert failed
212 return 0;
213
214 //the time of the column fSequenceFileWritten is set to 'not to be done'
215 vals=Form("fSequenceFirst=%d, fSequenceFileWritten='1970-01-01 00:00:00'", seq);
216
217 const Int_t rc2 = serv.Insert("SequencesProcessStatus", vals);
218
219 if (rc2<0) // dummy
220 return 1;
221 if (rc2==kFALSE) // insert failed
222 return 0;
223
224 return 1;
225 */
226}
227
228
Note: See TracBrowser for help on using the repository browser.