| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Protected Attributes | List of all members
Gaudi::RootEventExtractor Struct Reference
Collaboration diagram for Gaudi::RootEventExtractor:
[legend]

## Public Member Functions
| RootEventExtractor ()=default
| Default constructor. More...
| RootEventExtractor (const char *input, const char *output, const char *output_option)
| Initializing constructor directly opening the input file and the output file. More...
virtual | ~RootEventExtractor ()
| Default destructor. More...
ExtractStatus | openInput (const char *name)
| Open input file. More...
ExtractStatus | closeInput ()
| Close input file. More...
ExtractStatus | openOutput (const char *name, const char *option)
| Open output file. More...
ExtractStatus | closeOutput ()
| Close output file. More...
ExtractStatus | cancel ()
| Clear the list of event numbers to be extracted from the file. More...
ExtractStatus | select (int evt_num)
| Add a given entry number to the list of events to be selected to the output file. More...
ExtractStatus | extract ()
| Extract all previously selected events from the input file and write it to the output. More...

## Protected Attributes
std::unique_ptr< TFile > | m_in
TTree * | m_evt_in = nullptr
TTree * | m_ref_in = nullptr
TFile * | m_out = nullptr
TTree * | m_evt_out = nullptr
TTree * | m_ref_out = nullptr
int | m_localDB_id = 0
std::vector< int > | m_eventList

## Detailed Description

Definition at line 116 of file extractEvt.C.

## Constructor & Destructor Documentation

## ◆ RootEventExtractor() [1/2]

Gaudi::RootEventExtractor::RootEventExtractor | ( |  | ) |
| default

Default constructor.

## ◆ RootEventExtractor() [2/2]

RootEventExtractor::RootEventExtractor | ( | const char * | input,
|  | const char * | output,
|  | const char * | output_option
| ) |  |

Initializing constructor directly opening the input file and the output file.

Definition at line 169 of file extractEvt.C.

169 {
170 if ( EXTRACT_SUCCESS != openInput( input ) ) {
171 throw std::runtime_error( "Failed to open input file:" + std::string( input ) );
172 }
173 if ( EXTRACT_SUCCESS != openOutput( output, output_option ) ) {
174 throw std::runtime_error( "Failed to open output file:" + std::string( output ) );
175 }
176 }
gaudirun.output
output
Definition: gaudirun.py:484
Gaudi::RootEventExtractor::openOutput
ExtractStatus openOutput(const char *name, const char *option)
Open output file.
Definition: extractEvt.C:210
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
std::string
STL class.
std::runtime_error
STL class.
Gaudi::RootEventExtractor::openInput
ExtractStatus openInput(const char *name)
Open input file.
Definition: extractEvt.C:198

## ◆ ~RootEventExtractor()

RootEventExtractor::~RootEventExtractor | ( |  | ) |
| virtual

Default destructor.

Definition at line 179 of file extractEvt.C.

179 {
180 closeInput();
181 closeOutput();
182 }
Gaudi::RootEventExtractor::closeInput
ExtractStatus closeInput()
Close input file.
Definition: extractEvt.C:218
Gaudi::RootEventExtractor::closeOutput
ExtractStatus closeOutput()
Close output file.
Definition: extractEvt.C:230

## Member Function Documentation

## ◆ cancel()

ExtractStatus RootEventExtractor::cancel | ( |  | ) |

Clear the list of event numbers to be extracted from the file.

Definition at line 185 of file extractEvt.C.

185 {
186 m_eventList.clear();
187 ::printf( "+++ Event list cleared.\n" );
188 return EXTRACT_SUCCESS;
189 }
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
Gaudi::RootEventExtractor::m_eventList
std::vector< int > m_eventList
Definition: extractEvt.C:127
std::vector::clear
T clear(T... args)

## ◆ closeInput()

ExtractStatus RootEventExtractor::closeInput | ( |  | ) |

Close input file.

Definition at line 218 of file extractEvt.C.

218 {
219 if ( m_in ) {
220 ::printf( "+++ Closing input file:%s\n", m_in->GetName() );
221 m_in->Close();
222 }
223 m_in.reset();
224 m_evt_in = nullptr;
225 m_ref_in = nullptr;
226 return EXTRACT_SUCCESS;
227 }
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
std::unique_ptr::reset
T reset(T... args)
Gaudi::RootEventExtractor::m_evt_in
TTree * m_evt_in
Definition: extractEvt.C:119
Gaudi::RootEventExtractor::m_ref_in
TTree * m_ref_in
Definition: extractEvt.C:120
Gaudi::RootEventExtractor::m_in
std::unique_ptr< TFile > m_in
Definition: extractEvt.C:118

