source: tags/Mars-V2.1.1/mjobs/MSequence.h

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