source: trunk/Mars/mbase/MRunIter.cc@ 16284

Last change on this file since 16284 was 8907, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 4.3 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-2008
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 <iostream>
38
39#include <TMath.h>
40#include <TSystem.h>
41
42ClassImp(MRunIter);
43
44using namespace std;
45
46void MRunIter::SortRuns()
47{
48 const int n = GetNumRuns();
49
50 TArrayI idx(n);
51 TMath::Sort(n, fRuns.GetArray(), idx.GetArray(), kFALSE);
52
53 for (int i=0; i<n; i++)
54 idx[i] = fRuns[idx[i]];
55
56 fRuns = idx;
57}
58
59Int_t MRunIter::AddRun(UInt_t run, const char *path)
60{
61 TString p(path);
62
63 if (p.IsNull())
64 p = fPath;
65
66 if (p.IsNull())
67 p = ".";
68
69 // R. DeLosReyes and T. Bretz
70 // Changes to read the DAQ numbering format. Changes takes place
71 // between runs 35487 and 00035488 (2004_08_30)
72 const char *fmt;
73 if(fIsStandardFile)
74 {
75 fmt = "%05d-%s";
76 fIsRawFile = kFALSE;
77 }
78 else
79 fmt = run>35487 ? "*_%08d_*_%s" : "*_%05d_*_%s";
80
81 MDirIter NextR;
82 NextR.AddDirectory(p, Form(fmt, run,fIsRawFile?"*.raw":"*.root"), -1);
83
84 const TString name(NextR());
85 if (name.IsNull())
86 return 0;
87
88 AddRunNumber(run);
89
90 return AddDirectory(gSystem->DirName(name), gSystem->BaseName(name), -1);
91}
92
93// --------------------------------------------------------------------------
94//
95// Add runs specified in a character chain with the format:
96// run1,run2-run3,run4-run5,...
97// e.g if runrange="100,105-107,110-112,115"
98// runs 100,105,106,107,110,111,112 and 115 are included in the iterator list
99//
100Int_t MRunIter::AddRuns(const char* runrange, const char* path)
101{
102 const TString chcopy(runrange);
103
104 Ssiz_t last=0;
105 Int_t lowrun=-1;
106 UInt_t totdir=0;
107
108 // loop over the elements of the character chain
109 for (Int_t i=0;i<chcopy.Length();i++)
110 {
111 // look for a digit, a '-' or a ','
112 const char c=chcopy[i];
113 if (! ((c>='0' && c<='9') || c=='-' || c==','))
114 return totdir;
115
116 // if '-' is found, save the previous number as initial run
117 if (c=='-' && lowrun<0 && i>last)
118 {
119 const TSubString chrun = chcopy(last,i-last);
120 lowrun=atoi(chrun.Data());
121 last=i+1;
122 continue;
123 }
124 // if ',' or the end of the string are found, save the previous run or run range
125 if (c==',' && i>last)
126 {
127 const TSubString chrun = chcopy(last,i-last);
128 const Int_t up=atoi(chrun.Data());
129 if(lowrun>=0 && lowrun<=up)
130 totdir+=AddRuns(lowrun,up,path);
131 else if(lowrun<0)
132 totdir+=AddRun(up,path);
133
134 lowrun=-1;
135 last=i+1;
136 continue;
137 }
138
139 // if find two continous separators exit
140 if ((c=='-' && i==last) || (c==',' && i==last))
141 return totdir;
142 }
143
144 // save last run range
145 const TSubString chrun = chcopy(last,chcopy.Length()-last);
146 const Int_t upprun=atoi(chrun.Data());
147 if(lowrun>=0 && lowrun<=upprun)
148 {
149 totdir+=AddRuns(lowrun,upprun,path);
150 return totdir;
151 }
152
153 if(lowrun<0)
154 totdir+=AddRun(upprun,path);
155
156 return totdir;
157}
Note: See TracBrowser for help on using the repository browser.