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

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