source: releases/Mars.2014.05.26/mjobs/MSequence.h@ 18621

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