source: trunk/MagicSoft/Mars/macros/runbook.C@ 5138

Last change on this file since 5138 was 3957, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// runbook.C
28// =========
29//
30// This is an example macro how to extract the runbook information of
31// a given date from the runbook files.
32//
33// The argument is a date in regexp format, eg.
34// .x runbook.C("2004-05-1[0-9]")
35//
36// With an MDirIter you can tell the macro which directories and files
37// should be searched.
38//
39// The output are the runbook entries matching your query.
40//
41///////////////////////////////////////////////////////////////////////////
42
43void Wrap(TString &str)
44{
45 // Wrap lines to 80 chars
46 while (str.Length()>80)
47 {
48 TString ss = str(0, 80);
49 Int_t l = ss.Last(' ');
50 if (l<0)
51 break;
52 cout << str(0, l) << endl;
53 str.Remove(0, l);
54 }
55 cout << str << endl;
56}
57
58void ProcessFile(TString fname, TString date)
59{
60 // File processed
61 cout << fname << endl;
62
63 // Open file
64 ifstream fin(fname);
65
66 TString line;
67
68 int i=81;
69
70 TRegexp r0("20[0-2][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]");
71 TRegexp r1(date+" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]");
72
73 int lcnt=0;
74
75 int print = 0;
76
77 while (!fin.eof())
78 {
79 // Read file line by line
80 char *txt=new char[i];
81 fin.getline(txt, i-1);
82
83 if (lcnt++<4)
84 continue;
85
86 if (!fin)
87 txt[i-1]=0;
88
89 line += txt;
90 delete txt;
91
92 if (line.Length()==0)
93 {
94 if (print)
95 cout << endl;
96 continue;
97 }
98
99 if (!fin)
100 {
101 i *= 2;
102 fin.clear();
103 continue;
104 }
105
106 // Check whether line matches regexp
107 if (!line(r0).IsNull())
108 print = !line(r1).IsNull();
109
110 // Wrap lines to 80 chars
111 if (print)
112 Wrap(line);
113 line = "";
114 i=81;
115 }
116 cout << "DONE." << endl;
117}
118
119void runbook(const char *d="20[0-2][0-9]-[0-1][0-9]-[0-3][0-9]")
120{
121 // Regexp to check for valid date
122 TString regexp = "20[0-2][0-9]-[0-1][0-9]-[0-3][0-9]";
123
124 if (regexp!=d)
125 {
126 TRegexp r(regexp);
127
128 TString date=d;
129 if (date(r).IsNull())
130 {
131 cout << "ERROR - Date has wrong format (2003-05-06)" << endl;
132 return;
133 }
134 }
135
136 // Tell which dierctories and files to search
137 MDirIter Next;
138 Next.AddDirectory("/home/MAGIC/online_data/runbook", "CC_*.rbk");
139
140 // Loop over files
141 TString name;
142 while (1)
143 {
144 name=Next();
145 if (name.IsNull())
146 break;
147
148 ProcessFile(name, d);
149 }
150}
Note: See TracBrowser for help on using the repository browser.