source: trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C@ 7243

Last change on this file since 7243 was 7243, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 23.4 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): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// buildsequenceentries.C
29// ======================
30//
31// to group the runs of one night into sequences, this marco:
32// - reads the runinformation of one night from the database
33// - group the runs into sets of following runs with the same conditions
34// - groups the runs in this sets to sequences such that each run belongs
35// to the nearest (in time) calibration run
36// - check if the runs with the same runtype have the same calibration script
37// and the same trigger tables
38//
39/////////////////////////////////////////////////////////////////////////////
40#include <iostream>
41#include <iomanip>
42#include <fstream>
43
44#include <MSQLServer.h>
45#include <TSQLRow.h>
46#include <TSQLResult.h>
47
48#include <TEnv.h>
49#include <TMath.h>
50#include <TExMap.h>
51#include <TArrayI.h>
52#include <TRegexp.h>
53#include <TSystem.h>
54
55#include <MTime.h>
56#include <MDirIter.h>
57
58using namespace std;
59
60int debug = 0;
61
62Bool_t DeleteSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t sequ, Bool_t dummy)
63{
64 TString query1(Form("DELETE FROM Calibration WHERE fSequenceFirst=%d", sequ));
65 TString query2(Form("DELETE FROM Star WHERE fSequenceFirst=%d", sequ));
66 TString query3(Form("DELETE FROM SequenceProcessStatus WHERE fSequenceFirst=%d", sequ));
67 TString query4(Form("UPDATE RunData SET fSequenceFirst=0 WHERE fSequenceFirst=%d", sequ));
68 TString query5(Form("DELETE FROM Sequences WHERE fSequenceFirst=%d AND fManuallyChangedKEY=1", sequ));
69
70 TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(),sequ/10000, sequ));
71 TString command(Form("rm -r %s/callisto/%04d/%08d/", datapath.Data(), sequ/10000, sequ));
72 TString command2(Form("rm -r %s/star/%04d/%08d/", datapath.Data(), sequ/10000, sequ));
73
74 if (dummy)
75 {
76 cout << "not using dummy=kTRUE the following commands would be executed: " << endl;
77 cout << "queries: " << endl;
78 cout << query1 << endl;
79 cout << query2 << endl;
80 cout << query3 << endl;
81 cout << query4 << endl;
82 cout << query5 << endl;
83 cout << "removing files:" << endl;
84 cout << "unlink " << fname << endl;
85 cout << command << endl;
86 cout << command2 << endl;
87 return kTRUE;
88 }
89
90 TSQLResult *res = serv.Query(query1);
91 if (!res)
92 return kFALSE;
93 delete res;
94
95 res = serv.Query(query2);
96 if (!res)
97 return kFALSE;
98 delete res;
99
100 res = serv.Query(query3);
101 if (!res)
102 return kFALSE;
103 delete res;
104
105 res = serv.Query(query4);
106 if (!res)
107 return kFALSE;
108 delete res;
109
110 res = serv.Query(query5);
111 if (!res)
112 return kFALSE;
113 delete res;
114
115 gSystem->Unlink(fname);
116
117 gSystem->Exec(command);
118 gSystem->Exec(command2);
119
120 return kTRUE;
121}
122
123Int_t DoCheck(TSQLResult &res)
124{
125 TArrayI data(5);
126 Int_t n = 0;
127
128 TSQLRow *row=0;
129 while ((row=res.Next()))
130 {
131 n++;
132
133 if (data[0]==0)
134 {
135 for (int i=0; i<data.GetSize(); i++)
136 data[i] = atoi((*row)[i]);
137 continue;
138 }
139
140 for (int i=1; i<data.GetSize(); i++)
141 {
142 if (data[i] != atoi((*row)[i]))
143 return i+1;
144 }
145 }
146 return n==0 ? 0 : -1;
147}
148
149Bool_t CheckRuns(MSQLServer &serv, Int_t from, Int_t to, Int_t type)
150{
151 TString query("SELECT fRunNumber, fL1TriggerTableKEY, fL2TriggerTableKEY,"
152 " fCalibrationScriptKEY, fProjectKEY FROM RunData");
153 query += Form(" WHERE fRunTypeKEY=%d AND fExcludedFDAKEY=1 AND "
154 " (fRunNumber BETWEEN %d AND %d)"
155 " ORDER BY fRunNumber", type, from, to);
156
157 TSQLResult *res = serv.Query(query);
158 if (!res)
159 return kFALSE;
160
161 Int_t rc = DoCheck(*res);
162 delete res;
163
164 switch (rc)
165 {
166 case 0: cout << "ERROR - No runs found for check!" << endl; break;
167 case 1: cout << "ERROR - fRunNumber doesn't match!" << endl; break;
168 case 2: cout << "ERROR - fL1TriggerTableKEY doesn't match!" << endl; break;
169 case 3: cout << "ERROR - fL2TriggerTableKEY doesn't match!" << endl; break;
170 case 4: cout << "ERROR - fCalibrationScriptKEY doesn't match!" << endl; break;
171 case 5: cout << "ERROR - fProjectKEY doesn't match!" << endl; break;
172 }
173
174 return rc<0;
175}
176
177Bool_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
178{
179 Int_t rc=0; //rc=0 means sequence is still the same -> insert not neccessary
180 //rc=1 means deleting sequence(s) worked -> insert
181 //if deleting sequence doesn't work -> return -1
182
183
184 //getting # of sequence (in sequDB) between from and to
185 TString query(Form("SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst BETWEEN %d and %d", from, to));
186
187 TSQLResult *res = serv.Query(query);
188 if (!res)
189 return -1;
190
191 TArrayI Sequences;
192 Int_t numsequ=0;
193
194 TSQLRow *row=0;
195 while ((row=res.Next()))
196 {
197 numsequ++;
198 sequences.Set(numsequ);
199 sequences.AddAt(atoi((*row)[0]), numsequ-1);
200 }
201 delete res;
202
203 //if there's no sequence in the table Sequences -> check other tables
204 //if there's one sequence -> check if the sequence is identical
205 //if there are more sequences -> delete them
206 switch (numsequ)
207 {
208 case 0:
209 cout << "found no sequence in Sequ-DB -> check other tables" << endl;
210 cout << " deleting every sequence found in Calibration, Star or SequenceProcessStatus between "
211 << from << " and " << to << endl;
212
213 //calibration table
214 query(Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to));
215 res = serv.Query(query);
216 if (!res)
217 return -1;
218 row=0;
219 while ((row=res.Next()))
220 {
221 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
222 return -1;
223 else
224 rc=1;
225 }
226 delete res;
227
228 //Star table
229 query(Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to));
230 res = serv.Query(query);
231 if (!res)
232 return -1;
233 row=0;
234 while ((row=res.Next()))
235 {
236 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
237 return -1;
238 else
239 rc=1;
240 }
241 delete res;
242
243 //SequenceProcessStatus table
244 query(Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to));
245 res = serv.Query(query);
246 if (!res)
247 return -1;
248 row=0;
249 while ((row=res.Next()))
250 {
251 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
252 return -1;
253 else
254 rc=1;
255 }
256 delete res;
257
258
259 case 1:
260 cout << "found 1 sequence: " << sequences.At(0) << " -> check sequ# " << endl;
261 if (sequences.At(0)!=from)
262 {
263 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
264 return -1;
265 else
266 rc=1;
267 }
268 else
269 {
270 cout << "sequence# is the same -> checking the runs " << endl;
271
272 //getting olf runs
273 query(Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from));
274 res = serv.Query(query);
275 if (!res)
276 return -1;
277
278 TArrayI oldruns;
279 Int_t count=0;
280 row=0;
281 while ((row=res.Next()))
282 {
283 count++;
284 oldruns.Set(count);
285 oldruns.AddAt(atoi((*row)[0]), count-1);
286 }
287 delete res;
288
289 //getting new runs
290 query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to));
291 res = serv.Query(query);
292 if (!res)
293 return -1;
294 TArrayI newruns;
295 count=0;
296 row=0;
297 while ((row=res.Next()))
298 {
299 count++;
300 oldruns.Set(count);
301 oldruns.AddAt(atoi((*row)[0]), count-1);
302 }
303 delete res;
304
305 //comparing old and new runs (first the # of runs, if it is the same, also the single runnumbers
306 if (oldruns.GetSize()!=newruns.GetSize())
307 {
308 cout << " number of runs is not the same -> deleting sequence " << sequences.At(0) << endl;
309 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
310 return -1;
311 else
312 rc=1;
313 }
314 else
315 {
316 cout << " number of runs is the same -> checking the single runnumbers " << endl;
317
318 for (Int_t i=0;i<newruns.GetSize();i++)
319 {
320 if (newruns.At(i)==oldruns.At(i))
321 continue;
322
323 cout << i << ". run is not the same ( " << oldruns.At(i) << " -- " << newruns.At(i)
324 << ") -> deleting sequence " << sequences.At(0) << endl;
325 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
326 return -1;
327 else
328 rc=1;
329 break;
330 }
331 }
332 }
333
334 default:
335 cout << "found " << numsequ << " sequences -> deleting them " << endl;
336
337 for (Int_t i=0;i<sequences.GetSize();i++)
338 {
339 cout << "deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl;
340 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
341 return -1;
342 else
343 rc=1;
344 }
345 }
346
347 return rc;
348}
349
350Bool_t InsertSequence(MSQLServer &serv, Int_t from, Int_t to)
351{
352
353 // ========== Request number of events ==========
354 TString query("SELECT SUM(fNumEvents), "
355 " SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0,"
356 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60,"
357 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), ");
358 query += " MIN(fZenithDistance), MAX(fZenithDistance), ";
359 query += " MIN(fAzimuth), MAX(fAzimuth) ";
360 query += Form(" FROM RunData WHERE fRunTypeKEY=2 AND "
361 " (fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1",
362 from, to);
363
364 TSQLResult *res = serv.Query(query);
365 if (!res)
366 return kFALSE;
367
368 TSQLRow *row = res->Next();
369 if (!row || !(*row)[0])
370 {
371 cout << "ERROR - No result from query: " << query << endl;
372 return kFALSE;
373 }
374
375 TString nevts = (*row)[0];
376 TString secs = (*row)[1];
377 TString zdmin = (*row)[2];
378 TString zdmax = (*row)[3];
379 TString azmin = (*row)[4];
380 TString azmax = (*row)[5];
381
382 delete res;
383
384 // ========== Request start time of sequence ==========
385 query = Form("SELECT fRunStart FROM RunData WHERE fRunNumber=%d AND fExcludedFDAKEY=1", from);
386
387 res = serv.Query(query);
388 if (!res)
389 return kFALSE;
390
391 row = res->Next();
392 if (!row || !(*row)[0])
393 {
394 cout << "ERROR - No result from query: " << query << endl;
395 return kFALSE;
396 }
397
398 TString start((*row)[0]);
399
400 delete res;
401
402 // ========== Request data of sequence ==========
403 query = Form("SELECT fSourceKEY, fProjectKEY, "
404 " fL1TriggerTableKEY, fL1TriggerTableKEY,"
405 " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
406 " fTriggerDelayTableKEY, fLightConditionsKEY, fTestFlagKEY"
407 " FROM RunData"
408 " WHERE fRunTypeKEY=2 AND fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)"
409 " LIMIT 1", from, to);
410
411 res = serv.Query(query);
412 if (!res)
413 return kFALSE;
414
415 row = res->Next();
416 if (!row)
417 {
418 cout << "ERROR - No result from query: " << query << endl;
419 return kFALSE;
420 }
421
422 TString query1("INSERT Sequences SET");
423 query1+=Form(" fSequenceFirst=%d, fSequenceLast=%d,", from, to);
424 query1+=Form(" fProjectKEY=%s,", (*row)[0]);
425 query1+=Form(" fSourceKEY=%s,", (*row)[1]);
426 query1+=Form(" fNumEvents=%s,", nevts.Data());
427 query1+=Form(" fRunTime=%s,", secs.Data());
428 query1+=Form(" fRunStart=\"%s\",", start.Data());
429 query1+=Form(" fZenithDistanceMin=%s,", zdmin.Data());
430 query1+=Form(" fZenithDistanceMax=%s,", zdmax.Data());
431 query1+=Form(" fAzimuthMin=%s,", azmin.Data());
432 query1+=Form(" fAzimuthMax=%s,", azmax.Data());
433 query1+=Form(" fL1TriggerTableKEY=%s,", (*row)[2]);
434 query1+=Form(" fL2TriggerTableKEY=%s,", (*row)[3]);
435 query1+=Form(" fHvSettingsKEY=%s,", (*row)[4]);
436 query1+=Form(" fDiscriminatorThresholdTableKEY=%s,", (*row)[5]);
437 query1+=Form(" fTriggerDelayTableKEY=%s,", (*row)[6]);
438 query1+=Form(" fLightConditionsKEY=%s,", (*row)[7]);
439 query1+=Form(" fTestFlagKEY=%s, fManuallyChangedKEY=1", (*row)[8]);
440
441
442 TString query2 = Form("UPDATE RunData SET fSequenceFirst=%d WHERE"
443 " (fRunNumber BETWEEN %d AND %d) AND"
444 " (fRunTypeKEY BETWEEN 2 AND 4) AND"
445 " fSourceKEY=%d AND fHvSettingsKEY=%s AND fExcludedFDAKEY=1",
446 from, from, to, (*row)[1], (*row)[4]);
447
448 TString query3 = Form("INSERT SequenceProcessStatus SET fSequenceFirst=%d ", from);
449
450 delete res;
451
452 res = serv.Query(query1);
453 if (!res)
454 return kFALSE;
455 delete res;
456
457 res = serv.Query(query2);
458 if (!res)
459 return kFALSE;
460 delete res;
461
462 res = serv.Query(query3);
463 if (!res)
464 return kFALSE;
465 delete res;
466
467 return kTRUE;
468}
469
470Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
471{
472 cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
473
474 if (!CheckRuns(serv, from, to, 2))
475 {
476 cout << "Warning - Found inconsistency in data-runs (" << from << ", " << to << ")" << endl;
477 //sequence is not built, but kTRUE is returned, to allow
478 //the automatic processing of the other sequences of this day
479 return kTRUE;
480 }
481 if (!CheckRuns(serv, from, to, 3))
482 {
483 cout << "Warning - Found inconsistency in ped-runs (" << from << ", " << to << ")" << endl;
484 //sequence is not built, but kTRUE is returned, to allow
485 //the automatic processing of the other sequences of this day
486 return kTRUE;
487 }
488
489 cout << "ok." << endl;
490
491
492 cout << "checking Sequence..." << endl;
493
494 Bool_t rc=kFALSE;
495 switch (CheckSequence(serv, datapath, sequpath, from, to, dummy))
496 {
497 case 0:
498 cout << " inserting sequence not necessary" << endl;
499 return kTRUE;
500
501 case 1:
502 cout << " deleting successfully finished -> inserting sequence " << from << endl;
503 if (dummy)
504 return kTRUE;
505 rc = InsertSequence(serv, from, to);
506 if (!rc)
507 cout << "InsertSequence failed!" << endl;
508
509 case -1:
510 cout << " deleting went wrong " << endl;
511 rc=kFALSE;
512 }
513
514
515 return rc;
516}
517
518Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
519{
520
521 TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop"
522 " FROM RunData"
523 " WHERE fRunNumber BETWEEN %d AND %d AND "
524 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)"
525 " ORDER BY fRunNumber", from, to));
526
527 TSQLResult *res = serv.Query(query);
528 if (!res)
529 return kFALSE;
530
531 TExMap map;
532
533 Int_t start=0;
534 Int_t stop=0;
535 Int_t last=0;
536 Int_t first=0;
537
538 MTime lasttime;
539
540 TSQLRow *row=0;
541
542 enum { UNKNOWN, PED=3, CAL=4, DATA=2 };
543 Char_t status = UNKNOWN;
544
545 Int_t nblocks = 0;
546
547 while ((row=res->Next()))
548 {
549 if (!(*row)[1])
550 continue;
551
552 if (start==0)
553 {
554 first = atoi((*row)[0]);
555 if (debug)
556 cout << "First Run: " << first << endl;
557 }
558
559 switch (atoi((*row)[1]))
560 {
561 case CAL: // ---------- CALIBRATION ----------
562 if (status!=CAL)
563 {
564 start = stop = atoi((*row)[0]);
565 if (!(*row)[2])
566 cout << "No time available... skipped." << endl;
567 else
568 {
569 MTime *tm = new MTime;
570 tm->SetSqlDateTime((*row)[2]);
571 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
572 }
573 }
574 status = CAL;
575 break;
576 default:
577 if (status==CAL)
578 {
579 MTime *tm = new MTime(lasttime);
580 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
581
582 stop = last;
583 nblocks++;
584 if (debug)
585 cout << "Cal Block #" << nblocks << " from " << start << " to " << last << endl;
586 }
587 status = UNKNOWN;
588 break;
589 }
590 last = atoi((*row)[0]);
591 lasttime.SetSqlDateTime((*row)[3]);
592 }
593 if (status==CAL)
594 {
595 stop = last;
596 nblocks++;
597 if (debug)
598 cout << "Cal Block #" << nblocks << " from " << start << " to " << stop << endl;
599 }
600
601 if (debug)
602 cout << "Last Run: " << last << endl;
603 delete res;
604
605 if (debug)
606 cout << "Found " << nblocks << " calibration blocks" << endl;
607
608 res = serv.Query(query);
609 if (!res)
610 return kFALSE;
611
612 Int_t n = -1;
613
614 Bool_t rc = kTRUE;
615
616 start = first;
617 while ((row=res->Next()))
618 {
619 if (!(*row)[1])
620 continue;
621
622 MTime tstart, tstop;
623 tstart.SetSqlDateTime((*row)[2]);
624 tstop.SetSqlDateTime((*row)[3]);
625
626 MTime min;
627 Int_t nmin = -1;
628 Double_t dmin = 1e35;
629
630 Long_t key, val;
631 TExMapIter nmap(&map);
632 while (nmap.Next(key, val))
633 {
634 MTime *t = (MTime*)key;
635
636 if (nmin==-1)
637 {
638 nmin = val;
639 min = *(MTime*)key;
640 dmin = fabs((Double_t)*t-(Double_t)tstart);
641 }
642
643 if (fabs((Double_t)*t-(Double_t)tstart) < dmin)
644 {
645 nmin = val;
646 dmin = fabs((Double_t)*t-(Double_t)tstart);
647 min = *t;
648 }
649 if (fabs((Double_t)*t-(Double_t)tstop) < dmin)
650 {
651 nmin = val;
652 dmin = fabs((Double_t)*t-(Double_t)tstop);
653 min = *t;
654 }
655 }
656
657 if (n!=nmin)
658 {
659 if (n!=-1)
660 {
661 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
662 {
663 rc = kFALSE;
664 //continue;
665 }
666 }
667 n = nmin;
668 start = atoi((*row)[0]);
669 }
670 last = atoi((*row)[0]);
671 }
672
673 delete res;
674
675 if (n!=-1 && start!=last)
676 {
677 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
678 rc = kFALSE;
679 }
680
681 if (debug)
682 cout << endl;
683
684 return rc;
685}
686
687
688
689int buildsequenceentries(TString day, TString datapath, TString sequpath, Bool_t dummy=kTRUE)
690{
691 TEnv env("sql.rc");
692
693 MSQLServer serv(env);
694 if (!serv.IsConnected())
695 {
696 cout << "ERROR - Connection to database failed." << endl;
697 return 0;
698 }
699
700 cout << "buildsequences" << endl;
701 cout << "--------------" << endl;
702 cout << endl;
703 cout << "Connected to " << serv.GetName() << endl;
704 cout << "Night of sunrise at: " << day << endl;
705 cout << endl;
706
707 day += " 13:00:00";
708 const TString cond(Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
709 day.Data(), day.Data()));
710
711 TString query(Form("SELECT fRunNumber, fSourceKEY, fProjectKEY, fHvSettingsKEY, fLightConditionsKEY, fDiscriminatorThresholdTableKEY, fTriggerDelayTableKEY FROM RunData WHERE %s AND fExcludedFDAKEY=1 order by fRunNumber", cond.Data()));
712
713 TSQLResult *res = serv.Query(query);
714 if (!res)
715 return 0;
716
717 TString keys[6]= { "NULL", "NULL", "NULL", "NULL", "NULL", "NULL" };
718 TString stop = "NULL";
719 TString runstart = "NULL";
720 TString runstop = "NULL";
721 Int_t count = 0;
722 TExMap blocks;
723 Int_t runbegin;
724 Int_t runend;
725
726 TSQLRow *row=0;
727 while ((row=res->Next()))
728 {
729 if (count==0)
730 {
731 for (Int_t i=1 ; i<7 ; i++)
732 keys[i-1]=(*row)[i];
733 runstart=(*row)[0];
734 }
735
736 for (Int_t i=1 ; i<7 ; i++)
737 {
738 runbegin=atoi(runstart.Data());
739 runend=atoi(runstop.Data());
740 if (i==2 && runbegin>20100 && runend<45100)
741 continue;
742
743 TString value=(*row)[i];
744 TString key=keys[i-1];
745 if (!value.CompareTo(key))
746 continue;
747
748 keys[i-1]=value;
749 //hier einfuellen
750 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
751 runstart=(*row)[0];
752 for (Int_t i=1 ; i<7 ; i++)
753 keys[i-1]=(*row)[i];
754 break;
755 }
756 runstop=(*row)[0];
757 count++;
758 }
759
760 //und hier einfuellen (letzter wert)
761 runbegin=atoi(runstart.Data());
762 runend=atoi(runstop.Data());
763 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
764
765
766 Bool_t rc = kTRUE;
767
768 Long_t key, val;
769 TExMapIter nblocks(&blocks);
770 while (nblocks.Next(key, val))
771 {
772 Int_t runstart2 = (Int_t)key;
773 Int_t runstop2 = (Int_t)val;
774 cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
775
776 if (!Process(serv, datapath, sequpath, runstart2, runstop2, dummy))
777 rc = kFALSE;
778
779 }
780 return rc ? 1 : 0;
781}
782
783
784int buildsequenceentries(TString datapath, TString sequpath, Bool_t dummy=kTRUE)
785{
786 TEnv env("sql.rc");
787
788 MSQLServer serv(env);
789 if (!serv.IsConnected())
790 {
791 cout << "ERROR - Connection to database failed." << endl;
792 return 0;
793 }
794
795 TString query="SELECT fDate FROM SequenceBuildStatus";
796
797 TSQLResult *res = serv.Query(query);
798 if (!res)
799 return 0;
800
801 TSQLRow *row=0;
802 while ((row=res->Next()))
803 {
804 cout << "date: " << (*row)[0] << endl;
805 buildsequenceentries((*row)[0], dummy);
806 }
807
808 return 1;
809}
Note: See TracBrowser for help on using the repository browser.