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

Last change on this file since 5385 was 5307, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.0 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 // R. DeLosReyes and T. Bretz
55 // Changes to read the DAQ numbering format. Changes takes place
56 // between runs 35487 and 00035488 (2004_08_30)
57 const char *fmt = run>35487 ? "*_%08d_*_%s" : "*_%05d_*_%s";
58
59 MDirIter Next;
60 Next.AddDirectory(p, Form(fmt, run,fIsRawFile?"*.raw":"*.root"), -1);
61
62 const TString name(Next());
63 if (name.IsNull())
64 return 0;
65
66 AddRunNumber(run);
67
68 return AddDirectory(gSystem->DirName(name), gSystem->BaseName(name), -1);
69}
70
71// --------------------------------------------------------------------------
72//
73// Add runs specified in a character chain with the format:
74// run1,run2-run3,run4-run5,...
75// e.g if runrange="100,105-107,110-112,115"
76// runs 100,105,106,107,110,111,112 and 115 are included in the iterator list
77//
78Int_t MRunIter::AddRuns(const char* runrange, const char* path)
79{
80 const TString chcopy(runrange);
81
82 Ssiz_t last=0;
83 Int_t lowrun=-1;
84 UInt_t totdir=0;
85
86 // loop over the elements of the character chain
87 for (Int_t i=0;i<chcopy.Length();i++)
88 {
89 // look for a digit, a '-' or a ','
90 const char c=chcopy[i];
91 if (! ((c>='0' && c<='9') || c=='-' || c==','))
92 return totdir;
93
94 // if '-' is found, save the previous number as initial run
95 if (c=='-' && lowrun<0 && i>last)
96 {
97 const TSubString chrun = chcopy(last,i-last);
98 lowrun=atoi(chrun.Data());
99 last=i+1;
100 continue;
101 }
102 // if ',' or the end of the string are found, save the previous run or run range
103 if (c==',' && i>last)
104 {
105 const TSubString chrun = chcopy(last,i-last);
106 const Int_t up=atoi(chrun.Data());
107 if(lowrun>=0 && lowrun<=up)
108 totdir+=AddRuns(lowrun,up,path);
109 else if(lowrun<0)
110 totdir+=AddRun(up,path);
111
112 lowrun=-1;
113 last=i+1;
114 continue;
115 }
116
117 // if find two continous separators exit
118 if ((c=='-' && i==last) || (c==',' && i==last))
119 return totdir;
120 }
121
122 // save last run range
123 const TSubString chrun = chcopy(last,chcopy.Length()-last);
124 const Int_t upprun=atoi(chrun.Data());
125 if(lowrun>=0 && lowrun<=upprun)
126 {
127 totdir+=AddRuns(lowrun,upprun,path);
128 return totdir;
129 }
130
131 if(lowrun<0)
132 totdir+=AddRun(upprun,path);
133
134 return totdir;
135}
Note: See TracBrowser for help on using the repository browser.