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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Javier Rico, 4/2004 <mailto:jrico@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MRunIter
|
---|
29 | //
|
---|
30 | // Use this to iterate over run-files giving only the run-number.
|
---|
31 | //
|
---|
32 | // You need the specify the run-file root-directory (eg /data/MAGIC).
|
---|
33 | //
|
---|
34 | /////////////////////////////////////////////////////////////////////////////
|
---|
35 | #include "MRunIter.h"
|
---|
36 |
|
---|
37 | #include <TSystem.h>
|
---|
38 | #include <iostream>
|
---|
39 |
|
---|
40 | ClassImp(MRunIter);
|
---|
41 |
|
---|
42 | using namespace std;
|
---|
43 |
|
---|
44 | Int_t MRunIter::AddRun(UInt_t run, const char *path)
|
---|
45 | {
|
---|
46 | TString p(path);
|
---|
47 |
|
---|
48 | if (p.IsNull())
|
---|
49 | p = fPath;
|
---|
50 |
|
---|
51 | if (p.IsNull())
|
---|
52 | p = ".";
|
---|
53 |
|
---|
54 | MDirIter Next(p, Form("*_%05d_*_*.root", run), -1);
|
---|
55 |
|
---|
56 | const TString name(Next());
|
---|
57 | if (name.IsNull())
|
---|
58 | return 0;
|
---|
59 |
|
---|
60 | AddRunNumber(run);
|
---|
61 |
|
---|
62 | return AddDirectory(gSystem->DirName(name), gSystem->BaseName(name), -1);
|
---|
63 | }
|
---|
64 |
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Add runs specified in a character chain with the format:
|
---|
68 | // run1,run2-run3,run4-run5,...
|
---|
69 | // e.g if runrange="100,105-107,110-112,115"
|
---|
70 | // runs 100,105,106,107,110,111,112 and 115 are included in the iterator list
|
---|
71 | //
|
---|
72 | Int_t MRunIter::AddRuns(const char* runrange, const char* path)
|
---|
73 | {
|
---|
74 | char* last;
|
---|
75 | char chcopy[100];
|
---|
76 | Int_t lowrun=-1;
|
---|
77 | Int_t upprun;
|
---|
78 | Int_t totdir=0;
|
---|
79 |
|
---|
80 | // cout << "Analyzing chain " << runrange << " in path " << path << endl;
|
---|
81 |
|
---|
82 | sprintf(chcopy,"%s",runrange);
|
---|
83 | last=&chcopy[0];
|
---|
84 |
|
---|
85 | // loop over the elements of the character chain (break inside the loop)
|
---|
86 | for(char* cp=last;cp;cp++)
|
---|
87 | {
|
---|
88 | // look for a digit, a '-' or a ',' or end of string
|
---|
89 | char c=*cp;
|
---|
90 | if(! ((c>='0' && c<='9') || c=='-' || c==',' || c=='\0'))
|
---|
91 | return totdir;
|
---|
92 |
|
---|
93 | // if '-' is found, save the previous number as initial run
|
---|
94 | if(c=='-' && lowrun<0)
|
---|
95 | {
|
---|
96 | char chrun[100];
|
---|
97 | strncpy(chrun,last,cp-last);
|
---|
98 | lowrun=atoi(chrun);
|
---|
99 | last=cp+1;
|
---|
100 | }
|
---|
101 | // if ',' or the end of the string are found, save the previous run or run range
|
---|
102 | if(c==',' || c=='\0')
|
---|
103 | {
|
---|
104 | char chrun[100];
|
---|
105 | strncpy(chrun,last,cp-last);
|
---|
106 | upprun=atoi(chrun);
|
---|
107 | if(lowrun>=0 && lowrun<=upprun)
|
---|
108 | totdir+=AddRuns(lowrun,upprun,path);
|
---|
109 | else if(lowrun<0)
|
---|
110 | totdir+=AddRun(upprun,path);
|
---|
111 |
|
---|
112 | if(c=='\0')
|
---|
113 | break;
|
---|
114 | lowrun=-1;
|
---|
115 | last=cp+1;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | return totdir;
|
---|
119 | }
|
---|