source: trunk/MagicSoft/Mars/mbase/MRunIter.cc@ 4905

Last change on this file since 4905 was 3966, checked in by reyes, 21 years ago
*** empty log message ***
File size: 3.7 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, 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
40ClassImp(MRunIter);
41
42using namespace std;
43
44Int_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_*_%s", run,fIsRawFile?"*.raw":"*.root"), -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//
72Int_t MRunIter::AddRuns(const char* runrange, const char* path)
73{
74 const TString chcopy(runrange);
75
76 Ssiz_t last=0;
77 Int_t lowrun=-1;
78 UInt_t totdir=0;
79
80 // loop over the elements of the character chain
81 for (Int_t i=0;i<chcopy.Length();i++)
82 {
83 // look for a digit, a '-' or a ','
84 const char c=chcopy[i];
85 if (! ((c>='0' && c<='9') || c=='-' || c==','))
86 return totdir;
87
88 // if '-' is found, save the previous number as initial run
89 if (c=='-' && lowrun<0 && i>last)
90 {
91 const TSubString chrun = chcopy(last,i-last);
92 lowrun=atoi(chrun.Data());
93 last=i+1;
94 continue;
95 }
96 // if ',' or the end of the string are found, save the previous run or run range
97 if (c==',' && i>last)
98 {
99 const TSubString chrun = chcopy(last,i-last);
100 const Int_t up=atoi(chrun.Data());
101 if(lowrun>=0 && lowrun<=up)
102 totdir+=AddRuns(lowrun,up,path);
103 else if(lowrun<0)
104 totdir+=AddRun(up,path);
105
106 lowrun=-1;
107 last=i+1;
108 continue;
109 }
110
111 // if find two continous separators exit
112 if ((c=='-' && i==last) || (c==',' && i==last))
113 return totdir;
114 }
115
116 // save last run range
117 const TSubString chrun = chcopy(last,chcopy.Length()-last);
118 const Int_t upprun=atoi(chrun.Data());
119 if(lowrun>=0 && lowrun<=upprun)
120 {
121 totdir+=AddRuns(lowrun,upprun,path);
122 return totdir;
123 }
124
125 if(lowrun<0)
126 totdir+=AddRun(upprun,path);
127
128 return totdir;
129}
Note: See TracBrowser for help on using the repository browser.