Skip to content

Commit

Permalink
Merge pull request #1464 from VinzenzBildstein/main
Browse files Browse the repository at this point in the history
Fixing bug in TRunInfo and TGRSIFrame
  • Loading branch information
VinzenzBildstein authored Oct 16, 2024
2 parents cfc8d97 + 34a554f commit 784d5ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/TRunInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class TRunInfo : public TSingleton<TRunInfo> {
static bool IsBadCycle(int cycle);

void PrintRunList() const;
std::string ListOfMissingRuns() const;
std::string ListOfMissingRuns(bool all = false) const;
void PrintVersion() const;

static std::string CreateLabel(bool quiet = false);
Expand Down
8 changes: 7 additions & 1 deletion libraries/TFormat/TGRSIFrame.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ TGRSIFrame::TGRSIFrame()
fPpg = new TPPG;

// loop over input files, add them to the chain, and read the runinfo and calibration from them
bool first = true;
for(const auto& fileName : fOptions->RootInputFiles()) {
if(chain->Add(fileName.c_str(), 0) >= 1) { // setting nentries parameter to zero make TChain load the file header and return a 1 if the file was opened successfully
TFile* file = TFile::Open(fileName.c_str());
TRunInfo::AddCurrent();
if(first) {
first = false;
TRunInfo::Get();
} else {
TRunInfo::AddCurrent();
}
auto* ppg = static_cast<TPPG*>(file->Get("PPG"));
if(ppg != nullptr) {
fPpg->Add(ppg);
Expand Down
21 changes: 17 additions & 4 deletions libraries/TFormat/TRunInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ TEventBuildingLoop::EBuildMode TRunInfo::BuildMode() const
void TRunInfo::Add(TRunInfo* runinfo, bool verbose)
{
// add new run to list of runs (and check if the current run needs to be added)
if(fRunList.empty()) {
fRunList.emplace(fRunNumber, fSubRunNumber);
}
//if(fRunList.empty()) {
// fRunList.emplace(fRunNumber, fSubRunNumber);
//}
std::pair<int, int> newPair = std::make_pair(runinfo->fRunNumber, runinfo->fSubRunNumber);
// check for dual entries
if(fRunList.find(newPair) != fRunList.end()) {
Expand Down Expand Up @@ -529,10 +529,15 @@ void TRunInfo::PrintRunList() const
}
}

std::string TRunInfo::ListOfMissingRuns() const
std::string TRunInfo::ListOfMissingRuns(bool all) const
{
/// Outputs a comma separated list of all runs missing between fFirstRunNumber and fLastRunNumber.
/// If no runs are missing prints "none".

if(fRunList.empty()) {
return {"no run list -> none missing?"};
}

std::ostringstream result;

// loop over all runs between the first and the last one (we know that these two are included)
Expand All @@ -551,6 +556,14 @@ std::string TRunInfo::ListOfMissingRuns() const
return {"none"};
}

// unless the "all" flag is set, we limit ourself to printing 140 characters (should be 20 runs?)
std::cout << " current string length is " << result.str().length() << " and all is set to " << (all?"true":"false") << std::endl;
if(!all && result.str().length() > 140) {
result.str(result.str().substr(0, 140));
result.seekp(0, std::ios_base::end);
result << " ... and more";
std::cout << " limited string length is " << result.str().length() << std::endl;
}
return result.str();
}

Expand Down

0 comments on commit 784d5ad

Please sign in to comment.