How can I access Metadata from a root-file within a Macro?

Dear all,

I am writing a Macro and would like to use some Metadata. In this particular case, I want to extract the veto signal IDs from the TRestRawVetoAnalysisProcess.

I can see the parameter I want fVetoSignalId within the TRestRawVetoAnalysis-object when I open the root file in the Browser, and also PrintMetadata() shows me all the information, but I didn’t find a way to read-out this parameter within the Macro. Do I have to implement a method for this in the TRestRawVetoAnalysis process? Or is there a simpler way?

And a related problem:
In the TRestRawVetoAnalysis-object in the root file, I can see fVetoSignalId, but not for example fVetoGroupIds. I would like to read out this parameter, too. How can I make sure that it is saved to the file?

Hi Konrad, thanks for posting, this is a good a question.

This is probably still a quite straight-forward way. Just implement these lines at the process header

std::vector <Int_t> GetVetoSignalIDs() { return fVetoSignalId; }
Int_t GetVetoSignalID( Int_t index ) { if( index >= fVetoSignalID.size() ) return -1; return fVetoSignalID[index]; }

It is still possible to retrieve the data members using the name of the data member itself. If you have a pointer to your process, lets say pcsPointer, you are always allowed to retrieve the metadata members as follows:

iAmAStdVectorOfStrings = pcsPointer->GetDataMemberValues( "fVetoSignalIDs");

or a single value

iAmAString = pcsPointer->GetDataMemberValue( "fRange");

The returned value is allways a string, so in order to recover a particular type you need to use the methods StringToXX.

TVector2 myVector = StringTo2DVector( iAmAString );

Use the following method call to get detailed information on ALL the members in the class (also inherited).

pcsPointer->Dump()

It should be there, perhaps it is empty?

Hi Javier,
thank you for the explanation! I implemented a method in the TRestRawVetoAnalysisClass as you suggested to read the parameters.

I also had a problem to get the pointer to the process. For documentation, I copy here Javiers answer from Slack:

TRestRun gives access to the metadata structures. There are many ways to get the pointer.

The direct ROOT way:

TFile *f = new TFile("fileXXX.root");
TRestMyPcs *pcs = (TRestMyPcs *) f->Get("pcsName");

You may use .ls inside ROOT to get info about what it is inside the file

The REST way:

TRestRun *myRun = new TRestRun("fileXXX.root");
TRestMyPcs *pcs = (TRestMyPcs *) myRun->GetMetadataClass("TRestMyPcs");

Or, if you prefer by name (because there is more than 1 metadata class of that type inside the file)

TRestRun *myRun = new TRestRun("fileXXX.root");
TRestMyPcs *pcs = (TRestMyPcs *) myRun->GetMetadata("pcsName");

On top of that, it is possible to retrieve a metadata member without creating the pointer, using the GetDataMemberValue() method at TRestRun

TRestRun *myRun = new TRestRun("fileXXX.root");
myRun->GetDataMemberValue("TRestMyPcs::fDataMember");

or by name

TRestRun *myRun = new TRestRun("fileXXX.root");
myRun->GetDataMemberValue("pcsName::fDataMember");

Those methods are reasonable documented at the API documentation
This is because TRestRun keeps internally the pointers to all the metadata classes.