10 using namespace Diana;
18 fInputVar= GetString(
"Variable",
"",
true);
19 fOutputVar = GetString(
"OutputVar",
"",
true);
20 fFunction = GetString(
"Function",
"",
true);
22 fParamNames=FindVars(fFunction);
24 fOtherVars = FindQuantities(fFunction);
26 fChannels = GetVectorInt(
"Channels",vector<int>(),
true);
27 std::sort(fChannels.begin(),fChannels.end());
28 channelparams.resize(fChannels.size());
29 for(
size_t i =0; i<fChannels.size();i++){
30 channelparams[i].channel_number=fChannels[i];
34 StringParams = GetString(
"Parameters",
"",
true);
35 FindParameters(StringParams);
36 cout<<
"InputVar\t"<<fInputVar.GetStringLabel()<<endl;
37 cout<<
"OutputVar\t"<<fOutputVar<<endl;
38 cout<<
"Function\t"<<fFunction<<endl;
39 cout<<
"Parameter Names: ";
40 for(
size_t k=0;k<fParamNames.size();k++){
41 cout<<
"["<<fParamNames[k]<<
"] ";
44 cout<<
"Parameters:"<<endl;
45 for(
size_t k=0;k<channelparams.size(); k++){
46 if(channelparams[k].fParameters.size()!=fParamNames.size()){
47 Panic(
"Number of parameters in formula don't match parameter values provided for channel %d",channelparams[k].channel_number);
49 cout<<
"\tChannel "<< channelparams[k].channel_number<<
" Parameters: ";
50 for(
size_t i =0;i<channelparams[k].fParameters.size();i++){
51 cout<<channelparams[k].fParameters[i]<<
" ";
56 fFunc = TF1(
"EvalFunc",fFunction,-1e7,1e7);
57 cout<<
"Found Quantities"<<endl;
58 for(
size_t i =0;i<fOtherVars.size();i++){
59 cout<<
"\t["<<fParamNames.size()+i<<
"] "<<fOtherVars[i].GetStringLabel()<<endl;
60 SetReq(fOtherVars[i],ev);
69 if(lab.Contains(
"BaselineData")){
79 if(lab.Contains(
"BaselineData")){
81 TString varlab = lab(lab.First(
".")+1,lab.Length());
82 if(varlab.CompareTo(
"fBaseline")==0){
85 }
else if(varlab.CompareTo(
"fBaselineFlatRMS")==0){
88 }
else if(varlab.CompareTo(
"fBaselineIntercept")==0){
91 }
else if(varlab.CompareTo(
"fBaselineSlope")==0){
94 }
else if(varlab.CompareTo(
"fBaselineSlopeRMSWindow")==0){
97 }
else if(varlab.CompareTo(
"fBaselineRMS")==0){
100 }
else if(varlab.CompareTo(
"fRightBaseline")==0){
103 }
else if(varlab.CompareTo(
"fRightBaselineRMS")==0){
105 }
else if(varlab.CompareTo(
"fRightLeftBaseline")==0){
107 }
else if(varlab.CompareTo(
"fRightLeftBaselineInRMS")==0){
110 Panic(TString(
"'")+varlab+TString(
"' if not a valid choice for the 'Variable' field."));
122 size_t chan_counter=channelparams.size();
123 for(
size_t i =0;i<channelparams.size();i++){
124 if(channelparams[i].channel_number==chan){
130 if(chan_counter==channelparams.size()){
131 Panic(
"Channel %d not found in provided channels from cfg!",chan);
133 for(
size_t i =0;i<fParamNames.size();i++){
134 fFunc.SetParameter(fParamNames[i],channelparams[chan_counter].fParameters[i]);
137 const double variable=GetValue(fInputVar,ev);
138 for(
size_t i =0;i<fOtherVars.size();i++){
139 const double tmp = GetValue(fOtherVars[i],ev);
140 fFunc.SetParameter(fParamNames.size()+i,tmp);
142 ev.
Get<
QDouble>(fOutputVar.Data()) = fFunc.Eval(variable);
149 bool condition =
true;
151 idxclose=TString(instring(
int(idxopen),instring.Length()-
int(idxopen))).First(
']') + idxopen;
152 idxopen=TString(instring(
int(idxopen),instring.Length()-
int(idxopen))).First(
'[') + idxopen;
153 if(idxclose<=idxopen){
158 TString substr = TString(instring(
int(idxopen),
int(idxclose+1-idxopen)));
159 if(!substr.BeginsWith(
"[")){
165 for(
size_t j=0;j<out.size();j++){
166 if(out[j].CompareTo(TString(substr(1,substr.Length()-2)))==0){
171 out.push_back(TString(substr(1,substr.Length()-2)));
176 for(
size_t j=0;j<out.size();j++){
177 out2.push_back(out[j].Atoi());
179 std::sort (out2.begin(), out2.end());
191 idxclose=TString(instring(
int(idxopen),instring.Length()-
int(idxopen))).First(
'&') + idxopen;
192 idxopen=TString(instring(
int(idxopen),instring.Length()-
int(idxopen))).First(
'^') + idxopen;
193 if(idxclose<=idxopen){
198 TString substr = TString(instring(
int(idxopen),
int(idxclose+1-idxopen)));
199 if(!substr.BeginsWith(
"^")){
205 for(
size_t j=0;j<out.size();j++){
206 if(out[j].CompareTo(TString(substr(1,substr.Length()-2)))==0){
211 out.push_back(TString(substr(1,substr.Length()-2)));
215 TString modin = instring;
218 idxopen = modin.First(
"^");
219 idxclose = modin.First(
"&");
220 TString v = TString(modin(idxopen+1,idxclose-idxopen-1));
221 if(idxclose<=idxopen){
232 if (out[idx].CompareTo(v)!=0){
241 idxsub.Form(
"%lu",fParamNames.size()+idx);
242 modin = modin(0,
int(idxopen))+
"["+idxsub+
"]"+modin(
int(idxclose)+1,
int(modin.Length()));
245 vector<Diana::QEventLabel> out2;
246 for(
size_t j=0;j<out.size();j++){
247 out2.push_back(Diana::QEventLabel(out[j]));
257 for(
int i =0; i< instring.Length();i++){
258 if(TString(instring(i,1)).CompareTo(
" ")!=0){
259 manip+=TString(instring(i,1));
264 vector<int> separations={-1};
267 TString tmpstr=TString(manip(separations[separations.size()-1]+1,manip.Length()));
269 for(
int kk=0;kk<tmpstr.Length()-1;kk++){
270 if(TString(tmpstr(kk,2)).CompareTo(
"},")==0){
275 if(tmp==-1 or TString(manip(separations[separations.size()-1]+1,manip.Length())).Length()/2+TString(manip(separations[separations.size()-1]+1,manip.Length())).Length()%2==tmp){
278 separations.push_back(tmp+separations[separations.size()-1]+2);
282 size_t found_channels=0;
283 for(
size_t i =0;i<separations.size();i++){
285 if(i < separations.size()-1){
286 params = TString(manip(separations[i]+1,separations[i+1]-separations[i]-1));
288 params = TString(manip(separations[i]+1,manip.Length()));
292 int tmp = params.First(
":");
293 if(tmp==-1 or tmp ==params.Length()){
294 Panic(
"Please provide channel ! String %s not valid! Format channel:{param1,param2,..}",params.Data());
297 int ch = TString(params(0,tmp)).Atoi();
298 params = TString(params(tmp,params.Length()));
301 int start=params.First(
"{");
302 if(start==-1 or start ==params.Length()){
303 Panic(
"Wrong format ! String %s not valid! Format channel:{param1,param2,..}",params.Data());
305 int stop=params.First(
"}");
306 if(stop==-1 or stop ==params.Length()){
307 Panic(
"Wrong format ! String %s not valid! Format channel:{param1,param2,..}",params.Data());
310 params = TString(params(start,stop-start));
312 vector<int> paramssep={-1};
314 TString tmpstr2=TString(params(paramssep[paramssep.size()-1]+1,params.Length()));
316 for(
int kk=0;kk<tmpstr2.Length();kk++){
317 if(TString(tmpstr2(kk,1)).CompareTo(
",")==0){
322 if(tmp==-1 or TString(params(paramssep[paramssep.size()-1],params.Length())).Length()==tmp){
325 paramssep.push_back(tmp+paramssep[paramssep.size()-1]+1);
329 size_t chcounter=channelparams.size();
331 for(
size_t k=0;k<channelparams.size(); k++){
332 if(channelparams[k].channel_number == ch){
337 if(chcounter == channelparams.size()){
338 Panic(
"Selected Channel not found! Please include it in the cfg parameter!");
343 for(
size_t i =0;i<paramssep.size();i++){
346 params2 = TString(params(0,paramssep[1]));
347 }
else if(i < paramssep.size()-1){
348 params2 = TString(params(paramssep[i]+1,paramssep[i+1]-paramssep[i]));
351 params2 = TString(params(paramssep[i]+1,params.Length()));
353 channelparams[chcounter].fParameters.push_back(params2.Atof());
357 if(found_channels <channelparams.size()){
358 Panic(
"Please indicate parameters for all channels!");
359 }
else if(found_channels >channelparams.size()){
360 Panic(
"Something weird happening... more channels found than present");
#define REGISTER_MODULE(clazz)
Perform function on variable.
double GetValue(Diana::QEventLabel EvLab, Diana::QEvent &ev)
std::vector< Int_t > FindVars(TString instring)
void SetReq(Diana::QEventLabel EvLab, Diana::QEvent &ev)
void FindParameters(TString instring)
void Do(Diana::QEvent &ev)
Do method. Declare and implement only one of the two versions.
std::vector< Diana::QEventLabel > FindQuantities(TString instring)
void Init(Diana::QEvent &ev)
Init method.
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
double GetBaseline() const
double GetBaselineRMS() const
double GetBaselineSlope() const
double GetBaselineFlatRMS() const
double GetRightLeftBaselineInRMS() const
double GetRightLeftBaseline() const
double GetRightBaselineInRMS() const
double GetBaselineIntercept() const
double GetBaselineSlopeRMSWindow() const
double GetRightBaseline() const
label for QObject in the QEvent
std::string GetStringLabel() const
get string in the format "owner@name"
const std::string & GetOwner() const
get owner
const Q & GetByLabel(const QEventLabel &label) const
Get a QObject in read mode by label.
void RequireByLabel(const QEventLabel &label) const
notify the QEvent that we need a QObject, if not found an exception is thrown
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Raw event: bolometer channel, trigger positions and types.
const int & GetChannelId() const
Get ChannelId.
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...