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

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