## ◆ closeOutput()

ExtractStatus RootEventExtractor::closeOutput | ( |  | ) |

Close output file.

Definition at line 230 of file extractEvt.C.

230 {
231 if ( m_out ) {
232 ::printf( "+++ Closing output file:%s\n", m_out->GetName() );
233 if ( m_evt_out ) m_evt_out->Write();
234 if ( m_ref_out ) m_ref_out->Write();
235 m_out->Close();
236 delete m_out;
237 }
238 m_out = nullptr;
239 m_evt_out = nullptr;
240 m_ref_out = nullptr;
241 return EXTRACT_SUCCESS;
242 }
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
Gaudi::RootEventExtractor::m_ref_out
TTree * m_ref_out
Definition: extractEvt.C:124
Gaudi::RootEventExtractor::m_out
TFile * m_out
Definition: extractEvt.C:122
Gaudi::RootEventExtractor::m_evt_out
TTree * m_evt_out
Definition: extractEvt.C:123

## ◆ extract()

ExtractStatus RootEventExtractor::extract | ( |  | ) |

Extract all previously selected events from the input file and write it to the output.

Definition at line 245 of file extractEvt.C.

245 {
246 char text[1024];
247 bool new_output = false;
248 TBranch *br_in, *br_out;
249 if ( !m_in || m_in->IsZombie() ) {
250 throw std::runtime_error( "Input file missing - cannot extract events." );
251 } else if ( !m_out || m_out->IsZombie() ) {
252 throw std::runtime_error( "Output file missing - cannot extract events." );
253 } else {
254 m_evt_out = (TTree*)m_out->Get( "Event" );
255 if ( !m_evt_out ) { m_evt_out = m_evt_in->CloneTree( 0 ); }
256 m_ref_out = (TTree*)m_out->Get( "Refs" );
257 if ( !m_ref_out ) {
258 m_ref_out = m_ref_in->CloneTree( 0 );
259 new_output = true;
260 }
261 }
262 m_localDB_id = -1;
263 if ( new_output ) {
264 ::printf( "+++ Copy refs table to new output file:%s\n", m_out->GetName() );
265 br_in = m_ref_in->GetBranch( "Databases" );
266 br_in->SetAddress( text );
267 br_out = m_ref_out->GetBranch( "Databases" );
268 br_out->SetAddress( text );
269 for ( int i = 0; i < br_in->GetEntries(); ++i ) {
270 br_in->GetEntry( i );
271 br_out->Fill();
272 if ( m_localDB_id < 0 && strcmp( text, "<localDB>" ) == 0 ) { m_localDB_id = i; }
273 }
274
275 br_in = m_ref_in->GetBranch( "Containers" );
276 br_in->SetAddress( text );
277 br_out = m_ref_out->GetBranch( "Containers" );
278 br_out->SetAddress( text );
279 for ( int i = 0; i < br_in->GetEntries(); ++i ) {
280 br_in->GetEntry( i );
281 br_out->Fill();
282 }
283
284 br_in = m_ref_in->GetBranch( "Links" );
285 br_in->SetAddress( text );
286 br_out = m_ref_out->GetBranch( "Links" );
287 br_out->SetAddress( text );
288 for ( int i = 0; i < br_in->GetEntries(); ++i ) {
289 br_in->GetEntry( i );
290 br_out->Fill();
291 }
292
293 br_in = m_ref_in->GetBranch( "Params" );
294 br_in->SetAddress( text );
295 br_out = m_ref_out->GetBranch( "Params" );
296 br_out->SetAddress( text );
297 for ( int i = 0; i < br_in->GetEntries(); ++i ) {
298 br_in->GetEntry( i );
299 if ( strncmp( text, "PFN=", 4 ) == 0 ) { // Update PFN entry
300 ::snprintf( text, sizeof( text ), "PFN=%s", br_out->GetFile()->GetName() );
301 ::printf( "+++ PFN of the created output file is:%s\n", text );
302 } else if ( strncmp( text, "FID=", 4 ) == 0 ) { // Create new FID for new file
303 static const char* fmt = "FID=%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
304 union uuid_data {
305 unsigned char buf[16];
306 unsigned short sbuf[8];
307 unsigned int ibuf[4];
308 } d;
309 TUUID uuid;
310 uuid.GetUUID( d.buf );
311 ::snprintf( text, sizeof( text ), fmt, d.ibuf[0], d.sbuf[2], d.sbuf[3], d.buf[8], d.buf[9], d.buf[10],
312 d.buf[11], d.buf[12], d.buf[13], d.buf[14], d.buf[15] );
313 ::printf( "+++ FID of the created output file is:%s\n", text );
314 }
315 br_out->Fill();
316 }
317 m_ref_out->Write();
318 }
319
320 TIter next( m_evt_in->GetListOfBranches() );
321 while ( ( br_in = (TBranch*)next() ) ) {
322 TString name = br_in->GetName();
323 TClass* br_class = gROOT->GetClass( br_in->GetClassName(), kTRUE );
324 br_out = m_evt_out->GetBranch( name );
325 if ( !br_out ) {
326 ::printf( "+++ ERROR: Input and output event trees are incompatible. Selection not possible.\n" );
327 return EXTRACT_ERROR;
328 }
329 int out_num_entries = br_out->GetEntries();
330 for ( const auto& i : m_eventList ) {
331 int num_evt = i;
332 const char* br_type = "DataObject";
333 void* pObject = br_class->New();
334 br_in->SetAddress( &pObject );
335 br_out->SetAddress( &pObject );
336 int num_rd = br_in->GetEntry( num_evt );
337 if ( num_rd < 0 ) { // Definitive error
338 ::printf( "+++ ERROR: Failed to read data from branch:%s\n", name.Data() );
339 return EXTRACT_ERROR;
340 }
341 if ( name.EndsWith( "_R." ) ) {
342 RootObjectRefs* refs = (RootObjectRefs*)pObject;
343 for ( auto& ir : refs->refs ) {
344 RootRef& r = ir;
345 if ( r.dbase == m_localDB_id ) r.entry = out_num_entries;
346 }
347 br_type = "*Index*";
348 }
349 int num_wr = br_out->Fill();
350 if ( num_wr < 0 ) {
351 ::printf( "+++ ERROR: Failed to write data to extraction branch:%s "
352 "read:%d wrote:%d bytes [Length-mismatch]\n",
353 name.Data(), num_rd, num_wr );
354 return EXTRACT_ERROR;
355 }
356 ::printf( "+++ Copied %8d bytes to %-10s branch %s(%d)\n", num_rd, br_type, name.Data(), out_num_entries );
357 ++out_num_entries;
358 }
359 m_evt_out->SetEntries( br_out->GetEntries() + 1 );
360 }
361 m_evt_out->Write();
362 return cancel();
363 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::RootRef::entry
int entry
Definition: extractEvt.C:36
Gaudi::RootObjectRefs
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
Definition: extractEvt.C:71
Gaudi::RootEventExtractor::m_ref_out
TTree * m_ref_out
Definition: extractEvt.C:124
Gaudi::RootRef::dbase
int dbase
Data members to define object location in the persistent world.
Definition: extractEvt.C:36
Gaudi::RootRef
Persistent reference object.
Definition: extractEvt.C:34
Gaudi::RootEventExtractor::m_out
TFile * m_out
Definition: extractEvt.C:122
Gaudi::RootEventExtractor::m_localDB_id
int m_localDB_id
Definition: extractEvt.C:126
std::next
T next(T... args)
std::strcmp
T strcmp(T... args)
std::runtime_error
STL class.
Gaudi::EXTRACT_ERROR
Definition: extractEvt.C:114
Gaudi::RootEventExtractor::m_eventList
std::vector< int > m_eventList
Definition: extractEvt.C:127
Gaudi::RootEventExtractor::m_evt_out
TTree * m_evt_out
Definition: extractEvt.C:123
Gaudi::RootEventExtractor::m_evt_in
TTree * m_evt_in
Definition: extractEvt.C:119
std::strncmp
T strncmp(T... args)
Gaudi::RootEventExtractor::cancel
ExtractStatus cancel()
Clear the list of event numbers to be extracted from the file.
Definition: extractEvt.C:185
Gaudi::RootEventExtractor::m_ref_in
TTree * m_ref_in
Definition: extractEvt.C:120
Gaudi::RootObjectRefs::refs
std::vector< RootRef > refs
The references corresponding to the next layer of items in the data store.
Definition: extractEvt.C:75
Gaudi::RootEventExtractor::m_in
std::unique_ptr< TFile > m_in
Definition: extractEvt.C:118

## ◆ openInput()

ExtractStatus RootEventExtractor::openInput | ( | const char * | name | ) |

Open input file.

Close input file.

Definition at line 198 of file extractEvt.C.

198 {
199 if ( m_in ) closeInput();
200 m_in.reset( TFile::Open( name ) );
201 if ( m_in && !m_in->IsZombie() ) {
202 m_evt_in = (TTree*)m_in->Get( "Event" );
203 m_ref_in = (TTree*)m_in->Get( "Refs" );
204 return EXTRACT_SUCCESS;
205 }
206 return EXTRACT_ERROR;
207 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
Gaudi::RootEventExtractor::closeInput
ExtractStatus closeInput()
Close input file.
Definition: extractEvt.C:218
Gaudi::EXTRACT_ERROR
Definition: extractEvt.C:114
std::unique_ptr::reset
T reset(T... args)
Gaudi::RootEventExtractor::m_evt_in
TTree * m_evt_in
Definition: extractEvt.C:119
Gaudi::RootEventExtractor::m_ref_in
TTree * m_ref_in
Definition: extractEvt.C:120
Gaudi::RootEventExtractor::m_in
std::unique_ptr< TFile > m_in
Definition: extractEvt.C:118

## ◆ openOutput()

ExtractStatus RootEventExtractor::openOutput | ( | const char * | name,
|  | const char * | option
| ) |  |

Open output file.

Close input file.

Definition at line 210 of file extractEvt.C.

210 {
211 if ( m_out ) closeOutput();
212 m_out = TFile::Open( name, option );
213 m_evt_out = m_ref_out = nullptr;
214 return EXTRACT_SUCCESS;
215 }
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
Gaudi::RootEventExtractor::m_ref_out
TTree * m_ref_out
Definition: extractEvt.C:124
Gaudi::RootEventExtractor::closeOutput
ExtractStatus closeOutput()
Close output file.
Definition: extractEvt.C:230
Gaudi::RootEventExtractor::m_out
TFile * m_out
Definition: extractEvt.C:122
Gaudi::RootEventExtractor::m_evt_out
TTree * m_evt_out
Definition: extractEvt.C:123

## ◆ select()

ExtractStatus RootEventExtractor::select | ( | int | evt_num | ) |

Add a given entry number to the list of events to be selected to the output file.

Definition at line 192 of file extractEvt.C.

192 {
193 m_eventList.push_back( evt_num );
194 return EXTRACT_SUCCESS;
195 }
Gaudi::EXTRACT_SUCCESS
Definition: extractEvt.C:114
std::vector::push_back
T push_back(T... args)
Gaudi::RootEventExtractor::m_eventList
std::vector< int > m_eventList
Definition: extractEvt.C:127

## Member Data Documentation

## ◆ m_eventList

std::vector<int> Gaudi::RootEventExtractor::m_eventList
| protected

Definition at line 127 of file extractEvt.C.

## ◆ m_evt_in

TTree* Gaudi::RootEventExtractor::m_evt_in = nullptr
| protected

Definition at line 119 of file extractEvt.C.

## ◆ m_evt_out

TTree* Gaudi::RootEventExtractor::m_evt_out = nullptr
| protected

Definition at line 123 of file extractEvt.C.

## ◆ m_in

std::unique_ptr<TFile> Gaudi::RootEventExtractor::m_in
| protected

Definition at line 118 of file extractEvt.C.

## ◆ m_localDB_id

int Gaudi::RootEventExtractor::m_localDB_id = 0
| protected

Definition at line 126 of file extractEvt.C.

## ◆ m_out

TFile* Gaudi::RootEventExtractor::m_out = nullptr
| protected

Definition at line 122 of file extractEvt.C.

## ◆ m_ref_in

TTree* Gaudi::RootEventExtractor::m_ref_in = nullptr
| protected

Definition at line 120 of file extractEvt.C.

## ◆ m_ref_out

TTree* Gaudi::RootEventExtractor::m_ref_out = nullptr
| protected

Definition at line 124 of file extractEvt.C.

The documentation for this struct was generated from the following file:

- RootCnv/merge/extractEvt.C