GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TGRSIOptions.cxx
Go to the documentation of this file.
1#include "TGRSIOptions.h"
2
3#include <cctype>
4#include <iostream>
5
6#include "TEnv.h"
7#include "TKey.h"
8#include "TSystem.h"
9
10#include "Globals.h"
11#include "FullPath.h"
12#include "ArgParser.h"
13#include "DynamicLibrary.h"
14#include "GRootCommands.h"
15
19
20TGRSIOptions* TGRSIOptions::Get(int argc, char** argv)
21{
22 // The Getter for the singleton TGRSIOptions. This makes it
23 // so there is only ever one instance of the options during
24 // a session and it can be accessed from anywhere during that
25 // session.
26 if(fGRSIOptions == nullptr) {
27 fGRSIOptions = new TGRSIOptions(argc, argv);
28 }
29 return fGRSIOptions;
30}
31
32TGRSIOptions::TGRSIOptions(int argc, char** argv)
33{
34 /// Ctor used when interpreter is initialized
35 Load(argc, argv);
36}
37
38void TGRSIOptions::Clear(Option_t*)
39{
40 /// Clears all of the variables in the TGRSIOptions
41 fInputFiles.clear();
42 fInputRootFiles.clear();
43 fInputCalFiles.clear();
44 fInputOdbFiles.clear();
45 fExternalRunInfo.clear();
46 fMacroFiles.clear();
48
49 fInputCutFiles.clear();
50 fInputValFiles.clear();
51 fInputWinFiles.clear();
52 fInputRing = "";
53
60
64
65 fOptionsFile.clear();
66
67 fLogFile = "grsisort.log";
68
69 fCloseAfterSort = false;
70 fLogErrors = false;
71 fUseMidFileOdb = false;
72
73 fMakeAnalysisTree = false;
74 fUseRnTuple = false;
75 fReadingMaterial = false;
76 fIgnoreFileOdb = false;
77 fIgnoreOdbChannels = false;
78 fDownscaling = 1;
79
80 fIgnoreScaler = false;
81 fIgnoreEpics = false;
82 fWriteFragmentTree = false;
83 fWriteBadFrags = false;
84 fWriteDiagnostics = false;
86 fWordOffset = -1;
87
88 fBatch = false;
89
90 fShowedVersion = false;
91 fShowLogo = false;
92 fSortRaw = true;
93 fExtractWaves = false;
94 fIsOnline = false;
95 fStartGui = false;
96 fMakeHistos = false;
97 fSortMultiple = false;
98 fDebug = false;
99
102
103 fNumberOfEvents = 0;
104
105 fIgnoreMissingChannel = false;
106 fSkipInputSort = false;
107
108 fSeparateOutOfOrder = false;
109
110 fShouldExit = false;
111
112 fColumnWidth = 20;
113 fStatusWidth = 120;
114 fStatusInterval = 10;
115 fLongFileDescription = false;
116
119
120 // Proof only
121 fMaxWorkers = -1;
122 fSelectorOnly = false;
123 fTreeName.clear();
125 fParallelUnzip = false;
126 fCacheSize = -1;
127 fSubmergers = -1;
128 fProofStats = false;
129
130 fHelp = false;
131
132 fParserLibrary.clear();
133}
134
135void TGRSIOptions::Print(Option_t*) const
136{
137 /// Print the current status of TGRSIOptions, includes all names, lists and flags
138 std::cout << "fCloseAfterSort: " << fCloseAfterSort << std::endl
139 << "fLogErrors: " << fLogErrors << std::endl
140 << "fUseMidFileOdb: " << fUseMidFileOdb << std::endl
141 << "fSuppressErrors: " << fSuppressErrors << std::endl
142 << "fReconstructTimeStamp: " << fReconstructTimeStamp << std::endl
143 << std::endl
144 << "fMakeAnalysisTree: " << fMakeAnalysisTree << std::endl
145 << "fUseRnTuple: " << fUseRnTuple << std::endl
146 << "fReadingMaterial;: " << fReadingMaterial << std::endl
147 << "fIgnoreFileOdb: " << fIgnoreFileOdb << std::endl
148 << "fIgnoreOdbChannels: " << fIgnoreOdbChannels << std::endl
149 << "fDownscaling: " << fDownscaling << std::endl
150 << std::endl
151 << "fIgnoreScaler: " << fIgnoreScaler << std::endl
152 << "fIgnoreEpics: " << fIgnoreEpics << std::endl
153 << "fWriteFragmentTree: " << fWriteFragmentTree << std::endl
154 << "fWriteBadFrags: " << fWriteBadFrags << std::endl
155 << "fWriteDiagnostics: " << fWriteDiagnostics << std::endl
156 << "fCreateFragmentDiagnostics: " << fCreateFragmentDiagnostics << std::endl
157 << "fWordOffset: " << fWordOffset << std::endl
158 << std::endl
159 << "fBatch: " << fBatch << std::endl
160 << std::endl
161 << "fShowedVersion: " << fShowedVersion << std::endl
162 << "fShowLogo: " << fShowLogo << std::endl
163 << "fSortRaw: " << fSortRaw << std::endl
164 << "fExtractWaves;: " << fExtractWaves << std::endl
165 << "fIsOnline: " << fIsOnline << std::endl
166 << "fStartGui: " << fStartGui << std::endl
167 << "fMakeHistos: " << fMakeHistos << std::endl
168 << "fSortMultiple: " << fSortMultiple << std::endl
169 << "fDebug: " << fDebug << std::endl
170 << "fLogFile: " << fLogFile << std::endl
171 << std::endl
172 << "fFragmentWriteQueueSize: " << fFragmentWriteQueueSize << std::endl
173 << "fAnalysisWriteQueueSize: " << fAnalysisWriteQueueSize << std::endl
174 << std::endl
175 << "fIgnoreMissingChannel: " << fIgnoreMissingChannel << std::endl
176 << "fSkipInputSort: " << fSkipInputSort << std::endl
177 << "fSortDepth: " << fSortDepth << std::endl
178 << std::endl
179 << "fSeparateOutOfOrder: " << fSeparateOutOfOrder << std::endl
180 << std::endl
181 << "fShouldExit: " << fShouldExit << std::endl
182 << std::endl
183 << "fColumnWidth: " << fColumnWidth << std::endl
184 << "fStatusWidth: " << fStatusWidth << std::endl
185 << "fStatusInterval: " << fStatusInterval << std::endl
186 << "fLongFileDescription: " << fLongFileDescription << std::endl
187 << std::endl
188 << "fMaxWorkers: " << fMaxWorkers << std::endl
189 << "fSelectorOnly: " << fSelectorOnly << std::endl
190 << "fTreeName: " << fTreeName << std::endl
191 << "fAverageRateEstimation: " << fAverageRateEstimation << std::endl
192 << "fParallelUnzip: " << fParallelUnzip << std::endl
193 << "fCacheSize: " << fCacheSize << std::endl
194 << "fSubmergers: " << fSubmergers << std::endl
195 << "fProofStats: " << fProofStats << std::endl
196 << std::endl
197 << "fHelp: " << fHelp << std::endl
198 << std::endl
199 << "fParserLibrary: " << fParserLibrary << std::endl;
200
202}
203
204void TGRSIOptions::Load(int argc, char** argv)
205{
206 /// This checks all of the options provided to GRSISort. This also loads in some
207 /// libraries in order to do on the fly histogramming.
208 Clear();
209 fFragmentHistogramLib = gEnv->GetValue("GRSI.FragmentHistLib", "");
210 fAnalysisHistogramLib = gEnv->GetValue("GRSI.AnalysisHistLib", "");
211
212 fParserLibrary = gEnv->GetValue("GRSI.ParserLibrary", "");
213
214 // Load default TChannels, if specified.
215 {
216 std::string default_calfile = gEnv->GetValue("GRSI.CalFile", "");
217 if(!default_calfile.empty()) {
218 fInputCalFiles.push_back(default_calfile);
219 }
220 }
221
222 // Load default GValues, if specified.
223 {
224 std::string default_valfile = gEnv->GetValue("GRSI.ValFile", "");
225 if(!default_valfile.empty()) {
226 fInputValFiles.push_back(default_valfile);
227 }
228 }
229
230 // Get name of the program calling this function (removing any path from the name)
231 std::string program;
232 if(argc > 0) {
233 program = argv[0];
234 } else {
235 program = "unknown";
236 }
237 size_t lastSlash = program.rfind('/');
238 if(lastSlash != std::string::npos) {
239 program.erase(0, lastSlash + 1);
240 }
241
242 ArgParser parser;
243 bool useRecommendedFlags = false;
244
245 std::vector<std::string> input_files;
246 std::string default_file_format;
247
248 // parser.option() will initialize boolean values to false.
249
250 // general options
251 // these options are all to be set directly on the first parsing pass, so we set the firstPass flag to true
252 parser.default_option(&input_files, true).description("Input file(s)");
253 parser.option("h help ?", &fHelp, true).description("Show this help message");
254 parser.option("v version", &fShowedVersion, true).description("Show the version of GRSISort");
255
256 // analysis options, these options are to be parsed on the second pass, so firstPass is set to false
257 parser.option("build-window", &fAnalysisOptions->fBuildWindow, false)
258 .description("Build window, in ns.")
259 .colour(DCYAN);
260 parser.option("build-events-by-timestamp", &fAnalysisOptions->fBuildEventsByTimeStamp, false)
261 .description("Build events by timestamp w/o using CFD")
262 .colour(DCYAN);
263 parser.option("addback-window", &fAnalysisOptions->fAddbackWindow, false)
264 .description("Addback window, time in ns")
265 .colour(DCYAN);
266 parser.option("suppression-window", &fAnalysisOptions->fSuppressionWindow, false)
267 .description("BGO suppression window, time in ns")
268 .colour(DCYAN);
269 parser.option("suppression-energy", &fAnalysisOptions->fSuppressionEnergy, false)
270 .description("Minimum BGO energy for suppression")
271 .colour(DCYAN);
272 parser.option("static-window", &fAnalysisOptions->fStaticWindow, false)
273 .description("Use static window for event building")
274 .colour(DCYAN);
275 parser.option("waveform-fitting", &fAnalysisOptions->fWaveformFitting, false)
276 .description("Fit waveforms using SFU algorithms")
277 .colour(DCYAN);
278 parser.option("is-correcting-cross-talk", &fAnalysisOptions->fIsCorrectingCrossTalk, false)
279 .description("Correct cross-talk")
280 .colour(DCYAN);
281
282 // program specific options
283 if(program == "grsisort") {
284 // grsisort only options
285 parser.option("recommended", &useRecommendedFlags, true).description("Use recommended flags (those in " DGREEN "dark green" GREEN ")").colour(GREEN);
286 parser.option("output-fragment-tree", &fOutputFragmentFile, true).description("Filename of output fragment tree");
287 parser.option("output-analysis-tree", &fOutputAnalysisFile, true).description("Filename of output analysis tree");
288 parser.option("output-diagnostics", &fOutputDiagnosticsFile, true).description("Filename of output diagnostics");
289 parser.option("output-fragment-hists", &fOutputFragmentHistogramFile, true)
290 .description("Filename of output fragment hists");
291 parser.option("output-analysis-hists", &fOutputAnalysisHistogramFile, true)
292 .description("Filename of output analysis hists");
293
294 parser.option("a", &fMakeAnalysisTree, true).description("Make the analysis tree").colour(DGREEN);
295 parser.option("use-rntuple", &fUseRnTuple, true).description("Use experimental RNTuple instead of TTree");
296 parser.option("H histos", &fMakeHistos, true).description("Attempt to run events through MakeHisto lib");
297 parser.option("g start-gui", &fStartGui, true).description("Start the gui at program start");
298 parser.option("b batch", &fBatch, true).description("Run in batch mode");
299
300 parser.option("sort-depth", &fSortDepth, true)
301 .description("Number of events to hold when sorting by time/trigger_id")
302 .default_value(200000);
303
304 parser.option("q quit", &fCloseAfterSort, true).description("Quit after completing the sort").colour(DGREEN);
305 parser.option("l no-logo", &fShowLogo, true).description("Inhibit the startup logo").default_value(true).colour(DGREEN);
306 parser.option("w extract-waves", &fExtractWaves, true)
307 .description("Extract wave forms to data class when available.")
308 .default_value(false);
309 parser.option("d debug", &fDebug, true)
310 .description("Write debug information to output/file, e.g. enables writing of TDescantDebug at analysis stage")
311 .default_value(false);
312 parser.option("write-diagnostics", &fWriteDiagnostics, true).description("Write Parsing/SortingDiagnostics to root-file").colour(DGREEN);
313 parser.option("create-diagnostics", &fCreateFragmentDiagnostics, true).description("Create more diagnostics from the fragment loop");
314 parser.option("word-count-offset", &fWordOffset, true)
315 .description("Offset to the word count in the GRIFFIN header word, default is -1 (disabled).")
316 .default_value(-1)
317 .colour(DGREEN);
318 parser.option("log-errors", &fLogErrors, true);
319 parser.option("reading-material", &fReadingMaterial, true);
320 parser.option("write-fragment-tree write-frag-tree", &fWriteFragmentTree, true)
321 .description("Write fragment tree.");
322 parser.option("bad-frags write-bad-frags bad-fragments write-bad-fragments", &fWriteBadFrags, true)
323 .description("Write fragments that failed parsing to BadFragmentTree");
324 parser.option("separate-out-of-order", &fSeparateOutOfOrder, true)
325 .description("Write out-of-order fragments to a separate tree at the sorting stage")
326 .default_value(false)
327 .colour(DGREEN);
328 parser.option("ignore-odb", &fIgnoreFileOdb, true);
329 parser.option("ignore-odb-channels", &fIgnoreOdbChannels, true);
330 parser.option("downscaling", &fDownscaling, true).description("Downscaling factor for raw events to be processed").default_value(1);
331 parser.option("ignore-epics", &fIgnoreEpics, true);
332 parser.option("ignore-scaler", &fIgnoreScaler, true);
333 parser.option("suppress-error suppress-errors suppress_error suppress_errors", &fSuppressErrors, true)
334 .description("Suppress error output from parsing")
335 .colour(DGREEN);
336 parser.option("reconstruct-timestamp reconstruct-time-stamp", &fReconstructTimeStamp, true)
337 .description("Reconstruct missing high bits of timestamp")
338 .colour(DGREEN);
339 parser.option("ignore-missing-channel", &fIgnoreMissingChannel, true)
340 .description("Ignore missing channels completely (not written to fragment or analysis tree)")
341 .default_value(false);
342 parser.option("skip-input-sort", &fSkipInputSort, true)
343 .description("Skip sorting fragments before building events (default is false)")
344 .default_value(false);
345
346 parser.option("fragment-size", &fFragmentWriteQueueSize, true)
347 .description("Size of fragment write queue")
348 .default_value(10000000);
349 parser.option("analysis-size", &fAnalysisWriteQueueSize, true)
350 .description("Size of analysis write queue")
351 .default_value(1000000);
352
353 parser.option("column-width", &fColumnWidth, true).description("Width of one column of status").default_value(20);
354 parser.option("status-width", &fStatusWidth, true)
355 .description("Number of characters to be used for status output")
356 .default_value(120);
357 parser.option("status-interval", &fStatusInterval, true)
358 .description(
359 "Seconds between each detailed status output (each a new line), non-positive numbers mean no detailed status")
360 .default_value(10);
361 } else if(program == "grsiproof") {
362 // Proof only parser options
363 parser.option("max-workers", &fMaxWorkers, true)
364 .description("Max number of nodes to use when running a grsiproof session")
365 .default_value(-1);
366
367 parser.option("selector-only", &fSelectorOnly, true)
368 .description("Turns off PROOF to run a selector on the main thread");
369 parser.option("log-file", &fLogFile, true).description("File logs from grsiproof are written to");
370
371 parser.option("tree-name", &fTreeName, true)
372 .description("Name of tree to be proofed, default is empty, i.e. FragmentTree, AnalysisTree, and Lst2RootTree are checked");
373 parser.option("average-rate", &fAverageRateEstimation, true)
374 .description("use average rate instead of current rate");
375 parser.option("parallel-unzip", &fParallelUnzip, true)
376 .description("use parallel unzipping of input files");
377 parser.option("cache-size", &fCacheSize, true)
378 .description("set tree cache size (default = -1 = off)");
379 parser.option("sub-mergers", &fSubmergers, true)
380 .description("use sub mergers to merge result from workers (default = -1 = off, 0 = automatic number of mergers)");
381 parser.option("proof-stats", &fProofStats, true)
382 .description("enable proof stats");
383 } else if(program == "grsiframe") {
384 // grsiframe only parser options
385 parser.option("max-workers", &fMaxWorkers, true)
386 .description("Maximum number of nodes to use when running a grsiframe session")
387 .default_value(1);
388 parser.option("tree-name", &fTreeName, true)
389 .description("Name of tree to be used, default is empty, i.e. FragmentTree, and AnalysisTree are checked");
390 parser.option("d debug", &fDebug, true)
391 .description("Increases verbosity of RDataFrame (also turns off the progress bar)")
392 .default_value(false);
393 }
394
395 if(program == "grsiframe") {
396 // grsisort or grsiproof options
397 parser.option("max-events", &fNumberOfEvents, true)
398 .description("Maximum number of events read")
399 .default_value(0);
400 }
401
402 // look for any arguments ending with .info, pass to parser.
403 for(int i = 1; i < argc; i++) {
404 std::string filename = argv[i];
406 try {
407 parser.parse_file(filename);
408 } catch(ParseError& e) {
409 std::cerr << "ERROR: " << e.what() << "\n"
410 << parser << std::endl;
411 throw;
412 }
413 }
414 }
415
416 // Look at the command line.
417 try {
418 parser.parse(argc, argv, true);
419 } catch(ParseError& e) {
420 std::cerr << "ERROR: " << e.what() << "\n"
421 << parser << std::endl;
422 throw;
423 }
424
425 // Print version if requested
426 if(fShowedVersion) {
427 Version();
428 fShouldExit = true;
429 }
430
431 // print help if required
432 if(fHelp) {
433 std::cout << parser << std::endl;
434 fShouldExit = true;
435 }
436
437 if(fOutputFragmentHistogramFile.length() > 0 && fOutputFragmentHistogramFile != "none") {
438 fMakeHistos = true;
439 }
440 if(fOutputAnalysisHistogramFile.length() > 0 && fOutputAnalysisHistogramFile != "none") {
441 fMakeHistos = true;
442 }
443
444 for(auto& file : input_files) {
445 FileAutoDetect(file);
446 }
447
448 // load any additional parser library
449 if(!fParserLibrary.empty()) {
450 gSystem->Load(fParserLibrary.c_str());
451 }
452
453 // read analysis options from input file(s)
454 for(const std::string& file : fInputRootFiles) {
456 }
457 // parse analysis options from command line options
458 try {
459 parser.parse(argc, argv, false);
460 } catch(ParseError& e) {
461 std::cerr << "ERROR: " << e.what() << "\n"
462 << parser << std::endl;
463 throw;
464 }
465 if(useRecommendedFlags) {
466 fMakeAnalysisTree = true;
467 fShowLogo = false;
468 fCloseAfterSort = true;
469 fWriteDiagnostics = true;
470 fSeparateOutOfOrder = true;
471 fSuppressErrors = true;
473 fWordOffset = -1;
474 }
475}
476
477kFileType TGRSIOptions::DetermineFileType(const std::string& filename)
478{
479 size_t dotPos = filename.find_last_of('.');
480 size_t slashPos = filename.find_last_of('/');
481 // if we didn't find a . (or if it was before the last /) we don't have any extension
482 // => so it's a TDR file
483 if(dotPos == std::string::npos || (dotPos < slashPos && slashPos != std::string::npos)) {
484 return kFileType::TDR_FILE;
485 }
486 std::string ext = filename.substr(dotPos + 1);
487
488 // check if this is a zipped file and if so get the extension before the zip-extension
489 bool isZipped = (ext == "gz") || (ext == "bz2") || (ext == "zip");
490 if(isZipped) {
491 std::string remaining = filename.substr(0, dotPos);
492 ext = remaining.substr(remaining.find_last_of('.') + 1);
493 }
494
495 if(ext == "mid") {
497 }
498 if(ext == "lst") {
499 return kFileType::LST_FILE;
500 }
501 if(ext == "rlmd") {
503 }
504 if(ext == "evt") {
505 return kFileType::NSCL_EVT;
506 }
507 if(ext == "cal") {
509 }
510 if(ext == "root") {
512 }
513 if((ext == "cxx")) {
515 }
516 if((ext == "c") || (ext == "C") || (ext == "c+") || (ext == "C+") || (ext == "c++") || (ext == "C++")) {
518 }
519 if(ext == "dat" || ext == "cvt") {
520 if(filename.find("GlobalRaw") != std::string::npos) {
522 }
524 }
525 if(ext == "hist") {
527 }
528 if(ext == "so") {
530 }
531 if(ext == "info") {
533 }
534 if(ext == "val") {
535 return kFileType::GVALUE;
536 }
537 if(ext == "par") {
539 }
540 if(ext == "win") {
542 }
543 if(ext == "cuts") {
545 }
546 if(ext == "xml") {
547 return kFileType::XML_FILE;
548 }
549
550 // strip possible parenthese with arguments for the script from the extension
551 size_t openingPos = ext.find_first_of('(');
552 if(openingPos != std::string::npos) {
553 ext = ext.substr(0, openingPos);
554 if((ext == "c") || (ext == "C") || (ext == "c+") || (ext == "C+") || (ext == "c++") || (ext == "C++")) {
556 }
557 }
559}
560
561bool TGRSIOptions::FileAutoDetect(const std::string& filename)
562{
563 /// Detects the type of file provided on the command line. This uses the extension to determine
564 /// the type of the file. Once the type is determined, the file is sent to the appropriate list
565 /// in TGRSIOptions. This is also smart enough to dynamically link histogramming libraries.
566 switch(DetermineFileType(filename)) {
573 case kFileType::MIDAS_FILE: fInputFiles.push_back(filename); return true;
574
575 case kFileType::ROOT_DATA: fInputRootFiles.push_back(filename); return true;
576
577 case kFileType::ROOT_MACRO: fMacroFiles.push_back(filename); return true;
578
579 case kFileType::CALIBRATED: fInputCalFiles.push_back(filename); return true;
580
581 case kFileType::DATAFRAME: fDataFrameLibrary = full_path(filename); return true;
582
584 bool used = false;
585 // need absolute path not relative path in case the current working directory is not in LD_LIBRARY_PATH
586 std::string fullFilename = full_path(filename);
587 DynamicLibrary lib(fullFilename);
588 if(lib.GetSymbol("MakeFragmentHistograms") != nullptr) {
589 fFragmentHistogramLib = fullFilename;
590 used = true;
591 }
592 if(lib.GetSymbol("MakeAnalysisHistograms") != nullptr) {
593 fAnalysisHistogramLib = fullFilename;
594 used = true;
595 }
596 if(lib.GetSymbol("CreateParser") != nullptr && lib.GetSymbol("DestroyParser") != nullptr &&
597 lib.GetSymbol("CreateFile") != nullptr && lib.GetSymbol("DestroyFile") != nullptr) {
598 fParserLibrary = fullFilename;
599 used = true;
600 }
601 if(lib.GetSymbol("CreateHelper") != nullptr && lib.GetSymbol("DestroyHelper") != nullptr) {
602 fDataFrameLibrary = fullFilename;
603 used = true;
604 }
605 if(!used) {
606 std::cerr << fullFilename << " did not contain MakeFragmentHistograms or MakeAnalysisHistograms or CreateParser and others or CreateHelper and DestroyHelper" << std::endl;
607 }
608 return used;
609 }
610
611 case kFileType::GVALUE: fInputValFiles.push_back(filename); return true;
612
614 // if we haven't read any user setting create new ones and read the file, otherwise just read the file
615 if(fUserSettings == nullptr) {
616 fUserSettings = new TUserSettings(filename);
617 } else {
618 fUserSettings->ReadSettings(filename);
619 }
620 return true;
621
622 case kFileType::PRESETWINDOW: fInputWinFiles.push_back(filename); return true;
623
624 case kFileType::CUTS_FILE: fInputCutFiles.push_back(filename); return true;
625
626 case kFileType::CONFIG_FILE: return false;
627
628 case kFileType::XML_FILE: fInputOdbFiles.push_back(filename); return true;
629
631 default: std::cout << "\tDiscarding unknown file: " << filename << std::endl; return false;
632 }
633}
634
636{
637 /// Writes options information to the tree
638 // Maintain old gDirectory info
639 bool success = true;
640 TDirectory* oldDir = gDirectory;
641
642 if(file == nullptr) {
643 file = gDirectory->GetFile();
644 }
645 file->cd();
646 std::string oldoption = std::string(file->GetOption());
647 if(oldoption == "READ") {
648 file->ReOpen("UPDATE");
649 }
650 if(!gDirectory) { // we don't compare to nullptr here, as ROOT >= 6.24.00 uses the TDirectoryAtomicAdapter structure with a bool() operator
651 std::cout << "No file opened to write TGRSIOptions to." << std::endl;
652 success = false;
653 } else {
654 Get()->Write("GRSIOptions", TObject::kOverwrite);
656 if(!fUserSettings->empty()) { fUserSettings->Write("UserSettings", TObject::kOverwrite); }
657 }
658
659 std::cout << "Writing TGRSIOptions to " << gDirectory->GetFile()->GetName() << std::endl;
660 if(oldoption == "READ") {
661 std::cout << " Returning " << gDirectory->GetFile()->GetName() << " to \"" << oldoption << "\" mode." << std::endl;
662 file->ReOpen("READ");
663 }
664 oldDir->cd(); // Go back to original gDirectory
665
666 return success;
667}
668
670{
671 // Sets the TGRSIOptions to the info passes as tmp.
672 if((fGRSIOptions != nullptr) && (tmp != fGRSIOptions)) {
673 delete fGRSIOptions;
674 }
675 fGRSIOptions = tmp;
676}
677
678Bool_t TGRSIOptions::ReadFromFile(TFile* file)
679{
680 TDirectory* oldDir = gDirectory;
681 if(file != nullptr) {
682 file->cd();
683 }
684
685 if(gDirectory->GetFile() == nullptr) {
686 std::cout << "File does not exist" << std::endl;
687 oldDir->cd();
688 return false;
689 }
690
691 file = gDirectory->GetFile();
692
693 TList* list = file->GetListOfKeys();
694 TIter iter(list);
695 std::cout << "Reading options from file: " << CYAN << file->GetName() << RESET_COLOR << std::endl;
696 while(TKey* key = static_cast<TKey*>(iter.Next())) {
697 if((key == nullptr) || (strcmp(key->GetClassName(), "TGRSIOptions") != 0)) {
698 continue;
699 }
700
701 TGRSIOptions::SetOptions(static_cast<TGRSIOptions*>(key->ReadObj()));
702 oldDir->cd();
703 return true;
704 }
705 oldDir->cd();
706
707 return false;
708}
std::string full_path(const std::string &path)
Definition FullPath.cxx:9
void Version()
#define DGREEN
Definition Globals.h:17
#define DCYAN
Definition Globals.h:21
#define GREEN
Definition Globals.h:8
#define CYAN
Definition Globals.h:12
#define RESET_COLOR
Definition Globals.h:5
kFileType
Definition TGRSITypes.h:6
@ COMPILED_SHARED_LIBRARY
@ UNKNOWN_FILETYPE
void parse(int argc, char **argv, bool firstPass)
Definition ArgParser.h:333
ArgParseConfigT< T > & option(const std::string flag, T *output_location, bool firstPass)
Definition ArgParser.h:412
void parse_file(std::string &filename)
Definition ArgParser.h:365
ArgParseConfigT< std::vector< T > > & default_option(std::vector< T > *output_location, bool firstPass)
Definition ArgParser.h:420
Loads a Shared Object library.
void * GetSymbol(const char *symbol)
Extracts a symbol from the shared library.
bool fIsCorrectingCrossTalk
True if we are correcting for cross-talk in GRIFFIN at analysis-level.
bool WriteToFile(const std::string &file)
double fSuppressionEnergy
Minimum energy used to suppress Ge-Events. (default = 0 keV)
int64_t fBuildWindow
if building with a window(GRIFFIN) this is the size of the window. (default = 2us (2000))
void Print(Option_t *opt="") const override
double fSuppressionWindow
Time used to suppress Ge-Events. (default = 300 ns (300))
void Clear(Option_t *opt="") override
bool fBuildEventsByTimeStamp
use time stamps instead of time (including CFD) to build events
double fAddbackWindow
Time used to build Addback-Ge-Events for TIGRESS/GRIFFIN. (default = 300 ns (300))
bool fWaveformFitting
If true, waveform fitting with SFU algorithm will be performed.
void ReadFromFile(const std::string &file)
bool fStaticWindow
Flag to use static window (default moving)
bool fIgnoreScaler
Flag to ignore scalers in GRIFFIN.
std::string fTreeName
Name of tree to be analyzed (default is empty, i.e. FragmentTree, AnalysisTree, and Lst2RootTree are ...
bool fWriteDiagnostics
Flag to write diagnostics.
void Load(int argc, char **argv)
bool fReadingMaterial
Flag to show reading material (–reading-material)
bool fShouldExit
Flag to exit sorting.
std::vector< std::string > fInputFiles
A list of the input files.
bool fWriteBadFrags
Flag to write bad fragments.
std::vector< std::string > fInputValFiles
A list of the input GValue files.
bool fSeparateOutOfOrder
Flag to build out of order into seperate event tree.
static kFileType DetermineFileType(const std::string &filename)
bool fCloseAfterSort
Flag to close after sorting (-q)
static TGRSIOptions * Get(int argc=0, char **argv=nullptr)
Do not use!
bool fIgnoreFileOdb
Flag to ignore midas file odb.
std::vector< std::string > fInputCutFiles
A list of input cut files.
std::string fInputRing
The name of hte input ring.
bool fSortRaw
Flag to sort raw file.
bool fProofStats
enable proof stats
static TAnalysisOptions * fAnalysisOptions
contains all options for analysis
unsigned int fStatusInterval
Time between status updates.
size_t fAnalysisWriteQueueSize
Size of the analysis write Q.
bool fMakeAnalysisTree
Flag to make analysis tree (-a)
size_t fStatusWidth
Size of total verbose status.
bool fSelectorOnly
Flag to turn PROOF off in grsiproof.
std::vector< std::string > fInputCalFiles
A list of the input cal files.
std::string fOutputFragmentFile
The name of the fragment file to write to.
std::string fAnalysisHistogramLib
The name of the script for histogramming events.
int fWordOffset
Offset for word count in GRIFFIN header (default 1)
static TGRSIOptions * fGRSIOptions
int fCacheSize
set tree cache size, default is -1 (off)
std::string fFragmentHistogramLib
The name of the script for histogramming fragments.
int fMaxWorkers
Max workers used in grsiproof.
bool fCreateFragmentDiagnostics
Flag to create diagnostics from the fragment loop.
int fDownscaling
Downscaling factor for raw events to be processed.
bool fExtractWaves
Flag to keep waveforms (suppress with –no-waveforms)
bool fIgnoreMissingChannel
Flag to completely ignore missing channels.
std::vector< std::string > fOptionsFile
A list of the input .info files.
std::string fOutputFilteredFile
bool fLogErrors
Flag to log errors (–log-errors)
bool fSuppressErrors
Flag to suppress errors (–suppress-errors)
bool fSkipInputSort
Flag to sort on time or triggers.
int fSubmergers
set number of sub-mergers (0 = automatic), default is -1 (off)
bool fStartGui
Flag to start GUI (-g)
std::string fDataFrameLibrary
library (or .cxx file) for dataframe processing (used with grsiframe)
static void SetOptions(TGRSIOptions *tmp)
TGRSIOptions()=default
int fSortDepth
Size of Q that stores fragments to be built into events.
static bool WriteToFile(TFile *file=nullptr)
bool fReconstructTimeStamp
Flag to reconstruct missing high bits of time stamps (–reconstruct-timestamp)
std::string fOutputAnalysisFile
The name of the analysis file to write to.
void Clear(Option_t *opt="") override
bool fHelp
help requested?
static Bool_t ReadFromFile(TFile *file=nullptr)
std::string fOutputAnalysisHistogramFile
The name of the analysis histogram file.
std::string fOutputDiagnosticsFile
The name of the diagnostics file to write to.
size_t fNumberOfEvents
Number of events, fragments, etc. to process (0 - all)
bool fIgnoreEpics
Flag to ignore epics.
std::string fLogFile
The name of the output log file.
bool fBatch
Flag to use batch mode (-b)
size_t fColumnWidth
Size of verbose columns.
bool fIsOnline
Flag to sort online data.
std::vector< std::string > fInputWinFiles
A list of the input window files.
bool fSortMultiple
Flag to sort multiple files.
bool fIgnoreOdbChannels
Flag to ignore channels from midas file odb (but do use EPICS from ODB)
std::string fCompiledFilterFile
size_t fFragmentWriteQueueSize
Size of the Fragment write Q.
bool fMakeHistos
Flag to make histograms (-H)
void Print(Option_t *opt="") const override
bool fDebug
Flag for debug mode.
bool fParallelUnzip
enable use of parallel unzipping
bool fShowedVersion
Flag to show version.
bool fAverageRateEstimation
enable average rate estimation
std::string fParserLibrary
location of shared object library for data parser and files
bool fUseRnTuple
Flag to use experimental TRNTuple instead of TTree.
std::vector< std::string > fInputRootFiles
A list of the input root files.
bool fShowLogo
Flag to show logo (suppress with -l)
bool fLongFileDescription
bool fWriteFragmentTree
Flag to write fragment tree.
std::vector< std::string > fMacroFiles
A list of the input macro (.C) files.
bool FileAutoDetect(const std::string &filename)
bool fUseMidFileOdb
Flag to read odb from midas.
static TUserSettings * fUserSettings
contains user settings read from text-file
std::vector< std::string > fExternalRunInfo
A list of the input run info files.
std::vector< std::string > fInputOdbFiles
A list of the input odb files.
std::string fOutputFragmentHistogramFile
The name of the fragment histogram file.
void Clear(Option_t *="") override
bool ReadSettings(const std::string &settingsFile)