Storing an Array in a Branch

Hello,

probably this is a quite stupid question, but I did not find
the answer by myself (well, I am C++ newbie).

The following code illustrates my problem:

#include <TObject.h>
#include <TFile.h>
#include <TTree.h>
#include <TBranch.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;

int main(){


	Int_t ntimebins = 10;
        Int_t nochannels = 10;
      

	Int_t ADCcounts [nochannels][ntimebins];



	TFile *f = new TFile("test.root","RECREATE");
	TTree*	fTree = new TTree("Test","Test");


	fTree->Branch("ADCcounts", &ADCcounts, "ADCcounts[10][10]/I");

//	But I would like to have something like this:
//	fTree->Branch("ADCcounts", &ADCcounts, "ADCcounts[nochannels][ntimebins]/I");
//	which produces the following error message:
//      tlux@dhcp018:~/roottest> testroot
//      Error in <TBranch::TBranch>: Illegal leaf:ADCcounts/ADCcounts[nochannels][ntimebins]/I



//      The rest is just there for having an output

 	for (Int_t iEvent=0;iEvent<10;iEvent++) {

		for (Int_t itest=0;itest<nochannels;itest++) {
			for (Int_t idummy=0; idummy<ntimebins; idummy++){ 

				ADCcounts[itest][idummy]=idummy;

			     }
		}

		fTree->Fill();		
	}
	f->Write();
	f->Close();

	return 0;}
	

I create an array which size depends on nchannels and ntimebins, but in the definition of the TBranch I have to
use the hardcoded numbers.
Otherwise I get the following error message:

How can I solve this problem?
I am using root 4.03/02 and kernel 2.4.21-291.

Thanks for helping me

Thorsten

Use:

fTree->Branch("ADCcounts", &ADCcounts, Form("ADCcounts[%d][%d]/I",nochannels,ntimebins));

Cheers,
Philippe.

Yes, this works.

Thanks a lot!

Thorsten

Could you please tell me how to solve the problem? The solution is not displayed on the webpage

Note that the solution offered above is only valid when all array dimensions have fixed lengths.