17 TDirectory* savdir = gDirectory;
18 if(tempf !=
nullptr) {
22 if((gDirectory->GetFile()) ==
nullptr) {
23 std::cout <<
"File does not exist" << std::endl;
28 tempf = gDirectory->GetFile();
31 if(tempf->FindObjectAny(
"TRunInfo") !=
nullptr) {
38 TList* list = tempf->GetListOfKeys();
41 while((key =
static_cast<TKey*
>(iter.Next())) !=
nullptr) {
42 if(strcmp(key->GetClassName(),
"TRunInfo") != 0) {
49 while((key =
static_cast<TKey*
>(iter.Next())) !=
nullptr) {
77 std::ostringstream str;
78 str <<
"Title: " <<
RunTitle() << std::endl;
79 str <<
"Comment: " <<
RunComment() << std::endl;
80 auto tmpStart =
static_cast<time_t
>(
RunStart());
81 auto tmpStop =
static_cast<time_t
>(
RunStop());
82 struct tm runStart = *localtime(&tmpStart);
83 struct tm runStop = *localtime(&tmpStop);
84 str << std::setfill(
'0');
86 str <<
"\t\tRunNumber: " << std::setw(5) <<
RunNumber() << std::endl;
87 str <<
"\t\tSubRunNumber: " << std::setw(3) <<
SubRunNumber() << std::endl;
89 str <<
"\t\tRunNumber: " << std::setw(5) <<
RunNumber() << std::endl;
93 str <<
"\t\tNo missing runs" << std::endl;
95 str <<
"\t\tRunNumbers: " << std::setw(5) <<
fRunList.begin()->first <<
"-" << std::setw(5) <<
fRunList.rbegin()->first << std::endl;
98 str <<
"\t\tNo runs in list?" << std::endl;
100 str << std::setfill(
' ');
102 str <<
"\t\tRunStart: " << asctime(&runStart);
103 str <<
"\t\tRunStop: " << asctime(&runStop);
104 str <<
"\t\tRunLength: " <<
RunLength() <<
" s" << std::endl;
106 str <<
"\t\tCombined RunLength: " <<
RunLength() <<
" s" << std::endl;
108 if(strchr(opt,
'a') !=
nullptr) {
110 str <<
"\t==============================" << std::endl;
115 str <<
"no detector information" << std::endl;
117 str <<
"\t==============================" << std::endl;
119 std::cout << str.str();
142 std::cout <<
"Warning, overwriting non-default run-number " <<
RunNumber() <<
" with " << runnum << std::endl;
146 if(subrunnum != -1) {
148 std::cout <<
"Warning, overwriting non-default sub-run-number " <<
SubRunNumber() <<
" with " << subrunnum
177 std::string infilename;
178 infilename.append(filename);
179 std::cout <<
"Reading info from file: " <<
CYAN << filename <<
RESET_COLOR << std::endl;
180 if(infilename.length() == 0) {
181 std::cout <<
"Bad file name length" << std::endl;
185 std::ifstream infile;
186 infile.open(infilename.c_str());
188 std::cout <<
"could not open file." << std::endl;
191 infile.seekg(0, std::ios::end);
192 auto length = infile.tellg();
194 std::cout <<
"file is empty." << std::endl;
197 auto* buffer =
new char[length];
198 infile.seekg(0, std::ios::beg);
199 infile.read(buffer, length);
211 std::istringstream infile(inputdata);
216 while(!std::getline(infile, line).fail()) {
219 size_t comment = line.find(
"//");
220 if(comment != std::string::npos) {
221 line = line.substr(0, comment);
223 if(line.length() == 0u) {
227 size_t ntype = line.find(
':');
228 if(ntype == std::string::npos) {
232 std::string type = line.substr(0, ntype);
233 line = line.substr(ntype + 1, line.length());
235 std::transform(type.begin(), type.end(), type.begin(), ::toupper);
236 if(type ==
"CAL" || type ==
"CALFILE") {
239 }
else if(type ==
"MID" || type ==
"MIDAS" || type ==
"MIDASFILE") {
242 }
else if(type ==
"ARRAYPOS" || type ==
"HPGEPOS") {
243 std::istringstream str(line);
244 double temp_double = 0.;
247 }
else if(type ==
"BADCYCLE") {
248 std::istringstream str(line);
250 while(!(str >> tmp_int).fail()) {
256 if(strcmp(opt,
"q") != 0) {
257 std::cout <<
"parsed " << linenumber <<
" lines." << std::endl;
271 while((runinfo =
static_cast<TRunInfo*
>(iter.Next())) !=
nullptr) {
279 std::cout <<
"Bad Cycles:\t";
281 std::cout <<
"NONE" << std::endl;
284 std::cout <<
" " << item;
286 std::cout << std::endl;
313 bool bool2return =
true;
314 TDirectory* savdir = gDirectory;
318 if(fileptr ==
nullptr) {
319 fileptr = gDirectory->GetFile();
322 std::string oldoption = std::string(fileptr->GetOption());
323 if(oldoption ==
"READ") {
324 fileptr->ReOpen(
"UPDATE");
327 std::cout <<
"No file opened to write TRunInfo to." << std::endl;
330 runInfo->Write(
"RunInfo", TObject::kOverwrite);
334 std::cout <<
"Writing TRunInfo to " << gDirectory->GetFile()->GetName() << std::endl;
335 if(oldoption ==
"READ") {
336 std::cout <<
" Returning " << gDirectory->GetFile()->GetName() <<
" to \"" << oldoption <<
"\" mode." << std::endl;
337 fileptr->ReOpen(
"READ");
347 if(filename.length() > 0) {
348 std::ofstream infoout;
349 infoout.open(filename.c_str());
351 infoout << infostr.c_str();
352 infoout << std::endl;
353 infoout << std::endl;
356 std::cout <<
"Please enter a file name" << std::endl;
366 buffer.append(
"//The Array Position in mm.\n");
368 buffer.append(
"\n\n");
370 buffer.append(
"//A List of bad cycles.\n");
371 buffer.append(
"BadCycle:");
373 buffer.append(Form(
" %d", item));
375 buffer.append(
"\n\n");
396 std::cerr <<
DYELLOW <<
"Warning, adding run " << std::setfill(
'0') << std::setw(5) << newPair.first <<
"_" << std::setw(3) << newPair.second << std::setfill(
' ') <<
" again!" <<
RESET_COLOR << std::endl;
415 if(verbose) { std::cout <<
"found second run (" << runinfo->
fRunNumber <<
") before current run (" <<
fRunNumber <<
")" << std::endl; }
421 if(verbose) { std::cout <<
"found second run (" << runinfo->
fRunNumber <<
") after current run (" <<
fRunNumber <<
")" << std::endl; }
427 if(verbose) { std::cout <<
"found second run (" << runinfo->
fRunNumber <<
") non-consecutive to run (" <<
fRunNumber <<
")" << std::endl; }
442 if(verbose) { std::cout <<
"found another run (" << runinfo->
fRunNumber <<
") before first run (" <<
fFirstRunNumber <<
")" << std::endl; }
447 if(verbose) { std::cout <<
"found another run (" << runinfo->
fRunNumber <<
") after last run (" <<
fLastRunNumber <<
")" << std::endl; }
456 if(verbose) { std::cout <<
"changing run start/stop from " << std::setw(16) <<
fRunStart <<
"/" << std::setw(16) <<
fRunStop <<
" to "; }
459 if(verbose) { std::cout << std::setw(16) <<
fRunStart <<
"/" << std::setw(16) <<
fRunStop << std::endl; }
476 if(verbose) { std::cout <<
"found second sub run (" << runinfo->
fSubRunNumber <<
") before current sub run (" <<
fSubRunNumber <<
")" << std::endl; }
482 if(verbose) { std::cout <<
"found second sub run (" << runinfo->
fSubRunNumber <<
") after current sub run (" <<
fSubRunNumber <<
")" << std::endl; }
488 if(verbose) { std::cout <<
"found second sub run (" << runinfo->
fSubRunNumber <<
") non-consecutive to current sub run (" <<
fSubRunNumber <<
")" << std::endl; }
500 if(verbose) { std::cout <<
"found another sub run (" << runinfo->
fSubRunNumber <<
") before first sub run (" <<
fFirstSubRunNumber <<
")" << std::endl; }
505 if(verbose) { std::cout <<
"found another sub run (" << runinfo->
fSubRunNumber <<
") after last sub run (" <<
fLastSubRunNumber <<
")" << std::endl; }
523 std::cout <<
"No runs added to list of runs!" << std::endl;
526 std::cout <<
"Got " <<
fRunList.size() <<
" runs:" << std::endl;
528 std::cout << std::setw(5) << std::setfill(
'0') << pair.first <<
"_" << std::setw(3) << pair.second << std::setfill(
' ') << std::endl;
538 return {
"no run list -> none missing?"};
541 std::ostringstream result;
545 for(
int run =
fRunList.begin()->first; run <
fRunList.rbegin()->first; ++run) {
546 if(std::find_if(
fRunList.begin(),
fRunList.end(), [&run](std::pair<int, int> i) { return run == i.first; }) ==
fRunList.end()) {
547 if(!result.str().empty()) {
550 result << std::setw(5) << std::setfill(
'0') << run;
555 if(result.str().empty()) {
560 std::cout <<
" current string length is " << result.str().length() <<
" and all is set to " << (all ?
"true" :
"false") << std::endl;
561 if(!all && result.str().length() > 140) {
562 result.str(result.str().substr(0, 140));
563 result.seekp(0, std::ios_base::end);
564 result <<
" ... and more";
565 std::cout <<
" limited string length is " << result.str().length() << std::endl;
573 std::cout <<
YELLOW <<
"Unknown version, this file was probably generated with TRunInfo version 17 or older" <<
RESET_COLOR << std::endl;
575 std::cout <<
"This file was generated with GRSISort version " <<
fVersion <<
" (" <<
fFullVersion <<
")" << std::endl
576 <<
"From " <<
fDate << std::endl
589 if(runNumber != 0 && subRunNumber != -1) {
591 result = Form(
"%05d_%03d", runNumber, subRunNumber);
592 }
else if(runNumber != 0) {
600 if(!quiet) { std::cout <<
"Created label " << result << std::endl; }
void trim(std::string &line, const std::string &trimChars=" \f\n\r\t\v")
static size_t GetNumberOfChannels()
std::string fDate
The date of the last commit used in this version - GRSI_GIT_COMMIT_TIME from GVersion....
static void ClearVersion()
static void SetRunInfoFile(const char *ffile)
int fFirstSubRunNumber
The first sub run number (for combined subruns)
double fRunStart
The start of the current run in seconds - no idea why we store this as double?
std::vector< int > fBadCycleList
!List of bad cycles to be used for cycle rejection
static int LastRunNumber()
int fLastSubRunNumber
The last sub run number (for combined subruns)
static void SetDate(const char *ver)
static std::string PrintToString(Option_t *opt="")
void PrintRunList() const
std::string fFullVersion
The full version of GRSISort that generated the file (includes last commit) - GRSI_GIT_COMMIT from GV...
std::string fRunInfoFile
The contents of the run info file.
int fLastRunNumber
The last run number (for combined runs)
static void RemoveBadCycle(int cycle)
static void SetFullVersion(const char *ver)
Long64_t Merge(TCollection *list)
static int SubRunNumber()
std::string fLibraryPath
The path of the parser/file library that generated the file.
static Bool_t ReadInfoFile(const char *filename="")
void Clear(Option_t *opt="") override
static Bool_t ParseInputData(const char *inputdata="", Option_t *opt="q")
void Add(TRunInfo *runinfo, bool verbose=false)
static int LastSubRunNumber()
static std::string RunComment()
static void AddBadCycle(int bad_cycle)
static bool WriteToRoot(TFile *fileptr=nullptr)
static std::string RunTitle()
static int FirstSubRunNumber()
static void SetSubRunNumber(int tmp)
static void ClearFullVersion()
void Print(Option_t *opt="") const override
static double HPGeArrayPosition()
int fRunNumber
The current run number.
static int FirstRunNumber()
static double RunLength()
static void SetRunNumber(int tmp)
TDetectorInformation * fDetectorInformation
! pointer to detector specific information (set by each parser library)
static void SetHPGeArrayPosition(const double arr_pos)
double fRunStop
The stop of the current run in seconds - no idea why we store this as double?
static void SetRunInfo(int runnum=0, int subrunnum=-1)
std::string ListOfMissingRuns(bool all=false) const
static std::string CreateLabel(bool quiet=false)
int fFirstRunNumber
The first run number (for combined runs)
static void SetAnalysisTreeBranches(TTree *)
static void SetVersion(const char *ver)
std::string fLibraryVersion
The version of the parser/file library that generated the file.
virtual TEventBuildingLoop::EBuildMode BuildMode() const
void PrintVersion() const
double fHPGeArrayPosition
Position of the HPGe Array (default = 110.0 mm );.
std::string fVersion
The version of GRSISort that generated the file - GRSI_RELEASE from GVersion.h.
static Bool_t ReadInfoFromFile(TFile *tempf=nullptr)
static bool WriteInfoFile(const std::string &filename)
double fRunLength
The length of the current run in seconds - no idea why we store this as double?
std::set< std::pair< int, int > > fRunList
List of all runs added to this run info.
static bool IsBadCycle(int cycle)
static void PrintBadCycles()
static void SetRunInfoFileName(const char *fname)
int fSubRunNumber
The current sub run number.
static void PrintDirectory()
static TRunInfo * Get(bool verbose=false)
static void Set(TRunInfo *val)