source: tags/Mars-V0.9.4/datacenter/macros/buildsequenceentries.C

Last change on this file was 7254, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 24.2 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;
180 //rc=0 means sequence not found -> insert
181 //rc=1 means deleting sequence(s) worked -> insert
182 //rc=2 means sequence is still the same -> insert not neccessary
183 //if deleting sequence doesn't work -> return -1
184
185
186 //getting # of sequence (in sequDB) between from and to
187 TString query("SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst ");
188 query += Form("BETWEEN %d and %d OR fSequenceLast BETWEEN %d and %d",
189 from, to, from, to);
190
191 TSQLResult *res = serv.Query(query);
192 if (!res)
193 return -1;
194
195 TArrayI sequences;
196 Int_t numsequ=0;
197
198 TSQLRow *row=0;
199 while ((row=res->Next()))
200 {
201 numsequ++;
202 sequences.Set(numsequ);
203 sequences.AddAt(atoi((*row)[0]), numsequ-1);
204 }
205 delete res;
206
207 //if there's no sequence in the table Sequences -> check other tables
208 //if there's one sequence -> check if the sequence is identical
209 //if there are more sequences -> delete them
210 switch (numsequ)
211 {
212 case 0:
213 cout << "found no sequence in Sequ-DB -> check other tables" << endl;
214 cout << " deleting every sequence found in Calibration, Star or SequenceProcessStatus between "
215 << from << " and " << to << endl;
216
217 //calibration table
218 query(Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to));
219 res = serv.Query(query);
220 if (!res)
221 return -1;
222 row=0;
223 while ((row=res->Next()))
224 {
225 if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
226 return -1;
227 else
228 rc=1;
229 }
230 delete res;
231
232 //Star table
233 query(Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to));
234 res = serv.Query(query);
235 if (!res)
236 return -1;
237 row=0;
238 while ((row=res->Next()))
239 {
240 if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
241 return -1;
242 else
243 rc=1;
244 }
245 delete res;
246
247 //SequenceProcessStatus table
248 query(Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to));
249 res = serv.Query(query);
250 if (!res)
251 return -1;
252 row=0;
253 while ((row=res->Next()))
254 {
255 if (!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy))
256 return -1;
257 else
258 rc=1;
259 }
260 delete res;
261 break;
262
263 case 1:
264 cout << "found 1 sequence: " << sequences.At(0) << " -> check sequ# " << endl;
265 if (sequences.At(0)!=from)
266 {
267 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
268 return -1;
269 else
270 rc=1;
271 }
272 else
273 {
274 cout << "sequence# is the same -> checking the runs " << endl;
275
276 //getting olf runs
277 query(Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from));
278 res = serv.Query(query);
279 if (!res)
280 return -1;
281
282 TArrayI oldruns;
283 Int_t count=0;
284 row=0;
285 while ((row=res->Next()))
286 {
287 count++;
288 oldruns.Set(count);
289 oldruns.AddAt(atoi((*row)[0]), count-1);
290 }
291 delete res;
292
293 //getting new runs
294 query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to));
295 res = serv.Query(query);
296 if (!res)
297 return -1;
298 TArrayI newruns;
299 count=0;
300 row=0;
301 while ((row=res->Next()))
302 {
303 count++;
304 oldruns.Set(count);
305 oldruns.AddAt(atoi((*row)[0]), count-1);
306 }
307 delete res;
308
309 //comparing old and new runs (first the # of runs, if it is the same, also the single runnumbers
310 if (oldruns.GetSize()!=newruns.GetSize())
311 {
312 cout << " number of runs is not the same -> deleting sequence " << sequences.At(0) << endl;
313 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
314 return -1;
315 else
316 rc=1;
317 }
318 else
319 {
320 cout << " number of runs is the same -> checking the single runnumbers " << endl;
321
322 for (Int_t i=0;i<newruns.GetSize();i++)
323 {
324 if (newruns.At(i)==oldruns.At(i))
325 continue;
326
327 cout << i << ". run is not the same ( " << oldruns.At(i) << " -- " << newruns.At(i)
328 << ") -> deleting sequence " << sequences.At(0) << endl;
329 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy))
330 return -1;
331 else
332 rc=1;
333 break;
334 }
335 }
336 }
337 rc=2;
338 break;
339
340 default:
341 cout << "found " << numsequ << " sequences -> deleting them " << endl;
342
343 for (Int_t i=0;i<sequences.GetSize();i++)
344 {
345 cout << "deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl;
346 if (!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy))
347 return -1;
348 else
349 rc=1;
350 }
351 }
352
353 return rc;
354}
355
356Bool_t InsertSequence(MSQLServer &serv, Int_t from, Int_t to)
357{
358
359 cout << "Inserting sequence " << from << " ... " << endl;
360
361 // ========== Request number of events ==========
362 TString query("SELECT SUM(fNumEvents), "
363 " SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0,"
364 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60,"
365 " TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), ");
366 query += " MIN(fZenithDistance), MAX(fZenithDistance), ";
367 query += " MIN(fAzimuth), MAX(fAzimuth) ";
368 query += Form(" FROM RunData WHERE fRunTypeKEY=2 AND "
369 " (fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1",
370 from, to);
371
372 TSQLResult *res = serv.Query(query);
373 if (!res)
374 return kFALSE;
375
376 TSQLRow *row = res->Next();
377 if (!row || !(*row)[0])
378 {
379 cout << "ERROR - No result from query: " << query << endl;
380 return kFALSE;
381 }
382
383 TString nevts = (*row)[0];
384 TString secs = (*row)[1];
385 TString zdmin = (*row)[2];
386 TString zdmax = (*row)[3];
387 TString azmin = (*row)[4];
388 TString azmax = (*row)[5];
389
390 delete res;
391
392 // ========== Request start time of sequence ==========
393 query = Form("SELECT fRunStart FROM RunData WHERE fRunNumber=%d AND fExcludedFDAKEY=1", from);
394
395 res = serv.Query(query);
396 if (!res)
397 return kFALSE;
398
399 row = res->Next();
400 if (!row || !(*row)[0])
401 {
402 cout << "ERROR - No result from query: " << query << endl;
403 return kFALSE;
404 }
405
406 TString start((*row)[0]);
407
408 delete res;
409
410 // ========== Request data of sequence ==========
411 query = Form("SELECT fSourceKEY, fProjectKEY, "
412 " fL1TriggerTableKEY, fL1TriggerTableKEY,"
413 " fHvSettingsKEY, fDiscriminatorThresholdTableKEY,"
414 " fTriggerDelayTableKEY, fLightConditionsKEY, fTestFlagKEY"
415 " FROM RunData"
416 " WHERE fRunTypeKEY=2 AND fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)"
417 " LIMIT 1", from, to);
418
419 res = serv.Query(query);
420 if (!res)
421 return kFALSE;
422
423 row = res->Next();
424 if (!row)
425 {
426 cout << "ERROR - No result from query: " << query << endl;
427 return kFALSE;
428 }
429
430 TString query1("INSERT Sequences SET");
431 query1+=Form(" fSequenceFirst=%d, fSequenceLast=%d,", from, to);
432 query1+=Form(" fSourceKEY=%s,", (*row)[0]);
433 query1+=Form(" fProjectKEY=%s,", (*row)[1]);
434 query1+=Form(" fNumEvents=%s,", nevts.Data());
435 query1+=Form(" fRunTime=%s,", secs.Data());
436 query1+=Form(" fRunStart=\"%s\",", start.Data());
437 query1+=Form(" fZenithDistanceMin=%s,", zdmin.Data());
438 query1+=Form(" fZenithDistanceMax=%s,", zdmax.Data());
439 query1+=Form(" fAzimuthMin=%s,", azmin.Data());
440 query1+=Form(" fAzimuthMax=%s,", azmax.Data());
441 query1+=Form(" fL1TriggerTableKEY=%s,", (*row)[2]);
442 query1+=Form(" fL2TriggerTableKEY=%s,", (*row)[3]);
443 query1+=Form(" fHvSettingsKEY=%s,", (*row)[4]);
444 query1+=Form(" fDiscriminatorThresholdTableKEY=%s,", (*row)[5]);
445 query1+=Form(" fTriggerDelayTableKEY=%s,", (*row)[6]);
446 query1+=Form(" fLightConditionsKEY=%s,", (*row)[7]);
447 query1+=Form(" fTestFlagKEY=%s, fManuallyChangedKEY=1", (*row)[8]);
448
449
450 TString query2 = Form("UPDATE RunData SET fSequenceFirst=%d WHERE"
451 " (fRunNumber BETWEEN %d AND %d) AND"
452 " (fRunTypeKEY BETWEEN 2 AND 4) AND"
453 " fSourceKEY=%d AND fHvSettingsKEY=%s AND fExcludedFDAKEY=1",
454 from, from, to, (*row)[1], (*row)[4]);
455
456 TString query3 = Form("INSERT SequenceProcessStatus SET fSequenceFirst=%d ", from);
457
458 delete res;
459
460
461 res = serv.Query(query1);
462 if (!res)
463 {
464 cout << "ERROR - Could not insert Sequence into Sequences." << endl;
465 return kFALSE;
466 }
467 delete res;
468
469 res = serv.Query(query2);
470 if (!res)
471 {
472 cout << "ERROR - Could not update RunData." << endl;
473 return kFALSE;
474 }
475 delete res;
476
477 res = serv.Query(query3);
478 if (!res)
479 {
480 cout << "ERROR - Could not insert Sequence into SequenceProcessStatus." << endl;
481 return kFALSE;
482 }
483 delete res;
484
485 return kTRUE;
486}
487
488Bool_t NewSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
489{
490 cout << "Found Sequence (" << from << ", " << to << ") ... checking runs..." << flush;
491
492 if (!CheckRuns(serv, from, to, 2))
493 {
494 cout << "Warning - Found inconsistency in data-runs (" << from << ", " << to << ")" << endl;
495 //sequence is not built, but kTRUE is returned, to allow
496 //the automatic processing of the other sequences of this day
497 return kTRUE;
498 }
499 if (!CheckRuns(serv, from, to, 3))
500 {
501 cout << "Warning - Found inconsistency in ped-runs (" << from << ", " << to << ")" << endl;
502 //sequence is not built, but kTRUE is returned, to allow
503 //the automatic processing of the other sequences of this day
504 return kTRUE;
505 }
506
507 cout << "ok." << endl;
508
509
510 cout << "checking Sequence..." << endl;
511
512 Bool_t rc=kFALSE;
513 switch (CheckSequence(serv, datapath, sequpath, from, to, dummy))
514 {
515 case 0:
516 cout << " sequence not found -> inserting " << from << flush ;
517 if (dummy)
518 {
519 cout << " <dummy> " << endl;
520 return kTRUE;
521 }
522 cout << endl;
523 return InsertSequence(serv, from, to);
524
525 case 1:
526 cout << " deleting successfully finished -> inserting sequence " << from << flush;
527 if (dummy)
528 {
529 cout << " <dummy> " << endl;
530 return kTRUE;
531 }
532 cout << endl;
533 return InsertSequence(serv, from, to);
534
535 case 2:
536 cout << " sequence is already existing -> inserting not necessary" << endl;
537 return kTRUE;
538
539 case -1:
540 cout << " deleting went wrong " << endl;
541 return kFALSE;
542 }
543
544
545 return rc;
546}
547
548Bool_t Process(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy)
549{
550
551 TString query(Form("SELECT fRunNumber, fRunTypeKEY, fRunStart, fRunStop"
552 " FROM RunData"
553 " WHERE fRunNumber BETWEEN %d AND %d AND "
554 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)"
555 " ORDER BY fRunNumber", from, to));
556
557 TSQLResult *res = serv.Query(query);
558 if (!res)
559 return kFALSE;
560
561 TExMap map;
562
563 Int_t start=0;
564 Int_t stop=0;
565 Int_t last=0;
566 Int_t first=0;
567
568 MTime lasttime;
569
570 TSQLRow *row=0;
571
572 enum { UNKNOWN, PED=3, CAL=4, DATA=2 };
573 Char_t status = UNKNOWN;
574
575 Int_t nblocks = 0;
576
577 while ((row=res->Next()))
578 {
579 if (!(*row)[1])
580 continue;
581
582 if (start==0)
583 {
584 first = atoi((*row)[0]);
585 if (debug)
586 cout << "First Run: " << first << endl;
587 }
588
589 switch (atoi((*row)[1]))
590 {
591 case CAL: // ---------- CALIBRATION ----------
592 if (status!=CAL)
593 {
594 start = stop = atoi((*row)[0]);
595 if (!(*row)[2])
596 cout << "No time available... skipped." << endl;
597 else
598 {
599 MTime *tm = new MTime;
600 tm->SetSqlDateTime((*row)[2]);
601 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
602 }
603 }
604 status = CAL;
605 break;
606 default:
607 if (status==CAL)
608 {
609 MTime *tm = new MTime(lasttime);
610 map.Add((ULong_t)map.GetSize(), (Long_t)tm, (Long_t)nblocks);
611
612 stop = last;
613 nblocks++;
614 if (debug)
615 cout << "Cal Block #" << nblocks << " from " << start << " to " << last << endl;
616 }
617 status = UNKNOWN;
618 break;
619 }
620 last = atoi((*row)[0]);
621 lasttime.SetSqlDateTime((*row)[3]);
622 }
623 if (status==CAL)
624 {
625 stop = last;
626 nblocks++;
627 if (debug)
628 cout << "Cal Block #" << nblocks << " from " << start << " to " << stop << endl;
629 }
630
631 if (debug)
632 cout << "Last Run: " << last << endl;
633 delete res;
634
635 if (debug)
636 cout << "Found " << nblocks << " calibration blocks" << endl;
637
638 res = serv.Query(query);
639 if (!res)
640 return kFALSE;
641
642 Int_t n = -1;
643
644 Bool_t rc = kTRUE;
645
646 start = first;
647 while ((row=res->Next()))
648 {
649 if (!(*row)[1])
650 continue;
651
652 MTime tstart, tstop;
653 tstart.SetSqlDateTime((*row)[2]);
654 tstop.SetSqlDateTime((*row)[3]);
655
656 MTime min;
657 Int_t nmin = -1;
658 Double_t dmin = 1e35;
659
660 Long_t key, val;
661 TExMapIter nmap(&map);
662 while (nmap.Next(key, val))
663 {
664 MTime *t = (MTime*)key;
665
666 if (nmin==-1)
667 {
668 nmin = val;
669 min = *(MTime*)key;
670 dmin = fabs((Double_t)*t-(Double_t)tstart);
671 }
672
673 if (fabs((Double_t)*t-(Double_t)tstart) < dmin)
674 {
675 nmin = val;
676 dmin = fabs((Double_t)*t-(Double_t)tstart);
677 min = *t;
678 }
679 if (fabs((Double_t)*t-(Double_t)tstop) < dmin)
680 {
681 nmin = val;
682 dmin = fabs((Double_t)*t-(Double_t)tstop);
683 min = *t;
684 }
685 }
686
687 if (n!=nmin)
688 {
689 if (n!=-1)
690 {
691 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
692 {
693 rc = kFALSE;
694 //continue;
695 }
696 }
697 n = nmin;
698 start = atoi((*row)[0]);
699 }
700 last = atoi((*row)[0]);
701 }
702
703 delete res;
704
705 if (n!=-1 && start!=last)
706 {
707 if (!NewSequence(serv, datapath, sequpath, start, last, dummy))
708 rc = kFALSE;
709 }
710
711 if (debug)
712 cout << endl;
713
714 return rc;
715}
716
717
718
719int buildsequenceentries(TString day, TString datapath, TString sequpath, Bool_t dummy=kTRUE)
720{
721 TEnv env("sql.rc");
722
723 MSQLServer serv(env);
724 if (!serv.IsConnected())
725 {
726 cout << "ERROR - Connection to database failed." << endl;
727 return 0;
728 }
729
730 cout << "buildsequences" << endl;
731 cout << "--------------" << endl;
732 cout << endl;
733 cout << "Connected to " << serv.GetName() << endl;
734 cout << "Night of sunrise at: " << day << endl;
735 cout << endl;
736
737 day += " 13:00:00";
738 const TString cond(Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
739 day.Data(), day.Data()));
740
741 TString query(Form("SELECT fRunNumber, fSourceKEY, fProjectKEY, fHvSettingsKEY, fLightConditionsKEY, fDiscriminatorThresholdTableKEY, fTriggerDelayTableKEY FROM RunData WHERE %s AND fExcludedFDAKEY=1 order by fRunNumber", cond.Data()));
742
743 TSQLResult *res = serv.Query(query);
744 if (!res)
745 return 0;
746
747 TString keys[6]= { "NULL", "NULL", "NULL", "NULL", "NULL", "NULL" };
748 TString stop = "NULL";
749 TString runstart = "NULL";
750 TString runstop = "NULL";
751 Int_t count = 0;
752 TExMap blocks;
753 Int_t runbegin;
754 Int_t runend;
755
756 TSQLRow *row=0;
757 while ((row=res->Next()))
758 {
759 if (count==0)
760 {
761 for (Int_t i=1 ; i<7 ; i++)
762 keys[i-1]=(*row)[i];
763 runstart=(*row)[0];
764 }
765
766 for (Int_t i=1 ; i<7 ; i++)
767 {
768 runbegin=atoi(runstart.Data());
769 runend=atoi(runstop.Data());
770 if (i==2 && runbegin>20100 && runend<45100)
771 continue;
772
773 TString value=(*row)[i];
774 TString key=keys[i-1];
775 if (!value.CompareTo(key))
776 continue;
777
778 keys[i-1]=value;
779 //hier einfuellen
780 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
781 runstart=(*row)[0];
782 for (Int_t i=1 ; i<7 ; i++)
783 keys[i-1]=(*row)[i];
784 break;
785 }
786 runstop=(*row)[0];
787 count++;
788 }
789
790 //und hier einfuellen (letzter wert)
791 runbegin=atoi(runstart.Data());
792 runend=atoi(runstop.Data());
793 blocks.Add((ULong_t)blocks.GetSize(), (Long_t)runbegin, (Long_t)runend);
794
795
796 Bool_t rc = kTRUE;
797
798 Long_t key, val;
799 TExMapIter nblocks(&blocks);
800 while (nblocks.Next(key, val))
801 {
802 Int_t runstart2 = (Int_t)key;
803 Int_t runstop2 = (Int_t)val;
804 cout << endl << "datablock from " << runstart2 << " to " << runstop2 << endl;
805
806 if (!Process(serv, datapath, sequpath, runstart2, runstop2, dummy))
807 rc = kFALSE;
808
809 }
810 return rc ? 1 : 0;
811}
812
813
814int buildsequenceentries(TString datapath, TString sequpath, Bool_t dummy=kTRUE)
815{
816 TEnv env("sql.rc");
817
818 MSQLServer serv(env);
819 if (!serv.IsConnected())
820 {
821 cout << "ERROR - Connection to database failed." << endl;
822 return 0;
823 }
824
825 TString query="SELECT fDate FROM SequenceBuildStatus";
826
827 TSQLResult *res = serv.Query(query);
828 if (!res)
829 return 0;
830
831 TSQLRow *row=0;
832 while ((row=res->Next()))
833 {
834 cout << "date: " << (*row)[0] << endl;
835 buildsequenceentries((*row)[0], dummy);
836 }
837
838 return 1;
839}
Note: See TracBrowser for help on using the repository browser.