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