GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TRunInfo.h
Go to the documentation of this file.
1#ifndef TRUNINFO_H
2#define TRUNINFO_H
3
4/** \addtogroup Sorting
5 * @{
6 */
7
8/////////////////////////////////////////////////////////////////
9///
10/// \class TRunInfo
11///
12/// This Class is designed to store run dependent information.
13/// It is used to store run numbers, GRSISort version, existence of
14/// detector systems, etc.
15/// The TRunInfo is written to both the fragment and analysis trees,
16/// as well as to files create by grsiframe.
17///
18/// An example run info looks like this:
19///
20/// \code
21/// GRSI [0] TRunInfo::Get()->Print()
22/// Singleton 0x5651a3d5dc10 was read from analysis22151_000.root
23/// Title: All-singles-ZDF-off 133Ba_R0794
24/// Comment: All-singles-ZDF-off 133Ba_R0794
25/// RunNumber: 22151
26/// SubRunNumber: 000
27/// RunStart: Fri Dec 22 18:11:29 2023
28/// RunStop: Fri Dec 22 18:42:40 2023
29/// RunLength: 1871 s
30/// GRSI [1]
31/// \endcode
32///
33/// When subruns/runs are added together using gadd or when multiple
34/// subruns/runs are used in grsiframe, their TRunInfos get merged.
35///
36/// If all files are from one run, and the subruns are added in order
37/// without any missing, the information changes to reflect this:
38///
39/// \code
40/// GRSI [0] TRunInfo::Get()->Print()
41/// Singleton 0x55ab20f209a0 was read from Final21950_000-028.root
42/// Title: 100Zr_beam_with_PACES_lasers_on
43/// Comment: 100Zr_beam_with_PACES_lasers_on
44/// RunNumber: 21950
45/// SubRunNumbers: 000-028
46/// RunStart: Thu Dec 14 13:37:14 2023
47/// RunStop: Thu Dec 14 14:37:14 2023
48/// RunLength: 3599 s
49/// GRSI [1]
50/// \endcode
51///
52/// Internally this is signaled by the subrun number having been
53/// set to -1, while the run number is still nonzero, and the run
54/// start and run stop are set as well as the numbers of the first
55/// and last subrun.
56///
57/// If the subruns are not in order or a subrun is missing from the
58/// range added, the number of the first and last subrun are both set
59/// to -1, changing the line
60/// \code
61/// SubRunNumbers: 000-028
62/// \endcode
63/// to
64/// \code
65/// SubRunNumbers: -1--1
66/// \endcode
67///
68/// If the files are from multiple runs that are all in consecutive
69/// order without any missing ones, the run info will say:
70///
71/// \code
72/// Singleton 0x563c6c1c3a30 was read from Final21950-21980.root
73/// Title: 100Zr_beam_with_PACES_lasers_on
74/// Comment: 100Zr_beam_with_PACES_lasers_on
75/// RunNumbers: 21950-21980
76/// No missing runs
77/// RunStart: Thu Dec 14 13:37:14 2023
78/// RunStop: Fri Dec 15 19:06:11 2023
79/// RunLength: 101306 s
80/// \endcode
81///
82/// If however some runs in between are missing, it will say
83/// \code
84/// Singleton 0x55919586a8c0 was read from test50_51_54.root
85/// Title: 100Zr_beam_with_PACES_lasers_on
86/// Comment: 100Zr_beam_with_PACES_lasers_on
87/// RunNumbers: 21950-21954
88/// Missing runs: 21952, 21953
89/// Combined RunLength: 10794 s
90/// \endcode
91///
92/// From version 18 on TRunInfo also stores information about
93/// the GRSISort version used to sort the data.
94/// This can be accessed via
95/// \code
96/// TRunInfo::Get()->PrintVersion();
97/// \endcode
98///
99/// Using a newer version of grsiframe on data created with an
100/// older version of GRSISort should not overwrite the version
101/// reported.
102///
103/// Summary of different states the run info can be in:
104///
105/// | state | identifying markers |
106/// |---------------------------------------------------------------------------------------|---------------------------------------------------------|
107/// | single sub run | non-zero run number and sub run number != -1 |
108/// | consecutive sub runs of a single run (from FirstSubRunNumber() to LastSubRunNumber()) | non-zero run number and sub run number == -1 |
109/// | consecutive runs (from FirstRunNumber() to LastRunNumber()) | zero run number and FirstRunNumber() != LastRunNumber() |
110/// | non-consecutive runs | zero run number and non-empty run list |
111///
112/////////////////////////////////////////////////////////////////
113
114#include "TTree.h"
115#include "TFile.h"
116#include "TKey.h"
117
118#include "Globals.h"
119
120#include "TSingleton.h"
121#include "TEventBuildingLoop.h"
122#include "TDetectorInformation.h"
123
124class TRunInfo : public TSingleton<TRunInfo> {
125public:
126 friend class TSingleton<TRunInfo>;
127
128 TRunInfo(const TRunInfo&) = default;
129 TRunInfo(TRunInfo&&) noexcept = default;
130 TRunInfo& operator=(const TRunInfo&) = default;
131 TRunInfo& operator=(TRunInfo&&) noexcept = default;
132 ~TRunInfo() = default;
133 TRunInfo(); // This should not be used.
134 // root forces me have this here instead
135 // of a private class member in
136 // order to write this class to a tree.
137 // pcb.
138
139 static Bool_t ReadInfoFromFile(TFile* tempf = nullptr);
140
141 static std::string GetVersion() { return Get()->fVersion; }
142 static void ClearVersion() { Get()->fVersion.clear(); }
143 static void SetVersion(const char* ver) { SetVersion(std::string(ver)); }
144 static void SetVersion(std::string ver)
145 {
146 if(!Get()->fVersion.empty() && Get()->fVersion != ver) {
147 std::cout << ALERTTEXT << "WARNING; VERSION ALREADY SET TO " << Get()->fVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
148 } else {
149 Get()->fVersion = std::move(ver);
150 }
151 }
152
153 static std::string GetFullVersion() { return Get()->fFullVersion; }
154 static void ClearFullVersion() { Get()->fFullVersion.clear(); }
155 static void SetFullVersion(const char* ver) { SetFullVersion(std::string(ver)); }
156 static void SetFullVersion(std::string ver)
157 {
158 if(!Get()->fFullVersion.empty() && Get()->fFullVersion != ver) {
159 std::cout << ALERTTEXT << "WARNING; FULL VERSION ALREADY SET TO " << Get()->fFullVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
160 } else {
161 Get()->fFullVersion = std::move(ver);
162 }
163 }
164
165 static std::string GetDate() { return Get()->fDate; }
166 static void ClearDate() { Get()->fDate.clear(); }
167 static void SetDate(const char* ver) { SetDate(std::string(ver)); }
168 static void SetDate(std::string ver)
169 {
170 if(!Get()->fDate.empty() && Get()->fDate != ver) {
171 std::cout << ALERTTEXT << "WARNING; DATE ALREADY SET TO " << Get()->fDate << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
172 } else {
173 Get()->fDate = std::move(ver);
174 }
175 }
176
177 static std::string GetLibraryVersion() { return Get()->fLibraryVersion; }
178 static void ClearLibraryVersion() { Get()->fLibraryVersion.clear(); }
179 static void SetLibraryVersion(const char* ver) { SetLibraryVersion(std::string(ver)); }
180 static void SetLibraryVersion(std::string ver)
181 {
182 if(!Get()->fLibraryVersion.empty() && Get()->fLibraryVersion != ver) {
183 std::cout << ALERTTEXT << "WARNING; LIBRARY VERSION ALREADY SET TO " << Get()->fLibraryVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
184 } else {
185 Get()->fLibraryVersion = std::move(ver);
186 }
187 }
188
189 static std::string GetLibraryPath() { return Get()->fLibraryPath; }
190 static void ClearLibraryPath() { Get()->fLibraryPath.clear(); }
191 static void SetLibraryPath(const char* ver) { SetLibraryPath(std::string(ver)); }
192 static void SetLibraryPath(std::string ver)
193 {
194 if(!Get()->fLibraryPath.empty() && Get()->fLibraryPath != ver) {
195 std::cout << ALERTTEXT << "WARNING; LIBRARY PATH ALREADY SET TO " << Get()->fLibraryPath << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
196 } else {
197 Get()->fLibraryPath = std::move(ver);
198 }
199 }
200
201 static void SetRunInfo(int runnum = 0, int subrunnum = -1);
202 static void SetAnalysisTreeBranches(TTree*);
203
204 static void SetRunNumber(int tmp) { Get()->fRunNumber = tmp; }
205 static void SetSubRunNumber(int tmp) { Get()->fSubRunNumber = tmp; }
206
207 static int RunNumber() { return Get()->fRunNumber; }
208 static int SubRunNumber() { return Get()->fSubRunNumber; }
209
210 static int FirstRunNumber() { return Get()->fFirstRunNumber; }
211 static int FirstSubRunNumber() { return Get()->fFirstSubRunNumber; }
212
213 static int LastRunNumber() { return Get()->fLastRunNumber; }
214 static int LastSubRunNumber() { return Get()->fLastSubRunNumber; }
215
216 static void SetRunTitle(const char* run_title)
217 {
218 if(run_title != nullptr) { Get()->fRunTitle.assign(run_title); }
219 }
220 static void SetRunComment(const char* run_comment)
221 {
222 if(run_comment != nullptr) { Get()->fRunComment.assign(run_comment); }
223 }
224
225 static std::string RunTitle() { return Get()->fRunTitle; }
226 static std::string RunComment() { return Get()->fRunComment; }
227
228 static void SetRunStart(double tmp) { Get()->fRunStart = tmp; }
229 static void SetRunStop(double tmp) { Get()->fRunStop = tmp; }
230 static void SetRunLength(double tmp) { Get()->fRunLength = tmp; }
231 static void SetRunLength()
232 {
233 // if this is a single sub run or consecutive sub runs of a single run we can calculate the run length from the stop and start times
234 if(RunNumber() != 0) {
235 Get()->fRunLength = Get()->fRunStop - Get()->fRunStart;
236 }
237 // otherwise we have no idea how to calculate the run length (it should be summed up by the Add function)
238 // so we do nothing
239 }
240
241 static double RunStart() { return Get()->fRunStart; }
242 static double RunStop() { return Get()->fRunStop; }
243 static double RunLength() { return Get()->fRunLength; }
244
245 static void SetCalFileName(const char* name) { Get()->fCalFileName.assign(name); }
246 static void SetCalFileData(const char* data) { Get()->fCalFile.assign(data); }
247
248 static void SetXMLODBFileName(const char* name) { Get()->fXMLODBFileName.assign(name); }
249 static void SetXMLODBFileData(const char* data) { Get()->fXMLODBFile.assign(data); }
250
251 static const char* GetCalFileName() { return Get()->fCalFileName.c_str(); }
252 static const char* GetCalFileData() { return Get()->fCalFile.c_str(); }
253
254 static const char* GetXMLODBFileName() { return Get()->fXMLODBFileName.c_str(); }
255 static const char* GetXMLODBFileData() { return Get()->fXMLODBFile.c_str(); }
256
257 static const char* GetRunInfoFileName() { return Get()->fRunInfoFileName.c_str(); }
258 static const char* GetRunInfoFileData() { return Get()->fRunInfoFile.c_str(); }
259
260 static Bool_t ReadInfoFile(const char* filename = "");
261 static Bool_t ParseInputData(const char* inputdata = "", Option_t* opt = "q");
262
263 static void SetRunInfoFileName(const char* fname) { Get()->fRunInfoFileName.assign(fname); }
264 static void SetRunInfoFile(const char* ffile) { Get()->fRunInfoFile.assign(ffile); }
265
266 static void SetHPGeArrayPosition(const double arr_pos) { Get()->fHPGeArrayPosition = arr_pos; }
267 static double HPGeArrayPosition() { return Get()->fHPGeArrayPosition; }
268
269 Long64_t Merge(TCollection* list);
270 void Add(TRunInfo* runinfo, bool verbose = false);
271
273
274 static void PrintBadCycles();
275 static void AddBadCycle(int bad_cycle);
276 static void RemoveBadCycle(int cycle);
277 static bool IsBadCycle(int cycle);
278
279 void PrintRunList() const;
280 std::string ListOfMissingRuns(bool all = false) const;
281 void PrintVersion() const;
282
283 static std::string CreateLabel(bool quiet = false);
284
287
288 void Print(Option_t* opt = "") const override;
289 void Clear(Option_t* opt = "") override;
290
291 static bool WriteToRoot(TFile* fileptr = nullptr);
292 static bool WriteInfoFile(const std::string& filename);
293 static std::string PrintToString(Option_t* opt = "");
294
295private:
296 std::string fRunTitle; ///< The title of the run
297 std::string fRunComment; ///< The comment on the run
298 int fRunNumber{0}; ///< The current run number
299 int fSubRunNumber{-1}; ///< The current sub run number
300 int fFirstRunNumber{0}; ///< The first run number (for combined runs)
301 int fFirstSubRunNumber{-1}; ///< The first sub run number (for combined subruns)
302 int fLastRunNumber{0}; ///< The last run number (for combined runs)
303 int fLastSubRunNumber{-1}; ///< The last sub run number (for combined subruns)
304 std::set<std::pair<int, int>> fRunList; ///< List of all runs added to this run info
305
306 double fRunStart{0.}; ///< The start of the current run in seconds - no idea why we store this as double?
307 double fRunStop{0.}; ///< The stop of the current run in seconds - no idea why we store this as double?
308 double fRunLength{0.}; ///< The length of the current run in seconds - no idea why we store this as double?
309
310 std::string fVersion; ///< The version of GRSISort that generated the file - GRSI_RELEASE from GVersion.h
311 std::string fFullVersion; ///< The full version of GRSISort that generated the file (includes last commit) - GRSI_GIT_COMMIT from GVersion.h
312 std::string fDate; ///< The date of the last commit used in this version - GRSI_GIT_COMMIT_TIME from GVersion.h
313 std::string fLibraryVersion; ///< The version of the parser/file library that generated the file
314 std::string fLibraryPath; ///< The path of the parser/file library that generated the file
315
316 std::string fCalFileName; ///< Name of calfile that generated cal
317 std::string fCalFile; ///< Cal File to load into Cal of tree
318
319 std::string fXMLODBFileName; ///< Name of XML Odb file
320 std::string fXMLODBFile; ///< The odb
321
322 /////////////////////////////////////////////////
323 //////////////// Building Options ///////////////
324 /////////////////////////////////////////////////
325
326 std::string fRunInfoFileName; ///< The name of the Run info file
327 std::string fRunInfoFile; ///< The contents of the run info file
328
329 double fHPGeArrayPosition{110.}; ///< Position of the HPGe Array (default = 110.0 mm );
330
331 std::vector<int> fBadCycleList; //!<!List of bad cycles to be used for cycle rejection
332
333 TDetectorInformation* fDetectorInformation{nullptr}; //!<! pointer to detector specific information (set by each parser library)
334
335 /// \cond CLASSIMP
336 ClassDefOverride(TRunInfo, 18) // NOLINT(readability-else-after-return,modernize-type-traits)
337 /// \endcond
338};
339/*! @} */
340#endif
#define RESET_COLOR
Definition Globals.h:5
#define ALERTTEXT
Definition Globals.h:35
std::string fDate
The date of the last commit used in this version - GRSI_GIT_COMMIT_TIME from GVersion....
Definition TRunInfo.h:312
static void SetXMLODBFileData(const char *data)
Definition TRunInfo.h:249
TRunInfo(const TRunInfo &)=default
static void ClearVersion()
Definition TRunInfo.h:142
static void SetRunInfoFile(const char *ffile)
Definition TRunInfo.h:264
int fFirstSubRunNumber
The first sub run number (for combined subruns)
Definition TRunInfo.h:301
double fRunStart
The start of the current run in seconds - no idea why we store this as double?
Definition TRunInfo.h:306
std::string fRunInfoFileName
The name of the Run info file.
Definition TRunInfo.h:326
static void SetRunComment(const char *run_comment)
Definition TRunInfo.h:220
std::vector< int > fBadCycleList
!List of bad cycles to be used for cycle rejection
Definition TRunInfo.h:331
static void ClearLibraryPath()
Definition TRunInfo.h:190
static double RunStop()
Definition TRunInfo.h:242
static int LastRunNumber()
Definition TRunInfo.h:213
int fLastSubRunNumber
The last sub run number (for combined subruns)
Definition TRunInfo.h:303
static double RunStart()
Definition TRunInfo.h:241
static void SetRunStart(double tmp)
Definition TRunInfo.h:228
static void SetDate(const char *ver)
Definition TRunInfo.h:167
static void SetXMLODBFileName(const char *name)
Definition TRunInfo.h:248
static std::string PrintToString(Option_t *opt="")
Definition TRunInfo.cxx:363
void PrintRunList() const
Definition TRunInfo.cxx:521
std::string fFullVersion
The full version of GRSISort that generated the file (includes last commit) - GRSI_GIT_COMMIT from GV...
Definition TRunInfo.h:311
std::string fRunInfoFile
The contents of the run info file.
Definition TRunInfo.h:327
int fLastRunNumber
The last run number (for combined runs)
Definition TRunInfo.h:302
static void SetVersion(std::string ver)
Definition TRunInfo.h:144
static void RemoveBadCycle(int cycle)
Definition TRunInfo.cxx:298
static void SetFullVersion(const char *ver)
Definition TRunInfo.h:155
Long64_t Merge(TCollection *list)
Definition TRunInfo.cxx:263
static int SubRunNumber()
Definition TRunInfo.h:208
std::string fLibraryPath
The path of the parser/file library that generated the file.
Definition TRunInfo.h:314
static void SetRunStop(double tmp)
Definition TRunInfo.h:229
static Bool_t ReadInfoFile(const char *filename="")
Definition TRunInfo.cxx:174
void Clear(Option_t *opt="") override
Definition TRunInfo.cxx:122
static std::string GetLibraryVersion()
Definition TRunInfo.h:177
static Bool_t ParseInputData(const char *inputdata="", Option_t *opt="q")
Definition TRunInfo.cxx:207
void Add(TRunInfo *runinfo, bool verbose=false)
Definition TRunInfo.cxx:387
std::string fXMLODBFileName
Name of XML Odb file.
Definition TRunInfo.h:319
static int LastSubRunNumber()
Definition TRunInfo.h:214
static int RunNumber()
Definition TRunInfo.h:207
std::string fCalFile
Cal File to load into Cal of tree.
Definition TRunInfo.h:317
static std::string RunComment()
Definition TRunInfo.h:226
static void AddBadCycle(int bad_cycle)
Definition TRunInfo.cxx:290
std::string fRunComment
The comment on the run.
Definition TRunInfo.h:297
static bool WriteToRoot(TFile *fileptr=nullptr)
Definition TRunInfo.cxx:309
static std::string RunTitle()
Definition TRunInfo.h:225
static int FirstSubRunNumber()
Definition TRunInfo.h:211
static const char * GetRunInfoFileData()
Definition TRunInfo.h:258
static void SetSubRunNumber(int tmp)
Definition TRunInfo.h:205
static void ClearFullVersion()
Definition TRunInfo.h:154
void Print(Option_t *opt="") const override
Definition TRunInfo.cxx:72
static double HPGeArrayPosition()
Definition TRunInfo.h:267
int fRunNumber
The current run number.
Definition TRunInfo.h:298
static int FirstRunNumber()
Definition TRunInfo.h:210
static void SetCalFileData(const char *data)
Definition TRunInfo.h:246
static void SetCalFileName(const char *name)
Definition TRunInfo.h:245
static double RunLength()
Definition TRunInfo.h:243
static void SetRunNumber(int tmp)
Definition TRunInfo.h:204
TDetectorInformation * fDetectorInformation
! pointer to detector specific information (set by each parser library)
Definition TRunInfo.h:333
static const char * GetXMLODBFileData()
Definition TRunInfo.h:255
static std::string GetLibraryPath()
Definition TRunInfo.h:189
static void ClearDate()
Definition TRunInfo.h:166
static const char * GetXMLODBFileName()
Definition TRunInfo.h:254
static void SetRunLength(double tmp)
Definition TRunInfo.h:230
static void SetHPGeArrayPosition(const double arr_pos)
Definition TRunInfo.h:266
double fRunStop
The stop of the current run in seconds - no idea why we store this as double?
Definition TRunInfo.h:307
static void SetRunInfo(int runnum=0, int subrunnum=-1)
Definition TRunInfo.cxx:135
std::string ListOfMissingRuns(bool all=false) const
Definition TRunInfo.cxx:533
static const char * GetCalFileName()
Definition TRunInfo.h:251
static std::string GetFullVersion()
Definition TRunInfo.h:153
static std::string CreateLabel(bool quiet=false)
Definition TRunInfo.cxx:582
std::string fCalFileName
Name of calfile that generated cal.
Definition TRunInfo.h:316
static const char * GetRunInfoFileName()
Definition TRunInfo.h:257
static std::string GetDate()
Definition TRunInfo.h:165
int fFirstRunNumber
The first run number (for combined runs)
Definition TRunInfo.h:300
static void ClearLibraryVersion()
Definition TRunInfo.h:178
std::string fRunTitle
The title of the run.
Definition TRunInfo.h:296
static void SetAnalysisTreeBranches(TTree *)
Definition TRunInfo.cxx:169
static const char * GetCalFileData()
Definition TRunInfo.h:252
static std::string GetVersion()
Definition TRunInfo.h:141
static void SetVersion(const char *ver)
Definition TRunInfo.h:143
std::string fLibraryVersion
The version of the parser/file library that generated the file.
Definition TRunInfo.h:313
virtual TEventBuildingLoop::EBuildMode BuildMode() const
Definition TRunInfo.cxx:381
static void SetDetectorInformation(TDetectorInformation *inf)
Definition TRunInfo.h:285
void PrintVersion() const
Definition TRunInfo.cxx:571
double fHPGeArrayPosition
Position of the HPGe Array (default = 110.0 mm );.
Definition TRunInfo.h:329
std::string fVersion
The version of GRSISort that generated the file - GRSI_RELEASE from GVersion.h.
Definition TRunInfo.h:310
static void SetFullVersion(std::string ver)
Definition TRunInfo.h:156
static void SetLibraryVersion(std::string ver)
Definition TRunInfo.h:180
static Bool_t ReadInfoFromFile(TFile *tempf=nullptr)
Definition TRunInfo.cxx:15
static void SetLibraryVersion(const char *ver)
Definition TRunInfo.h:179
static bool WriteInfoFile(const std::string &filename)
Definition TRunInfo.cxx:344
double fRunLength
The length of the current run in seconds - no idea why we store this as double?
Definition TRunInfo.h:308
static void SetDate(std::string ver)
Definition TRunInfo.h:168
static void SetLibraryPath(std::string ver)
Definition TRunInfo.h:192
static void SetRunTitle(const char *run_title)
Definition TRunInfo.h:216
std::set< std::pair< int, int > > fRunList
List of all runs added to this run info.
Definition TRunInfo.h:304
static void SetRunLength()
Definition TRunInfo.h:231
TRunInfo(TRunInfo &&) noexcept=default
std::string fXMLODBFile
The odb.
Definition TRunInfo.h:320
static bool IsBadCycle(int cycle)
Definition TRunInfo.cxx:304
static void PrintBadCycles()
Definition TRunInfo.cxx:277
static void SetRunInfoFileName(const char *fname)
Definition TRunInfo.h:263
static void SetLibraryPath(const char *ver)
Definition TRunInfo.h:191
int fSubRunNumber
The current sub run number.
Definition TRunInfo.h:299
static TDetectorInformation * GetDetectorInformation()
Definition TRunInfo.h:286
static TRunInfo * Get(bool verbose=false)
Definition TSingleton.h:33