20 #include <TInterpreter.h>
116 unsigned long clid = 1;
175 using namespace Gaudi;
197 ::printf(
"+++ Event list cleared.\n" );
203 m_eventList.push_back( evt_num );
209 if ( m_in ) closeInput();
210 m_in.reset( TFile::Open(
name ) );
211 if ( m_in && !m_in->IsZombie() ) {
212 m_evt_in = (TTree*)m_in->Get(
"Event" );
213 m_ref_in = (TTree*)m_in->Get(
"Refs" );
221 if ( m_out ) closeOutput();
222 m_out = TFile::Open(
name, option );
223 m_evt_out = m_ref_out =
nullptr;
230 ::printf(
"+++ Closing input file:%s\n", m_in->GetName() );
242 ::printf(
"+++ Closing output file:%s\n", m_out->GetName() );
243 if ( m_evt_out ) m_evt_out->Write();
244 if ( m_ref_out ) m_ref_out->Write();
257 bool new_output =
false;
258 TBranch *br_in, *br_out;
259 if ( !m_in || m_in->IsZombie() ) {
261 }
else if ( !m_out || m_out->IsZombie() ) {
264 m_evt_out = (TTree*)m_out->Get(
"Event" );
265 if ( !m_evt_out ) { m_evt_out = m_evt_in->CloneTree( 0 ); }
266 m_ref_out = (TTree*)m_out->Get(
"Refs" );
268 m_ref_out = m_ref_in->CloneTree( 0 );
274 ::printf(
"+++ Copy refs table to new output file:%s\n", m_out->GetName() );
275 br_in = m_ref_in->GetBranch(
"Databases" );
276 br_in->SetAddress( text );
277 br_out = m_ref_out->GetBranch(
"Databases" );
278 br_out->SetAddress( text );
279 for (
int i = 0; i < br_in->GetEntries(); ++i ) {
280 br_in->GetEntry( i );
282 if ( m_localDB_id < 0 &&
strcmp( text,
"<localDB>" ) == 0 ) { m_localDB_id = i; }
285 br_in = m_ref_in->GetBranch(
"Containers" );
286 br_in->SetAddress( text );
287 br_out = m_ref_out->GetBranch(
"Containers" );
288 br_out->SetAddress( text );
289 for (
int i = 0; i < br_in->GetEntries(); ++i ) {
290 br_in->GetEntry( i );
294 br_in = m_ref_in->GetBranch(
"Links" );
295 br_in->SetAddress( text );
296 br_out = m_ref_out->GetBranch(
"Links" );
297 br_out->SetAddress( text );
298 for (
int i = 0; i < br_in->GetEntries(); ++i ) {
299 br_in->GetEntry( i );
303 br_in = m_ref_in->GetBranch(
"Params" );
304 br_in->SetAddress( text );
305 br_out = m_ref_out->GetBranch(
"Params" );
306 br_out->SetAddress( text );
307 for (
int i = 0; i < br_in->GetEntries(); ++i ) {
308 br_in->GetEntry( i );
309 if (
strncmp( text,
"PFN=", 4 ) == 0 ) {
310 ::snprintf( text,
sizeof( text ),
"PFN=%s", br_out->GetFile()->GetName() );
311 ::printf(
"+++ PFN of the created output file is:%s\n", text );
312 }
else if (
strncmp( text,
"FID=", 4 ) == 0 ) {
313 static const char*
fmt =
"FID=%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
315 unsigned char buf[16];
316 unsigned short sbuf[8];
317 unsigned int ibuf[4];
320 uuid.GetUUID( d.buf );
321 ::snprintf( text,
sizeof( text ),
fmt, d.ibuf[0], d.sbuf[2], d.sbuf[3], d.buf[8], d.buf[9], d.buf[10],
322 d.buf[11], d.buf[12], d.buf[13], d.buf[14], d.buf[15] );
323 ::printf(
"+++ FID of the created output file is:%s\n", text );
330 TIter
next( m_evt_in->GetListOfBranches() );
331 while ( ( br_in = (TBranch*)
next() ) ) {
332 TString
name = br_in->GetName();
333 TClass* br_class = gROOT->GetClass( br_in->GetClassName(), kTRUE );
334 br_out = m_evt_out->GetBranch(
name );
336 ::printf(
"+++ ERROR: Input and output event trees are incompatible. Selection not possible.\n" );
339 int out_num_entries = br_out->GetEntries();
340 for (
const auto& i : m_eventList ) {
342 const char* br_type =
"DataObject";
343 void* pObject = br_class->New();
344 br_in->SetAddress( &pObject );
345 br_out->SetAddress( &pObject );
346 int num_rd = br_in->GetEntry( num_evt );
348 ::printf(
"+++ ERROR: Failed to read data from branch:%s\n",
name.Data() );
351 if (
name.EndsWith(
"_R." ) ) {
353 for (
auto& ir : refs->
refs ) {
355 if ( r.
dbase == m_localDB_id ) r.
entry = out_num_entries;
359 int num_wr = br_out->Fill();
361 ::printf(
"+++ ERROR: Failed to write data to extraction branch:%s "
362 "read:%d wrote:%d bytes [Length-mismatch]\n",
363 name.Data(), num_rd, num_wr );
366 ::printf(
"+++ Copied %8d bytes to %-10s branch %s(%d)\n", num_rd, br_type,
name.Data(), out_num_entries );
369 m_evt_out->SetEntries( br_out->GetEntries() + 1 );
389 int main(
int,
char**) {
390 gROOT->SetBatch(kTRUE);
391 gSystem->Load(
"libCintex.so");
392 gInterpreter->ProcessLine(
"ROOT::Cintex::Enable()");
393 return extractEvtFunc(
"castor:/castor/cern.ch/grid/lhcb/LHCb/Collision12/FULL.DST/00020565/0000/00020565_00005381_1.full.dst",
"bla.root",2);