From 803ad821a136f220302d6715356cbcc031c7cd18 Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Mon, 30 Jul 2018 16:59:31 -0400 Subject: [PATCH] Allow lists of run numbers and run ranges in THcParmList::Load When Load is called with a run number, then the input file is ignored until a line with a list of run numbers or run number ranges is found. For example: 44,50-90,113 If the run number matches one of these run numbers or ranges, parameter definitions after the match are loaded. (Until the next list of run numbers and ranges.) Before this commit, only a single run number or a single range of run numbers was allowed. --- src/THcParmList.cxx | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index 9cc662d..15dd070 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -241,20 +241,30 @@ The ENGINE CTP support parameter "blocks" which were marked with // If RunNumber>0 and first line we encounter is not a run range, need to // print an error if(RunNumber>0) { - if(line.find_first_not_of("0123456789-")==string::npos) { // Interpret as runnum range - if( (pos=line.find_first_of("-")) != string::npos) { - Int_t RangeStart=atoi(line.substr(0,pos).c_str()); - Int_t RangeEnd=atoi(line.substr(pos+1,string::npos).c_str()); - if(RunNumber >= RangeStart && RunNumber <= RangeEnd) { - InRunRange = 1; - } else { - InRunRange = 0; - } - } else { // A single number. Run - if(atoi(line.c_str()) == RunNumber) { - InRunRange = 1; - } else { - InRunRange = 0; + if(line.find_first_not_of("0123456789-,")==string::npos) { // Interpret as runnum range + // Interpret line as a list of comma separated run numbers or ranges + TString runnums(line.c_str()); + TObjArray *runnumarr = runnums.Tokenize(","); + Int_t nranges=runnumarr->GetLast()+1; + + InRunRange = 0; + Int_t ind; + for(Int_t i=0;i<nranges;i++) { + TString runstr = ((TObjString *)runnumarr->At(i))->GetString(); + if(runstr.IsDec()) { // A single run number + if(RunNumber == runstr.Atoi()) { + InRunRange = 1; + break; + } + } else if ((ind=runstr.First('-'))>=0) { // A run range + TString start=runstr(0,ind); + TString end=runstr(ind+1,runstr.Length()); + if(start.IsDec() && end.IsDec()) { + if((RunNumber >= start.Atoi()) && (RunNumber <= end.Atoi())) { + InRunRange = 1; + break; + } + } } } continue; // Skip to next line -- GitLab