10 #include "TInterpreter.h" 165 using namespace Gaudi;
187 ::printf(
"+++ Event list cleared.\n" );
193 m_eventList.push_back( evt_num );
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" );
211 if ( m_out ) closeOutput();
212 m_out = TFile::Open(
name, option );
213 m_evt_out = m_ref_out =
nullptr;
220 ::printf(
"+++ Closing input file:%s\n", m_in->GetName() );
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();
247 bool new_output =
false;
248 TBranch *br_in, *br_out;
249 if ( !m_in || m_in->IsZombie() ) {
251 }
else if ( !m_out || m_out->IsZombie() ) {
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" );
258 m_ref_out = m_ref_in->CloneTree( 0 );
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 );
272 if ( m_localDB_id < 0 &&
strcmp( text,
"<localDB>" ) == 0 ) { m_localDB_id = i; }
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 );
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 );
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 ) {
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 ) {
303 static const char* fmt =
"FID=%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
305 unsigned char buf[16];
306 unsigned short sbuf[8];
307 unsigned int ibuf[4];
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 );
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 );
326 ::printf(
"+++ ERROR: Input and output event trees are incompatible. Selection not possible.\n" );
329 int out_num_entries = br_out->GetEntries();
330 for (
const auto& i : m_eventList ) {
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 );
338 ::printf(
"+++ ERROR: Failed to read data from branch:%s\n",
name.Data() );
341 if (
name.EndsWith(
"_R." ) ) {
343 for (
auto& ir : refs->
refs ) {
345 if ( r.
dbase == m_localDB_id ) r.
entry = out_num_entries;
349 int num_wr = br_out->Fill();
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 );
356 ::printf(
"+++ Copied %8d bytes to %-10s branch %s(%d)\n", num_rd, br_type,
name.Data(), out_num_entries );
359 m_evt_out->SetEntries( br_out->GetEntries() + 1 );
379 int main(
int,
char**) {
380 gROOT->SetBatch(kTRUE);
381 gSystem->Load(
"libCintex.so");
382 gInterpreter->ProcessLine(
"ROOT::Cintex::Enable()");
383 return extractEvtFunc(
"castor:/castor/cern.ch/grid/lhcb/LHCb/Collision12/FULL.DST/00020565/0000/00020565_00005381_1.full.dst",
"bla.root",2);
RootRef(const RootRef &c)
Copy constructor.
std::vector< int > links
The links of the link manager.
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject.
RootObjectRefs(const RootObjectRefs &r)
Copy constructor.
int dbase
Data members to define object location in the persistent world.
Persistent reference object.
std::string optional
Optional description.
RootNTupleDescriptor()=default
Standard constructor.
~RootObjectRefs()=default
Default destructor.
std::string description
Description string.
void reset()
Reset data content.
RootObjectRefs()=default
Default constructor.
int extractEvt(const char *input, const char *output, long num_evt)
Function to extract single event and write it to an output file.
virtual ~RootNTupleDescriptor()=default
Standard destructor.
RootObjectRefs & operator=(const RootObjectRefs &r)
Assignment operator.
std::string container
Identifier of description.
unsigned long clid
Class ID of the described object.
RootRef & operator=(const RootRef &c)
Assignment operator.
int main(int argc, char *argv[])
std::vector< RootRef > refs
The references corresponding to the next layer of items in the data store.
RootRef()
Standard constructor.
Header file for std:chrono::duration-based Counters.