Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable sized arrays/vectors include size in name - breaks output because Find() fails #153

Closed
leadmocha opened this issue Mar 13, 2018 · 9 comments

Comments

@leadmocha
Copy link
Member

Both VarriableArrayVar and VectorVar leave the square brackets in the name where as FixedArrayVar removes it. For example

OBJ: THaVar sbs.hcal.a.m0[250] Raw ADC samples

for a VectorVar/VarriableArrayVar vs

OBJ: THaVar sbs.hcal.a.m0 Raw ADC samples

for a FixedArrayVar. The consequence of this is that THaVarList::Find() will not find these variables in the list leading to errors such as

THaOutput::Init: WARNING: Global variable sbs.hcal.a.m0[250] does not exist.

and no output. In the above case the output is specified by a block statement block sbs.hcal.a.m* which is what adds the [250] when it expands the variable name. Similarly looking for it without the [250] yields the same error because ::Find() specifically ignores the brackets, and we still get an error like so

THaOutput::Init: WARNING: Global variable sbs.hcal.a.m0 does not match any variables.

Another consequence is that one is able to generate duplicate variables with that name because again Find() fails to find them so it does not recognize it as a duplicate entry.

I tentatively fixed it by copying code from THaVarList::Find() and tweaking it slightly to change the name on constructors of VarriableArrayVar and VectorVar:

const char* name = pvar->TNamed::GetName();                                      
const char* p = strchr( name, '[' );                                             
if( p ) {                                                                        
  size_t n = p-name;                                                             
  char* basename = new char[ n+1 ];                                              
  strncpy( basename, name, n );                                                  
  basename[n] = '\0';                                                            
  pvar->TNamed::SetName(basename);                                               
}                                                                                

Adding a SanatizeName() function Variable with similar functionality can work too. Would be nice to have this fixed on the main repo.

@hansenjo
Copy link
Member

hansenjo commented Mar 13, 2018 via email

@hansenjo
Copy link
Member

hansenjo commented Mar 13, 2018 via email

@leadmocha
Copy link
Member Author

leadmocha commented Mar 13, 2018

Hi Ole,

The brackets are not added by me, but rather by THaVarList::DefineVariables (line 499-500 in master).

In the SBS-offline repository in SBSHCal.cxx lines 264-293 is an example of how I define them. I have an updated version that just uses vectors since I've just discovered that the analyzer can handle vectors all on its own.

FixedArrayVar seems to know to remove the brackets before setting the name, but nothing in the constructor of VariableArrayVar and VectorVar presently tries to remove the brackets.

Thanks again for looking into this.

Best,
Juan Carlos

@leadmocha
Copy link
Member Author

Hi again,

Just to answer your question: the 250 is the maximum size for that vector/array. I also agree that for variable sized objects it doesn't make sense to include it in the name. Maybe changing the way THaVarList::DefineVariables works may be the better way to fix it. i.e. by modifying line 483 to read

if ( item->size>1 && !item->count )

That ought to ensure the brackets are not added for variable sized arrays and still leave it in there for FixedVarArray (which seems to need it to determine the size of the array).

@leadmocha
Copy link
Member Author

Oh, oops, that would only work for variable arrays but still fail for vectors....

@hansenjo
Copy link
Member

hansenjo commented Mar 13, 2018 via email

@leadmocha
Copy link
Member Author

Oh I did not realize VarDef was on its way out. I would have used it except it doesn't seem to be able to handle 2d vectors. Each entry in the first vector is a different global variable/leaf. VarDef does let me specify that.

But perhaps I'll continue this discussion with you via email.

@hansenjo
Copy link
Member

Copied to Redmine bug no 334

@hansenjo
Copy link
Member

Hi Carlos,

I guess you saw that this bug has been fixed in the current version of the analyzer. Read the comments for commit d52843a for details.

The root cause of the incorrect variable definitions (with square brackets in their names) is line 279 in SBSHCal.cxx:

v.size = MAX_FADC_SAMPLES;

That should be

v.size = 0;

because v.count is also set, indicating that you want to define a variable-size array. The analyzer failed to handle this contradictory input properly.

The fixed code now detects this situation (fixed and a variable array requested at the same time?), ignores v.size, prints a warning, and defines a variable-size array with size v.count.

Variable-size arrays can be any size. There is no check on maximum array size because such a limit would be arbitrary, so the "size" parameter in VarDef is meaningless.

Hope that helps. Thanks again for discovering this flaw.

Ole

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants