Home | News | Documentation | Download

How to make operate the code for large number of files

Rooters … :thinking::thinking:

You could loop over all files in a given directory. Something like:

void ProcessFilesInDirectory(const char *dirname = "/home/baja/")
{
   void* dirp = gSystem->OpenDirectory(dirname);
   if (dirp) {
   TString name;
   while ((name = gSystem->GetDirEntry(dirp)) != "" ) {
      if (name.EndsWith(".root")) {
         /// Do whatever you want with the root file...
      }
   }
}

Thank you for your reply,

Could you try to learn instead of asking people to modify your code?

BTW, what this part of the code is supposed to do?

for (int i = 0; i < 8192; i++)
Spectra->Draw ("hist][");

You draw 8192 times the same histogram?

8912 is the number of input points from one file. the x axes in the canvas will be in range (0 to 8192)

Sorry, but it doesn’t make any sense. The code simply draws 8192 times the same histogram (which is useless)…

Try something like this:

void ProcessFilesInDirectory(const char *dirname = "/home/baja/")
{
   double lifetime;
   TString name;
   void* dirp = gSystem->OpenDirectory(dirname);
   if (dirp) {
      while ((name = gSystem->GetDirEntry(dirp)) != "" ) {
         if (name.EndsWith(".root")) {
            /// Do whatever you want with the root file...
            auto Spectra = new TH1F("Area","Area",8192,0,8192);
            Code(Spectra, name, lifetime);
         }
      }
   }
}

And please try to adapt the code to your use case before asking to modify it for you…

I am already try to solve my code problems with my self, when i cant… I post my problem in root forum.
Not all users are experts, sure there are some beginners like me … And i did not know that the root forum just for the advanced problems… Anyway thank you for your effort.

That’s not the point. The point is you should try to understand the code, instead of simply copy/paste and claim it doesn’t work. :wink:

P.S. And if you’re not sure, there is the Newbies category

I get the point. If I come back to post in the fourm again … will think many times befor posting the code problems in the future.

Its Ok, i will quit the root fourm.

Oh please, sorry if you misinterpreted my answer, I just wanted to help you trying to understand…

you dont need to apologize, its was simple. anyway thank you

I Think you should not reply her inquiry if you have not the intention to help. Or just guided here to the Newbie section. maybe this make bad impression for the new root users about the root forum. :roll_eyes:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.