Multiple files with root calls

Hello. I am using root to histogram directly from CMSSW (the CMS analysis framework). Currently I have all of the root functionality in one .h file, however this is becoming very long and a bit unwieldy. I tried to split it into 2 .h files and came into a problem-i would have to declare 2 .root files for the histograms to be placed into, else the second .h file called from my program would overwrite the information from the first .h file.

However I would like to have all the information go into one .root file (i.e. myrootfile.root) which is filled from the information retrieved and filled from 2 different, seperate .h files. Is there a way to do this? I do have some directory structure defined.

Thank you.

Hi,

there is no connection between a .h and a .root file. Or did you run TTree::MakeClass / MakeSelector? Anyway - we need more details, like your code, to be able to understand what you’re trying to do. If you’re limited by something which is part of the CMSSW framework (e.g. some I/O vs. .h file dependency) then you might want to talk to them.

Axel.

My code is a bit of a mess. I and long. So I am hesitent to send it.

Let me give what I think is a simpler example. Say you have 2 .C macros. The both do different things, i.e. make different histograms for 2 differen’t cases. You do this because it’s difficult and unwieldy to have on big hude macro. BUT, you want the data output to go into the SAME .root file, so when you make the declaration myFile=new TFile(“myFile.root”, “recreate”); then I would like that line to be the same for BOTH macros. But as it is, whichever macro I run second is, of course, the one which I find in myFile.root when I open it.

Is there some way around this, perhaps? Thanks.

Hi,

use TFile::Open(“UPDATE”) in both your macros, instead of “RECREATE”.

Axel.

Hello. Although update worked well when I tested it in 2 simple macros, problems arose when I tried to get more sophisticared. My actual programs have a fairly elaborate directory structure, i.e. a directory per chamber (I work for EMu), then subdirectories inside of that. These are being filled fine when I used “RECREATE”. However with “UPDATE” I get a crash and right before it I see the message “object chamber3114” (my first directory in the structure) already exists". Then the crash.

Is there some way to use RECREATE with UPDATE? I thought I read something about it in the user’s manual, however when I attempted to implement this, it ONLY RECREATE’s.

Thank you for your continued help.

Hi,

please send a macro that runs and that shows what you do. I assume you should check whether the directory exists before you try to create it. But without knowing your code this is impossible to tell.

Axel.