| 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-2006 | 
|---|
| 22 | ! | 
|---|
| 23 | ! | 
|---|
| 24 | \* ======================================================================== */ | 
|---|
| 25 |  | 
|---|
| 26 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 27 | // | 
|---|
| 28 | // writesequencefile.C | 
|---|
| 29 | // =================== | 
|---|
| 30 | // | 
|---|
| 31 | // reads the sequence information from the database and writes it into a | 
|---|
| 32 | // txt file | 
|---|
| 33 | // | 
|---|
| 34 | // Usage: | 
|---|
| 35 | //  .x writesequencefile.C+(sequno,"sequpath") | 
|---|
| 36 | // | 
|---|
| 37 | // Make sure, that database and password are corretly set in a resource | 
|---|
| 38 | // file called sql.rc and the resource file is found. | 
|---|
| 39 | // | 
|---|
| 40 | // Returns 2 in case of failure, 1 in case of success and 0 if the connection | 
|---|
| 41 | // to the database is not working. | 
|---|
| 42 | // | 
|---|
| 43 | // | 
|---|
| 44 | // This tool will work from Period017 (2004_05_17) on... | 
|---|
| 45 | // | 
|---|
| 46 | // For more details see MSequence and MSequenceSQL | 
|---|
| 47 | // | 
|---|
| 48 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 49 | #include <iostream> | 
|---|
| 50 |  | 
|---|
| 51 | #include "MSQLMagic.h" | 
|---|
| 52 | #include "MSequenceSQL.h" | 
|---|
| 53 |  | 
|---|
| 54 | using namespace std; | 
|---|
| 55 |  | 
|---|
| 56 | int writesequencefile(Int_t sequno, Int_t tel, TString sequpath="") | 
|---|
| 57 | { | 
|---|
| 58 | MSQLMagic serv("sql.rc"); | 
|---|
| 59 | if (!serv.IsConnected()) | 
|---|
| 60 | { | 
|---|
| 61 | cout << "ERROR - Connection to database failed." << endl; | 
|---|
| 62 | return 0; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | cout << "writesequencefile" << endl; | 
|---|
| 66 | cout << "-----------------" << endl; | 
|---|
| 67 | cout << endl; | 
|---|
| 68 | cout << "Connected to " << serv.GetName() << endl; | 
|---|
| 69 | cout << "Sequence:  " << sequno << endl; | 
|---|
| 70 | cout << "Telescope: " << tel << endl; | 
|---|
| 71 | cout << endl; | 
|---|
| 72 |  | 
|---|
| 73 | const MSequenceSQL s(serv, sequno, tel); | 
|---|
| 74 | if (!s.IsValid()) | 
|---|
| 75 | return 2; | 
|---|
| 76 |  | 
|---|
| 77 | if (sequpath.IsNull()) | 
|---|
| 78 | { | 
|---|
| 79 | s.Print(); | 
|---|
| 80 | return 1; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | const TString fname(Form("%s/%04d/sequence%08d.txt", sequpath.Data(), sequno/10000, sequno)); | 
|---|
| 84 |  | 
|---|
| 85 | cout << "File:     " << fname << endl; | 
|---|
| 86 |  | 
|---|
| 87 | return s.WriteFile(fname) ? 1 : 2; | 
|---|
| 88 | } | 
|---|