source: tags/Mars-V1.0/mbase/MRunIter.cc

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