# How to make operate the code for large number of files

**URL:** <https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581>\
**Category:** ROOT\
**Created:** [August 9, 2019, 1:34pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581 "2019-08-09T13:34:45Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 1:34pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/1 "2019-08-09T13:34:45Z")

</div>

Rooters … 🤔🤔

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:05pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/2 "2019-08-09T14:05:37Z")

</div>

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

```auto
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...
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:24pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/3 "2019-08-09T14:24:35Z")

</div>

Thank you for your reply,

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:30pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/4 "2019-08-09T14:30:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:33pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/5 "2019-08-09T14:33:54Z")

</div>

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

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

```

You draw 8192 times the same histogram?

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:36pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/6 "2019-08-09T14:36:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:37pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/7 "2019-08-09T14:37:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:40pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/8 "2019-08-09T14:40:19Z")

</div>

Try something like this:

```auto
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…

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/9 "2019-08-09T14:44:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:46pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/10 "2019-08-09T14:46:14Z")

</div>

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. 😉

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:48pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/11 "2019-08-09T14:48:02Z")

</div>

P.S. And if you’re not sure, there is the [Newbies category](https://root-forum.cern.ch/t/newbie-forum-for-when-youre-not-sure/30804)

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:48pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/12 "2019-08-09T14:48:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:50pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/13 "2019-08-09T14:50:34Z")

</div>

Its Ok, i will quit the root fourm.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 9, 2019, 2:51pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/14 "2019-08-09T14:51:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BAJA](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/a183cd/32.png) [@BAJA](https://root-forum.cern.ch/u/BAJA)\
**Post date:** [August 9, 2019, 2:56pm UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/15 "2019-08-09T14:56:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Khallod](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/e8c25b/32.png) [@Khallod](https://root-forum.cern.ch/u/Khallod)\
**Post date:** [August 10, 2019, 4:28am UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/16 "2019-08-10T04:28:51Z")

</div>

I Think you should not reply her inquiry if you have not the intention to help. Or just guided here to the [Newbie](https://root-forum.cern.ch/c/newbie) section. maybe this make bad impression for the new root users about the root forum. 🙄

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 24, 2019, 4:28am UTC](https://root-forum.cern.ch/t/how-to-make-operate-the-code-for-large-number-of-files/35581/17 "2019-08-24T04:28:55Z")

</div>

Closed on August 24, 2019, 4:28am UTC

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