@@ -158,209 +158,6 @@ TEST(RNTuple, MultiColumnExpansion)
158158 }
159159}
160160
161- // Stress test the asynchronous cluster pool by a deliberately unfavourable read pattern
162- TEST (RNTuple, RandomAccess)
163- {
164- #ifdef R__USE_IMT
165- ROOT::EnableImplicitMT ();
166- #endif
167- FileRaii fileGuard (" test_ntuple_random_access.root" );
168-
169- auto modelWrite = RNTupleModel::Create ();
170- auto wrValue = modelWrite->MakeField <std::int32_t >(" value" );
171-
172- constexpr unsigned int nEvents = 1000000 ;
173- {
174- RNTupleWriteOptions options;
175- options.SetCompression (0 );
176- options.SetEnablePageChecksums (false );
177- options.SetApproxZippedClusterSize (nEvents * sizeof (std::int32_t ) / 10 );
178- auto ntuple = RNTupleWriter::Recreate (std::move (modelWrite), " myNTuple" , fileGuard.GetPath (), options);
179- for (unsigned int i = 0 ; i < nEvents; ++i) {
180- *wrValue = i;
181- ntuple->Fill ();
182- }
183- }
184-
185- RNTupleReadOptions options;
186- options.SetClusterCache (RNTupleReadOptions::EClusterCache::kOn );
187- auto ntuple = RNTupleReader::Open (" myNTuple" , fileGuard.GetPath (), options);
188- EXPECT_EQ (10 , ntuple->GetDescriptor ().GetNClusters ());
189-
190- auto viewValue = ntuple->GetView <std::int32_t >(" value" );
191-
192- std::int64_t sum = 0 ;
193- std::int64_t expected = 0 ;
194- constexpr unsigned int nSamples = 50000 ;
195- TRandom3 rnd (42 );
196- for (unsigned int i = 0 ; i < nSamples; ++i) {
197- auto entryId = floor (rnd.Rndm () * (nEvents - 1 ));
198- expected += entryId;
199- sum += viewValue (entryId);
200- }
201- EXPECT_EQ (expected, sum);
202- }
203-
204-
205- #if !defined(_MSC_VER) || defined(R__ENABLE_BROKEN_WIN_TESTS)
206- TEST (RNTuple, LargeFile1)
207- {
208- #ifdef R__USE_IMT
209- ROOT::EnableImplicitMT ();
210- #endif
211- FileRaii fileGuard (" test_large_file1.root" );
212-
213- auto modelWrite = RNTupleModel::Create ();
214- auto & wrEnergy = *modelWrite->MakeField <double >(" energy" );
215-
216- TRandom3 rnd (42 );
217- double chksumWrite = 0.0 ;
218- {
219- RNTupleWriteOptions options;
220- options.SetCompression (0 );
221- auto ntuple = RNTupleWriter::Recreate (std::move (modelWrite), " myNTuple" , fileGuard.GetPath (), options);
222- constexpr std::uint64_t nEvents = 1024 * 1024 * 256 ; // Exceed 2GB file size
223- for (std::uint64_t i = 0 ; i < nEvents; ++i) {
224- wrEnergy = rnd.Rndm ();
225- chksumWrite += wrEnergy;
226- ntuple->Fill ();
227- }
228- }
229- #ifdef R__SEEK64
230- FILE *file = fopen64 (fileGuard.GetPath ().c_str (), " rb" );
231- ASSERT_TRUE (file != nullptr );
232- EXPECT_EQ (0 , fseeko64 (file, 0 , SEEK_END));
233- EXPECT_GT (ftello64 (file), 2048LL * 1024LL * 1024LL );
234- #else
235- FILE *file = fopen (fileGuard.GetPath ().c_str (), " rb" );
236- ASSERT_TRUE (file != nullptr );
237- EXPECT_EQ (0 , fseek (file, 0 , SEEK_END));
238- EXPECT_GT (ftell (file), 2048LL * 1024LL * 1024LL );
239- #endif
240- fclose (file);
241-
242- {
243- auto reader = RNTupleReader::Open (" myNTuple" , fileGuard.GetPath ());
244- auto rdEnergy = reader->GetView <double >(" energy" );
245-
246- double chksumRead = 0.0 ;
247- for (auto i : reader->GetEntryRange ()) {
248- chksumRead += rdEnergy (i);
249- }
250- EXPECT_EQ (chksumRead, chksumWrite);
251- }
252-
253- {
254- auto f = std::unique_ptr<TFile>(TFile::Open (fileGuard.GetPath ().c_str (), " READ" ));
255- EXPECT_TRUE (f);
256- auto ntuple = std::unique_ptr<ROOT::RNTuple>(f->Get <ROOT::RNTuple>(" myNTuple" ));
257- auto reader = RNTupleReader::Open (*ntuple);
258- auto rdEnergy = reader->GetView <double >(" energy" );
259-
260- double chksumRead = 0.0 ;
261- for (auto i : reader->GetEntryRange ()) {
262- chksumRead += rdEnergy (i);
263- }
264- EXPECT_EQ (chksumRead, chksumWrite);
265- }
266- }
267-
268-
269- TEST (RNTuple, LargeFile2)
270- {
271- #ifdef R__USE_IMT
272- ROOT::EnableImplicitMT ();
273- #endif
274- FileRaii fileGuard (" test_large_file2.root" );
275-
276- // Start out with a mini-file created small file
277- auto model = RNTupleModel::Create ();
278- *model->MakeField <float >(" pt" ) = 42.0 ;
279- auto writer = RNTupleWriter::Recreate (std::move (model), " small" , fileGuard.GetPath ());
280- writer->Fill ();
281- writer = nullptr ;
282-
283- // Update the file with another object
284- auto f = std::unique_ptr<TFile>(TFile::Open (fileGuard.GetPath ().c_str (), " UPDATE" ));
285- std::string str = " one" ;
286- f->WriteObject (&str, " s1" );
287-
288- // Turn it into a large file
289- model = RNTupleModel::Create ();
290- auto E = model->MakeField <double >(" E" );
291- RNTupleWriteOptions options;
292- options.SetCompression (0 );
293- writer = RNTupleWriter::Append (std::move (model), " large" , *f, options);
294-
295- TRandom3 rnd (42 );
296- double chksumWrite = 0.0 ;
297- constexpr std::uint64_t nEvents = 1024 * 1024 * 256 ; // Exceed 2GB file size
298- for (std::uint64_t i = 0 ; i < nEvents; ++i) {
299- *E = rnd.Rndm ();
300- chksumWrite += *E;
301- writer->Fill ();
302- }
303-
304- // Add one more object before the ntuple writer commits the footer
305- str = " two" ;
306- f->WriteObject (&str, " s2" );
307- writer = nullptr ;
308- f->Close ();
309- f = nullptr ;
310-
311- #ifdef R__SEEK64
312- FILE *file = fopen64 (fileGuard.GetPath ().c_str (), " rb" );
313- ASSERT_TRUE (file != nullptr );
314- EXPECT_EQ (0 , fseeko64 (file, 0 , SEEK_END));
315- EXPECT_GT (ftello64 (file), 2048LL * 1024LL * 1024LL );
316- #else
317- FILE *file = fopen (fileGuard.GetPath ().c_str (), " rb" );
318- ASSERT_TRUE (file != nullptr );
319- EXPECT_EQ (0 , fseek (file, 0 , SEEK_END));
320- EXPECT_GT (ftell (file), 2048LL * 1024LL * 1024LL );
321- #endif
322- fclose (file);
323-
324- f = std::unique_ptr<TFile>(TFile::Open (fileGuard.GetPath ().c_str ()));
325- {
326- auto reader = RNTupleReader::Open (" small" , fileGuard.GetPath ());
327- reader->LoadEntry (0 );
328- EXPECT_EQ (42 .0f , *reader->GetModel ().GetDefaultEntry ().GetPtr <float >(" pt" ));
329-
330- reader = RNTupleReader::Open (" large" , fileGuard.GetPath ());
331- auto viewE = reader->GetView <double >(" E" );
332- double chksumRead = 0.0 ;
333- for (auto i : reader->GetEntryRange ()) {
334- chksumRead += viewE (i);
335- }
336- EXPECT_EQ (chksumRead, chksumWrite);
337- }
338-
339- {
340- f = std::unique_ptr<TFile>(TFile::Open (fileGuard.GetPath ().c_str (), " READ" ));
341- EXPECT_TRUE (f);
342- auto s1 = f->Get <std::string>(" s1" );
343- EXPECT_EQ (" one" , *s1);
344- auto s2 = f->Get <std::string>(" s2" );
345- EXPECT_EQ (" two" , *s2);
346-
347- auto small = std::unique_ptr<ROOT::RNTuple>(f->Get <ROOT::RNTuple>(" small" ));
348- auto reader = RNTupleReader::Open (*small);
349- reader->LoadEntry (0 );
350- EXPECT_EQ (42 .0f , *reader->GetModel ().GetDefaultEntry ().GetPtr <float >(" pt" ));
351-
352- auto large = std::unique_ptr<ROOT::RNTuple>(f->Get <ROOT::RNTuple>(" large" ));
353- reader = RNTupleReader::Open (*large);
354- auto viewE = reader->GetView <double >(" E" );
355- double chksumRead = 0.0 ;
356- for (auto i : reader->GetEntryRange ()) {
357- chksumRead += viewE (i);
358- }
359- EXPECT_EQ (chksumRead, chksumWrite);
360- }
361- }
362- #endif
363-
364161TEST (RNTuple, LargePages)
365162{
366163 FileRaii fileGuard (" test_ntuple_large_pages.root" );
0 commit comments