//////////////////////////////////// // KRATTA Run Info // for the Asy-Eos experiment // TRunInfo DEFINITION // Apr 2014 // revison 04/2014 // E.d.F ver 1.0 // sebastian.kupny@uj.edu.pl // Changes: //////////////////////////////////// #include "TRunInfo.h" using namespace std; //______________________________________________________________________ TRunInfo::TRunInfo () : fLastLoadedFile(""), fDebugLevel(1) { } //______________________________________________________________________ void TRunInfo::Config( void ) { TString defaultFileWithWholeRunlist = "/calfiles/KRATTA/LmdFiles_v1.list"; TString dir = gSystem->Getenv("VMCWORKDIR"); TString fullPath = dir + defaultFileWithWholeRunlist; Config ( fullPath ); } //______________________________________________________________________ void TRunInfo::Config( TString fileWithWholeRunlist ) { ClearRunlist(); fLastLoadedFile = fileWithWholeRunlist; if ( fDebugLevel > 0 ){ cout << "[TRunInfo::Config:] Loading parameters from file: "; cout << "\"" << fLastLoadedFile << "\"" << endl; } LoadFilesWithListV1( fileWithWholeRunlist ); } //______________________________________________________________________ void TRunInfo::ClearRunlist( void ) { fListOfRuns.clear(); } //______________________________________________________________________ vector TRunInfo::SplitString( string lineToSplit) { string buf; // Have a buffer string stringstream ss( lineToSplit ); // Insert the string into a stream vector tokens; // Create vector to hold our words while (ss >> buf) tokens.push_back(buf); return tokens; } //______________________________________________________________________ string TRunInfo::TruncateComment( string iStr ) { string valuableString = ""; //string line = TrimString (iStr); int i = 0; for (i = 0; i < iStr.length(); i++) { if ( iStr.at(i) == '#') /// The sign "#" denotes beginning of the comment { break; } } if ( fDebugLevel > 5 && i < iStr.length()-1 ){ /// if index i is smaller than length of the string -> there was the sign "#" i.e. comment cout << "[TRunInfo::TruncateComment:] Some comment found. Text after # is ignored" << endl; } valuableString = iStr.substr(0,i); return valuableString; } //______________________________________________________________________ TRunInfoCont TRunInfo::ParseTokensV1 ( vector vt ) { /// Here is defined the way how to parse the line with information about run. /// What kind of tokens are accetped and what not (the rest). /// This function convert vector of strings (tokens) to the instance /// of class TRunInfoCont which is returned. TRunInfoCont ri; Float_t f = 0; if ( vt.size()>0 ){ ri.fRunNumber = atoi( vt[0].c_str() ) ; } /// TOKEN #1: RunNumber int fRunNumber. Eg: 1334 if ( vt.size()>1 ){ ri.fShadowBar = vt[1]=="yes"?1:0; } /// TOKEN #2: ShadowBar bool fShadowBar. Eg: ? if ( vt.size()>2 ){ ri.fCalib = vt[2]=="yes"?1:0; } /// TOKEN #3: Calibibration run bool fCalib. Eg: 0 if ( vt.size()>3 ){ ri.fAutomClosed = vt[3]=="yes"?1:0; } /// TOKEN #4: AutomaticClosed bool fAutomClosed. Eg: yes if ( vt.size()>4 ){ ri.fBadFile = vt[4]=="yes"?1:0; } /// TOKEN #5: BadFile bool fBadFile. Eg: 0 if ( vt.size()>5 ){ //if (vt[5]=="?"){ ri.fProjectile = kPUnknown; } if (vt[5]=="Au"){ ri.fProjectile = kPAu; } if (vt[5]=="Zr"){ ri.fProjectile = kPZr; } if (vt[5]=="Ru"){ ri.fProjectile = kPRu; } } /// TOKEN #6: Projectile enum fProjectile. Eg: Au if ( vt.size()>6 ){ //if (vt[6]=="?" ){ ri.fTarget = kTUnknown; } if (vt[6]=="Au"){ ri.fTarget = kTAu; } if (vt[6]=="Zr"){ ri.fTarget = kTZr; } if (vt[6]=="Ru"){ ri.fTarget = kTRu; } } /// TOKEN #7: Target enum fTarget. Eg: Au_1.8% if ( vt.size()>7 ){ ri.fSetting = vt[8 ]=="yes"?1:0; } /// TOKEN #8: setting bool fSetting. Eg: 0 if ( vt.size()>8 ){ ri.fRegStat = vt[9 ]=="yes"?1:0; } /// TOKEN #9: regular statisics bool fRegStat. Eg: ? if ( vt.size()>9 ){ ri.fGoodPhys = vt[10]=="yes"?1:0; } /// TOKEN #10: good for physics bool fGoodPhys. Eg: yes if ( vt.size()>10){ f=0.; sscanf(vt[10].c_str(),"%f", &f); ri.fNBeamPart =Long_t(f); } /// TOKEN #11: Good beam particles float fNBeamPart. Eg: 1.10E+007 if ( vt.size()>11){ f=0.; sscanf(vt[11].c_str(),"%f", &f); ri.fNBeamBeamAcc =Long_t(f); } /// TOKEN #12: Good beam accepted float fNBeamBeamAcc. Eg: 0.00E+000 if ( vt.size()>12){ f=0.; sscanf(vt[12].c_str(),"%f", &f); ri.fNCosmicLandAcc=Long_t(f); } /// TOKEN #13: Cosmic land accepted float fNCosmicLandAcc. Eg: 6.23E+003 if ( vt.size()>13){ f=0.; sscanf(vt[13].c_str(),"%f", &f); ri.fNTofGbAcc =Long_t(f); } /// TOKEN #14: TOF+GB accepted float fNTofGbAcc. Eg: 1.86E+005 if ( vt.size()>14){ f=0.; sscanf(vt[14].c_str(),"%f", &f); ri.fNTofGbLandAcc =Long_t(f); } /// TOKEN #15: TOF+GB+LAND accepted float fNTofGbLandAcc. Eg: 5.17E+004 if ( vt.size()>15){ ri.fGoodNBeamPart = vt[15]=="yes"?1:0; } /// TOKEN #16: Good beam particles bool fGoodNBeamPart. Eg: ? if ( vt.size()>16){ ri.fGoodNBeamBeamAcc = vt[16]=="yes"?1:0; } /// TOKEN #17: Good beam accepted bool fGoodNBeamBeamAcc. Eg: ? if ( vt.size()>17){ ri.fGoodNCosmicLandAcc = vt[17]=="yes"?1:0; } /// TOKEN #18: Cosmic land accepted bool fGoodNCosmicLandAcc. Eg: ? if ( vt.size()>18){ ri.fGoodNTofGbAcc = vt[18]=="yes"?1:0; } /// TOKEN #19: TOF+GB accepted bool fGoodNTofGbAcc. Eg: ? if ( vt.size()>19){ ri.fGoodNTofGbLandAcc = vt[19]=="yes"?1:0; } /// TOKEN #20: TOF+GB+LAND accepted bool fGoodNTofGbLandAcc. Eg: ? if ( vt.size()>20){ for (int i = 20; i < vt.size()-1; i++) { ri.fNote += vt[i] + " "; } ri.fNote += vt[vt.size()-1]; } /// TOKEN 21: Note string Note. Eg: ? return ri; } //______________________________________________________________________ Int_t TRunInfo::LoadFilesWithListV1( TString iFileWithListOfRunsFeatures ) { fLastLoadedFile = iFileWithListOfRunsFeatures; Int_t requredNumberOfParam = 7; /// for func. ParseTokensV1 this limit is not really needed. string line; ifstream fileDescr ( fLastLoadedFile.Data() ); if ( fileDescr.is_open() ) { vector tokensInLine; while ( getline (fileDescr, line) ) { if( fDebugLevel > 2) cout << "Got line: \"" << line << "\"" << endl; tokensInLine = SplitString( line ); if ( tokensInLine.size() >= requredNumberOfParam ) { /// Here fill the structure newRun with data from vector tokensInLine ;=) TRunInfoCont newRun = ParseTokensV1( tokensInLine ); /// If necessary define and use your own ParseTokensVX function fListOfRuns.push_back(newRun); if (fDebugLevel > 2) cout << "[+] added " << newRun << endl; } } fileDescr.close(); }else{ if (fDebugLevel > 0) cout << "[TRunInfo::LoadFilesWithListV1:] Erorr: couldn't open file \"" << fLastLoadedFile << "\"" << endl; } } //______________________________________________________________________ Bool_t TRunInfo::IsRunInfoCont( Int_t run) { Bool_t result = kFALSE; for (unsigned i=0; i 3) cout << "[TRunInfo::GetRunInfoCont:] Found " << run << " at position " << i << endl; ric = fListOfRuns[i]; if (fDebugLevel > 4) cout << "[TRunInfo::GetRunInfoCont:] " << fListOfRuns[i] << endl; break; } } fLastUsedRunInfoCont = ric; return fLastUsedRunInfoCont; } //______________________________________________________________________ Bool_t TRunInfo::UpdateLastUsedRunInfoCont( Int_t run ) { /// First version of this function. Updates last run. If success returns true, otherwise false /// Keep in fLastUsedRunInfoCont only last _good_ instance of TRunInfoCont Bool_t result = kFALSE; if ( fLastUsedRunInfoCont.GetRunNumber() != run) { fLastUsedRunInfoCont = GetRunInfoCont( run ); } /// Check if run has been found. The empty container has the default run number = -1. if ( fLastUsedRunInfoCont.GetRunNumber() >0 ) { result = kTRUE; } return result; } //______________________________________________________________________ // string TRunInfo::TrimString(string istr) // { // /// Source: http://www.codeproject.com/Articles/10880/A-trim-implementation-for-std-string // string str = istr; // string::size_type pos = str.find_last_not_of(' '); // if(pos != string::npos) { // str.erase(pos + 1); // pos = str.find_first_not_of(' '); // if(pos != string::npos) str.erase(0, pos); // } // else str.erase(str.begin(), str.end()); // return str; // } //______________________________________________________________________ // Bool_t TRunInfo::IsComment( string iStr ) // { // Bool_t result = kFALSE; // string line = TrimString (iStr); // if ( line.length() > 0) // { // if ( line.at(0) == '#') // { // result = kTRUE; // } // } // // return result; // } ClassImp( TRunInfo )