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 <cstdio>
115
116#include "TObject.h"
117#include "TTree.h"
118#include "TFile.h"
119#include "TKey.h"
120
121#include "Globals.h"
122
123#include "TSingleton.h"
124#include "TChannel.h"
125#include "TEventBuildingLoop.h"
126#include "TDetectorInformation.h"
127
128class TRunInfo : public TSingleton<TRunInfo> {
129public:
130 friend class TSingleton<TRunInfo>;
131
132 TRunInfo(const TRunInfo&) = default;
133 TRunInfo(TRunInfo&&) noexcept = default;
134 TRunInfo& operator=(const TRunInfo&) = default;
135 TRunInfo& operator=(TRunInfo&&) noexcept = default;
136 ~TRunInfo() = default;
137 TRunInfo(); // This should not be used.
138 // root forces me have this here instead
139 // of a private class member in
140 // order to write this class to a tree.
141 // pcb.
142
143 static Bool_t ReadInfoFromFile(TFile* tempf = nullptr);
144
145 static std::string GetVersion() { return Get()->fVersion; }
146 static void ClearVersion() { Get()->fVersion.clear(); }
147 static void SetVersion(const char* ver) { SetVersion(std::string(ver)); }
148 static void SetVersion(std::string ver)
149 {
150 if(!Get()->fVersion.empty() && Get()->fVersion != ver) {
151 std::cout << ALERTTEXT << "WARNING; VERSION ALREADY SET TO " << Get()->fVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
152 } else {
153 Get()->fVersion = std::move(ver);
154 }
155 }
156
157 static std::string GetFullVersion() { return Get()->fFullVersion; }
158 static void ClearFullVersion() { Get()->fFullVersion.clear(); }
159 static void SetFullVersion(const char* ver) { SetFullVersion(std::string(ver)); }
160 static void SetFullVersion(std::string ver)
161 {
162 if(!Get()->fFullVersion.empty() && Get()->fFullVersion != ver) {
163 std::cout << ALERTTEXT << "WARNING; FULL VERSION ALREADY SET TO " << Get()->fFullVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
164 } else {
165 Get()->fFullVersion = std::move(ver);
166 }
167 }
168
169 static std::string GetDate() { return Get()->fDate; }
170 static void ClearDate() { Get()->fDate.clear(); }
171 static void SetDate(const char* ver) { SetDate(std::string(ver)); }
172 static void SetDate(std::string ver)
173 {
174 if(!Get()->fDate.empty() && Get()->fDate != ver) {
175 std::cout << ALERTTEXT << "WARNING; DATE ALREADY SET TO " << Get()->fDate << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
176 } else {
177 Get()->fDate = std::move(ver);
178 }
179 }
180
181 static std::string GetLibraryVersion() { return Get()->fLibraryVersion; }
182 static void ClearLibraryVersion() { Get()->fLibraryVersion.clear(); }
183 static void SetLibraryVersion(const char* ver) { SetLibraryVersion(std::string(ver)); }
184 static void SetLibraryVersion(std::string ver)
185 {
186 if(!Get()->fLibraryVersion.empty() && Get()->fLibraryVersion != ver) {
187 std::cout << ALERTTEXT << "WARNING; LIBRARY VERSION ALREADY SET TO " << Get()->fLibraryVersion << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
188 } else {
189 Get()->fLibraryVersion = std::move(ver);
190 }
191 }
192
193 static std::string GetLibraryPath() { return Get()->fLibraryPath; }
194 static void ClearLibraryPath() { Get()->fLibraryPath.clear(); }
195 static void SetLibraryPath(const char* ver) { SetLibraryPath(std::string(ver)); }
196 static void SetLibraryPath(std::string ver)
197 {
198 if(!Get()->fLibraryPath.empty() && Get()->fLibraryPath != ver) {
199 std::cout << ALERTTEXT << "WARNING; LIBRARY PATH ALREADY SET TO " << Get()->fLibraryPath << " NOT " << ver << "!!" << RESET_COLOR << std::endl;
200 } else {
201 Get()->fLibraryPath = std::move(ver);
202 }
203 }
204
205 static void SetRunInfo(int runnum = 0, int subrunnum = -1);
206 static void SetAnalysisTreeBranches(TTree*);
207
208 static inline void SetRunNumber(int tmp) { Get()->fRunNumber = tmp; }
209 static inline void SetSubRunNumber(int tmp) { Get()->fSubRunNumber = tmp; }
210
211 static inline int RunNumber() { return Get()->fRunNumber; }
212 static inline int SubRunNumber() { return Get()->fSubRunNumber; }
213
214 static inline int FirstRunNumber() { return Get()->fFirstRunNumber; }
215 static inline int FirstSubRunNumber() { return Get()->fFirstSubRunNumber; }
216
217 static inline int LastRunNumber() { return Get()->fLastRunNumber; }
218 static inline int LastSubRunNumber() { return Get()->fLastSubRunNumber; }
219
220 static inline void SetRunTitle(const char* run_title)
221 {
222 if(run_title != nullptr) { Get()->fRunTitle.assign(run_title); }
223 }
224 static inline void SetRunComment(const char* run_comment)
225 {
226 if(run_comment != nullptr) { Get()->fRunComment.assign(run_comment); }
227 }
228
229 static inline std::string RunTitle() { return Get()->fRunTitle; }
230 static inline std::string RunComment() { return Get()->fRunComment; }
231
232 static inline void SetRunStart(double tmp) { Get()->fRunStart = tmp; }
233 static inline void SetRunStop(double tmp) { Get()->fRunStop = tmp; }
234 static inline void SetRunLength(double tmp) { Get()->fRunLength = tmp; }
235 static inline void SetRunLength()
236 {
237 // 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
238 if(RunNumber() != 0) {
239 Get()->fRunLength = Get()->fRunStop - Get()->fRunStart;
240 }
241 // otherwise we have no idea how to calculate the run length (it should be summed up by the Add function)
242 // so we do nothing
243 }
244
245 static inline double RunStart() { return Get()->fRunStart; }
246 static inline double RunStop() { return Get()->fRunStop; }
247 static inline double RunLength() { return Get()->fRunLength; }
248
249 static inline void SetCalFileName(const char* name) { Get()->fCalFileName.assign(name); }
250 static inline void SetCalFileData(const char* data) { Get()->fCalFile.assign(data); }
251
252 static inline void SetXMLODBFileName(const char* name) { Get()->fXMLODBFileName.assign(name); }
253 static inline void SetXMLODBFileData(const char* data) { Get()->fXMLODBFile.assign(data); }
254
255 static const char* GetCalFileName() { return Get()->fCalFileName.c_str(); }
256 static const char* GetCalFileData() { return Get()->fCalFile.c_str(); }
257
258 static const char* GetXMLODBFileName() { return Get()->fXMLODBFileName.c_str(); }
259 static const char* GetXMLODBFileData() { return Get()->fXMLODBFile.c_str(); }
260
261 static const char* GetRunInfoFileName() { return Get()->fRunInfoFileName.c_str(); }
262 static const char* GetRunInfoFileData() { return Get()->fRunInfoFile.c_str(); }
263
264 static Bool_t ReadInfoFile(const char* filename = "");
265 static Bool_t ParseInputData(const char* inputdata = "", Option_t* opt = "q");
266
267 static inline void SetRunInfoFileName(const char* fname) { Get()->fRunInfoFileName.assign(fname); }
268 static inline void SetRunInfoFile(const char* ffile) { Get()->fRunInfoFile.assign(ffile); }
269
270 static inline void SetHPGeArrayPosition(const double arr_pos) { Get()->fHPGeArrayPosition = arr_pos; }
271 static inline double HPGeArrayPosition() { return Get()->fHPGeArrayPosition; }
272
273 Long64_t Merge(TCollection* list);
274 void Add(TRunInfo* runinfo, bool verbose = false);
275
277
278 static void PrintBadCycles();
279 static void AddBadCycle(int bad_cycle);
280 static void RemoveBadCycle(int cycle);
281 static bool IsBadCycle(int cycle);
282
283 void PrintRunList() const;
284 std::string ListOfMissingRuns(bool all = false) const;
285 void PrintVersion() const;
286
287 static std::string CreateLabel(bool quiet = false);
288
291
292 void Print(Option_t* opt = "") const override;
293 void Clear(Option_t* opt = "") override;
294
295 static bool WriteToRoot(TFile* fileptr = nullptr);
296 static bool WriteInfoFile(const std::string& filename);
297 static std::string PrintToString(Option_t* opt = "");
298
299private:
300 std::string fRunTitle; ///< The title of the run
301 std::string fRunComment; ///< The comment on the run
302 int fRunNumber{0}; ///< The current run number
303 int fSubRunNumber{-1}; ///< The current sub run number
304 int fFirstRunNumber{0}; ///< The first run number (for combined runs)
305 int fFirstSubRunNumber{-1}; ///< The first sub run number (for combined subruns)
306 int fLastRunNumber{0}; ///< The last run number (for combined runs)
307 int fLastSubRunNumber{-1}; ///< The last sub run number (for combined subruns)
308 std::set<std::pair<int, int>> fRunList; ///< List of all runs added to this run info
309
310 double fRunStart{0.}; ///< The start of the current run in seconds - no idea why we store this as double?
311 double fRunStop{0.}; ///< The stop of the current run in seconds - no idea why we store this as double?
312 double fRunLength{0.}; ///< The length of the current run in seconds - no idea why we store this as double?
313
314 std::string fVersion; ///< The version of GRSISort that generated the file - GRSI_RELEASE from GVersion.h
315 std::string fFullVersion; ///< The full version of GRSISort that generated the file (includes last commit) - GRSI_GIT_COMMIT from GVersion.h
316 std::string fDate; ///< The date of the last commit used in this version - GRSI_GIT_COMMIT_TIME from GVersion.h
317 std::string fLibraryVersion; ///< The version of the parser/file library that generated the file
318 std::string fLibraryPath; ///< The path of the parser/file library that generated the file
319
320 std::string fCalFileName; ///< Name of calfile that generated cal
321 std::string fCalFile; ///< Cal File to load into Cal of tree
322
323 std::string fXMLODBFileName; ///< Name of XML Odb file
324 std::string fXMLODBFile; ///< The odb
325
326 /////////////////////////////////////////////////
327 //////////////// Building Options ///////////////
328 /////////////////////////////////////////////////
329
330 std::string fRunInfoFileName; ///< The name of the Run info file
331 std::string fRunInfoFile; ///< The contents of the run info file
332
333 double fHPGeArrayPosition{110.}; ///< Position of the HPGe Array (default = 110.0 mm );
334
335 std::vector<int> fBadCycleList; //!<!List of bad cycles to be used for cycle rejection
336
337 TDetectorInformation* fDetectorInformation{nullptr}; //!<! pointer to detector specific information (set by each parser library)
338
339 /// \cond CLASSIMP
340 ClassDefOverride(TRunInfo, 18) // NOLINT(readability-else-after-return)
341 /// \endcond
342};
343/*! @} */
344#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:316
static void SetXMLODBFileData(const char *data)
Definition TRunInfo.h:253
TRunInfo(const TRunInfo &)=default
static void ClearVersion()
Definition TRunInfo.h:146
static void SetRunInfoFile(const char *ffile)
Definition TRunInfo.h:268
int fFirstSubRunNumber
The first sub run number (for combined subruns)
Definition TRunInfo.h:305
double fRunStart
The start of the current run in seconds - no idea why we store this as double?
Definition TRunInfo.h:310
std::string fRunInfoFileName
The name of the Run info file.
Definition TRunInfo.h:330
static void SetRunComment(const char *run_comment)
Definition TRunInfo.h:224
std::vector< int > fBadCycleList
!List of bad cycles to be used for cycle rejection
Definition TRunInfo.h:335
static void ClearLibraryPath()
Definition TRunInfo.h:194
static double RunStop()
Definition TRunInfo.h:246
static int LastRunNumber()
Definition TRunInfo.h:217
int fLastSubRunNumber
The last sub run number (for combined subruns)
Definition TRunInfo.h:307
static double RunStart()
Definition TRunInfo.h:245
static void SetRunStart(double tmp)
Definition TRunInfo.h:232
static void SetDate(const char *ver)
Definition TRunInfo.h:171
static void SetXMLODBFileName(const char *name)
Definition TRunInfo.h:252
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:315
std::string fRunInfoFile
The contents of the run info file.
Definition TRunInfo.h:331
int fLastRunNumber
The last run number (for combined runs)
Definition TRunInfo.h:306
static void SetVersion(std::string ver)
Definition TRunInfo.h:148
static void RemoveBadCycle(int cycle)
Definition TRunInfo.cxx:298
static void SetFullVersion(const char *ver)
Definition TRunInfo.h:159
Long64_t Merge(TCollection *list)
Definition TRunInfo.cxx:263
static int SubRunNumber()
Definition TRunInfo.h:212
std::string fLibraryPath
The path of the parser/file library that generated the file.
Definition TRunInfo.h:318
static void SetRunStop(double tmp)
Definition TRunInfo.h:233
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:181
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:323
static int LastSubRunNumber()
Definition TRunInfo.h:218
static int RunNumber()
Definition TRunInfo.h:211
std::string fCalFile
Cal File to load into Cal of tree.
Definition TRunInfo.h:321
static std::string RunComment()
Definition TRunInfo.h:230
static void AddBadCycle(int bad_cycle)
Definition TRunInfo.cxx:290
std::string fRunComment
The comment on the run.
Definition TRunInfo.h:301
static bool WriteToRoot(TFile *fileptr=nullptr)
Definition TRunInfo.cxx:309
static std::string RunTitle()
Definition TRunInfo.h:229
static int FirstSubRunNumber()
Definition TRunInfo.h:215
static const char * GetRunInfoFileData()
Definition TRunInfo.h:262
static void SetSubRunNumber(int tmp)
Definition TRunInfo.h:209
static void ClearFullVersion()
Definition TRunInfo.h:158
void Print(Option_t *opt="") const override
Definition TRunInfo.cxx:72
static double HPGeArrayPosition()
Definition TRunInfo.h:271
int fRunNumber
The current run number.
Definition TRunInfo.h:302
static int FirstRunNumber()
Definition TRunInfo.h:214
static void SetCalFileData(const char *data)
Definition TRunInfo.h:250
static void SetCalFileName(const char *name)
Definition TRunInfo.h:249
static double RunLength()
Definition TRunInfo.h:247
static void SetRunNumber(int tmp)
Definition TRunInfo.h:208
TDetectorInformation * fDetectorInformation
! pointer to detector specific information (set by each parser library)
Definition TRunInfo.h:337
static const char * GetXMLODBFileData()
Definition TRunInfo.h:259
static std::string GetLibraryPath()
Definition TRunInfo.h:193
static void ClearDate()
Definition TRunInfo.h:170
static const char * GetXMLODBFileName()
Definition TRunInfo.h:258
static void SetRunLength(double tmp)
Definition TRunInfo.h:234
static void SetHPGeArrayPosition(const double arr_pos)
Definition TRunInfo.h:270
double fRunStop
The stop of the current run in seconds - no idea why we store this as double?
Definition TRunInfo.h:311
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:255
static std::string GetFullVersion()
Definition TRunInfo.h:157
static std::string CreateLabel(bool quiet=false)
Definition TRunInfo.cxx:582
std::string fCalFileName
Name of calfile that generated cal.
Definition TRunInfo.h:320
static const char * GetRunInfoFileName()
Definition TRunInfo.h:261
static std::string GetDate()
Definition TRunInfo.h:169
int fFirstRunNumber
The first run number (for combined runs)
Definition TRunInfo.h:304
static void ClearLibraryVersion()
Definition TRunInfo.h:182
std::string fRunTitle
The title of the run.
Definition TRunInfo.h:300
static void SetAnalysisTreeBranches(TTree *)
Definition TRunInfo.cxx:169
static const char * GetCalFileData()
Definition TRunInfo.h:256
static std::string GetVersion()
Definition TRunInfo.h:145
static void SetVersion(const char *ver)
Definition TRunInfo.h:147
std::string fLibraryVersion
The version of the parser/file library that generated the file.
Definition TRunInfo.h:317
virtual TEventBuildingLoop::EBuildMode BuildMode() const
Definition TRunInfo.cxx:381
static void SetDetectorInformation(TDetectorInformation *inf)
Definition TRunInfo.h:289
void PrintVersion() const
Definition TRunInfo.cxx:571
double fHPGeArrayPosition
Position of the HPGe Array (default = 110.0 mm );.
Definition TRunInfo.h:333
std::string fVersion
The version of GRSISort that generated the file - GRSI_RELEASE from GVersion.h.
Definition TRunInfo.h:314
static void SetFullVersion(std::string ver)
Definition TRunInfo.h:160
static void SetLibraryVersion(std::string ver)
Definition TRunInfo.h:184
static Bool_t ReadInfoFromFile(TFile *tempf=nullptr)
Definition TRunInfo.cxx:15
static void SetLibraryVersion(const char *ver)
Definition TRunInfo.h:183
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:312
static void SetDate(std::string ver)
Definition TRunInfo.h:172
static void SetLibraryPath(std::string ver)
Definition TRunInfo.h:196
static void SetRunTitle(const char *run_title)
Definition TRunInfo.h:220
std::set< std::pair< int, int > > fRunList
List of all runs added to this run info.
Definition TRunInfo.h:308
static void SetRunLength()
Definition TRunInfo.h:235
TRunInfo(TRunInfo &&) noexcept=default
std::string fXMLODBFile
The odb.
Definition TRunInfo.h:324
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:267
static void SetLibraryPath(const char *ver)
Definition TRunInfo.h:195
int fSubRunNumber
The current sub run number.
Definition TRunInfo.h:303
static TDetectorInformation * GetDetectorInformation()
Definition TRunInfo.h:290
static TRunInfo * Get(bool verbose=false)
Definition TSingleton.h:33