Warning in <TTree::ReadStream>: Couldn't read formatted data in "Voltaje(mV)" for branch Voltaje(mV) on line 1

Hi,
I’m new to ROOT and C++. I need to read a .csv file for plotting. I share with you the file.

Screenshot 2022-01-25 192259

This is the .c file:

void CurvasUmbral()
{
	TTree *tree = new TTree("tree", "tree title");
	tree->ReadFile("CurvasUmbral.csv", "Voltaje(mV)/D:CH1:CH2:CH12:Etension(mV):ECH1:ECH2:ECH12");
	Int_t entries = tree->GetEntries();
	cout<<entries<<endl;
	
	Double_t Voltaje, CH1, CH2, CH12, Etension, ECH1, ECH2, ECH12;
	
	tree->SetBranchAddress("Voltaje(mV)", &Voltaje);
}

And I get the error:

Warning in <TTree::ReadStream>: Couldn't read formatted data in "Voltaje(mV)" for branch Voltaje(mV) on line 1; ignoring line
Warning in <TTree::ReadStream>: Read too few columns (1 < 8) in line 1; ignoring line
16
Error in <TTree::SetBranchAddress>: The pointer type given "Float_t" (5) does not correspond to the type needed "Double_t" (8) by the branch: Voltaje(mV)

Thanks for the help!


Please read tips for efficient and successful posting and posting code

ROOT Version: ROOT 6.24/06
Platform: Not Provided
Compiler: Not Provided


Try:
tree->ReadFile("CurvasUmbral.csv", "Voltaje_mV/D:CH1:CH2:CH12:Etension_mV:ECH1:ECH2:ECH12");

BTW. If you do not want to see a warning about the first line, add a “#” in its beginning.

Now from:

void CurvasUmbral()
{
	
	
	
	
	TTree *tree = new TTree("tree", "tree title");
	tree->ReadFile("CurvasUmbral.csv", "Voltaje_mV/D:CH1:CH2:CH12:Etension_mV:ECH1:ECH2:ECH12");
	Int_t entries = tree->GetEntries();
	
	cout<<entries<<endl;
}

I get:

Warning in <TTree::ReadStream>: Couldn't read formatted data in "Voltaje(mV)" for branch Voltaje_mV on line 1; ignoring line
Warning in <TTree::ReadStream>: Read too few columns (1 < 8) in line 1; ignoring line

I need this data to make a graph. I cannot ignore the warning.

The first line does not contain data. Either prepend it with a “#” character or remove it completely.

But then the branches are unknown:

Error in <TTree::SetBranchAddress>: unknown branch -> Voltaje(mV)
Error in <TTree::SetBranchAddress>: unknown branch -> Etension(mV)

Hi @acgc99 ,
here are two small examples that will hopefully get you started:

Using TTree directly:

// tree_read_csv.C
void tree_read_csv() {
   TTree t("t", "t");
   t.ReadFile("CurvasUmbral.csv");
   std::cout << t.GetEntries() << std::endl;
   t.Draw("CH1");
}

Using RDataFrame:

// df_read_csv.C
void df_read_csv() {
   auto df = ROOT::RDF::MakeCsvDataFrame("CurvasUmbral.csv");
   df.Histo1D("CH1")->DrawClone();
}

I ran these two macros on the following CSV file and the histogram was produced correctly:

Voltaje(mV),CH1,CH2
1,2,3
4,5,6

For more complete examples see our tutorials, e.g. ROOT: tutorials/dataframe/df014_CSVDataSource.py File Reference .

Cheers,
Enrico

Thanks @eguiraud ,
I tried to use TTree before directly and it works. I was trying to understand how to call TTree.ReadFile with other parameters than default ones. Using TTree directly makes my data as Float_t (this is enough for me now); nevertheless, I was trying to create Double_t data.

Regards,
Abel

Then something like this should work:

With data.csv:

1,2,3
4,5,6

and foo.C:

void foo() {
   TTree t("t", "t");
   t.ReadFile("data.csv", "Voltaje(mV)/D:CH1/D:CH2/D");

   double volt;
   t.SetBranchAddress("Voltaje(mV)", &volt);
   t.GetEntry(0);
   std::cout << volt << '\n';
   t.GetEntry(1);
   std::cout << volt << '\n';
}

then

$ root -l foo.C
root [0]
Processing foo.C...
1
4

Please provide a minimal self-contained reproducer that we can run and debug if something like the above does not work in your case.

Cheers,
Enrico

Hi,
I upload things here, the .cvs is a .txt since I can’t upload .csv here, just change extension. Here is the error:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.24/06                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Sep 02 2021, 14:20:23                 |
  | From tags/v6-24-06@v6-24-06                                      |
  | With                                                             |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0]
Processing Minimal.c...
Warning in <TTree::ReadStream>: Couldn't read formatted data in "Voltaje(mV)" for branch Voltaje_mV on line 1; ignoring line
Warning in <TTree::ReadStream>: Read too few columns (1 < 8) in line 1; ignoring line
Error in <TTree::SetBranchAddress>: unknown branch -> Voltaje(mV)
Error in <TTree::SetBranchAddress>: unknown branch -> Etension(mV)

Minimal.c (672 Bytes)
CurvasUmbral.txt (616 Bytes)

# Voltaje(mV),CH1,CH2,CH12,Etension(mV),ECH1,ECH2,ECH12

tree->SetBranchAddress("Voltaje_mV", &Voltaje);
tree->SetBranchAddress("Etension_mV", &Etension);

Hi @acgc99 ,
you can check with tree->Print() what schema the tree constructed from your CSV file has:

******************************************************************************
*Tree    :tree      : tree title                                             *
*Entries :       16 : Total =            6552 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :Voltaje_mV : Voltaje_mV/D                                          *
*Entries :       16 : Total  Size=        811 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :CH1       : CH1/D                                                  *
*Entries :       16 : Total  Size=        769 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :CH2       : CH2/D                                                  *
*Entries :       16 : Total  Size=        769 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    3 :CH12      : CH12/D                                                 *
*Entries :       16 : Total  Size=        775 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    4 :Etension_mV : Etension_mV/D                                        *
*Entries :       16 : Total  Size=        817 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    5 :ECH1      : ECH1/D                                                 *
*Entries :       16 : Total  Size=        775 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :ECH2      : ECH2/D                                                 *
*Entries :       16 : Total  Size=        775 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    7 :ECH12     : ECH12/D                                                *
*Entries :       16 : Total  Size=        781 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

As you see the name of the “Voltaje(mV)” column has been transformed to “Voltaje_mV”. So changing your code to mimic what @Wile_E_Coyote suggests should do the trick (and adding a # at the beginning of the first line will remove the warnings).

Cheers,
Enrico