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

Last change on this file since 7248 was 7248, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 23.5 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 break;
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(0), 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 break;
334
335 default:
336 cout << "found " << numsequ << " sequences -> deleting them " << endl;
337
338 for (Int_t i=0;i<sequences.GetSize();i++)
339 {
340 cout << "deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl;
341 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
342 return -1;
343 else
344 rc=1;
345 }
346 }
347
348 return rc;
349}
350
351Bool_t InsertSequence(MSQLServer &serv, Int_t from, Int_t to)
352{
353
354 // ========== Request number of events ==========
355 TString query("SELECT SUM(fNumEvents), "
356 " SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0,"
357 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60,"
358 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), ");
359 query += " MIN(fZenithDistance), MAX(fZenithDistance), ";
360 query += " MIN(fAzimuth), MAX(fAzimuth) ";
361 query += Form(" FROM RunData WHERE fRunTypeKEY=2 AND "
362 " (fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1",
363 from, to);
364
365 TSQLResult *res = serv.Query(query);
366 if (!res)
367 return kFALSE;
368
369 TSQLRow *row = res->Next();
370 if (!row || !(*row)[0])
371 {
372 cout << "ERROR - No result from query: " << query << endl;
373 return kFALSE;
374 }
375
376 TString nevts = (*row)[0];
377 TString secs = (*row)[1];
378 TString zdmin = (*row)[2];
379 TString zdmax = (*row)[3];
380 TString azmin = (*row)[4];
381 TString azmax = (*row)[5];
382
383 delete res;
384
385 // ========== Request start time of sequence ==========
386 query = Form("SELECT fRunStart FROM RunData WHERE fRunNumber=%d AND fExcludedFDAKEY=1", from);
387
388 res = serv.Query(query);
389 if (!res)
390 return kFALSE;
391
392 row = res->Next();
393 if (!row || !(*row)[0])
394 {
395 cout << "ERROR - No result from query: " << query << endl;
396 return kFALSE;
397 }
398
399 TString start((*row)[0]);
400
401 delete res;
402
403 // ========== Request data of sequence ==========
404 query = Form("SELECT fSourceKEY, fProjectKEY, "
405 " fL1TriggerTableKEY, fL1TriggerTableKEY,"
406 " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
407 " fTriggerDelayTableKEY, fLightConditionsKEY, fTestFlagKEY"
408 " FROM RunData"
409 " WHERE fRunTypeKEY=2 AND fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)"
410 " LIMIT 1", from, to);
411
412 res = serv.Query(query);
413 if (!res)
414 return kFALSE;
415
416 row = res->Next();
417 if (!row)
418 {
419 cout << "ERROR - No result from query: " << query << endl;
420 return kFALSE;
421 }
422
423 TString query1("INSERT Sequences SET");
424 query1+=Form(" fSequenceFirst=%d, fSequenceLast=%d,", from, to);
425 query1+=Form(" fProjectKEY=%s,", (*row)[0]);
426 query1+=Form(" fSourceKEY=%s,", (*row)[1]);
427 query1+=Form(" fNumEvents=%s,", nevts.Data());
428 query1+=Form(" fRunTime=%s,", secs.Data());
429 query1+=Form(" fRunStart=\"%s\",", start.Data());
430 query1+=Form(" fZenithDistanceMin=%s,", zdmin.Data());
431 query1+=Form(" fZenithDistanceMax=%s,", zdmax.Data());
432 query1+=Form(" fAzimuthMin=%s,", azmin.Data());
433 query1+=Form(" fAzimuthMax=%s,", azmax.Data());
434 query1+=Form(" fL1TriggerTableKEY=%s,", (*row)[2]);
435 query1+=Form(" fL2TriggerTableKEY=%s,", (*row)[3]);
436 query1+=Form(" fHvSettingsKEY=%s,", (*row)[4]);
437 query1+=Form(" fDiscriminatorThresholdTableKEY=%s,", (*row)[5]);
438 query1+=Form(" fTriggerDelayTableKEY=%s,", (*row)[6]);
439 query1+=Form(" fLightConditionsKEY=%s,", (*row)[7]);
440 query1+=Form(" fTestFlagKEY=%s, fManuallyChangedKEY=1", (*row)[8]);
441
442
443 TString query2 = Form("UPDATE RunData SET fSequenceFirst=%d WHERE"
444 " (fRunNumber BETWEEN %d AND %d) AND"
445 " (fRunTypeKEY BETWEEN 2 AND 4) AND"
446 " fSourceKEY=%d AND fHvSettingsKEY=%s AND fExcludedFDAKEY=1",
447 from, from, to, (*row)[1], (*row)[4]);
448
449 TString query3 = Form("INSERT SequenceProcessStatus SET fSequenceFirst=%d ", from);
450
451 delete res;
452
453 res = serv.Query(query1);
454 if (!res)
455 return kFALSE;
456 delete res;
457
458 res = serv.Query(query2);
459 if (!res)
460 return kFALSE;
461 delete res;
462
463 res = serv.Query(query3);
464 if (!res)
465 return kFALSE;
466 delete res;
467
468 return kTRUE;
469}
470
471Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
472{
473 cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
474
475 if (!CheckRuns(serv, from, to, 2))
476 {
477 cout << "Warning - Found inconsistency in data-runs (" << from << ", " << to << ")" << endl;
478 //sequence is not built, but kTRUE is returned, to allow
479 //the automatic processing of the other sequences of this day
480 return kTRUE;
481 }
482 if (!CheckRuns(serv, from, to, 3))
483 {
484 cout << "Warning - Found inconsistency in ped-runs (" << from << ", " << to << ")" << endl;
485 //sequence is not built, but kTRUE is returned, to allow
486 //the automatic processing of the other sequences of this day
487 return kTRUE;
488 }
489
490 cout << "ok." << endl;
491
492
493 cout << "checking Sequence..." << endl;
494
495 Bool_t rc=kFALSE;
496 switch (CheckSequence(serv, datapath, sequpath, from, to, dummy))
497 {
498 case 0:
499 cout << " inserting sequence not necessary" << endl;
500 return kTRUE;
501
502 case 1:
503 cout << " deleting successfully finished -> inserting sequence " << from << endl;
504 if (dummy)
505 return kTRUE;
506 rc = InsertSequence(serv, from, to);
507 if (!rc)
508 cout << "InsertSequence failed!" << endl;
509 break;
510
511 case -1:
512 cout << " deleting went wrong " << endl;
513 rc=kFALSE;
514 }
515
516
517 return rc;
518}
519
520Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
521{
522
523 TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop"
524 " FROM RunData"
525 " WHERE fRunNumber BETWEEN %d AND %d AND "
526 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)"
527 " ORDER BY fRunNumber", from, to));
528
529 TSQLResult *res = serv.Query(query);
530 if (!res)
531 return kFALSE;
532
533 TExMap map;
534
535 Int_t start=0;
536 Int_t stop=0;
537 Int_t last=0;
538 Int_t first=0;
539
540 MTime lasttime;
541
542 TSQLRow *row=0;
543
544 enum { UNKNOWN, PED=3, CAL=4, DATA=2 };
545 Char_t status = UNKNOWN;
546
547 Int_t nblocks = 0;
548
549 while ((row=res->Next()))
550 {
551 if (!(*row)[1])
552 continue;
553
554 if (start==0)
555 {
556 first = atoi((*row)[0]);
557 if (debug)
558 cout << "First Run: " << first << endl;
559 }
560
561 switch (atoi((*row)[1]))
562 {
563 case CAL: // ---------- CALIBRATION ----------
564 if (status!=CAL)
565 {
566 start = stop = atoi((*row)[0]);
567 if (!(*row)[2])
568 cout << "No time available... skipped." << endl;
569 else
570 {
571 MTime *tm = new MTime;
572 tm->SetSqlDateTime((*row)[2]);
573 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
574 }
575 }
576 status = CAL;
577 break;
578 default:
579 if (status==CAL)
580 {
581 MTime *tm = new MTime(lasttime);
582 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
583
584 stop = last;
585 nblocks++;
586 if (debug)
587 cout << "Cal Block #" << nblocks << " from " << start << " to " << last << endl;
588 }
589 status = UNKNOWN;
590 break;
591 }
592 last = atoi((*row)[0]);
593 lasttime.SetSqlDateTime((*row)[3]);
594 }
595 if (status==CAL)
596 {
597 stop = last;
598 nblocks++;
599 if (debug)
600 cout << "Cal Block #" << nblocks << " from " << start << " to " << stop << endl;
601 }
602
603 if (debug)
604 cout << "Last Run: " << last << endl;
605 delete res;
606
607 if (debug)
608 cout << "Found " << nblocks << " calibration blocks" << endl;
609
610 res = serv.Query(query);
611 if (!res)
612 return kFALSE;
613
614 Int_t n = -1;
615
616 Bool_t rc = kTRUE;
617
618 start = first;
619 while ((row=res->Next()))
620 {
621 if (!(*row)[1])
622 continue;
623
624 MTime tstart, tstop;
625 tstart.SetSqlDateTime((*row)[2]);
626 tstop.SetSqlDateTime((*row)[3]);
627
628 MTime min;
629 Int_t nmin = -1;
630 Double_t dmin = 1e35;
631
632 Long_t key, val;
633 TExMapIter nmap(&map);
634 while (nmap.Next(key, val))
635 {
636 MTime *t = (MTime*)key;
637
638 if (nmin==-1)
639 {
640 nmin = val;
641 min = *(MTime*)key;
642 dmin = fabs((Double_t)*t-(Double_t)tstart);
643 }
644
645 if (fabs((Double_t)*t-(Double_t)tstart) < dmin)
646 {
647 nmin = val;
648 dmin = fabs((Double_t)*t-(Double_t)tstart);
649 min = *t;
650 }
651 if (fabs((Double_t)*t-(Double_t)tstop) < dmin)
652 {
653 nmin = val;
654 dmin = fabs((Double_t)*t-(Double_t)tstop);
655 min = *t;
656 }
657 }
658
659 if (n!=nmin)
660 {
661 if (n!=-1)
662 {
663 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
664 {
665 rc = kFALSE;
666 //continue;
667 }
668 }
669 n = nmin;
670 start = atoi((*row)[0]);
671 }
672 last = atoi((*row)[0]);
673 }
674
675 delete res;
676
677 if (n!=-1 && start!=last)
678 {
679 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
680 rc = kFALSE;
681 }
682
683 if (debug)
684 cout << endl;
685
686 return rc;
687}
688
689
690
691int buildsequenceentries(TString day, TString datapath, TString sequpath, Bool_t dummy=kTRUE)
692{
693 TEnv env("sql.rc");
694
695 MSQLServer serv(env);
696 if (!serv.IsConnected())
697 {
698 cout << "ERROR - Connection to database failed." << endl;
699 return 0;
700 }
701
702 cout << "buildsequences" << endl;
703 cout << "--------------" << endl;
704 cout << endl;
705 cout << "Connected to " << serv.GetName() << endl;
706 cout << "Night of sunrise at: " << day << endl;
707 cout << endl;
708
709 day += " 13:00:00";
710 const TString cond(Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
711 day.Data(), day.Data()));
712
713 TString query(Form("SELECT fRunNumber, fSourceKEY, fProjectKEY, fHvSettingsKEY, fLightConditionsKEY, fDiscriminatorThresholdTableKEY, fTriggerDelayTableKEY FROM RunData WHERE %s AND fExcludedFDAKEY=1 order by fRunNumber", cond.Data()));
714
715 TSQLResult *res = serv.Query(query);
716 if (!res)
717 return 0;
718
719 TString keys[6]= { "NULL", "NULL", "NULL", "NULL", "NULL", "NULL" };
720 TString stop = "NULL";
721 TString runstart = "NULL";
722 TString runstop = "NULL";
723 Int_t count = 0;
724 TExMap blocks;
725 Int_t runbegin;
726 Int_t runend;
727
728 TSQLRow *row=0;
729 while ((row=res->Next()))
730 {
731 if (count==0)
732 {
733 for (Int_t i=1 ; i<7 ; i++)
734 keys[i-1]=(*row)[i];
735 runstart=(*row)[0];
736 }
737
738 for (Int_t i=1 ; i<7 ; i++)
739 {
740 runbegin=atoi(runstart.Data());
741 runend=atoi(runstop.Data());
742 if (i==2 && runbegin>20100 && runend<45100)
743 continue;
744
745 TString value=(*row)[i];
746 TString key=keys[i-1];
747 if (!value.CompareTo(key))
748 continue;
749
750 keys[i-1]=value;
751 //hier einfuellen
752 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
753 runstart=(*row)[0];
754 for (Int_t i=1 ; i<7 ; i++)
755 keys[i-1]=(*row)[i];
756 break;
757 }
758 runstop=(*row)[0];
759 count++;
760 }
761
762 //und hier einfuellen (letzter wert)
763 runbegin=atoi(runstart.Data());
764 runend=atoi(runstop.Data());
765 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
766
767
768 Bool_t rc = kTRUE;
769
770 Long_t key, val;
771 TExMapIter nblocks(&blocks);
772 while (nblocks.Next(key, val))
773 {
774 Int_t runstart2 = (Int_t)key;
775 Int_t runstop2 = (Int_t)val;
776 cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
777
778 if (!Process(serv, datapath, sequpath, runstart2, runstop2, dummy))
779 rc = kFALSE;
780
781 }
782 return rc ? 1 : 0;
783}
784
785
786int buildsequenceentries(TString datapath, TString sequpath, Bool_t dummy=kTRUE)
787{
788 TEnv env("sql.rc");
789
790 MSQLServer serv(env);
791 if (!serv.IsConnected())
792 {
793 cout << "ERROR - Connection to database failed." << endl;
794 return 0;
795 }
796
797 TString query="SELECT fDate FROM SequenceBuildStatus";
798
799 TSQLResult *res = serv.Query(query);
800 if (!res)
801 return 0;
802
803 TSQLRow *row=0;
804 while ((row=res->Next()))
805 {
806 cout << "date: " << (*row)[0] << endl;
807 buildsequenceentries((*row)[0], dummy);
808 }
809
810 return 1;
811}
Note: See TracBrowser for help on using the repository browser.