source: trunk/MagicSoft/Mars/mjobs/MSequence.h@ 9019

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