source: trunk/Mars/mjobs/MSequence.h@ 12665

Last change on this file since 12665 was 9441, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 10.0 KB
Line 
1#ifndef MARS_MSequence
2#define MARS_MSequence
3
4#ifndef ROOT_TArrayI
5#include <TArrayI.h>
6#endif
7
8#ifndef MARS_MTime
9#include "MTime.h"
10#endif
11
12class MDirIter;
13
14class MSequence : public MParContainer
15{
16 friend class MSequenceSQL;
17
18public:
19 enum LightCondition_t { kNA, kNoMoon, kTwilight, kMoon, kDay };
20
21 enum FileExt_t {
22 kRaw =BIT(0),
23 kRoot =BIT(1),
24 kReport=BIT(2),
25 kCer =BIT(3), // Corsika files
26 };
27 enum RunType_t {
28 kPed =BIT(4), // Don't use overlapping bits!
29 kCal =BIT(5),
30 kDat =BIT(6),
31 kExcl =BIT(7),
32 kAll =kPed|kDat|kCal,
33 kImage =BIT(8),
34 kCalib =BIT(9)
35 };
36
37 enum { kRunType = kPed|kCal|kDat|kImage|kCalib };
38 enum { kFileType = kRaw|kRoot|kReport|kCer };
39 enum { kFilePaths = kFileType|kImage|kCalib };
40
41 enum FileType_t {
42 kRawDat = kRaw |kDat,
43 kRawPed = kRaw |kPed,
44 kRawCal = kRaw |kCal,
45 kRawAll = kRaw |kAll,
46 kRootDat = kRoot |kDat,
47 kRootPed = kRoot |kPed,
48 kRootCal = kRoot |kCal,
49 kRootAll = kRoot |kAll,
50 kReportPed = kReport|kPed,
51 kReportCal = kReport|kCal,
52 kReportDat = kReport|kDat,
53 kReportAll = kReport|kAll,
54 kCalibrated = kRoot |kCalib,
55 kImages = kRoot |kImage,
56 kCorsika = kCer |kDat,
57 };
58
59private:
60 TString fFileName; // Expanded file name
61 TString fDataPath; // Path to data files
62
63 UShort_t fTelescope; // Telescope number
64 UInt_t fSequence; // Sequence number
65
66 MTime fStart; // Start time of sequence
67
68 UInt_t fLastRun; // Last run in sequence (necessary?)
69 UInt_t fNumEvents; // Number of events in sequence
70
71 UInt_t fPeriod; // Observation period of the sequence
72 MTime fNight; // Night (day of sunrise) of the sequence
73
74 LightCondition_t fLightCondition;
75
76 TString fProject;
77 TString fSource;
78 TString fTriggerTable;
79 TString fHvSettings;
80 TString fComment;
81
82 TArrayI fRuns; // Run numbers
83 TArrayI fRunsSub; // Sub runs (files)
84
85 TArrayI fCalRuns; // Numbers of calibration runs/files
86 TArrayI fCalRunsSub; // Sub runs (files) of calibration runs
87
88 TArrayI fPedRuns; // Numbers of pedestal runs/files
89 TArrayI fPedRunsSub; // Sub runs (files) of pedestal runs
90
91 TArrayI fDatRuns; // Numbers of data runs/files
92 TArrayI fDatRunsSub; // Sub runs (files) of data runs
93
94 TArrayI fExclRuns; // Numbers of excluded runs/files
95 TArrayI fExclRunsSub; // Sub runs (files) of excluded runs
96
97 Bool_t fMonteCarlo; // Flag for Monte Carlo sequences
98
99 // Helper for interpretation
100 void AddEntry(Int_t run, Int_t file, TArrayI &data, TArrayI &sub) const;
101 void EvalEntry(const TEnv *env, const TString &prefix, const TString &num, TArrayI &data, TArrayI &sub) const;
102
103 void Split(TString &runs, TArrayI &data, TArrayI &sub, const TEnv *env=0, const TString prefix="") const;
104 void Split(const TEnv &env, const TString &prefix, const char *name, TArrayI &data, TArrayI &sub) const;
105
106 LightCondition_t GetLightCondition(const TString &str) const;
107
108 // Helper for file setup
109 void GetArrays(const TArrayI* &r, const TArrayI* &f, Int_t type) const;
110 Bool_t FindPath(TString &path, FileType_t type) const;
111 TString FindPath(FileType_t type, TString path="") const { FindPath(path, type); return path; }
112 TString FindFile(const TString &d, const TString &f) const;
113 TString GetPathName(TString d, FileType_t type) const;
114 TString GetFileRegexp(UInt_t num, const TArrayI &arr, const TArrayI &sub, FileType_t type) const;
115 TString GetFileName(UInt_t i, const TArrayI &arr, const TArrayI &sub, FileType_t type, const char *path) const;
116 UInt_t GetRuns(MDirIter &iter, const TArrayI &arr, const TArrayI &file, FileType_t type, TString path="") const;
117
118 // Helper for Print()
119 TString GetNumSequence(Int_t pos, Int_t n, const TArrayI &f) const;
120 TString GetNumSequence(Int_t &pos, const TArrayI &n, const TArrayI &f) const;
121
122 void PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const;
123 TString PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const;
124
125 // General helper
126 Bool_t HasSubRuns() const { return fRunsSub.GetSize()!=0 || fDatRunsSub.GetSize()!=0 || fPedRunsSub.GetSize()!=0 || fCalRunsSub.GetSize()!=0 || fExclRunsSub.GetSize()!=0; }
127 Bool_t IsContained(const TArrayI &arr, const TArrayI &sub, UInt_t num, UInt_t file) const;
128
129 // Some helpers to handle the arrays
130 static Int_t SortArraySub(Int_t p, Int_t n, Int_t *arr1, Int_t *arr2);
131 static void SortArrays(TArrayI &arr1, TArrayI &arr2);
132 static Int_t GetSubArray(Int_t p, Int_t n, Int_t *arr1);
133
134public:
135/*
136 MSequence() : fTelescope(1), fSequence((UInt_t)-1), fLastRun((UInt_t)-1),
137 fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fLightCondition(kNA), fMonteCarlo(kFALSE)
138 {
139 fName = "MSequence";
140 fTitle = "Sequence file";
141 }
142 */
143 MSequence(const char *fname=0, const char *path=0, UInt_t id=(UInt_t)-1);
144 MSequence(const char *fname, UInt_t seq, UShort_t tel=0);
145 MSequence(const MSequence &s) : MParContainer(s),
146 fFileName(s.fFileName), fDataPath(s.fDataPath),
147 fTelescope(s.fTelescope),
148 fSequence(s.fSequence), fStart(s.fStart),
149 fLastRun(s.fLastRun), fNumEvents(s.fNumEvents), fPeriod(s.fPeriod),
150 fNight(s.fNight), fLightCondition(s.fLightCondition),
151 fProject(s.fProject), fSource(s.fSource),
152 fTriggerTable(s.fTriggerTable), fHvSettings(s.fHvSettings),
153 fRuns(s.fRuns), fRunsSub(s.fRunsSub), fCalRuns(s.fCalRuns),
154 fCalRunsSub(s.fCalRunsSub), fPedRuns(s.fPedRuns),
155 fPedRunsSub(s.fPedRunsSub), fDatRuns(s.fDatRuns),
156 fDatRunsSub(s.fDatRunsSub), fExclRuns(s.fExclRuns),
157 fExclRunsSub(s.fExclRunsSub), fMonteCarlo(s.fMonteCarlo) { }
158
159 Bool_t IsCompatible(const MSequence &s) const;
160 Bool_t IsIdentical(const MSequence &s) const;
161 Bool_t operator==(const MSequence &s) const;
162
163 // I/O
164 Int_t Read(const char *name=0);
165 Bool_t ReadDatabase(TString sql, UInt_t seq=0, UShort_t tel=0);
166 Bool_t ReadFile(const char *filename, UInt_t id=(UInt_t)-1);
167 Bool_t WriteFile(const char *filename, const Option_t *o) const;
168 Bool_t WriteFile(const char *filename) const { return WriteFile(filename,""); } //*MENU *ARGS={filename=>fBaseName}
169 Bool_t SetDataPath(const char *path="");
170
171 // TObject
172 void Print(ostream &out, Option_t *o) const;
173 void Print(Option_t *o) const;
174 void Print() const { Print(""); } //*MENU*
175
176 // Genaral interface
177 Bool_t IsValid() const { return fTelescope>0 && fSequence!=(UInt_t)-1; }
178 Bool_t IsMonteCarlo() const { return fMonteCarlo; }
179 Bool_t IsExcluded(UInt_t run, UInt_t file) const { return IsContained(fExclRuns, fExclRunsSub, run, file); }
180 Bool_t IsContained(UInt_t run, UInt_t file) const { return IsContained(fCalRuns, fCalRunsSub, run, file) || IsContained(fPedRuns, fPedRunsSub, run, file) || IsContained(fDatRuns, fDatRunsSub, run, file); }
181
182 // Setter
183 void SetNight(const char*night);
184
185 void AddRun(UInt_t run, RunType_t type=kAll) { AddFile(run, 0, type); }
186 void AddRuns(UInt_t run1, UInt_t run2, RunType_t type=kAll) { for (UInt_t i=run1; i<=run2; i++) AddFile(i, 0, type); }
187 void AddFile(UInt_t run, UInt_t file, RunType_t type=kAll);
188 void AddFiles(UInt_t run, UInt_t f1, UInt_t f2, RunType_t type=kAll) { for (UInt_t i=f1; i<=f2; i++) AddFile(run, i, type); }
189
190 void ExcludeFile(UInt_t run, UInt_t file=0) { /*if (!force || !IsExcluded(run, file))*/ AddFile(run, file, kExcl); }
191 void ExcludeRuns(TString runs);
192
193 void SetMonteCarlo(Bool_t ismc=kTRUE) { fMonteCarlo=ismc; }
194
195 // Getter
196 UInt_t GetNumExclRuns() const { return fExclRuns.GetSize(); }
197
198 UShort_t GetTelescope() const { return fTelescope; }
199 UInt_t GetSequence() const { return fSequence; }
200 UInt_t GetLastRun() const { return fLastRun; }
201 UInt_t GetPeriod() const { return fPeriod; }
202 Bool_t HasMoon() const { return fLightCondition==kMoon; }
203
204 Int_t GetFile(UInt_t i, RunType_t type, UInt_t &run, UInt_t &file) const;
205
206 LightCondition_t GetLightCondition() const { return fLightCondition; }
207
208 const MTime &GetStart() const { return fStart; }
209 const MTime &GetNight() const { return fNight; }
210 const TString &GetSource() const { return fSource; }
211
212 const TString GetExcludedRuns() const;
213
214 // Filesystem interface
215 UInt_t GetRuns(MDirIter &iter, FileType_t type, const char *path=0) const;
216 TString GetFileRegexp(UInt_t num, FileType_t type) const;
217 TString GetFileName(UInt_t i, FileType_t type, const char *path=0) const;
218 UInt_t GetNumEntries(RunType_t type=kAll) const;
219
220 // Filesystem getter
221 const char *GetBaseName() const;
222 const char *GetFilePath() const;
223 const TString &GetFileName() const { return fFileName; }
224 const TString &GetDataPath() const { return fDataPath; }
225
226 const TString GetStandardPath() const { return GetStandardPath(fMonteCarlo); }
227
228 // Static function for external access
229 static TString GetStandardPath(Bool_t mc) { return mc?"/magic/montecarlo/":"/magic/data/"; }
230 static Bool_t InflateSeq(TString &seq, /*FIXME: TELNUM*/ Bool_t ismc=kFALSE);
231
232 static TString InflateFileName(const MTime &night, UShort_t tel, Int_t run, Int_t file, Int_t type=kRawAll);
233 static TString InflateFileName(const MTime &night, Int_t run, Int_t type=kRawAll) { return InflateFileName(night, 1, run, 0, type); }
234
235 static TString InflateFilePath(const MTime &night, UShort_t tel, Int_t run, Int_t file=0, Int_t type=kRawAll);
236 static TString InflateFilePath(const MTime &night, Int_t run, Int_t type=kRawAll) { return InflateFilePath(night, 1, run, 0, type); }
237
238 static TString InflateFilePath(const MTime &night, Bool_t mc=kFALSE);
239
240 ClassDef(MSequence, 6) // Describes a sequences, reads and writes sequence files
241};
242
243#endif
Note: See TracBrowser for help on using the repository browser.