70 typedef map<string, double>::value_type valType;
72 auto pos = sdata.find(
'=');
73 if (pos != string::npos) {
74 string temp1{sdata.substr(0,pos)};
75 string temp2{sdata.substr(pos+1,sdata.length())};
77 if (temp2.find(
'=') != string::npos)
79 (sdata.substr(pos+2,sdata.length()));
80 if (strlen(temp2.c_str()) > 0) {
81 double tdat = atof(temp2.c_str());
82 fAssign.insert(valType(temp1,tdat));
84 fAssign.insert(valType(temp1,0));
90 auto pos1 =
input.find(
'\'');
91 if (pos1 != string::npos) {
92 string temp1{
input.substr(pos1+1,
input.length())};
93 auto pos2 = temp1.find(
'\'');
94 if (pos2 != string::npos) {
95 result.assign(temp1.substr(0,pos2));
96 result += temp1.substr(pos2+1,temp1.length());
104 for(
const auto& pm :
fAssign ) {
105 if (
input == pm.first) {
122 :
tree{other.
tree},
name{other.
name}, ndata{other.ndata}, nsize{other.nsize},
144 name = std::move(_name);
146 string sname =
"Ndata." +
name;
148 tree->Branch(sname.c_str(),&
ndata,(leaf+
"/I").c_str());
150 leaf =
name +
"[" + leaf +
"]/D";
158 if( i >
MAX )
return true;
160 while ( i >= newsize ) { newsize *= 2; }
161 if( newsize >
MAX ) newsize =
MAX;
172 : fNvar(0), fVar(nullptr), fEpicsVar(nullptr), fTree(nullptr),
173 fEpicsTree(nullptr), fInit(false),
174 fExtra(nullptr), fEpicsHandler(nullptr),
175 nx(0), ny(0), iscut(0), xlo(0), xhi(0), ylo(0), yhi(0),
176 fOpenEpics(false), fFirstEpics(false), fIsScalar(false)
199 for (
auto & od :
fOdata)
delete od;
200 for (
auto & form :
fFormulas)
delete form;
201 for (
auto & cut :
fCuts)
delete cut;
202 for (
auto & histo :
fHistos)
delete histo;
214 cout <<
"\nTHaOutput::Init: Info: THaOutput cannot be completely"
215 <<
" re-initialized. Keeping existing definitions." << endl;
216 cout <<
"Global Variables are being re-attached and formula/cuts"
217 <<
" are being re-compiled." << endl;
221 if (
Attach() )
return -4;
232 fTree =
new TTree(
"T",
"Hall A Analyzer Output DST");
243 else if( err != 0 ) {
258 if (pvar->IsArray()) {
265 cout <<
"\nTHaOutput::Init: WARNING: Global variable ";
266 cout <<
fVarnames[ivar] <<
" does not exist. "<< endl;
267 cout <<
"There is probably a typo error... "<<endl;
272 string tinfo =
Form(
"f%d",k);
275 Int_t status = pform->Init();
277 cout <<
"THaOutput::Init: WARNING: Error in formula ";
278 cout << *inam << endl;
279 cout <<
"There is probably a typo error... " << endl;
280 pform->ErrPrint(status);
285 pform->SetOutput(
fTree);
291 vector<string> avar = pform->GetVars();
292 for(
const auto& str : avar ) {
296 if (pvar->IsArray()) {
311 for(
auto iodat =
fOdata.begin(); iodat !=
fOdata.end(); ++iodat, ++k )
315 for (k = 0; k <
fNvar; ++k) {
316 string tinfo =
fVNames[k] +
"/D";
323 Int_t status = pcut->Init();
325 cout <<
"THaOutput::Init: WARNING: Error in formula ";
326 cout << *inam << endl;
327 cout <<
"There is probably a typo error... " << endl;
328 pcut->ErrPrint(status);
333 pcut->SetOutput(
fTree);
334 fCuts.push_back(pcut);
338 for(
auto* pVhist :
fHistos ) {
344 sfvarx = pVhist->GetVarX();
345 sfvary = pVhist->GetVarY();
347 string stemp(pVform->GetName());
349 pVhist->SetX(pVform);
352 pVhist->SetY(pVform);
355 if (pVhist->HasCut()) {
356 scut = pVhist->GetCutStr();
357 for(
auto* pcut :
fCuts ) {
358 string stemp(pcut->GetName());
360 pVhist->SetCut(pcut);
371 for(
size_t i = 0; i < siz; ++i ) {
374 string tinfo = epicsbr +
"/D";
405 if (vdata.empty())
return;
407 if (vdata.size() < 2)
return;
411 if (vdata.size() < 2)
return;
422 if (vdata.size() > 1) {
423 vector<string> esdata =
reQuote(vdata);
424 for (
int k = 1; k < (int)esdata.size(); k++) {
451 for (
UInt_t ivar = 0; ivar < NVar; ivar++) {
454 if ( !pvar->IsArray() ) {
457 cout <<
"\tTHaOutput::Attach: ERROR: Global variable " <<
fVNames[ivar]
458 <<
" changed from simple to array!! Leaving empty space for variable"
463 cout <<
"\nTHaOutput::Attach: WARNING: Global variable ";
464 cout <<
fVarnames[ivar] <<
" NO LONGER exists (it did before). "<< endl;
465 cout <<
"This is not supposed to happen... "<<endl;
470 for (
UInt_t ivar = 0; ivar < NAry; ivar++) {
473 if ( pvar->IsArray() ) {
476 cout <<
"\tTHaOutput::Attach: ERROR: Global variable " <<
fVNames[ivar]
477 <<
" changed from ARRAY to Simple!! Leaving empty space for variable"
482 cout <<
"\nTHaOutput::Attach: WARNING: Global variable ";
483 cout <<
fVarnames[ivar] <<
" NO LONGER exists (it did before). "<< endl;
484 cout <<
"This is not supposed to happen... "<<endl;
493 for (
auto & cut :
fCuts) {
509 if ( !epicshandle )
return 0;
515 extras->fEpicsEvtNum = evdata->
GetEvNum();
517 for(
size_t i = 0; i < siz; ++i ) {
530 extras->fEpicsTimestamp =
549 if (form) form->Process();
553 for (
auto & cut :
fCuts)
554 if (cut) cut->Process();
567 for (
auto it =
fOdata.begin(); it !=
fOdata.end(); ++it, ++k) {
571 if ( pvar ==
nullptr )
continue;
573 Int_t i = pvar->GetLen();
580 if (pdat->
Fill(i,
x) != 1) {
582 cerr <<
"THaOutput::ERROR: storing too much variable sized data: "
583 << pvar->GetName() <<
" "<<pvar->GetLen()<<endl;
615 cout <<
"Output timing summary:" << endl;
634 const char*
const here =
"THaOutput::LoadFile";
637 ::Error(
here,
"invalid file name, no output definition loaded" );
641 ifstream odef(loadfile.c_str());
646 vector<string> strvect;
649 while (getline(odef,sline)) {
652 sline.length() >
kIncTag.length() ) {
656 ostr <<
"Error in #include specification: " << sline;
657 ::Error(
here,
"%s", ostr.str().c_str() );
662 ostr <<
"Error opening include file: " << sline;
663 ::Error(
here,
"%s", ostr.str().c_str() );
670 ostr <<
"File cannot include itself: " << sline;
671 ::Error(
here,
"%s", ostr.str().c_str() );
680 string::size_type pos = 0;
682 (pos = sline.find_first_not_of(
kWhiteSpace)) == string::npos ||
686 if( (pos = sline.find(
comment)) != string::npos )
689 vector<string> lines( 1, sline );
690 if( gHaTextvars->Substitute(lines) )
692 for(
auto& str : lines ) {
694 strvect = vsplit(str);
698 if( special_before || special_now )
700 if (strvect.size() < 2) {
705 string svkey =
svPrefix(strvect[0]);
713 if (strvect.size() < 3) {
721 if (strvect.size() < 3) {
751 cout <<
"\nTHaOutput::Init: WARNING: Block ";
752 cout << strvect[1] <<
" does not match any variables. " << endl;
753 cout <<
"There is probably a typo error... "<<endl;
760 cout <<
"Warning: keyword "<<svkey<<
" undefined "<<endl;
770 if ( *Vi == *(Vi+1) ) {
788 string sresult = histtype;
789 if (ldebug) cout <<
"svPrefix histogram type = "<<histtype<<
" histtype length "<<histtype.length()<<endl;
793 if (histtype.length() != 5)
return sresult;
794 string sfirst = histtype.substr(0,1);
795 if (ldebug) cout <<
"sfirst = "<<sfirst<<endl;
797 sresult=histtype.substr(1);
802 (
CmpNoCase(sresult,
"th2d")!=0) )
return histtype;
804 cout <<
"result "<<sresult<< endl;
805 if (
fIsScalar) cout <<
"fScalar is TRUE"<<endl;
823 static const vector<KeyMap> keymap = {
824 {
"variable",
kVar },
825 {
"formula",
kForm },
836 for(
const auto& it : keymap ) {
849 static const string open_brack(
"[");
850 static const string close_brack(
"]");
852 auto pos1 = var.find(open_brack,0);
853 auto pos2 = var.find(close_brack,0);
854 if ((pos1 != string::npos) &&
855 (pos2 != string::npos)) {
856 result = var.substr(0,pos1);
857 result += var.substr(pos2+1,var.length());
875 string temp1,temp2,temp3;
876 for(
const auto& str :
input ) {
878 auto pos1 = temp1.find(
'\'');
879 if (pos1 != string::npos) {
881 temp2.assign(temp1.substr(pos1,temp1.length()));
884 temp3.assign(temp1.substr(pos1+1,temp1.length()));
885 auto pos2 = temp3.find(
'\'');
886 if (pos2 != string::npos) {
887 temp1.assign(temp3.substr(0,pos2));
888 temp2.assign(temp3.substr
889 (pos2+1,temp3.length()));
924 static const char badchar[]=
":+-*/=";
925 static const string goodchar =
"_";
926 int numbad =
sizeof(badchar)/
sizeof(
char) - 1;
928 string output =
input;
930 for (
int i = 0; i < numbad; i++) {
931 string sbad(&badchar[i]);
932 sbad.erase(1,sbad.size());
933 string::size_type pos =
input.find(sbad,0);
934 while (pos != string::npos) {
935 output.replace(pos,1,goodchar);
936 pos =
input.find(sbad,pos+1);
948 cerr <<
"<THaOutput::LoadFile> WARNING: file " << sline;
949 cerr <<
" does not exist." << endl;
950 cerr <<
"See $ANALYZER/examples/output.def for an example.\n";
951 cerr <<
"Output will only contain event objects "
952 "(this may be all you want).\n";
956 cerr <<
"THaOutput::ERROR: Syntax error in output definition file."<<endl;
957 cerr <<
"The offending line is :\n"<<sline<<endl<<endl;
960 cerr <<
"For variables, the syntax is: "<<endl;
961 cerr <<
" variable variable-name"<<endl;
962 cerr <<
"Example: "<<endl;
963 cerr <<
" variable R.vdc.v2.nclust"<<endl;
967 cerr <<
"For formulas or cuts, the syntax is: "<<endl;
968 cerr <<
" formula(or cut) formula-name formula-expression"<<endl;
969 cerr <<
"Example: "<<endl;
970 cerr <<
" formula targetX 1.464*B.bpm4b.x-0.464*B.bpm4a.x"<<endl;
974 cerr <<
"For 1D histograms, the syntax is: "<<endl;
975 cerr <<
" TH1F(or TH1D) name 'title' ";
976 cerr <<
"variable nbin xlo xhi [cut-expr]"<<endl;
977 cerr <<
"Example: "<<endl;
978 cerr <<
" TH1F tgtx 'target X' targetX 100 -2 2"<<endl;
979 cerr <<
"(Title in single quotes. Variable can be a formula)"<<endl;
980 cerr <<
"optionally can impose THaCut expression 'cut-expr'"<<endl;
984 cerr <<
"For 2D histograms, the syntax is: "<<endl;
985 cerr <<
" TH2F(or TH2D) name 'title' varx vary";
986 cerr <<
" nbinx xlo xhi nbiny ylo yhi [cut-expr]"<<endl;
987 cerr <<
"Example: "<<endl;
988 cerr <<
" TH2F t12 't1 vs t2' D.timeroc1 D.timeroc2";
989 cerr <<
" 100 0 20000 100 0 35000"<<endl;
990 cerr <<
"(Title in single quotes. Variable can be a formula)"<<endl;
991 cerr <<
"optionally can impose THaCut expression 'cut-expr'"<<endl;
994 cerr <<
"Illegal line: " << sline << endl;
995 cerr <<
"See the documentation or ask Bob Michaels"<<endl;
1009 ::Warning(
"THaOutput",
"no output defined");
1011 cout << endl <<
"THaOutput definitions: " << endl;
1013 cout <<
"=== Number of variables "<<
fVarnames.size()<<endl;
1020 cout <<
"Variable # "<<i<<
" = "<<(*ivar)<<endl;
1025 cout <<
"=== Number of formulas "<<
fFormulas.size()<<endl;
1030 iform !=
fFormulas.end(); i++, iform++ ) {
1031 cout <<
"Formula # "<<i<<endl;
1033 (*iform)->LongPrint();
1035 (*iform)->ShortPrint();
1039 if( !
fCuts.empty() ) {
1040 cout <<
"=== Number of cuts "<<
fCuts.size()<<endl;
1044 for (
auto icut =
fCuts.begin(); icut !=
fCuts.end();
1046 cout <<
"Cut # "<<i<<endl;
1048 (*icut)->LongPrint();
1050 (*icut)->ShortPrint();
1055 cout <<
"=== Number of histograms "<<
fHistos.size()<<endl;
1061 cout <<
"Histogram # "<<i<<endl;
1081 string::size_type pos1 = sline.find_first_of(
'\'');
1082 string::size_type pos2 = sline.find_last_of(
'\'');
1083 if (pos1 != string::npos && pos2 > pos1) {
1084 stitle = sline.substr(pos1+1,pos2-pos1-1);
1086 string ctemp = sline.substr(pos2+1,sline.size()-pos2);
1087 vector<string> stemp =
Split(ctemp);
1088 if (stemp.size() > 1) {
1090 UInt_t ssize = stemp.size();
1091 if (ssize == 4 || ssize == 5) {
1092 sscanf(stemp[1].c_str(),
"%8d",&
nx);
1093 sscanf(stemp[2].c_str(),
"%16f",&
xlo);
1094 sscanf(stemp[3].c_str(),
"%16f",&
xhi);
1100 if (ssize == 8 || ssize == 9) {
1102 sscanf(stemp[2].c_str(),
"%8d",&
nx);
1103 sscanf(stemp[3].c_str(),
"%16f",&
xlo);
1104 sscanf(stemp[4].c_str(),
"%16f",&
xhi);
1105 sscanf(stemp[5].c_str(),
"%8d",&
ny);
1106 sscanf(stemp[6].c_str(),
"%16f",&
ylo);
1107 sscanf(stemp[7].c_str(),
"%16f",&
yhi);
1115 if ((iden ==
kH1f || iden ==
kH1d) &&
1117 if ((iden ==
kH2f || iden ==
kH2d) &&
1137 TRegexp re(blockn.c_str(),
true);
1141 while(
TObject* obj = next() ) {
std::map< std::string, std::string > keyval
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
R__EXTERN class THaVarList * gHaVars
static const char comment('#')
static THaBenchmark fgBench
static const char *const here
char * Form(const char *fmt,...)
virtual void Stop(const char *name)
virtual void Begin(const char *name)
virtual void Print(Option_t *name="") const
Double_t GetData(const char *tag, UInt_t event=0) const
TString GetString(const char *tag, UInt_t event=0) const
time_t GetTime(const char *tag, UInt_t event=0) const
Bool_t IsLoaded(const char *tag) const
void AddAssign(const string &input)
map< string, Double_t > fAssign
static string findQuotes(const string &input)
Double_t Eval(const string &input)
Double_t Eval(const TString &input)
virtual Bool_t IsMyEvent(UInt_t type) const
void Clear(Option_t *="")
THaOdata & operator=(const THaOdata &rhs)
void AddBranches(TTree *T, std::string name)
Int_t Fill(Int_t i, Double_t dat)
std::vector< std::string > fCutnames
std::vector< THaVar * > fVariables
virtual std::string StripBracket(const std::string &var) const
std::vector< std::string > fCutdef
virtual Int_t FindKey(const std::string &key) const
std::vector< THaVform * > fCuts
static const Int_t kNbout
std::vector< std::string > fVNames
std::vector< THaOdata * > fOdata
std::vector< THaVar * > fArrays
std::vector< std::string > fFormnames
virtual Int_t BuildBlock(const std::string &blockn)
static const Int_t fgNocut
virtual Int_t LoadFile(const char *filename)
std::vector< std::string > fVarnames
std::vector< std::string > fArrayNames
virtual Int_t Init(const char *filename="output.def")
virtual Int_t ProcEpics(THaEvData *ev, THaEpicsEvtHandler *han)
std::vector< THaVhist * > fHistos
static std::string CleanEpicsName(const std::string &var)
static std::vector< std::string > reQuote(const std::vector< std::string > &input)
static void SetVerbosity(Int_t level)
std::vector< THaVform * > fFormulas
void BuildList(const std::vector< std::string > &vdata)
std::string svPrefix(std::string &histype)
std::vector< std::string > fFormdef
virtual void ErrFile(Int_t iden, const std::string &sline) const
std::vector< THaEpicsKey * > fEpicsKey
virtual Int_t ChkHistTitle(Int_t key, const std::string &sline)
virtual THaVar * Find(const char *name) const
static Bool_t Initialized()
const char * Data() const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual void SetAutoSave(Long64_t autos=-300000000)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
Int_t CheckIncludeFilePath(string &incfile)
Int_t GetIncludeFileName(const string &line, string &incfile)
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty)
int CmpNoCase(const string &r, const string &s)