ATLAS Offline Software
AtlCoolCopy.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // AtlCoolCopy.cxx
6 // COOL copying utility, C++ based on PyCoolCopy from Sven Schmidt
7 // Richard Hawkings, started 30/5/06
8 // compiles in offline cmt framework to binary executable, needs offline env
9 
10 #include <algorithm>
11 #include <cmath>
12 #include <ctime>
13 #include <fstream>
14 #include <iostream>
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 #include <nlohmann/json.hpp>
19 #include <curl/curl.h>
20 
21 #include "CoolKernel/DatabaseId.h"
22 #include "CoolKernel/Exception.h"
23 #include "CoolKernel/IDatabaseSvc.h"
24 #include "CoolKernel/IDatabase.h"
25 #include "CoolKernel/IFolder.h"
26 #include "CoolKernel/FolderSpecification.h"
27 #include "CoolKernel/IFolderSet.h"
28 #include "CoolKernel/IObject.h"
29 #include "CoolKernel/IObjectIterator.h"
30 #include "CoolKernel/IRecordIterator.h"
31 #include "CoolApplication/Application.h"
32 #include "CoralBase/AttributeListException.h"
33 
40 #include "RelationalAccess/ConnectionService.h"
41 #include "RelationalAccess/IConnectionServiceConfiguration.h"
42 #include "RelationalAccess/ISessionProxy.h"
43 #include "RelationalAccess/ITransaction.h"
44 #include "RelationalAccess/ISchema.h"
45 #include "RelationalAccess/ITable.h"
46 #include "RelationalAccess/IQuery.h"
47 #include "RelationalAccess/ICursor.h"
48 
53 
55 
56 #include "PoolMapElement.h"
57 #include "ReplicaSorter.h"
58 #include "CoolTagInfo.h"
59 
60 #include "TFile.h"
61 #include "TTree.h"
62 #include "TH1.h"
63 #include "TObjString.h"
64 
65 size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *s) {
66  size_t newLength = size * nmemb;
67 
68  try
69  {
70  s->append((char *)contents, newLength);
71  }
72  catch (std::bad_alloc &e)
73  {
74  // handle memory problem
75  return 0;
76  }
77  return newLength;
78 }
79 
80 
81 class AtlCoolCopy {
82  public:
83  AtlCoolCopy(const std::string& sourcedb, const std::string& destdb,
84  bool allowcreate=false);
85  bool isOpen() const;
86  bool addFolder(const std::string& folder,const bool onlyTags);
87  bool addExclude(const std::string& folder);
89  (const std::string& folder,const std::vector<std::string>& taglist);
90  int doCopy ATLAS_NOT_THREAD_SAFE ();
91  int setOpts(int argc, const char* argv[]);
92 
93  private:
94  // methods
95  bool openConnections(const std::string& sourcedb, const std::string& destdb,
96  bool allowcreate);
97  bool openCoraCool();
98  bool getLockedTags();
99  bool procOptVector(const int argc, const char* argv[],
100  std::vector<std::string>& folders);
101  static std::string transConn(const std::string& inconn);
102  void setChannelRange(const cool::IFolderPtr& sourcefl);
103  static cool::ChannelId channelID(const cool::IFolderPtr& folder,
104  const std::string& chanstring);
106  (const std::string& folder,const std::string& destfolder,
107  const cool::IFolderPtr& sourcefl,const CoraCoolFolderPtr& sourceflc,
108  const cool::IFolderPtr& destfl,const CoraCoolFolderPtr& destflc,
109  const std::string& sourcetag,const std::string& desttag,
110  const cool::ValidityKey since,const cool::ValidityKey until,
111  bool timestamp,bool checkrefs,bool iscora,
112  const cool::PayloadMode::Mode paymode, bool created);
113  void adjustIOVs(const cool::ValidityKey& since,
114  const cool::ValidityKey& until,
115  const cool::ValidityKey& qsince,
116  const cool::ValidityKey& quntil,
117  cool::ValidityKey& newsince,
118  cool::ValidityKey& newuntil,
119  const bool timestamp) const;
120  int nocopyIOVs(const std::string& folder,
121  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
122  const cool::ValidityKey since,const cool::ValidityKey until,
123  bool checkrefs);
124  int verifyIOVs(const std::string& folder,
125  const cool::IFolderPtr& sourcefl,const CoraCoolFolderPtr& sourceflc,
126  const cool::IFolderPtr& destfl,const CoraCoolFolderPtr& destflc,
127  const std::string& sourcetag,
128  const cool::ValidityKey since,const cool::ValidityKey until,
129  const bool checkrefs,const bool iscora,
130  const cool::PayloadMode::Mode paymode);
131  int rootIOVs(const std::string& folder,
132  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
133  const cool::ValidityKey since,const cool::ValidityKey until,
134  const bool timestamp);
135  std::string rootDirs(const std::string& folder, const std::string& toproot);
136  bool rootAllocate(const cool::IFieldSpecification& spec,
137  void*& sptr,char& rootID) const;
138  void rootWrite(void* sptr, const cool::IField& field) const;
139  static bool isNumeric(const char* input);
140  static bool equalRecord(const cool::IRecord& lhs,
141  const cool::IRecord& rhs);
142  int analyseIOVs(const std::string& folder,
143  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
144  const cool::ValidityKey since,const cool::ValidityKey until,
145  const bool timestamp);
146  static TH1F* bookOrFindTH1F(const std::string& hID, const std::string& htitle,
147  const int chan, const float xlow, const float xhigh);
148  static cool::ValidityKey timeVal(const char* input);
149  static std::string timeString(const cool::ValidityKey iovtime);
150  static cool::ValidityKey runLBVal(const char* input1, const char* input2);
151  bool getTimeFromRun();
152  bool getOnlineRun();
153  bool getBulkRun();
154  bool getRunList();
155 
156  static int getUpdateMode(std::string_view desc, std::string_view tag);
157 
158  bool checkChannels(const std::string& folder,
159  const cool::IFolderPtr& sourcefl,const cool::IFolderPtr& destfl,
160  bool newfolder);
161  void checkRef(const cool::IRecord& payload,
162  const std::string& folder,const std::string& tag);
163  int tagParents();
164  int writeTagInfo();
165  int listPoolRefs();
166  int resolvePoolRefs ATLAS_NOT_THREAD_SAFE ();
167  static std::string getCoolHistGUID(const std::string& file);
168  void filePoolRefs();
169  static pool::IFileCatalog* setupCatalog(const std::vector<std::string>& catvec);
170 
171  // input parameters
172  std::string m_sourcedb;
173  std::string m_destdb;
180  bool m_debug;
181  bool m_alliov;
182  bool m_verify;
183  bool m_root;
185  bool m_analyse;
187  bool m_listpfn;
189  bool m_poolall;
190  bool m_nocopy;
191  bool m_nodata;
193  bool m_chdesc;
194  bool m_hitag;
195  bool m_nohitag;
204  bool m_skipout;
205  bool m_skiprep;
206  bool m_applock;
209  bool m_gettime;
212  bool m_getbulk;
222  cool::ValidityKey m_runemin;
223  cool::ValidityKey m_runemax;
224  cool::ValidityKey m_timemin;
225  cool::ValidityKey m_timemax;
226  cool::ValidityKey m_newrunemin;
227  cool::ValidityKey m_newrunemax;
228  cool::ValidityKey m_newtimemin;
229  cool::ValidityKey m_newtimemax;
230  cool::ValidityKey m_srunemin;
231  cool::ValidityKey m_srunemax;
232  std::vector<std::string> m_channelRange;
233  std::string m_channel1;
234  std::string m_channel2;
237  long long m_anadelt;
238  std::string m_outfolder;
239  std::string m_outtag;
240  std::string m_newdataset;
241  std::string m_checkoutputfile;
242  std::string m_timedb;
243  std::string m_taglabel;
244  std::string m_runinfohost;
245  std::vector<std::string> m_addguid; // additional guids to be processsed
246  std::vector<std::string> m_addlfn; // additional LFNs to be processsed
247  std::vector<std::string> m_parfile; // list of additional files with params
248  std::vector<cool::ChannelId> m_excludechans; // list of channels to exclude
249  std::vector<std::string> m_runfile; // list of filenames with run numbers
250  std::vector<unsigned int> m_runlist; // list of runs open for UPD2 tags
251 
252  // internal variables
253  coral::ConnectionService m_coralsvc;
254  cool::Application m_coolapp;
255  cool::IDatabaseSvc* m_dbSvc;
257  cool::IDatabasePtr m_sourceDbPtr;
258  cool::IDatabasePtr m_destDbPtr;
261  std::vector<std::string> m_folderlist; // list of leaf folders to process
262  std::vector<std::string> m_folderexcl; // list of leaf folders to exclude
263  std::vector<std::string> m_tags; // list of tags
264  std::vector<std::string> m_magic; // list magic tags fragments to match
265  std::vector<std::string> m_poolcat; // list of POOL catalogues for input
266  std::vector<std::string> m_mergecat; // list of POOL catalogues for mergechk
267  bool m_open;
268  cool::ChannelSelection m_chansel;
269  typedef std::map<std::string,PoolMapElement> PoolMap;
270  PoolMap::iterator m_poollast; // pointer to last POOL ref updated
271  PoolMap m_poolrefs; // POOL refs and usage counts
272  // hierarchical tags - tag name and folder
273  using HiTagMap = std::map<std::string, std::string>;
275  // tags indirectly used in the hierarchy and have to be treated at end
276  std::vector<std::string> m_hiparent;
277  // map of CoolTagInfo objects - tags which have have their descriptions
278  // and lock status set in the destination DB at the end
279  using CoolTagMap = std::map<std::string, CoolTagInfo>;
281  // output root file for ROOT file export and IOV analysis
282  TFile* p_rootfile;
283 
284  // ROOT ntuple variables.
285  ULong64_t m_nt_since = 0;
286  ULong64_t m_nt_until = 0;
287  UInt_t m_nt_runsince = 0;
288  UInt_t m_nt_rununtil = 0;
289  UInt_t m_nt_lbsince = 0;
290  UInt_t m_nt_lbuntil = 0;
291  UInt_t m_nt_channel = 0;
292  char m_nt_tagid[256] = {0};
293  std::string m_nt_treename;
294  std::vector<void*> m_nt_bufferptr;
295 };
296 
297 inline bool AtlCoolCopy::isOpen() const { return m_open; }
298 
299 void printHelp();
300 
301 AtlCoolCopy::AtlCoolCopy(const std::string& sourcedb, const std::string& destdb,
302  bool allowcreate) :
303  m_sourcedb(sourcedb),m_destdb(destdb),m_allowcreate(allowcreate),
304  m_recreate(false),
305  m_includehead(false),m_excludehead(false),
306  m_usertags(true),m_userupdatehead(false),m_debug(false),m_alliov(false),
307  m_verify(false),m_root(false),m_zeronull(false),m_analyse(false),
308  m_checkrefs(false),m_listpfn(false),m_poolopen(false),m_poolall(false),
309  m_nocopy(false),m_nodata(false),m_nochannel(false),m_chdesc(false),
310  m_hitag(false),m_nohitag(false),m_forcesingle(false),m_forcemulti(false),
311  m_forcerune(false),m_forcetime(false),m_forcepay(false),m_forcenopay(false),
312  m_sourceread(true),m_truncate(false),m_skipout(false),m_skiprep(false),
313  m_applock(false),m_applocksv(false),
314  m_readoracle(false),m_gettime(false),m_getonline(false),m_onlinerun(false),
315  m_getbulk(false),
316  m_prunetags(false),m_lockedonly(false),m_copytaginfo(false),
317  m_copytaglock(false),m_coracool(true),m_ignoremode(false),
318  m_ignorespec(false),m_checkdesttag(false),m_noclobroot(false),
319  m_runemin(cool::ValidityKeyMin),m_runemax(cool::ValidityKeyMax),
320  m_timemin(cool::ValidityKeyMin),m_timemax(cool::ValidityKeyMax),
321  m_newrunemin(cool::ValidityKeyMin),m_newrunemax(cool::ValidityKeyMax),
322  m_newtimemin(cool::ValidityKeyMin),m_newtimemax(cool::ValidityKeyMax),
323  m_srunemin(cool::ValidityKeyMin),m_srunemax(cool::ValidityKeyMax),
324  m_channel1(""),m_channel2(""),m_bufsize(1000),m_sealmsg(5),
325  m_anadelt(-1),m_outfolder(""),m_outtag(""),m_newdataset(""),
326  m_checkoutputfile(""),m_timedb(""),m_taglabel(""),
327  m_runinfohost("http://atlas-run-info-api.web.cern.ch/api"),
328  m_coolapp(&m_coralsvc),
329  m_dbSvc(&(m_coolapp.databaseService())),m_repsort(nullptr),
330  m_open(false),m_chansel(cool::ChannelSelection::all()),p_rootfile(nullptr)
331 {
332  m_poolrefs.clear();
333  m_poollast=m_poolrefs.end();
334  // configure CORAL components
335  coral::IConnectionServiceConfiguration& csconfig=m_coralsvc.configuration();
336  csconfig.disablePoolAutomaticCleanUp();
337  csconfig.setConnectionTimeOut(0);
338 }
339 
340 bool AtlCoolCopy::openConnections(const std::string& sourcedb,
341  const std::string& destdb,bool allowcreate) {
342  // check connections not already open
343  if (m_open) return true;
344  // initialise replica sorter if it was requested
345  if (m_readoracle) {
346  m_repsort=new ReplicaSorter();
347  coral::IConnectionServiceConfiguration& csconfig=m_coralsvc.configuration();
348  csconfig.setReplicaSortingAlgorithm(*m_repsort);
349  }
350  // cool::IDatabaseSvc& dbSvc=cool::DatabaseSvcFactory::databaseService();
351  // open source database
352  std::cout << "Open source database: " << sourcedb << std::endl;
353  if (!m_sourceread) std::cout << "... in UPDATE mode" << std::endl;
354  try {
355  m_sourceDbPtr=m_dbSvc->openDatabase(transConn(sourcedb),m_sourceread);
356  }
357  catch (std::exception& e) {
358  std::cout << "Cool exception caught: " << e.what() << std::endl;
359  return false;
360  }
361  // open destination database
362  if (m_nocopy) {
363  m_open=true;
364  return true;
365  } else if (m_root || m_analyse) {
366  std::cout << "Open destination ROOT file: " << destdb << std::endl;
367  p_rootfile=new TFile(destdb.c_str(),"RECREATE");
368  if (p_rootfile==nullptr) std::cout << "ERROR: Could not open ROOT file" <<
369  std::endl;
370  m_open=(p_rootfile!=nullptr);
371  return m_open;
372  }
373  std::string tdestdb=transConn(destdb);
374  std::cout << "Open destination database: " << tdestdb << std::endl;
375  try {
376  m_destDbPtr=m_dbSvc->openDatabase(tdestdb,m_verify);
377  // if the open succeeds and we are using recreate mode, drop/delete
378  // the existing database first
379  if (m_recreate) {
380  std::cout <<
381  "Forcing recreation of destination database - deleting existing data!"
382  << std::endl;
383  m_destDbPtr.reset();
384  m_dbSvc->dropDatabase(tdestdb);
385  // go into catch to recrete database
386  throw cool::DatabaseDoesNotExist("old database deleted");
387  }
388  }
389  catch (std::exception& e) {
390  std::cout << "COOL exception caught: " << e.what() << std::endl;
391  // try to recover by creating new DB if possible and requested
392  if (allowcreate || m_recreate) {
393  std::cout << "Try to create new conditions DB" << std::endl;
394  try {
395  m_destDbPtr=m_dbSvc->createDatabase(tdestdb);
396  std::cout << "Creation succeeded" << std::endl;
397  }
398  catch (cool::Exception& e) {
399  std::cout << "Creation failed" << std::endl;
400  return false;
401  }
402  } else {
403  return false;
404  }
405  }
406  m_open=true;
407  return true;
408 }
409 
411  if (m_sourceCoraPtr.get()==nullptr) {
412  std::cout << "Attempt to open source CoraCool DB " << m_sourcedb <<
413  std::endl;
416  std::cout << "Opened CoraCool source DB" << std::endl;
417  }
418  // skip destination DB if not copying
419  if (m_nocopy) return true;
420  if (m_destCoraPtr.get()==nullptr) {
421  std::cout << "Attempt to open destination CoraCool DB " << m_destdb <<
422  std::endl;
425  std::cout << "Opened CoraCool dest DB" << std::endl;
426  }
427  return true;
428 }
429 
431  // set m_tags to list of top level tags which are locked
432  m_tags.clear();
433  cool::IFolderSetPtr topfolder=m_sourceDbPtr->getFolderSet("/");
434  const std::vector<std::string>& toptaglist=topfolder->listTags();
435  for (std::vector<std::string>::const_iterator toptag=toptaglist.begin();
436  toptag!=toptaglist.end();++toptag) {
437  cool::HvsTagLock::Status tstat=topfolder->tagLockStatus(*toptag);
438  if (tstat==cool::HvsTagLock::LOCKED ||
439  tstat==cool::HvsTagLock::PARTIALLYLOCKED) {
440  std::cout << "Top-level tag " << *toptag << " will be copied" <<
441  std::endl;
442  m_tags.push_back(*toptag);
443  }
444  }
445  std::cout << "Total of " << m_tags.size() << " top-level tags to be copied"
446  << std::endl;
447  return (!m_tags.empty());
448 }
449 
450 std::string AtlCoolCopy::transConn(const std::string& inconn) {
451  // translate simple connection string (no slash) to mycool.db with given
452  // instance name, all others are left alone
453  if (inconn.find('/')==std::string::npos) {
454  return "sqlite://X;schema=mycool.db;dbname="+inconn;
455  } else {
456  return inconn;
457  }
458 }
459 
460 
461 bool AtlCoolCopy::addFolder(const std::string& folder,const bool onlyTags) {
462  std::cout << "Add folders in path:" << folder << " [ ";
463  const std::vector<std::string> nodelist=m_sourceDbPtr->listAllNodes();
464  // find all matching leaf folders
465  for (std::vector<std::string>::const_iterator nodeitr=nodelist.begin();
466  nodeitr!=nodelist.end();++nodeitr) {
467  // match exact folder name or leading part of path
468  // for leading part matches, next char in folder name must be '/'
469  // so /CALO/SetA matches /CALO/SetA/X but not /CALO/SetAB
470  if (*nodeitr==folder || folder=="/" ||
471  (nodeitr->compare(0,folder.size(),folder)==0 &&
472  nodeitr->size()>folder.size() && nodeitr->compare(folder.size(),1,"/")==0)) {
473  // check if folder on exclude list
474  bool exclude=false;
475  for (std::vector<std::string>::const_iterator iexcl=m_folderexcl.begin();
476  iexcl!=m_folderexcl.end();++iexcl) {
477  if (iexcl->compare(0,1,"/")==0) {
478  // exclude pattern starting / matches folder path (/SCT or /SCT/DCS)
479  exclude=(exclude || nodeitr->compare(0,iexcl->size(),*iexcl)==0);
480  } else {
481  // exclude pattern without leading / matches anywhere in folder
482  exclude=(exclude || (nodeitr->find(*iexcl)!=std::string::npos));
483  }
484  }
485  // check folder exists (is a leaf folder), and not excluded
486  if (m_sourceDbPtr->existsFolder(*nodeitr) && !exclude && !onlyTags) {
487  // only add if folder not already on list
488  if (find(m_folderlist.begin(),m_folderlist.end(),*nodeitr)==
489  m_folderlist.end()) {
490  std::cout << *nodeitr << " ";
491  m_folderlist.push_back(*nodeitr);
492  }
493  }
494  // if its a folderset, check for any hierarchical tags
495  if (!m_nohitag && m_sourceDbPtr->existsFolderSet(*nodeitr) && !exclude) {
496  if (!m_prunetags) {
497  const std::vector<std::string> foldersettags=
498  m_sourceDbPtr->getFolderSet(*nodeitr)->listTags();
499  if (!foldersettags.empty()) {
500  for (std::vector<std::string>::const_iterator
501  itr=foldersettags.begin();itr!=foldersettags.end();++itr) {
502  m_hitagmap[*itr]=*nodeitr;
503  }
504  }
505  } else {
506  // only take tags in this folder which are referenced from one of
507  // the input tags (assumed to be top-level tags)
508  cool::IFolderSetPtr sfolder=m_sourceDbPtr->getFolderSet(*nodeitr);
509  for (std::vector<std::string>::const_iterator toptag=m_tags.begin();
510  toptag!=m_tags.end();++toptag) {
511  try {
512  std::string rtag=sfolder->resolveTag(*toptag);
513  m_hitagmap[rtag]=*nodeitr;
514  }
515  // catch exceptions indicating tag defines nothing here
516  // note std::exception rather than COOL exception to cover case
517  // when trying to resolve a leaf tag in the '/' folder, which
518  // throws a coral AttributeException
519  catch (std::exception& e) {}
520  }
521  }
522  }
523  }
524  }
525  std::cout << "]" << std::endl;
526  return true;
527 }
528 
529 bool AtlCoolCopy::addExclude(const std::string& folder) {
530  std::cout << "Adding folder to exclude list: " << folder << std::endl;
531  m_folderexcl.push_back(folder);
532  return true;
533 }
534 
536  (const std::string& folder,const std::vector<std::string>& taglist) {
537  // get source folder
538  cool::IFolderPtr sourcefl,destfl;
539  CoraCoolFolderPtr sourceflc,destflc;
540  try {
541  sourcefl=m_sourceDbPtr->getFolder(folder);
542  }
543  catch (cool::Exception& e) {
544  std::cout << "Could not get source folder: " << folder << std::endl;
545  return 20;
546  }
547  const std::string& sourcedesc=sourcefl->description();
548  // check if folder should be skipped from replication
549  if (m_skiprep && sourcedesc.find("<norep/>")!=std::string::npos) {
550  std::cout << "Folder " << folder <<
551  " skipped due to <norep/> metadata" << std::endl;
552  return 0;
553  }
554  const bool iscora=(m_coracool &&
555  sourcedesc.find("<coracool")!=std::string::npos);
556  if (iscora) {
557  // activate CoraCool and get source folder pointer
558  openCoraCool();
559  sourceflc=m_sourceCoraPtr->getFolder(folder);
560  }
561  // setup the channel-range
562  setChannelRange(sourcefl);
563 
564  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
565  cool::FolderVersioning::Mode dvermode=vermode;
566  if (m_forcesingle) {
567  dvermode=cool::FolderVersioning::SINGLE_VERSION;
568  std::cout << "Forcing destination folder to singleversion" << std::endl;
569  }
570  if (m_forcemulti) {
571  dvermode=cool::FolderVersioning::MULTI_VERSION;
572  std::cout << "Forcing destination folder to multiversion" << std::endl;
573  }
574  // setup type of folder (payload mode, inline, separate, or vector)
575  const cool::PayloadMode::Mode spaymode=
576  sourcefl->folderSpecification().payloadMode();
577  cool::PayloadMode::Mode dpaymode=spaymode;
578 
579  // set name for destination folder
580  std::string destfolder=folder;
581  if (!m_outfolder.empty()) {
582  destfolder=m_outfolder;
583  std::cout << "Destination folder will be renamed to " << destfolder <<
584  std::endl;
585  }
586 
587 // get destination folder, try to create if not there (and not verifying!)
588  bool created=false;
589  if (!m_nocopy && !m_root && !m_analyse) {
590  if (!m_destDbPtr->existsFolder(destfolder) && !m_verify) {
591  std::cout << "Creating folder " << destfolder << " payload-type " <<
592  dpaymode << " on destination" << std::endl;
593  created=true;
594  std::string metadata=sourcedesc;
595  if (m_forcerune || m_forcetime) {
596  std::string newmeta=m_forcerune ? "run-lumi" : "time";
597  std::string::size_type p1,p2;
598  p1=metadata.find("<timeStamp>");
599  p2=metadata.find("</timeStamp>");
600  if (p1!=std::string::npos && p2!=std::string::npos) {
601  metadata.replace(0,p2,"<timeStamp>"+newmeta);
602  std::cout << "Forced destination folder to " << newmeta << " : "
603  << metadata << std::endl;
604  } else {
605  std::cout <<
606  "ERROR: Could not parse metadata string to force timestamp type"
607  << std::endl;
608  }
609  }
610  // force separate or inline payload, but not if input is vector
611  if (m_forcepay && spaymode!=cool::PayloadMode::VECTORPAYLOAD)
612  dpaymode=cool::PayloadMode::SEPARATEPAYLOAD;
613  if (m_forcenopay && spaymode!=cool::PayloadMode::VECTORPAYLOAD)
614  dpaymode=cool::PayloadMode::INLINEPAYLOAD;
615 
616  try {
617  if (iscora) {
618  destflc=m_destCoraPtr->createFolder(destfolder,
619  sourceflc->coralTableName(),
620  sourceflc->fkSpecification(),
621  sourceflc->payloadSpecification(),
622  sourceflc->coralFKey(),
623  sourceflc->coralPKey(),
624  metadata,dvermode,true);
625  std::cout << "Created CoraCool folder" << std::endl;
626  destfl=m_destDbPtr->getFolder(destfolder);
627  } else {
628  destfl=m_destDbPtr->createFolder(destfolder,
629  cool::FolderSpecification(dvermode,
630  sourcefl->payloadSpecification(),dpaymode),
631  metadata,true);
632  }
633  }
634  catch (cool::Exception&e ) {
635  std::cout << "Create folder failed - aborting" << std::endl;
636  return 30;
637  }
638  }
639  // now get the pointer to destination folder if needed
640  // note both COOL and CoraCool pointers are set if needed
641  try {
642  if (iscora) destflc=m_destCoraPtr->getFolder(destfolder);
643  destfl=m_destDbPtr->getFolder(destfolder);
644  }
645  catch (cool::Exception& e) {
646  std::cout << "Could not get destination folder: " << destfolder
647  << std::endl;
648  return 21;
649  }
650  // check payload specifications of folders are the same
651  const cool::IRecordSpecification& sourcespec=
652  sourcefl->payloadSpecification();
653  const cool::IRecordSpecification& destspec=
654  destfl->payloadSpecification();
655  if (!(sourcespec==destspec)) {
656  bool badspec=false;
657  if (m_ignorespec) {
658  // specifications differ - check names are same
659  std::cout <<
660  "WARNING Source and destination folder specifications differ" <<
661  std::endl;
662  for (unsigned int i=0;i<sourcespec.size();++i) {
663  const std::string& sname=sourcespec[i].name();
664  if (!destspec.exists(sname)) {
665  std::cout << "ERROR: Field " << sname << " absent from destination"
666  << std::endl;
667  badspec=true;
668  }
669  }
670  } else {
671  badspec=true;
672  }
673  if (badspec) {
674  std::cout <<
675  "ERROR Source and destination folder specifications differ"
676  << std::endl;
677  return 22;
678  }
679  }
680  // check folder descriptions are the same - just print WARNING if not
681  const std::string& destdesc=destfl->description();
682  if (sourcedesc!=destdesc) {
683  std::cout << "WARNING: Source and destination folder descriptions (meta-data) differ" << std::endl;
684  std::cout << "Source folder: " << sourcedesc << std::endl;
685  std::cout << "Destn folder: " << destdesc << std::endl;
686  }
687  // check payload modes are same - print warning if not
688  const cool::PayloadMode::Mode dpaymode=
689  destfl->folderSpecification().payloadMode();
690  if (spaymode!=dpaymode) {
691  std::cout << "WARNING: Source (" << spaymode << ") and destination (" <<
692  dpaymode << " folder payload modes differ" << std::endl;
693  }
694 
695  // check/set channels table if requested
696  if (!m_nochannel) {
697  if (!checkChannels(folder,sourcefl,destfl,created)) return 23;
698  }
699  }
700  // if only copying structures, stop here
701  if (m_nodata) return 0;
702  // extract folder/range information
703  std::cout << "Start to process folder: " << folder;
704  // check for timestamp XML
705  bool timestamp=(sourcefl->description().find("<timeStamp>time")!=
706  std::string::npos);
707  cool::ValidityKey since,until;
708  if (timestamp) {
709  since=m_timemin;
710  until=m_timemax;
711  std::cout << " (timestamp)" << std::endl;
712  } else {
713  since=m_runemin;
714  until=m_runemax;
715  std::cout << " (run/lumi)" << std::endl;
716  }
717  if (m_alliov || m_truncate)
718  std::cout << "Output IOVs will be modified" << std::endl;
719  if (m_skipout)
720  std::cout << "IOVs extending outside selection range will be skipped"
721  << std::endl;
722 
723  bool checkrefs=false;
724  const std::string name0=sourcefl->payloadSpecification()[0].name();
725  if (m_checkrefs && (name0=="PoolRef" || name0=="fileGUID")) {
726  checkrefs=true;
727  std::cout << "Check POOL references in folder " << folder << std::endl;
728  }
729  // if nocopy, and checking POOL references, and folder is not a POOL ref one
730  // can skip the data access
731  if (m_checkrefs && m_nocopy && !checkrefs) return 0;
732 
733  // check for <fullrep/> metadata indicating copy all tags if -skiprep option
734  bool copyall=
735  (m_skiprep && (sourcedesc.find("<fullrep/>")!=std::string::npos));
736  if (copyall) std::cout <<
737  "All tags in folder will be copied due to <fullrep/> metadata" << std::endl;
738 
739  // set up true list of tags to copy
740  std::vector<std::string> tags;
741  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
742  std::cout << "Single version folder" << std::endl;
743  tags.emplace_back("HEAD");
744  } else {
745  std::cout << "Multi version folder: consider tags [ ";
746  // get list of tags in this node which are requested
747  const std::vector<std::string> foldertags=sourcefl->listTags();
748  for (std::vector<std::string>::const_iterator itag=foldertags.begin();
749  itag!=foldertags.end();++itag) {
750  bool copyit=copyall;
751  // if input taglist is empty, take all tags in folder
752  if (taglist.empty() ||
753  find(taglist.begin(),taglist.end(),*itag)!=taglist.end())
754  copyit=true;
755  for (std::vector<std::string>::const_iterator imtag=m_magic.begin();
756  imtag!=m_magic.end();++imtag) {
757  if (itag->find(*imtag)!=std::string::npos) copyit=true;
758  }
759  if (copyit) {
760  tags.push_back(*itag);
761  std::cout << *itag << " ";
762  }
763  }
764  // if no tags were found, or doing inclusive hierarchical tag copying
765  // try resolving input tags hierarchically
766  if (tags.empty() || m_hitag) {
767  for (std::vector<std::string>::const_iterator itag=taglist.begin();
768  itag!=taglist.end();++itag) {
769  try {
770  std::string htag=sourcefl->resolveTag(*itag);
771  if (find(tags.begin(),tags.end(),htag)==tags.end()) {
772  std::cout << *itag << "=" << htag << " ";
773  tags.push_back(htag);
774  }
775  }
776  // ignore exceptions indicating tag not defined here
777  // note std::exception rather than COOL exception to cover case
778  // when trying to resolve a leaf tag in the '/' folder, which
779  // throws a coral AttributeException
780  catch (std::exception& e) { }
781  }
782  }
783  std::cout << "]" << std::endl;
784  // if still no tags were found, or forced HEAD tag copying, or no
785  // tags in the folder at all (=MV folder being used as SV), add HEAD
786  if (((tags.empty() || m_includehead) && !m_excludehead) ||
787  foldertags.empty())
788  tags.emplace_back("HEAD");
789  }
790 
791  sourcefl->setPrefetchAll(false);
792  for (std::vector<std::string>::const_iterator itag=tags.begin();
793  itag!=tags.end();++itag) {
794  std::string outtag=*itag;
795  if (!m_outtag.empty()) outtag=m_outtag;
796  int retcode;
797  // verify or copy folder
798  if (m_verify) {
799  retcode=verifyIOVs(folder,sourcefl,sourceflc,destfl,destflc,
800  *itag,since,until,checkrefs,iscora,spaymode);
801  } else if (m_nocopy) {
802  retcode=nocopyIOVs(folder,sourcefl,*itag,since,until,checkrefs);
803  } else if (m_root) {
804  retcode=rootIOVs(folder,sourcefl,*itag,since,until,timestamp);
805  } else if (m_analyse) {
806  retcode=analyseIOVs(folder,sourcefl,*itag,since,until,timestamp);
807  } else {
808  retcode=copyIOVs(folder,destfolder,sourcefl,sourceflc,destfl,destflc,
809  *itag,outtag,since,until,timestamp,checkrefs,iscora,
810  spaymode,created);
811  }
812  if (retcode!=0) {
813  std::cout << "ERROR operation failed for folder " << folder << " tag " <<
814  *itag << std::endl;
815  return retcode;
816  }
817  }
818  return 0;
819 }
820 
821 void AtlCoolCopy::setChannelRange(const cool::IFolderPtr& sourcefl) {
822  // add range specified via -ch1 -ch2 if given
823  if (!m_channel1.empty() && !m_channel2.empty()) {
824  m_channelRange.clear();
825  m_channelRange.push_back(m_channel1+":"+m_channel2);
826  }
828  const size_t nChanRange=m_channelRange.size();
829  for (size_t i=0;i<nChanRange;i++) {
830  size_t cpos=m_channelRange[i].find(':');
831  if (cpos==std::string::npos || cpos > m_channelRange[i].size()-1) {
832  // single channel
833  std::cout << "Adding channel " << m_channelRange[i] <<
834  " to channel selection" << std::endl;
835  if (m_chansel.allChannels())
836  m_chansel=cool::ChannelSelection(channelID(sourcefl,
837  m_channelRange[i]));
838  else
839  m_chansel.addChannel(channelID(sourcefl,m_channelRange[i]));
840  }
841  else {
842  // Channel Range
843  std::string c1=m_channelRange[i].substr(0,cpos);
844  std::string c2=m_channelRange[i].substr(1+cpos);
845  std::cout << "Adding channel range " << c1 << " to " << c2 <<
846  " to channel selection" << std::endl;
847  if (m_chansel.allChannels())
848  m_chansel=cool::ChannelSelection(channelID(sourcefl,c1),
849  channelID(sourcefl,c2));
850  else
851  m_chansel.addRange(channelID(sourcefl,c1),channelID(sourcefl,c2));
852  }
853  }//end loop over channel ranges
854 }
855 
856 cool::ChannelId AtlCoolCopy::channelID(const cool::IFolderPtr& folder,
857  const std::string& chanstring) {
858  const char* cstr=chanstring.c_str();
859  if (isNumeric(cstr)) {
860  // channel is a number
861  return cool::ChannelId(strtoul(cstr,nullptr,10));
862  } else {
863  cool::ChannelId chan=0;
864  try {
865  chan=folder->channelId(chanstring);
866  std::cout << "Channel name " << chanstring << " maps to channelID "
867  << chan << std::endl;
868  }
869  catch (cool::Exception& e) {
870  std::cout << "ERROR: Channel name " << chanstring <<
871  " not defined in folder " << std::endl;
872  }
873  return chan;
874  }
875 }
876 
877 // Calls non-thread-safe functions of CoraCoolFolder.
878 int AtlCoolCopy::copyIOVs ATLAS_NOT_THREAD_SAFE
879  (const std::string& folder,
880  const std::string& destfolder,
881  const cool::IFolderPtr& sourcefl,const CoraCoolFolderPtr& sourceflc,
882  const cool::IFolderPtr& destfl,const CoraCoolFolderPtr& destflc,
883  const std::string& sourcetag,const std::string& desttag,
884  const cool::ValidityKey since,const cool::ValidityKey until,
885  bool timestamp,bool checkrefs,bool iscora,
886  const cool::PayloadMode::Mode paymode ,bool created) {
887 
888  std::cout << "Copying tag " << sourcetag << " of folder " << folder <<
889  " to destination tag " << desttag << std::endl;
890  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
891  cool::FolderVersioning::Mode dvermode=destfl->versioningMode();
892  // check for online mode
893  int updatemode=getUpdateMode(destfl->description(),desttag);
894  std::vector<std::string> dtaglist=destfl->listTags();
895  // if online mode, must have --getonline and either -truncate or -alliov
896  // only if destination DB is oracle
897  if (updatemode==1 && m_destdb.find("oracle")!=std::string::npos &&
898  (!m_getonline || (!m_truncate && !m_alliov))) {
899  if (m_ignoremode) {
900  std::cout << "Folder is online (UPD1) mode but IGNORING PROTECTION"
901  << std::endl;
902  } else {
903  if(find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
904  std::cout << "Folder is online mode (UPD1) and tag already exist - -getonline and -truncate or -alliov options MUST be used" << std::endl;
905  return 35;
906  }
907  else {
908  std::cout << "Folder is online mode (UPD1), new tag will be created" << std::endl;
909  }
910 
911  }
912  }
913  // if UPD4 mode, must have -getbulk and either -truncate or -alliov
914  if (updatemode==4 && m_destdb.find("oracle")!=std::string::npos &&
915  (!m_getbulk || (!m_truncate && !m_alliov))) {
916  if (m_ignoremode) {
917  std::cout << "Folder is bulkreco (UPD4) mode but IGNORING PROTECTION"
918  << std::endl;
919  } else {
920  if(find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()) {
921  std::cout << "Folder is bulkreco mode (UPD4) - -getbulk and -truncate or -alliov options MUST be used" << std::endl;
922  return 35;
923  } else {
924  std::cout << "Folder is bulkreco mode (UPD4), new tag will be created" << std::endl;
925  }
926 
927  }
928  }
929 
930  // if destination tags are being checked, check if this tag already
931  // exists in destination folder, if so skip copy
932  // also skip if tag is HEAD, and folder was not newly created
933  if (m_checkdesttag) {
934  if (find(dtaglist.begin(),dtaglist.end(),desttag)!=dtaglist.end()
935  || (desttag=="HEAD" && !created)) {
936  std::cout << "Destination tag " << desttag <<
937  " already exists in folder " << folder << " - skip copy" << std::endl;
938  return 0;
939  }
940  }
941  bool relock=false; // tag must be relocked afterwards
942  bool prot=false; //update is protected, irrespective of if tag must be locked
943  if ((m_applock || (updatemode==1 && m_getonline) || updatemode==2 ||
944  (updatemode==4 && m_getbulk)) &&
945  dvermode==cool::FolderVersioning::MULTI_VERSION) {
946  // check if the destination tag exists and is locked
947  std::vector<std::string> dtaglist=destfl->listTags();
948  for (std::vector<std::string>::const_iterator itr=dtaglist.begin();
949  itr!=dtaglist.end();++itr) {
950  if (desttag==*itr) {
951  // tag exists - must protect it unless ignoremode
952  prot=!m_ignoremode;
953  // check lock status
954  if (destfl->tagLockStatus(desttag)==cool::HvsTagLock::LOCKED) {
955  std::cout << "Unlocking destination tag " << desttag <<
956  " for append or UPDx access" << std::endl;
957  if (m_applocksv) {
958  std::cout << "Appending according to SV folder rules" << std::endl;
959  if (updatemode!=3) {
960  std::cout <<
961  "ERROR: Only allowed for UPD3 mode tags" << std::endl;
962  return 36;
963  }
964  }
965  destfl->setTagLockStatus(desttag,cool::HvsTagLock::UNLOCKED);
966  relock=true;
967  }
968  }
969  }
970  }
971  int nobj=0;
972  int nbuf=0;
973  int nskip=0;
974  int nbad=0;
975  // set up tag to be used at point of insertion
976  std::string localtag="";
977  if (dvermode==cool::FolderVersioning::MULTI_VERSION &&
978  desttag!="HEAD" && m_usertags) localtag=desttag;
979  // now loop over IOVs - separate for CoraCool and COOL
980  try {
981  if (iscora) {
982  // branch for CoraCool
983  sourceflc->setPrefetchAll(false);
984  CoraCoolObjectIterPtr sourceitr;
985  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
986  sourceitr=sourceflc->browseObjects(since,until,m_chansel);
987  } else {
988  sourceitr=sourceflc->browseObjects(since,until,m_chansel,sourcetag);
989  }
990  // keep track of new FKs of inserted objects
991  std::map<int,int> insertkeymap;
992  unsigned int nref=0;
993  while (sourceitr->hasNext()) {
994  CoraCoolObjectPtr obj=sourceitr->next();
995  // check object should not be skipped as spreading outside select-IOV
996  if (m_skipout &&
997  (obj->since()<m_srunemin || obj->until()>m_srunemax)) {
998  ++nskip;
999  continue;
1000  }
1001  // check object should not be skipped as excluded channel
1002  if (!m_excludechans.empty()) {
1003  if (find(m_excludechans.begin(),m_excludechans.end(),
1004  obj->channelId())!=m_excludechans.end()) {
1005  ++nskip;
1006  continue;
1007  }
1008  }
1009  if (nbuf==0) {
1010  if (m_debug) std::cout <<
1011  "Setup new CoraCool storage buffer at object " << nobj << std::endl;
1012  destflc->setupStorageBuffer();
1013  }
1014  cool::ValidityKey newsince,newuntil;
1015  adjustIOVs(obj->since(),obj->until(),since,until,newsince,newuntil,
1016  timestamp);
1017  // skip negative/zero IOV lengths
1018  if (newsince>=newuntil) {
1019  std::cout << "WARNING: Skipping IOV with since " << newsince <<
1020  ">= until" << newuntil << std::endl;
1021  ++nbad;
1022  continue;
1023  }
1024  // find the old FK, check if we have already inserted this
1025  // in which case a reference can be added
1026  int oldfk=0;
1027  std::map<int,int>::const_iterator ikey=insertkeymap.end();
1028  bool foundkey=false;
1029  // ensure returned data is not of zero size - if so cannot extract
1030  // and remember the FK
1031  if (obj->size()>0) {
1032  oldfk=sourceflc->getAttrKey(
1033  (*obj->begin())[sourceflc->coralFKey()]);
1034  ikey=insertkeymap.find(oldfk);
1035  foundkey=true;
1036  }
1037  if (ikey==insertkeymap.end()) {
1038  int newfk=
1039  destflc->storeObject(newsince,newuntil,obj->begin(),obj->end(),
1040  obj->channelId(),localtag,
1041  (!m_userupdatehead && !localtag.empty()));
1042  if (foundkey) insertkeymap[oldfk]=newfk;
1043  } else {
1044  destflc->referenceObject(newsince,newuntil,ikey->second,
1045  obj->channelId(),localtag,
1046  (!m_userupdatehead && !localtag.empty()));
1047  ++nref;
1048  }
1049  ++nbuf;
1050  // flush buffer every m_bufsize objects
1051  if (nbuf==m_bufsize) {
1052  if (m_debug) std::cout << "Flush buffer after " << nobj << "," <<
1053  nbuf << " objects " << std::endl;
1054  // note CoraCool requires explicit re-setup of buffer after a flush
1055  destflc->flushStorageBuffer();
1056  destflc->setupStorageBuffer();
1057  nbuf=0;
1058  }
1059  ++nobj;
1060  }
1061  sourceitr->close();
1062  if (nref>0) std::cout << "Reference-to-existing used for " << nref
1063  << " payload objects" << std::endl;
1064  if (nbuf>0) {
1065  if (m_debug) std::cout << "Final buffer flush at " << nobj <<
1066  "," << nbuf << std::endl;
1067  destflc->flushStorageBuffer();
1068  }
1069  } else {
1070  // branch for pure COOL objects
1071  cool::IObjectIteratorPtr sourceitr;
1072  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1073  sourceitr=sourcefl->browseObjects(since,until,m_chansel);
1074  } else {
1075  sourceitr=sourcefl->browseObjects(since,until,m_chansel,sourcetag);
1076  }
1077  while (sourceitr->goToNext()) {
1078  const cool::IObject& obj=sourceitr->currentRef();
1079  // check object should not be skipped as spreading outside select-IOV
1080  if (m_skipout && (obj.since()<m_srunemin || obj.until()>m_srunemax)) {
1081  ++nskip;
1082  continue;
1083  }
1084  // check object should not be skipped as excluded channel
1085  if (!m_excludechans.empty()) {
1086  if (find(m_excludechans.begin(),m_excludechans.end(),
1087  obj.channelId())!=m_excludechans.end()) {
1088  ++nskip;
1089  continue;
1090  }
1091  }
1092  if (nbuf==0) {
1093  if (m_debug) std::cout << "Setup new storage buffer at object " <<
1094  nobj << std::endl;
1095  destfl->setupStorageBuffer();
1096  }
1097  cool::ValidityKey newsince;
1098  cool::ValidityKey newuntil;
1099  adjustIOVs(obj.since(),obj.until(),since,until,newsince,newuntil,
1100  timestamp);
1101  // skip negative/zero IOV lengths
1102  if (newsince>=newuntil) {
1103  std::cout << "WARNING: Skipping IOV with since " << newsince <<
1104  ">= until" << newuntil << std::endl;
1105  ++nbad;
1106  continue;
1107  }
1108  if (checkrefs) checkRef(obj.payload(),folder,sourcetag);
1109  if (prot) {
1110  // check existing data in destination DB to ensure no clash
1111  if (m_applocksv) {
1112  // appendlockedsv mode - all IOV ends must be infinite
1113  // and new since must be greater than old since
1114  if (newuntil!=cool::ValidityKeyMax) {
1115  std::cout << "New IOVs must have until=cool::ValidityKeyMax" << std::endl;
1116  throw cool::Exception("Illegal insert over locked IOV",
1117  "AtlCoolCopy");
1118  }
1119  cool::IObjectIteratorPtr checkitr=destfl->browseObjects(newsince,
1120  newuntil,obj.channelId(),desttag);
1121  while (checkitr->goToNext()) {
1122  const cool::IObject& checkobj=checkitr->currentRef();
1123  if (checkobj.since()>=newsince) {
1124  std::cout << "ERROR:: Attempt to insert SV overlapping IOV whilst appending to locked tag" << std::endl;
1125  throw cool::Exception("Illegal insert over locked IOV",
1126  "AtlCoolCopy");
1127  }
1128  if (checkobj.until()!=cool::ValidityKeyMax) {
1129  std::cout << "Existing IOVs must have until=cool::ValidityKeyMax" << std::endl;
1130  throw cool::Exception("Illegal insert over locked IOV",
1131  "AtlCoolCopy");
1132  }
1133  }
1134  checkitr->close();
1135  } else if (m_applock) {
1136  // appendlocked mode - just make sure no objects in this IOV
1137  const unsigned int nexist=
1138  destfl->countObjects(newsince,newuntil,obj.channelId(),desttag);
1139  if (nexist>0) {
1140  std::cout << "ERROR: Attempt to insert IOV over " << nexist <<
1141  " objects whilst appending to locked tag" << std::endl;
1142  throw cool::Exception("Illegal insert over locked IOV",
1143  "AtlCoolCopy");
1144  }
1145  } else if (updatemode==2) {
1146  // UPD2 tag - make sure run is on list of runs open for update
1147  // only for run/lumi based folders
1148  if (timestamp)
1149  throw cool::Exception(
1150  "Attempt to insert into locked UPD2 tag with timestamp format",
1151  "AtlCoolCopy");
1152  unsigned int run1=newsince >> 32;
1153  unsigned int run2=(newuntil-1) >> 32;
1154  for (unsigned int irun=run1;irun<=run2;++irun) {
1155  if (!std::binary_search(m_runlist.begin(),m_runlist.end(),irun))
1156  {
1157  std::cout << "Run " << irun << " from range [" << run1 << ","
1158  << run2 << "] not found in runfile list" << std::endl;
1159  throw cool::Exception("Illegal insert over locked IOV",
1160  "AtlCoolCopy");
1161  }
1162  }
1163  }
1164  // updatemode==1 will fall through, but no checks are done here
1165  }
1166  if (paymode==cool::PayloadMode::VECTORPAYLOAD) {
1167  // cool vector payload object copy
1168  cool::IRecordIterator& pitr=obj.payloadIterator();
1169  const cool::IRecordVectorPtr vptr=pitr.fetchAllAsVector();
1170  destfl->storeObject(newsince,newuntil,
1171  *vptr,obj.channelId(),localtag,
1172  (!m_userupdatehead && !localtag.empty()));
1173  nbuf+=vptr->size();
1174  pitr.close();
1175  } else {
1176  // standard COOL object copy
1177  destfl->storeObject(newsince,newuntil,
1178  obj.payload(),obj.channelId(),localtag,
1179  (!m_userupdatehead && !localtag.empty()));
1180  ++nbuf;
1181  }
1182  // flush buffer every m_bufsize objects
1183  if (nbuf>=m_bufsize) {
1184  if (m_debug) std::cout << "Flush buffer after " << nobj << "," <<
1185  nbuf << " objects " << std::endl;
1186  destfl->flushStorageBuffer();
1187  nbuf=0;
1188  }
1189  ++nobj;
1190  }
1191  // finished with the iterator
1192  sourceitr->close();
1193  if (nbuf>0) {
1194  if (m_debug) std::cout << "Final buffer flush at " << nobj <<
1195  "," << nbuf << std::endl;
1196  destfl->flushStorageBuffer();
1197  } // end of COOL-specific part
1198  }
1199  std::cout << "Folder copied with " << nobj << " objects" << std::endl;
1200  if (nskip>0) std::cout << nskip <<
1201  " objects were skipped extending outside IOV selection or excluded channel"
1202  << std::endl;
1203  if (nbad>0) std::cout << nbad <<
1204  " objects were skipped having zero or negative IOV lengths" << std::endl;
1205  }
1206  // exceptions thrown from insert loop (both COOL or CORACOOL)
1207  catch (cool::Exception& e) {
1208  std::cout << "Exception thrown from copy loop: " << e.what() <<
1209  std::endl;
1210  if (relock) {
1211  std::cout << "Relocking destination tag " << desttag << std::endl;
1212  destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1213  }
1214  return 31;
1215  }
1216  // check if tag needs to be relocked
1217  if (relock) {
1218  std::cout << "Relocking destination tag " << desttag << std::endl;
1219  destfl->setTagLockStatus(desttag,cool::HvsTagLock::LOCKED);
1220  }
1221 
1222  if (dvermode==cool::FolderVersioning::MULTI_VERSION && desttag!="HEAD") {
1223  if (!m_usertags) {
1224  // apply HEAD style tagging
1225  std::cout << "Tag folder with HEAD-style tagging for tag: " << desttag
1226  << std::endl;
1227  try {
1228  destfl->tagCurrentHead(desttag,sourcefl->tagDescription(sourcetag));
1229  }
1230  catch (cool::Exception& e) {
1231  std::cout << "Exception thrown in HEAD-style folder-tag: " <<
1232  e.what() << std::endl;
1233  return 32;
1234  }
1235  }
1236  // record information about this tag for later
1237  if (m_copytaginfo) m_cooltagmap.insert(
1238  CoolTagMap::value_type(desttag,CoolTagInfo(m_sourceDbPtr,folder,
1239  destfolder,sourcetag,desttag,m_taglabel)));
1240  // check if any hierarchical tags reference the just-copied tag
1241  if (!m_hitagmap.empty()) {
1242  for (HiTagMap::const_iterator imap=m_hitagmap.begin();
1243  imap!=m_hitagmap.end();++imap) {
1244  try {
1245  if (sourcefl->findTagRelation(imap->first)==sourcetag) {
1246  std::cout << "Create hierarchical tag between " << desttag <<
1247  " and " << imap->first << " in folder " << imap->second <<
1248  std::endl;
1249  // first check this relation has not already been created
1250  try {
1251  std::string etag=destfl->resolveTag(imap->first);
1252  if (etag==desttag) {
1253  std::cout << "This relation has already been created" << std::endl;
1254  } else {
1255  std::cout << "ERROR: Tag in parent already related to " <<
1256  desttag << std::endl;
1257  }
1258  }
1259  catch (cool::Exception& e ) {
1260  // only do creation if does not already exist - via exception
1261  try {
1262  destfl->createTagRelation(imap->first,desttag);
1263  // check if this implicates a new parent folder
1264  // to be checked for further tags up the tree
1265  if (find(m_hiparent.begin(),m_hiparent.end(),imap->second)==
1266  m_hiparent.end()) m_hiparent.push_back(imap->second);
1267  // store the original tag information to transfer
1268  // properties later
1269  if (m_copytaginfo &&
1270  m_cooltagmap.find(imap->first)==m_cooltagmap.end())
1271  m_cooltagmap.insert(CoolTagMap::value_type(imap->first,
1272  CoolTagInfo(m_sourceDbPtr,imap->second,imap->second,
1273  imap->first,imap->first)));
1274  }
1275  catch (cool::Exception& e) {
1276  std::cout << "Cool exception " << e.what() <<
1277  "thrown in hierarchical tag creation" << std::endl;
1278  return 34;
1279  }
1280  }
1281  }
1282  }
1283  catch (cool::Exception& e) {
1284  }
1285  }
1286  }
1287  }
1288  return 0;
1289 }
1290 
1291 void AtlCoolCopy::adjustIOVs(const cool::ValidityKey& since,
1292  const cool::ValidityKey& until,
1293  const cool::ValidityKey& qsince,
1294  const cool::ValidityKey& quntil,
1295  cool::ValidityKey& newsince,
1296  cool::ValidityKey& newuntil,
1297  bool timestamp) const {
1298  // set newsince/until to since/until
1299  // but doing any required truncation/adjustment
1300  newsince=since;
1301  newuntil=until;
1302  if (m_alliov) {
1303  // make IOV cover specified range
1304  if (timestamp) {
1305  newsince=m_newtimemin;
1306  newuntil=m_newtimemax;
1307  } else {
1308  newsince=m_newrunemin;
1309  newuntil=m_newrunemax;
1310  }
1311  }
1312  // check for IOV truncation to range of query
1313  if (m_truncate) {
1314  if (newsince<qsince) newsince=qsince;
1315  if (newuntil>quntil) newuntil=quntil;
1316  }
1317  // check not requesting an IOV with negative length
1318  if (newuntil<newsince) throw cool::Exception(
1319  "Attempt to insert IOV with -ve length","AtlCoolCopy::adjustIOVs");
1320 }
1321 
1322 int AtlCoolCopy::nocopyIOVs(const std::string& folder,
1323  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
1324  const cool::ValidityKey since,const cool::ValidityKey until,
1325  bool checkrefs) {
1326 
1327  std::cout << "Reading tag " << sourcetag << " of folder " << folder <<
1328  " (no copy)" << std::endl;
1329  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
1330  int nobj=0;
1331  cool::IObjectIteratorPtr sourceitr;
1332  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1333  sourceitr=sourcefl->browseObjects(since,until,m_chansel);
1334  } else {
1335  sourceitr=sourcefl->browseObjects(since,until,m_chansel,sourcetag);
1336  }
1337  try {
1338  while (sourceitr->goToNext()) {
1339  const cool::IObject& obj=sourceitr->currentRef();
1340  if (checkrefs) checkRef(obj.payload(),folder,sourcetag);
1341  ++nobj;
1342  }
1343  std::cout << "Folder scanned with " << nobj << " objects" << std::endl;
1344  }
1345  // exceptions thrown from read loop
1346  catch (cool::Exception& e) {
1347  std::cout << "Exception thrown from read loop: " << e.what() <<
1348  std::endl;
1349  return 33;
1350  }
1351  // finished with the iterator
1352  sourceitr->close();
1353  return 0;
1354 }
1355 
1356 int AtlCoolCopy::verifyIOVs(const std::string& folder,
1357  const cool::IFolderPtr& sourcefl,const CoraCoolFolderPtr& sourceflc,
1358  const cool::IFolderPtr& destfl,const CoraCoolFolderPtr& destflc,
1359  const std::string& sourcetag,
1360  const cool::ValidityKey since,const cool::ValidityKey until,
1361  const bool checkrefs,const bool iscora,
1362  const cool::PayloadMode::Mode paymode) {
1363 
1364  std::cout << "Verifying tag " << sourcetag << " of folder " << folder <<
1365  std::endl;
1366  destfl->setPrefetchAll(false);
1367  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
1368  int nobj=0;
1369  cool::IObjectIteratorPtr sourceitr,destitr;
1370  CoraCoolObjectIterPtr csourceitr,cdestitr;
1371  std::string tag=sourcetag;
1372  if (vermode==cool::FolderVersioning::SINGLE_VERSION || sourcetag=="HEAD")
1373  tag="";
1374  try {
1375  if (iscora) {
1376  sourceflc->setPrefetchAll(false);
1377  csourceitr=sourceflc->browseObjects(since,until,m_chansel,tag);
1378  cdestitr=destflc->browseObjects(since,until,m_chansel,tag);
1379  } else {
1380  sourceitr=sourcefl->browseObjects(since,until,m_chansel,tag);
1381  destitr=destfl->browseObjects(since,until,m_chansel,tag);
1382  }
1383  }
1384  catch (std::exception& e) {
1385  std::cout << "Exception thrown from verify iterator setup: " << e.what() <<
1386  std::endl;
1387  return 105;
1388  }
1389  try {
1390  // the check algorithm assumes the two databases will give back the
1391  // results of the query in the same order, which is currently the
1392  // case in COOL 1.3. If this changes, the verification will be more complex
1393  if (iscora) {
1394  const std::string& cfkey=sourceflc->coralFKey();
1395  const std::string& cpkey=sourceflc->coralPKey();
1396  while (csourceitr->hasNext()) {
1397  CoraCoolObjectPtr sobj=csourceitr->next();
1398  // check object should not be skipped as excluded channel
1399  if (!m_excludechans.empty()) {
1400  if (find(m_excludechans.begin(),m_excludechans.end(),
1401  sobj->channelId())!=m_excludechans.end()) {
1402  continue;
1403  }
1404  }
1405  if (cdestitr->hasNext()) {
1406  CoraCoolObjectPtr dobj=cdestitr->next();
1407  // check objects are the same
1408  int iret=0;
1409  // check IOV equality
1410  if (sobj->since()!=dobj->since() || sobj->until()!=dobj->until())
1411  iret=100;
1412  // check channel equality
1413  if (sobj->channelId()!=dobj->channelId())
1414  iret=101;
1415  // check size of payloads
1416  if (sobj->size()!=dobj->size()) {
1417  std::cout << "ERROR CoraCool object " << nobj <<
1418  " sizes do not match: " << sobj->size() << " " << dobj->size()
1419  << std::endl;
1420  iret=102;
1421  }
1422  // check payload equality (does not check attribute names)
1423  CoraCoolObject::const_iterator ditr=dobj->begin();
1424  for (CoraCoolObject::const_iterator sitr=sobj->begin();
1425  sitr!=sobj->end();++sitr,++ditr) {
1426  // loop over all the attributes, in order to skip PK and FK
1427  for (coral::AttributeList::const_iterator aitr=sitr->begin();
1428  aitr!=sitr->end();++aitr) {
1429  const std::string& aname=aitr->specification().name();
1430  if (aname!=cfkey && aname!=cpkey) {
1431  try {
1432  if (*aitr!=(*ditr)[aname]) {
1433  std::cout << "ERROR Values of attriute " << aname <<
1434  " differ" << std::endl;
1435  iret=102;
1436  }
1437  }
1438  catch (coral::AttributeListException& e) {
1439  std::cout << "ERROR: CoraCool attribute " << aname <<
1440  " not found in destination!" << std::endl;
1441  iret=102;
1442  }
1443  }
1444  }
1445  }
1446  if (iret!=0) {
1447  std::cout << "ERROR database entries do not match: since: " <<
1448  sobj->since() << "," << dobj->since() << " until: " <<
1449  sobj->until() << "," << dobj->until() << " channel: " <<
1450  sobj->channelId() << "," << dobj->channelId() << std::endl;
1451  return iret;
1452  }
1453  } else {
1454  std::cout <<
1455  "ERROR destination folder no matching CoraCool iterator for object "
1456  << nobj << std::endl;
1457  return 103;
1458  }
1459  ++ nobj;
1460  }
1461  } else {
1462  while (sourceitr->goToNext()) {
1463  const cool::IObject& sobj=sourceitr->currentRef();
1464  // check object should not be skipped as excluded channel
1465  if (!m_excludechans.empty()) {
1466  if (find(m_excludechans.begin(),m_excludechans.end(),
1467  sobj.channelId())!=m_excludechans.end()) {
1468  continue;
1469  }
1470  }
1471  if (checkrefs) checkRef(sobj.payload(),folder,sourcetag);
1472  if (destitr->goToNext()) {
1473  const cool::IObject& dobj=destitr->currentRef();
1474  // check objects are the same
1475  int iret=0;
1476  // check IOV equality
1477  if (sobj.since()!=dobj.since() || sobj.until()!=dobj.until())
1478  iret=100;
1479  // check channel equality
1480  if (sobj.channelId()!=dobj.channelId())
1481  iret=101;
1482  // check payload equality (does not check attribute names)
1483  // do not use cool::IRecord equality operator as does not correctly
1484  // handle null values
1485  if (paymode==cool::PayloadMode::VECTORPAYLOAD) {
1486  cool::IRecordIterator& spitr=sobj.payloadIterator();
1487  const cool::IRecordVectorPtr svptr=spitr.fetchAllAsVector();
1488  cool::IRecordIterator& dpitr=dobj.payloadIterator();
1489  const cool::IRecordVectorPtr dvptr=dpitr.fetchAllAsVector();
1490  if (svptr->size()!=dvptr->size()) {
1491  iret=102;
1492  } else {
1493  // loop through the payloads, checking equality - assumes
1494  // order is significant and same in source and destination DBs
1495  cool::IRecordVector::const_iterator svitr=svptr->begin();
1496  cool::IRecordVector::const_iterator svend=svptr->end();
1497  cool::IRecordVector::const_iterator dvitr=dvptr->begin();
1498  for (;svitr!=svend;++svitr,++dvitr) {
1499  if (!equalRecord(**svitr,**dvitr)) iret=102;
1500  }
1501  }
1502  if (iret!=0) {
1503  std::cout << "ERROR vector payloads do not match (size " << svptr->size() << "," << dvptr->size() << ")" << std::endl;
1504  }
1505 
1506  } else {
1507  // standard COOL folder - simple check of payloads
1508  if (!equalRecord(sobj.payload(),dobj.payload())) iret=102;
1509  }
1510 
1511  if (iret!=0) {
1512  std::cout << "ERROR database entries do not match: since: " <<
1513  sobj.since() << "," << dobj.since() << " until: " <<
1514  sobj.until() << "," << dobj.until() << " channel: " <<
1515  sobj.channelId() << "," << dobj.channelId() << std::endl;
1516  std::cout << "Source payload:" << std::endl;
1517  sobj.payload().attributeList().toOutputStream(std::cout);
1518  std::cout << std::endl << "Destination payload:" << std::endl;
1519  dobj.payload().attributeList().toOutputStream(std::cout);
1520  std::cout << std::endl;
1521  return iret;
1522  }
1523  } else {
1524  std::cout <<
1525  "ERROR destination folder no matching iterator for object "
1526  << nobj << std::endl;
1527  return 103;
1528  }
1529  ++nobj;
1530  }
1531  }
1532  }
1533  catch (cool::Exception& e) {
1534  std::cout << "Exception thrown from verify loop: " << e.what() <<
1535  std::endl;
1536  return 104;
1537  }
1538  // finished with the iterators
1539  if (iscora) {
1540  } else {
1541  sourceitr->close();
1542  destitr->close();
1543  }
1544  std::cout << "Verification of folder " << folder << " tag " <<
1545  sourcetag << " OK (" << nobj << " objects)" << std::endl;
1546  return 0;
1547 }
1548 
1549 
1550 
1551 int AtlCoolCopy::rootIOVs(const std::string& folder,
1552  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
1553  const cool::ValidityKey since,const cool::ValidityKey until,
1554  const bool timestamp) {
1555  // copy this selection to ROOT
1556  std::cout << "Write tag " << sourcetag << " of folder " << folder <<
1557  " to ROOT file" << std::endl;
1558  // create the directory structure - top directory COOL
1559  std::string treename=rootDirs(folder,"COOL");
1560  bool timestamp2=timestamp;
1561  if (m_forcetime) timestamp2=true;
1562  if (m_forcerune) timestamp2=false;
1563  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
1564  // create TTree with appropriate structure - only if it does not exist
1565  // could have been created from a previous tag in the same folder
1566  TTree* tree=static_cast<TTree*>(gDirectory->FindObject(treename.c_str()));
1567  if (tree==nullptr) {
1568  std::cout << "Book TTree " << treename << std::endl;
1569  tree=new TTree(treename.c_str(),"COOL datadump");
1570  if (timestamp2) {
1571  tree->Branch("IOVSince",&m_nt_since,"IOVSince/l");
1572  tree->Branch("IOVUntil",&m_nt_until,"IOVUntil/l");
1573  } else {
1574  tree->Branch("RunSince",&m_nt_runsince,"RunSince/i");
1575  tree->Branch("RunUntil",&m_nt_rununtil,"RunUntil/i");
1576  tree->Branch("LBSince",&m_nt_lbsince,"LBSince/i");
1577  tree->Branch("LBUntil",&m_nt_lbuntil,"LBUntil/i");
1578  }
1579  tree->Branch("ChannelID",&m_nt_channel,"ChannelID/i");
1580  if (vermode==cool::FolderVersioning::MULTI_VERSION)
1581  tree->Branch("TagID",m_nt_tagid,"TagID/C");
1582  // now loop through specification, creating payload buffer and tree
1583  const cool::IRecordSpecification& spec=
1584  (sourcefl->folderSpecification()).payloadSpecification();
1585  unsigned int ncolumns=spec.size();
1586  // clear the buffer of pointers - note this leaks the memory of the
1587  // previous buffers, but to do this properly would have to remember
1588  // the type of each object and delete appropriately
1589  m_nt_treename=treename;
1590  m_nt_bufferptr.clear();
1591  for (unsigned int icol=0;icol<ncolumns;++icol) {
1592  const cool::IFieldSpecification& fieldspec=spec[icol];
1593  void* ptr=nullptr;
1594  char rootID;
1595  if (rootAllocate(fieldspec,ptr,rootID)) {
1596  tree->Branch(fieldspec.name().c_str(),ptr,
1597  (fieldspec.name()+"/"+rootID).c_str());
1598  if (m_debug) std::cout << "Defining column for " << spec[icol].name()
1599  << " of type " << spec[icol].storageType().name() << std::endl;
1600  } else {
1601  std::cout << "Attribute " << spec[icol].name() << " of type " <<
1602  spec[icol].storageType().name() << " will be skipped" << std::endl;
1603  }
1604  m_nt_bufferptr.push_back(ptr);
1605  }
1606  } else {
1607  std::cout << "TTree " << treename << " already exists" << std::endl;
1608  // check we have seen and defined this tree
1609  unsigned int size=
1610  (sourcefl->folderSpecification()).payloadSpecification().size();
1611  if (treename!=m_nt_treename || size!=m_nt_bufferptr.size()) {
1612  std::cout << "ERROR in tree buffer definition: expect " << treename <<
1613  " size " << size << " but buffer has " << m_nt_treename << " size "
1614  << m_nt_bufferptr.size() << std::endl;
1615  return 123;
1616  }
1617  }
1618 
1619  int nobj=0;
1620  int nex=0;
1621  cool::IObjectIteratorPtr sourceitr;
1622  try {
1623  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1624  sourceitr=sourcefl->browseObjects(since,until,m_chansel);
1625  } else {
1626  sourceitr=sourcefl->browseObjects(since,until,m_chansel,sourcetag);
1627  }
1628  }
1629  catch (cool::Exception& e) {
1630  std::cout << "Exception thrown from ROOT copy iterator setup: " <<
1631  e.what() << std::endl;
1632  return 125;
1633  }
1634  // now loop over all IOVs to copy them
1635  try {
1636  while (sourceitr->goToNext()) {
1637  const cool::IObject& sobj=sourceitr->currentRef();
1638  if (timestamp2) {
1639  m_nt_since=sobj.since();
1640  m_nt_until=sobj.until();
1641  } else {
1642  m_nt_runsince=(sobj.since() >> 32);
1643  m_nt_rununtil=(sobj.until() >> 32);
1644  m_nt_lbsince=(sobj.since() & 0xFFFFFFFF);
1645  m_nt_lbuntil=(sobj.until() & 0xFFFFFFFF);
1646  }
1647  m_nt_channel=sobj.channelId();
1648  if (vermode==cool::FolderVersioning::MULTI_VERSION) {
1649  // truncate the string first to avoid coverity complaining about
1650  // potential buffer overruns
1651  std::string sourcetag2=sourcetag.substr(0,255);
1652  strncpy(m_nt_tagid,sourcetag2.c_str(),sizeof(m_nt_tagid)-1);
1653  }
1654  // loop over the payload elements and fill the ones for which buffers
1655  // are defined
1656  try {
1657  const cool::IRecord& record=sobj.payload();
1658  for (unsigned int icol=0;icol<record.size();++icol) {
1659  if (m_nt_bufferptr[icol]!=nullptr) rootWrite(m_nt_bufferptr[icol],record[icol]);
1660  }
1661  tree->Fill();
1662  ++nobj;
1663  }
1664  catch (cool::Exception& e) {
1665  // can get exceptions due to NULL values
1666  // catch them and continue...
1667  ++nex;
1668  }
1669  }
1670  sourceitr->close();
1671  std::cout << "Written " << nobj << " objects to ROOT TTree with " << nex
1672  << " nulls/exceptions" << std::endl;
1673  }
1674  catch (cool::Exception& e) {
1675  std::cout << "Exception thrown from ROOT file writing loop: " <<
1676  e.what() << std::endl;
1677  return 124;
1678  }
1679  return 0;
1680 }
1681 
1682 std::string AtlCoolCopy::rootDirs(const std::string& folder,
1683  const std::string& toproot) {
1684  // create a ROOT directory structure start with toproot (=COOL or COOLANA)
1685  // and cd to the directory where a tree should be created
1686  // return the tree name (=leaf of the COOL foldername)
1687  p_rootfile->cd();
1688  if (p_rootfile->FindObject(toproot.c_str())==nullptr) {
1689  p_rootfile->mkdir(toproot.c_str());
1690  std::cout << "Made top directory " << toproot << std::endl;
1691  }
1692  gDirectory->cd(toproot.c_str());
1693  // now parse the COOL folder name to create intermediate directories
1694  // assume folder names begin with '/', to be skipped
1695  std::string::size_type iofs1=1;
1696  std::string::size_type iofs2=1;
1697  std::string treename;
1698  while (iofs2!=std::string::npos) {
1699  iofs2=folder.find('/',iofs1);
1700  if (iofs2==std::string::npos) {
1701  // no more /, so current part of string is leaf tree name
1702  treename=folder.substr(iofs1);
1703  } else {
1704  std::string dirname=folder.substr(iofs1,iofs2-iofs1);
1705  iofs1=iofs2+1;
1706  if (gDirectory->FindObject(dirname.c_str())==nullptr) {
1707  std::cout << "Make directory " << dirname << std::endl;
1708  gDirectory->mkdir(dirname.c_str());
1709  }
1710  gDirectory->cd(dirname.c_str());
1711  }
1712  }
1713  return treename;
1714 }
1715 
1716 bool AtlCoolCopy::rootAllocate(const cool::IFieldSpecification& spec,
1717  void*& sptr,char& rootID) const {
1718  const cool::StorageType& stype=spec.storageType();
1719  rootID=' ';
1720  sptr=nullptr;
1721  if (stype==cool::StorageType::Bool) {
1722  // map bool to uint32 for now
1723  sptr=static_cast<void*>(new unsigned int(0));
1724  rootID='i';
1725  } else if (stype==cool::StorageType::UChar) {
1726  sptr=static_cast<void*>(new unsigned char(' '));
1727  rootID='C';
1728  } else if (stype==cool::StorageType::Int16) {
1729  sptr=static_cast<void*>(new short(0));
1730  rootID='S';
1731  } else if (stype==cool::StorageType::UInt16) {
1732  sptr=static_cast<void*>(new unsigned short(0));
1733  rootID='s';
1734  } else if (stype==cool::StorageType::Int32) {
1735  sptr=static_cast<void*>(new int(0));
1736  rootID='I';
1737  } else if (stype==cool::StorageType::UInt32) {
1738  sptr=static_cast<void*>(new unsigned int(0));
1739  rootID='i';
1740  } else if (stype==cool::StorageType::Int64) {
1741  sptr=static_cast<void*>(new long long int(0));
1742  rootID='L';
1743  } else if (stype==cool::StorageType::UInt63) {
1744  sptr=static_cast<void*>(new unsigned long long int(0));
1745  rootID='l';
1746  } else if (stype==cool::StorageType::Float) {
1747  sptr=static_cast<void*>(new float(0.));
1748  rootID='F';
1749  } else if (stype==cool::StorageType::Double) {
1750  sptr=static_cast<void*>(new double(0.));
1751  rootID='D';
1752  } else if (stype==cool::StorageType::String4k ||
1753  stype==cool::StorageType::String255) {
1754  sptr=static_cast<void*>(new char[4100]);
1755  rootID='C';
1756  } else if (stype==cool::StorageType::String64k && !m_noclobroot) {
1757  sptr=static_cast<void*>(new char[65536]);
1758  rootID='C';
1759  } else if (stype==cool::StorageType::String16M && !m_noclobroot) {
1760  sptr=static_cast<void*>(new char[67108864]);
1761  rootID='C';
1762  } else {
1763  std::cout << "rootAllocate: Unsupported storage type for attribute: " <<
1764  spec.name() << std::endl;
1765  }
1766  return (sptr!=nullptr);
1767 }
1768 
1769 void AtlCoolCopy::rootWrite(void* sptr,const cool::IField& field) const {
1770  // check for NULL value
1771  bool recnull=(field.isNull() && m_zeronull);
1772  const cool::StorageType& stype=field.storageType();
1773  if (stype==cool::StorageType::Bool) {
1774  if (recnull) {
1775  *(static_cast<int*>(sptr))=0;
1776  } else {
1777  *(static_cast<int*>(sptr))=(field.data<bool>() ? 1 : 0);
1778  }
1779  } else if (stype==cool::StorageType::UChar) {
1780  if (recnull) {
1781  *(static_cast<unsigned char*>(sptr))=0;
1782  } else {
1783  *(static_cast<unsigned char*>(sptr))=field.data<unsigned char>();
1784  }
1785  } else if (stype==cool::StorageType::Int16) {
1786  if (recnull) {
1787  *(static_cast<short*>(sptr))=0;
1788  } else {
1789  *(static_cast<short*>(sptr))=field.data<short>();
1790  }
1791  } else if (stype==cool::StorageType::UInt16) {
1792  if (recnull) {
1793  *(static_cast<unsigned short*>(sptr))=0;
1794  } else {
1795  *(static_cast<unsigned short*>(sptr))=field.data<unsigned short>();
1796  }
1797  } else if (stype==cool::StorageType::Int32) {
1798  if (recnull) {
1799  *(static_cast<int*>(sptr))=0;
1800  } else {
1801  *(static_cast<int*>(sptr))=field.data<int>();
1802  }
1803  } else if (stype==cool::StorageType::UInt32) {
1804  if (recnull) {
1805  *(static_cast<unsigned int*>(sptr))=0;
1806  } else {
1807  *(static_cast<unsigned int*>(sptr))=field.data<unsigned int>();
1808  }
1809  } else if (stype==cool::StorageType::Int64) {
1810  if (recnull) {
1811  *(static_cast<long long*>(sptr))=0;
1812  } else {
1813  *(static_cast<long long*>(sptr))=field.data<long long>();
1814  }
1815  } else if (stype==cool::StorageType::UInt63) {
1816  if (recnull) {
1817  *(static_cast<unsigned long long*>(sptr))=0;
1818  } else {
1819  *(static_cast<unsigned long long*>(sptr))=field.data<unsigned long long>();
1820  }
1821  } else if (stype==cool::StorageType::Float) {
1822  if (recnull) {
1823  *(static_cast<float*>(sptr))=0.;
1824  } else {
1825  *(static_cast<float*>(sptr))=field.data<float>();
1826  }
1827  } else if (stype==cool::StorageType::Double) {
1828  if (recnull) {
1829  *(static_cast<double*>(sptr))=0.;
1830  } else {
1831  *(static_cast<double*>(sptr))=field.data<double>();
1832  }
1833  } else if (stype==cool::StorageType::String255 ||
1834  stype==cool::StorageType::String4k ||
1835  stype==cool::StorageType::String64k ||
1836  stype==cool::StorageType::String16M) {
1837  if (recnull) {
1838  strcpy(static_cast<char*>(sptr),"NULL");
1839  } else {
1840  strcpy(static_cast<char*>(sptr),field.data<std::string>().c_str());
1841  }
1842  } else {
1843  std::cout << "ERROR: Unknown storage type in rootWrite!" << std::endl;
1844  }
1845 }
1846 
1847 int AtlCoolCopy::analyseIOVs(const std::string& folder,
1848  const cool::IFolderPtr& sourcefl,const std::string& sourcetag,
1849  const cool::ValidityKey since,const cool::ValidityKey until,
1850  const bool timestamp) {
1851  // analyse the IOV and channel structure of this folder/tag, make ROOT histos
1852  std::cout << "Analyse tag " << sourcetag << " of folder " << folder <<
1853  std::endl;
1854  bool anatime=(m_anadelt>=0);
1855  if (anatime) {
1856  std::cout << "Analyse time structures with tolerance of " <<
1857  m_anadelt/1.E9 << " seconds " << std::endl;
1858  }
1859  // create COOLANA/folder structure and create leaf directory for histograms
1860  std::string dirname=rootDirs(folder,"COOLANA");
1861  if (gDirectory->FindObject(dirname.c_str())==nullptr) {
1862  std::cout << "Make directory " << dirname << std::endl;
1863  gDirectory->mkdir(dirname.c_str());
1864  }
1865  gDirectory->cd(dirname.c_str());
1866  // get channels
1867  std::vector<cool::ChannelId> channels=sourcefl->listChannels();
1868  unsigned int nchan=channels.size();
1869  // end of last IOV seen on this channel
1870  long long* lastiov=new long long[nchan];
1871  long long* iovtotlen=new long long[nchan];
1872  long long* iovtotgap=new long long[nchan];
1873  int* iovn=new int[nchan];
1874  for (unsigned int i=0;i<nchan;++i) {
1875  lastiov[i]=-1; // no IOV seen on this channel yet
1876  iovtotlen[i]=0;
1877  iovtotgap[i]=0;
1878  iovn[i]=0;
1879  }
1880  cool::ValidityKey globsince=cool::ValidityKeyMax;
1881  cool::ValidityKey globuntil=cool::ValidityKeyMin;
1882 
1883  // book histograms - only if the objects do not already exist (previous tag)
1884  TH1F* h_iovchan=bookOrFindTH1F("IOVSperChannel","IOVs per channel",
1885  nchan,-0.5,nchan-0.5);
1886  TH1F* h_iovname=bookOrFindTH1F("IOVSperChannelName",
1887  "IOVs per channel-name (copy of IOVSperChannel)",
1888  nchan,-0.5,nchan-0.5);
1889  TH1F* h_iovlength=bookOrFindTH1F("IOVLogLength","IOV log10 length",
1890  100,0.,20.);
1891  TH1F* h_iovgap=bookOrFindTH1F("IOVLogGapLength","IOV log10 gap length",
1892  100,0.,20.);
1893  // histograms for time analysis if needed
1894  TH1F* h_anadelt=nullptr;
1895  TH1F* h_chandelt=nullptr;
1896  if (anatime) {
1897  h_anadelt=bookOrFindTH1F("IOVAlignLogDelT","IOV alignment log deltaT",
1898  100,0.,20.);
1899  // add factor 2 in number of channels, to catch those where a channel
1900  // changes many times within the m_anadelt window (i.e. noise/jitter)
1901  h_chandelt=bookOrFindTH1F("AlignedChanPerIOV","Aligned channels per IOV",
1902  nchan*2,0.5,nchan*2-0.5);
1903  }
1904  std::cout << "Booked histograms for folder with " << nchan << " channels"
1905  << std::endl;
1906  // setup storage for IOV time analysis
1907  using IOVTimeMap = std::map<cool::ValidityKey, int>;
1908  IOVTimeMap iov_time_map;
1909 
1910  // setup iterator to loop over objects
1911  int nobj=0;
1912  cool::FolderVersioning::Mode vermode=sourcefl->versioningMode();
1913  cool::IObjectIteratorPtr sourceitr;
1914  try {
1915  if (vermode==cool::FolderVersioning::SINGLE_VERSION) {
1916  sourceitr=sourcefl->browseObjects(since,until,m_chansel);
1917  } else {
1918  sourceitr=sourcefl->browseObjects(since,until,m_chansel,sourcetag);
1919  }
1920  }
1921  catch (cool::Exception& e) {
1922  std::cout << "Exception thrown from analysis copy iterator setup: " <<
1923  e.what() << std::endl;
1924  return 135;
1925  }
1926  // look up names of all the channels in one go
1927  std::map<cool::ChannelId,std::string>
1928  chanmap=sourcefl->listChannelsWithNames();
1929  // now loop over all IOVs and write them
1930  try {
1931  while (sourceitr->goToNext()) {
1932  const cool::IObject& sobj=sourceitr->currentRef();
1933  // get channel and find its index
1934  cool::ChannelId ichanid=sobj.channelId();
1935  const std::string& cname=chanmap[ichanid];
1938  std::equal_range(channels.begin(),channels.end(),ichanid);
1939  if (chanitr.first!=chanitr.second) {
1940  cool::ChannelId ichan=std::distance(channels.begin(),chanitr.first);
1941  Int_t bin=h_iovchan->Fill(ichan);
1942  if (ichan && !h_iovname->GetBinContent(bin)) {
1943  h_iovname->GetXaxis()->SetBinLabel(bin,cname.c_str());
1944  }
1945  h_iovname->Fill(ichan);
1946  // analyse IOV start/stop
1947  cool::ValidityKey since2=sobj.since();
1948  cool::ValidityKey until2=sobj.until();
1949  if (since2<globsince) globsince=since2;
1950  // dont count IOV is open-ended, so length statistics will make sense
1951  if (until2!=cool::ValidityKeyMax) {
1952  if (until2>globuntil) globuntil=until2;
1953  long long len=until2-since2;
1954  h_iovlength->Fill(log10(len));
1955  iovn[ichan]+=1;
1956  iovtotlen[ichan]+=len;
1957  }
1958  if (lastiov[ichan]<static_cast<long long>(since2) &&
1959  lastiov[ichan]>=0) {
1960  // have a gap in the IOV structure for this channel
1961  long long gap=since2-lastiov[ichan];
1962  iovtotgap[ichan]+=gap;
1963  h_iovgap->Fill(log10(gap));
1964  std::cout << "Gap of " << gap << std::endl;
1965  }
1966  if (until2!=cool::ValidityKeyMax) {
1967  lastiov[ichan]=until2;
1968  } else {
1969  lastiov[ichan]=since2;
1970  }
1971  // analyse IOV alignment
1972  if (anatime) {
1973  long long del1=-1;
1974  long long del2=-1;
1975  // find the nearest time to this one
1976  // this gives the first value exceeding since2
1977  IOVTimeMap::iterator hiitr=iov_time_map.lower_bound(since2);
1978  IOVTimeMap::iterator lowitr=hiitr;
1979  if (hiitr!=iov_time_map.end()) {
1980  // del1 is +ve time interval to next one
1981  del1=hiitr->first-since2;
1982  }
1983  if (lowitr!=iov_time_map.begin()) {
1984  // del2 is +ve time interval to previous one
1985  --lowitr;
1986  del2=since2-lowitr->first;
1987  }
1988  long long del=-1;
1989  IOVTimeMap::iterator moditr;
1990  bool domod=false;
1991  if (del1<=m_anadelt && del1>-1) {
1992  moditr=hiitr;
1993  del=del1;
1994  domod=true;
1995  }
1996  if (del2<=m_anadelt && del2>-1 && (del2<del || del==-1)) {
1997  moditr=lowitr;
1998  del=del2;
1999  domod=true;
2000  }
2001  if (domod) {
2002  ++(moditr->second);
2003  if (del>0) {
2004  h_anadelt->Fill(log10(del));
2005  } else {
2006  h_anadelt->Fill(0.);
2007  }
2008  } else {
2009  iov_time_map[since2]=0;
2010  }
2011  }
2012  } else {
2013  // channel ID not found
2014  std::cout << "ERROR :Channel " << ichanid <<
2015  " not found in channel list - ignored" << std::endl;
2016  }
2017  ++nobj;
2018  }
2019  std::cout << "Finished analysis with " << nobj << " objects" << std::endl;
2020  if (timestamp) {
2021  std::cout << "IOV timestamp range: " << globsince << " " <<
2022  timeString(globsince) << "to " << globuntil << " " <<
2023  timeString(globuntil) << std::endl;
2024  } else {
2025  std::cout << "IOV run/LB range [" << (globsince >> 32) << "," <<
2026  (globsince & 0xFFFFFFFF) << "] to [" << (globuntil >> 32) << "," <<
2027  (globuntil & 0xFFFFFFFF) << "]" << std::endl;
2028  }
2029  // calculate statistics for each channel
2030  TH1F* h_iovoccchan=bookOrFindTH1F("ChannelOcc","Channel Occupancy",
2031  nchan,-0.5,nchan-0.5);
2032  TH1F* h_iovlenchan=bookOrFindTH1F("IOVLenChan",
2033  "Mean IOV length per channel",nchan,-0.5,nchan-0.5);
2034  for (unsigned int i=0;i<nchan;++i) {
2035  float occ=0.;
2036  float avlen=0.;
2037  if (iovn[i]>0) {
2038  occ=1.-float(iovtotgap[i])/float(iovtotlen[i]+iovtotgap[i]);
2039  avlen=float(iovtotlen[i])/iovn[i];
2040  }
2041  h_iovoccchan->Fill(i,occ);
2042  h_iovlenchan->Fill(i,avlen);
2043  }
2044  if (anatime) {
2045  std::cout << "Alignment analysis: " << iov_time_map.size()
2046  << " seperate IOV starts (tolerance " << m_anadelt/1.E9 <<
2047  " seconds)" << std::endl;
2048  // fill histogram of number of channels incremented per IOV
2049  for (IOVTimeMap::const_iterator itr=iov_time_map.begin();
2050  itr!=iov_time_map.end();++itr) {
2051  h_chandelt->Fill(itr->second);
2052  }
2053  }
2054  }
2055  catch (cool::Exception& e) {
2056  std::cout << "Exception thrown from folder analysis reading loop: " <<
2057  e.what() << std::endl;
2058  return 134;
2059  }
2060  sourceitr->close();
2061  delete [] lastiov;
2062  delete [] iovtotlen;
2063  delete [] iovtotgap;
2064  delete[] iovn; iovn=nullptr;
2065  return 0;
2066 }
2067 
2068 TH1F* AtlCoolCopy::bookOrFindTH1F(const std::string& hID,
2069  const std::string& htitle,
2070  const int nchan, const float xlow, const float xhigh) {
2071  // check histogram does not exist in current directory
2072  // if yes, return pointer to it, else book and return pointer
2073  TObject* obj=gDirectory->FindObject(hID.c_str());
2074  if (obj==nullptr) {
2075  return new TH1F(hID.c_str(),htitle.c_str(),nchan,xlow,xhigh);
2076  } else {
2077  return static_cast<TH1F*>(obj);
2078  }
2079 }
2080 
2081 
2082 int AtlCoolCopy::doCopy ATLAS_NOT_THREAD_SAFE () {
2083  if (isOpen()) {
2084  int retcode=0;
2085  // execute copy for all defined folders
2086  for (std::vector<std::string>::const_iterator ifolder=
2087  m_folderlist.begin();ifolder!=m_folderlist.end();++ifolder) {
2088  int code=copyFolder(*ifolder,m_tags);
2089  if (code>retcode) retcode=code;
2090  }
2091  if (!m_hiparent.empty()) {
2092  // fill in any hierarchical tags for parent folders
2093  int code=tagParents();
2094  if (code>retcode) retcode=code;
2095  }
2096  if (m_copytaginfo) {
2097  // write information (tag description, lock status) to dest tags
2098  int code=writeTagInfo();
2099  if (code>retcode) retcode=code;
2100  }
2101  if (m_checkrefs) {
2102  int code=0;
2103  if (m_poolcat.empty()) {
2104  code=listPoolRefs();
2105  if (!m_checkoutputfile.empty()) filePoolRefs();
2106  } else {
2107  code=resolvePoolRefs();
2108  }
2109  if (code>retcode) retcode=code;
2110  }
2111  if (p_rootfile) {
2112  p_rootfile->Write();
2113  delete p_rootfile;
2114  }
2115  return retcode;
2116  } else {
2117  return 10;
2118  }
2119 }
2120 
2121 bool AtlCoolCopy::procOptVector(const int argc, const char* argv[],
2122  std::vector<std::string>& folders) {
2123  // process an array of options, return True if OK, False if not
2124  int ic=0;
2125  bool error=false;
2126  while (ic<argc) {
2127  int ir=argc-ic;
2128  std::string_view par0=argv[ic];
2129  // strip double "--" to achieve compatability with python-style options
2130  if (par0.compare(0,2,"--")==0) par0=par0.substr(1);
2131  if ((par0=="-f" || par0=="-folder") && ir>1) {
2132  folders.emplace_back(argv[ic+1]);
2133  ++ic;
2134  } else if ((par0=="-e" || par0=="-exclude") && ir>1) {
2135  addExclude(argv[ic+1]);
2136  ++ic;
2137  } else if ((par0=="-t" || par0=="-tag") && ir>1) {
2138  m_tags.emplace_back(argv[ic+1]);
2139  ++ic;
2140  } else if ((par0=="-mt" || par0=="-magic") && ir>1) {
2141  m_magic.push_back("_"+std::string(argv[ic+1]));
2142  ++ic;
2143  } else if ((par0=="-of" || par0=="-outfolder") && ir>1) {
2144  m_outfolder=argv[ic+1];
2145  ++ic;
2146  } else if ((par0=="-ot" || par0=="-outtag") && ir>1) {
2147  m_outtag=argv[ic+1];
2148  ++ic;
2149  } else if ((par0=="-bs" || par0=="-buffersize") && ir>1) {
2150  m_bufsize=atoi(argv[ic+1]);
2151  ++ic;
2152  } else if ((par0=="-sl" || par0=="-seal") && ir>1) {
2153  m_sealmsg=atoi(argv[ic+1]);
2154  ++ic;
2155  } else if ((par0=="-rls" || par0=="-runlumisince") && ir>2) {
2156  m_runemin=runLBVal(argv[ic+1],argv[ic+2]);
2157  ic+=2;
2158  } else if ((par0=="-rlu" || par0=="-runlumiuntil") && ir>2) {
2159  m_runemax=runLBVal(argv[ic+1],argv[ic+2]);
2160  ic+=2;
2161  } else if ((par0=="-nrls" || par0=="-newrunlumisince") && ir>2) {
2163  ic+=2;
2164  } else if ((par0=="-nrlu" || par0=="-newrunlumiuntil") && ir>2) {
2166  ic+=2;
2167  } else if ((par0=="-srls" || par0=="-skiprunlumisince") && ir>2) {
2168  m_srunemin=runLBVal(argv[ic+1],argv[ic+2]);
2169  m_skipout=true;
2170  ic+=2;
2171  } else if ((par0=="-srlu" || par0=="-skiprunlumiuntil") && ir>2) {
2172  m_srunemax=runLBVal(argv[ic+1],argv[ic+2]);
2173  m_skipout=true;
2174  ic+=2;
2175  } else if (par0=="-ro" || par0=="-root") {
2176  m_root=true;
2177  } else if (par0=="-zn" || par0=="-zeronull") {
2178  m_zeronull=true;
2179  } else if (par0=="-ana" || par0=="-analyse") {
2180  m_analyse=true;
2181  float ttime=atof(argv[ic+1])*1.E9;
2182  m_anadelt=static_cast<long long>(ttime);
2183  ++ic;
2184  } else if ((par0=="-rs" || par0=="-runsince") && ir>1) {
2185  m_runemin=(static_cast<long long>(atol(argv[ic+1])) << 32);
2186  ++ic;
2187  } else if ((par0=="-ru" || par0=="-rununtil") && ir>1) {
2188  m_runemax=(static_cast<long long>(1+atol(argv[ic+1])) << 32)-1;
2189  ++ic;
2190  } else if ((par0=="-r" || par0=="-run") && ir>1) {
2191  m_runemin=(static_cast<long long>(atol(argv[ic+1])) << 32);
2192  m_runemax=(static_cast<long long>(1+atol(argv[ic+1])) << 32)-1;
2193  ++ic;
2194  } else if ((par0=="-ts" || par0=="-timesince") && ir>1) {
2195  m_timemin=timeVal(argv[ic+1]);
2196  ++ic;
2197  } else if ((par0=="-tu" || par0=="-timeuntil") && ir>1) {
2198  m_timemax=timeVal(argv[ic+1]);
2199  ++ic;
2200  } else if ((par0=="-nts" || par0=="-newtimesince") && ir>1) {
2202  ++ic;
2203  } else if ((par0=="-ntu" || par0=="-newtimeuntil") && ir>1) {
2205  ++ic;
2206  } else if (par0=="-c" || par0=="-create") {
2207  m_allowcreate=true;
2208  } else if ((par0=="-ch" || par0=="-channel") && ir>1) {
2209  m_channelRange.emplace_back(argv[ic+1]);
2210  ++ic;
2211  } else if ((par0=="-ch1" || par0=="-channel1") && ir>1) {
2212  m_channel1=argv[ic+1];
2213  ++ic;
2214  } else if ((par0=="-ch2" || par0=="-channel2") && ir>1) {
2215  m_channel2=argv[ic+1];
2216  ++ic;
2217  } else if (par0=="-chd" || par0=="-channeldesc") {
2218  m_chdesc=true;
2219  // no abbreviaton for this one - dangerous option
2220  } else if (par0=="-forcerecreate") {
2221  m_recreate=true;
2222  } else if (par0=="-d" || par0=="-debug") {
2223  m_debug=true;
2224  } else if (par0=="-a" || par0=="-alliov") {
2225  m_alliov=true;
2226  } else if (par0=="-ih" || par0=="-includehead") {
2227  m_includehead=true;
2228  } else if (par0=="-eh" || par0=="-excludehead") {
2229  m_excludehead=true;
2230  } else if (par0=="-ht" || par0=="-headtag") {
2231  m_usertags=false;
2232  } else if (par0=="-uht" || par0=="-userheadtag") {
2233  m_userupdatehead=true;
2234  } else if (par0=="-v" || par0=="-verify") {
2235  m_verify=true;
2236  } else if (par0=="-nc" || par0=="-nocopy") {
2237  m_nocopy=true;
2238  } else if (par0=="-noc" || par0=="-nocoracool") {
2239  m_coracool=false;
2240  } else if (par0=="-nch" || par0=="-nochannel") {
2241  m_nochannel=true;
2242  } else if (par0=="-ncr" || par0=="-noclobroot") {
2243  m_noclobroot=true;
2244  } else if (par0=="-nd" || par0=="-nodata") {
2245  m_nodata=true;
2246  } else if (par0=="-nh" || par0=="-nohitag") {
2247  m_nohitag=true;
2248  } else if (par0=="-hi" || par0=="-hitag") {
2249  m_hitag=true;
2250  } else if ((par0=="-ec" || par0=="-excludechannel") && ir>1) {
2251  m_excludechans.push_back(strtoul(argv[ic+1],nullptr,10));
2252  ++ic;
2253  } else if (par0=="-fs" || par0=="-forcesingle") {
2254  m_forcesingle=true;
2255  } else if (par0=="-fm" || par0=="-forcemulti") {
2256  m_forcemulti=true;
2257  } else if (par0=="-frl" || par0=="-forcerunlumi") {
2258  m_forcerune=true;
2259  } else if (par0=="-ftm" || par0=="-forcetime") {
2260  m_forcetime=true;
2261  } else if (par0=="-fp" || par0=="-forcepayload") {
2262  m_forcepay=true;
2263  } else if (par0=="-fnp" || par0=="-forcenopayload") {
2264  m_forcenopay=true;
2265  } else if (par0=="-cr" || par0=="-checkrefs") {
2266  m_checkrefs=true;
2267  } else if (par0=="-lp" || par0=="-listpfn") {
2268  m_listpfn=true;
2269  m_checkrefs=true;
2270  } else if (par0=="-cf" || par0=="-checkfiles") {
2271  m_poolopen=true;
2272  m_checkrefs=true;
2273  } else if (par0=="-pa" || par0=="-poolall") {
2274  m_poolall=true;
2275  } else if ((par0=="-co" || par0=="-checkoutput") && ir>1) {
2277  ++ic;
2278  } else if ((par0=="-pc" || par0=="-poolcat") && ir>1) {
2279  m_poolcat.emplace_back(argv[ic+1]);
2280  ++ic;
2281  } else if ((par0=="-mc" || par0=="-mergecat") && ir>1) {
2282  m_mergecat.emplace_back(argv[ic+1]);
2283  ++ic;
2284  } else if ((par0=="-ds" || par0=="-dataset") && ir>1) {
2285  m_newdataset=argv[ic+1];
2286  ++ic;
2287  } else if (par0=="-us" || par0=="-updatesource") {
2288  m_sourceread=false;
2289  } else if (par0=="-cd" || par0=="-checkdest") {
2290  m_checkdesttag=true;
2291  } else if (par0=="-tr" || par0=="-truncate") {
2292  m_truncate=true;
2293  } else if (par0=="-al" || par0=="-appendlocked") {
2294  m_applock=true;
2295  } else if (par0=="-alsv" || par0=="-appendlockedsv") {
2296  m_applock=true;
2297  m_applocksv=true;
2298  } else if (par0=="-rdo" || par0=="-readoracle") {
2299  m_readoracle=true;
2300  } else if (par0=="-skiprep" || par0=="-sr") {
2301  m_skiprep=true;
2302  } else if (par0=="-go" || par0=="-getonline") {
2303  m_getonline=true;
2304  } else if (par0=="-onr" || par0=="-onlinerun") {
2305  m_onlinerun=true;
2306  } else if (par0=="-gb" || par0=="-getbulk") {
2307  m_getbulk=true;
2308  } else if (par0=="-gt" || par0=="-gettime") {
2309  m_gettime=true;
2310  } else if ((par0=="-tdb" || par0=="-timedb") && ir>1) {
2311  m_timedb=argv[ic+1];
2312  ++ic;
2313  } else if (par0=="-ignoremode" && ir>1) {
2314  std::cout << "Ignoremode password is " << argv[ic+1] << ":end" << std::endl;
2315  if (strcmp(argv[ic+1],"BackDoor")==0) {
2316  m_ignoremode=true;
2317  } else {
2318  std::cout << "ERROR: Incorrect password for -ignoremode" << std::endl;
2319  error=true;
2320  }
2321  ++ic;
2322  } else if (par0=="-is" || par0=="-ignorespec") {
2323  m_ignorespec=true;
2324  } else if (par0=="-pt" || par0=="-prunetags") {
2325  m_prunetags=true;
2326  m_excludehead=true;
2327  } else if (par0=="-lo" || par0=="-lockedonly") {
2328  m_lockedonly=true;
2329  m_prunetags=true;
2330  m_excludehead=true;
2331  } else if (par0=="-cti" || par0=="-copytaginfo") {
2332  m_copytaginfo=true;
2333  } else if (par0=="-ctl" || par0=="-copytaglock") {
2334  m_copytaginfo=true;
2335  m_copytaglock=true;
2336  } else if ((par0=="-tl" || par0=="-taglabel") && ir>1) {
2337  m_taglabel=argv[ic+1];
2338  ++ic;
2339  m_copytaginfo=true;
2340  } else if ((par0=="-ag" || par0=="-addguid") && ir>1) {
2341  m_addguid.emplace_back(argv[ic+1]);
2342  ++ic;
2343  } else if ((par0=="-alf" || par0=="-addlfn") && ir>1) {
2344  m_addlfn.emplace_back(argv[ic+1]);
2345  ++ic;
2346  } else if ((par0=="-pf" || par0=="-parfile") && ir>1) {
2347  m_parfile.emplace_back(argv[ic+1]);
2348  ++ic;
2349  } else if ((par0=="-rf" || par0=="-runfile") && ir>1) {
2350  m_runfile.emplace_back(argv[ic+1]);
2351  ++ic;
2352  } else if ((par0=="-ws" || par0=="-runinfohost") && ir>1) {
2353  m_runinfohost=argv[ic+1];
2354  ++ic;
2355  } else if (par0=="-h" || par0=="-help") {
2356  // help printout triggered by -999 return code
2357  return 999;
2358  } else {
2359  std::cout << "Parameter error for argument: " << par0 << std::endl;
2360  error=true;
2361  }
2362  ++ic;
2363  }
2364  return !error;
2365 }
2366 
2367 
2368 int AtlCoolCopy::setOpts(int argc, const char* argv[]) {
2369  // accumulate raw folder list
2370  std::vector<std::string> folders;
2371  // process options given on command-line
2372  if (!procOptVector(argc,argv,folders)) return 2;
2373 
2374  // parse any parameters in files via parfile option
2375  for (std::vector<std::string>::const_iterator ifile=m_parfile.begin();
2376  ifile!=m_parfile.end();++ifile) {
2377  std::cout << "Reading parameters from file " << *ifile << std::endl;
2378  FILE* p_inp=fopen(ifile->c_str(),"r");
2379  if (p_inp==nullptr) {
2380  std::cout << "File not found" << std::endl;
2381  return 3;
2382  }
2383  char* p_buf=new char[999];
2384  while (!feof(p_inp)) {
2385  char* p_line=fgets(p_buf,999,p_inp);
2386  if (p_line!=nullptr) {
2387  int fargc=0;
2388  const char* fargv[99];
2389  // split this line into tokens
2390  char* p_start=nullptr;
2391  while (*p_line!='\0') {
2392  if (*p_line==' ' || *p_line=='\n') {
2393  // pointing at a space/newline, marking the end of a parameter
2394  if (p_start!=nullptr) {
2395  // if we have a parameter, mark the end and store it
2396  *p_line='\0';
2397  fargv[fargc]=p_start;
2398  fargc++;
2399  p_start=nullptr;
2400  }
2401  } else {
2402  // mark the start of a parameter
2403  if (p_start==nullptr) p_start=p_line;
2404  }
2405  ++p_line;
2406  }
2407  if (fargc>0) {
2408  if (!procOptVector(fargc,&fargv[0],folders)) {
2409  fclose(p_inp);
2410  return 3;
2411  }
2412  }
2413  }
2414  }
2415  std::cout << "Close file" << std::endl;
2416  fclose(p_inp);
2417  delete[] p_buf;
2418  }
2419 
2420  // now open the database so folder lookup will work
2422  std::cout << "Problem opening connections" << std::endl;
2423  return 10;
2424  } else {
2425  // having assembled the raw list of folders and exclude list, construct
2426  // real list of folders (allows exclude to be specified after folders on
2427  // command line), if none given, add '/'
2428  if (m_lockedonly) {
2429  if (getLockedTags()==0) return 11;
2430  }
2431  if (folders.empty()) {
2432  // no folders specified, take all with tags
2433  addFolder("/",false);
2434  } else {
2435  // explicit list of folders
2436  for (std::vector<std::string>::const_iterator ifold=folders.begin();
2437  ifold!=folders.end();++ifold) addFolder(*ifold,false);
2438  // need to process only tags in root folder, if inclusive hiearchicals
2439  if (m_hitag) addFolder("/",true);
2440  }
2441  }
2442  if (m_getonline) {
2443  if (!getOnlineRun()) return 6;
2444  }
2445  if (m_getbulk) {
2446  if (!getBulkRun()) return 6;
2447  }
2448  if (m_gettime) {
2449  if (!getTimeFromRun()) return 5;
2450  }
2451  if (!m_runfile.empty()) {
2452  if (!getRunList()) return 7;
2453  }
2454  // list out parameter changes
2455  if (m_runemin!=cool::ValidityKeyMin || m_runemax!=cool::ValidityKeyMax)
2456  std::cout << "Source run/LB range [" << (m_runemin >> 32) << "," <<
2457  (m_runemin & 0xFFFFFFFF) << "] to [" << (m_runemax >> 32) << "," <<
2458  (m_runemax & 0xFFFFFFFF) << "]" << std::endl;
2459  if (m_timemin!=cool::ValidityKeyMin || m_timemax!=cool::ValidityKeyMax)
2460  std::cout << "Source timestamp range " << m_timemin << " " <<
2461  timeString(m_timemin) << "to " << m_timemax << " " <<
2462  timeString(m_timemax) << std::endl;
2463  if (m_alliov)
2464  std::cout << "Change o/p run/LB range [" << (m_newrunemin >> 32) << "," <<
2465  (m_newrunemin & 0xFFFFFFFF) << "] to [" << (m_newrunemax >> 32) << "," <<
2466  (m_newrunemax & 0xFFFFFFFF) << "]" << std::endl;
2467  if (m_alliov)
2468  std::cout << "Change o/p timestamp range " << m_newtimemin << " " <<
2469  timeString(m_newtimemin) << "to " << m_newtimemax << " " <<
2470  timeString(m_newtimemax) << std::endl;
2471  if (m_skipout) {
2472  std::cout << "Skip IOVs extending outside run/LB range [" <<
2473  (m_srunemin >> 32) << "," << (m_srunemin & 0xFFFFFFFF) << "] to [" <<
2474  (m_srunemax >> 32) << "," << (m_srunemax & 0xFFFFFFFF) << "]" <<
2475  std::endl;
2476  }
2477  if (!m_excludechans.empty()) {
2478  for (std::vector<cool::ChannelId>::const_iterator itr=
2479  m_excludechans.begin();itr!=m_excludechans.end();++itr)
2480  std::cout << "Channel " << *itr << " will be excluded" << std::endl;
2481  }
2482  if (m_hitag) std::cout << "All hierachical tags connecting to referenced tags will be copied" << std::endl;
2483  if (m_nohitag) std::cout << "Hierarchical tag relations will not be copied"
2484  << std::endl;
2485  return 0;
2486 }
2487 
2488 bool AtlCoolCopy::isNumeric(const char* input) {
2489  // determine if input string is numeric or string
2490  bool isnum=true;
2491  const char* cptr=input;
2492  while (*cptr!='\0') {
2493  if (!isdigit(*cptr)) { isnum=false; break;}
2494  ++cptr;
2495  }
2496  return isnum;
2497 }
2498 
2499 bool AtlCoolCopy::equalRecord(const cool::IRecord& lhs,
2500  const cool::IRecord& rhs) {
2501  // equality test for COOL IRecords, handling NULL string attributes correctly
2502  // tests values and types of Attributes, not names
2503  if (lhs.size()!=rhs.size()) return false;
2504  for (size_t i=0;i<lhs.size();++i) {
2505  // types must match - have to test explicitly first
2506  if (lhs[i].specification().storageType()!=
2507  rhs[i].specification().storageType())
2508  return false;
2509  // now use IField equality to for final test (spec again and data)
2510  if (lhs[i]!=rhs[i]) {
2511  // if not equal, check for special case of strings and compare directly
2512  // types are known to be equal so only test LHS
2513  const cool::StorageType& stype=lhs[i].specification().storageType();
2514  if (stype==cool::StorageType::String255 ||
2515  stype==cool::StorageType::String4k ||
2516  stype==cool::StorageType::String64k ||
2517  stype==cool::StorageType::String16M) {
2518  // check if string data payloads are really equal or not
2519  if (lhs[i].data<std::string>()!=rhs[i].data<std::string>())
2520  return false;
2521  } else {
2522  // if not string, trust the result of IField !=operator
2523  return false;
2524  }
2525  }
2526  }
2527  return true;
2528 }
2529 
2530 
2531 cool::ValidityKey AtlCoolCopy::timeVal(const char* input) {
2532  // convert input char* string to 64bit COOL validityKey
2533  // input either represents a string in seconds, or a date in the form
2534  // yyyy/mm/dd:hh:mm:ss
2535  // first determine if input is a number
2536  if (isNumeric(input)) {
2537  return static_cast<long long>(atol(input))*
2538  static_cast<long long>(1.E9);
2539  } else {
2540  struct tm mytm{},mytm2{};
2541  char* result=strptime(input,"%Y-%m-%d:%T",&mytm);
2542  if (result!=nullptr) {
2543  // make the DST field zero, so the time is interpreted without daylight
2544  // savings time
2545  mytm.tm_isdst=0;
2546  // now have to correct for the local time zone - do this by also
2547  // calculating the time since epoch for 2/1/1970 midnight (no DST)
2548  cool::ValidityKey itime=static_cast<cool::ValidityKey>(mktime(&mytm));
2549  strptime("1970-01-02:00:00:00","%Y-%m-%d:%T",&mytm2);
2550  cool::ValidityKey caltime=static_cast<cool::ValidityKey>(mktime(&mytm2));
2551  itime+=24*60*60-caltime;
2552  return itime*static_cast<cool::ValidityKey>(1.E9);
2553  } else {
2554  std::cout <<
2555  "ERROR in format of time value, use e.g. 2007-05-25:14:01:00" <<
2556  std::endl;
2557  return 0;
2558  }
2559  }
2560 }
2561 
2562 std::string AtlCoolCopy::timeString(const cool::ValidityKey iovtime) {
2563  if (iovtime==cool::ValidityKeyMin) {
2564  return "ValidityKeyMin ";
2565  } else if (iovtime==cool::ValidityKeyMax) {
2566  return "ValidityKeyMax ";
2567  } else {
2568  time_t time=static_cast<time_t>(iovtime/1E9);
2569  struct tm result;
2570  char buf[32];
2571  return "UTC "+std::string(asctime_r(gmtime_r(&time, &result), buf));
2572  }
2573 }
2574 
2575 cool::ValidityKey AtlCoolCopy::runLBVal(const char* input1,const char* input2) {
2576  // parse the inputs as run/LB numbers to generate a validitykey
2577  // used in processing -rls-type options
2578  cool::ValidityKey val;
2579  if (input1[0]=='M' || input1[0]=='m') {
2580  val=((1LL << 31)-1) << 32;
2581  } else {
2582  val=static_cast<long long>(atol(input1)) << 32;
2583  }
2584  if (input2[0]=='M' || input2[0]=='m') {
2585  val+=(1LL << 32);
2586  } else {
2587  val+=atoll(input2);
2588  }
2589  if (val>cool::ValidityKeyMax) val=cool::ValidityKeyMax;
2590  return val;
2591 }
2592 
2593 
2595  // extract time limits for a run range using the expected information
2596  // in the /TDAQ/RunCtrl/SOR_Params and EOR_Params on the given DB connection
2597 
2598  // choose database instance based on run number switchover if none is given
2599  if (m_timedb.empty()) {
2600  if ((m_runemin >> 32)>=236107) {
2601  m_timedb="COOLONL_TDAQ/CONDBR2";
2602  } else {
2603  m_timedb="COOLONL_TDAQ/COMP200";
2604  }
2605  }
2606  // select foldername based on database instance
2607  std::string sorfolder="/TDAQ/RunCtrl/SOR_Params";
2608  std::string eorfolder="/TDAQ/RunCtrl/EOR_Params";
2609  if (m_timedb.find ("CONDBR2")!=std::string::npos) {
2610  sorfolder="/TDAQ/RunCtrl/SOR";
2611  eorfolder="/TDAQ/RunCtrl/EOR";
2612  }
2613  std::cout << "Extracting times for run range [" << (m_runemin >> 32) <<
2614  "," << (m_runemax >> 32) << "] from database " << m_timedb <<
2615  " folder " << sorfolder << std::endl;
2616  if (m_runemin==cool::ValidityKeyMin || m_runemax==cool::ValidityKeyMax) {
2617  std::cout << "ERROR: Run range not correctly specified" << std::endl;
2618  return false;
2619  }
2620  // open database connection
2621  cool::IDatabasePtr tdaqdb;
2622  try {
2623  tdaqdb=m_dbSvc->openDatabase(transConn(m_timedb),m_sourceread);
2624  std::cout << "Opened database connection" << std::endl;
2625  }
2626  catch (std::exception& e) {
2627  std::cout << "COOL exception caught: " << e.what() << std::endl;
2628  return false;
2629  }
2630  // start of run information
2631  try {
2632  cool::IFolderPtr folder=tdaqdb->getFolder(sorfolder);
2633  // channel number is arbitrary - have to loop
2634  cool::IObjectIteratorPtr itr=folder->browseObjects(m_runemin,m_runemin,
2636  int nobj=0;
2637  while (itr->goToNext()) {
2638  const cool::IRecord& payload=itr->currentRef().payload();
2639  m_timemin=payload["SORTime"].data<unsigned long long>();
2640  ++nobj;
2641  }
2642  itr->close();
2643  if (nobj!=1) {
2644  std::cout << "ERROR: Found " << nobj << " SOR records" << std::endl;
2645  return false;
2646  }
2647  }
2648  catch (std::exception& e) {
2649  std::cout << "Exception accessing SOR information: " << e.what() <<
2650  std::endl;
2651  return false;
2652  }
2653  // end of run information
2654  try {
2655  cool::IFolderPtr folder=tdaqdb->getFolder(eorfolder);
2656  // channel number is arbitrary - have to loop
2657  cool::IObjectIteratorPtr itr=folder->browseObjects(((m_runemax >> 32) << 32),((m_runemax >> 32) << 32),
2659  int nobj=0;
2660  while (itr->goToNext()) {
2661  const cool::IRecord& payload=itr->currentRef().payload();
2662  m_timemax=payload["EORTime"].data<unsigned long long>();
2663  ++nobj;
2664  }
2665  itr->close();
2666  if (nobj!=1) {
2667  std::cout << "ERROR: Found " << nobj << " EOR records" << std::endl;
2668  return false;
2669  }
2670  }
2671  catch (std::exception& e) {
2672  std::cout << "Exception accessing SOR information: " << e.what() <<
2673  std::endl;
2674  return false;
2675  }
2676  tdaqdb->closeDatabase();
2677  std::cout << "Timestamp range set to " << m_timemin << " " <<
2678  timeString(m_timemin) << "to " << m_timemax << " " <<
2679  timeString(m_timemax) << std::endl;
2680  return true;
2681 }
2682 
2684  // open using the ATLAS_COOLONL_GLOBAL schema, since we have authentication
2685  // information for this one by default
2686  // get minimum run-number/timestamp for bulk reco update
2687  std::cout << "Extracting current run-number from ATLAS_RUN_NUMBER @ ATONR_ADG ... " <<
2688  // Initialize libcurl
2689  curl_global_init(CURL_GLOBAL_ALL);
2690  using uniqueCurl_t = std::unique_ptr<CURL,decltype(&curl_easy_cleanup)>;
2691  uniqueCurl_t curl(curl_easy_init(), curl_easy_cleanup);
2692  CURLcode res = CURLE_OK;
2693  if (curl) {
2694  std::string url = m_runinfohost + "/runs?sort=runnumber:DESC&size=1";
2695  // Set the URL
2696  res = curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
2697  if (res != CURLE_OK) {
2698  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2699  return false;
2700  }
2701  // Follow HTTP redirections
2702  res = curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
2703  if (res != CURLE_OK) {
2704  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2705  return false;
2706  }
2707  // Response data buffer
2708  std::string response;
2709 
2710  // Set the callback function to receive response data
2711  res = curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback);
2712  if (res != CURLE_OK) {
2713  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2714  return false;
2715  }
2716  res = curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response);
2717  if (res != CURLE_OK) {
2718  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2719  return false;
2720  }
2721 
2722  // Perform the request
2723  res = curl_easy_perform(curl.get());
2724  if (res != CURLE_OK) {
2725  std::cerr << "Failed to perform request: " << curl_easy_strerror(res) << ":" << url.c_str() << std::endl;
2726  return false;
2727  } else {
2728  // Print the received response
2729  std::cout << "Response: " << std::endl;
2730  std::cout << response << std::endl;
2731  // Parse the JSON string
2732  try {
2734 
2735  // Extract the runnumber field
2736  int runNumber = jsonData["resources"][0]["runnumber"];
2737  int nextrun=runNumber+1;
2738  std::cout << "Next run started will be " << nextrun << std::endl;
2739  const long long rtime=time(nullptr);
2740  std::cout << "Epoch time extracted " << rtime << std::endl;
2741  if (m_alliov) {
2742  // if overwriting IOVs, set the new IOV lower limit
2743  m_newrunemin=(static_cast<long long>(nextrun)) << 32;
2744  m_newtimemin=rtime*static_cast<long long>(1E9);
2745  } else {
2746  // set the query lower limit - for use with truncate option
2747  m_runemin=(static_cast<long long>(nextrun)) << 32;
2748  m_timemin=rtime*static_cast<long long>(1E9);
2749  m_truncate=true;
2750  }
2751  } catch (nlohmann::json::parse_error& e) {
2752  std::cerr << "Failed to parse JSON response: " << e.what() << std::endl;
2753  return false;
2754  } catch (nlohmann::json::type_error& e) {
2755  std::cerr << "Failed to extract data from JSON response: " << e.what() << std::endl;
2756  return false;
2757  } catch (std::exception& e) {
2758  std::cerr << "Failed to extract run and timestamp from JSON response: " << e.what() << std::endl;
2759  return false;
2760  }
2761  }
2762  // Clean up done by unique_ptr d'tor
2763  } else {
2764  std::cerr << "Failed to initialize libcurl." << std::endl;
2765  return false;
2766  }
2767  // Cleanup libcurl
2768  curl_global_cleanup();
2769  return true;
2770 }
2772  // get minimum run-number/timestamp for bulk reco update
2773  if (m_getonline) {
2774  std::cout << "ERROR: -getonline and -getbulk cannot be used simultaneously"
2775  << std::endl;
2776  return false;
2777  }
2778  std::cout << "Call getbulk using URL" << std::endl;
2779  // Initialize libcurl
2780  curl_global_init(CURL_GLOBAL_ALL);
2781  using uniqueCurl_t = std::unique_ptr<CURL,decltype(&curl_easy_cleanup)>;
2782  uniqueCurl_t curl(curl_easy_init(), curl_easy_cleanup);
2783  //CURL *curl = curl_easy_init();
2784  CURLcode res = CURLE_OK;
2785 
2786  if (curl) {
2787  std::string url = m_runinfohost + "/runs/nemop/sync";
2788  // Set the URL
2789  res = curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
2790  if (res != CURLE_OK) {
2791  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2792  return false;
2793  }
2794  // Follow HTTP redirections
2795  res = curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
2796  if (res != CURLE_OK) {
2797  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2798  return false;
2799  }
2800  // Response data buffer
2801  std::string response;
2802 
2803  // Set the callback function to receive response data
2804  res = curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback);
2805  if (res != CURLE_OK) {
2806  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2807  return false;
2808  }
2809  res = curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response);
2810  if (res != CURLE_OK) {
2811  std::cerr << "Failed to perform request: curl_easy_setopt, line "<<__LINE__<<std::endl;
2812  return false;
2813  }
2814  // Perform the request
2815  res = curl_easy_perform(curl.get());
2816  if (res != CURLE_OK) {
2817  std::cerr << "Failed to perform request: " << curl_easy_strerror(res) << ":" << url.c_str() << std::endl;
2818  return false;
2819  } else {
2820  // Print the received response
2821  std::cout << "Response: " << std::endl;
2822  std::cout << response << std::endl;
2823  try {
2824  // Split the response into two fields
2826  // Extract the run and timestamp fields
2827  int nextrun = jsonData["run"];
2828  long long rtime = jsonData["timestamp"];
2829  std::cout << "Next run started will be " << nextrun << std::endl;
2830  std::cout << "Epoch time extracted " << rtime << std::endl;
2831  if (m_alliov) {
2832  // if overwriting IOVs, set the new IOV lower limit
2833  m_newrunemin=(static_cast<long long>(nextrun)) << 32;
2834  m_newtimemin=rtime*static_cast<long long>(1E9);
2835  } else {
2836  // set the query lower limit - for use with truncate option
2837  m_runemin=(static_cast<long long>(nextrun)) << 32;
2838  m_timemin=rtime*static_cast<long long>(1E9);
2839  m_truncate=true;
2840  }
2841  } catch (nlohmann::json::parse_error& e) {
2842  std::cerr << "Failed to parse JSON response: " << e.what() << std::endl;
2843  return false;
2844  } catch (nlohmann::json::type_error& e) {
2845  std::cerr << "Failed to extract data from JSON response: " << e.what() << std::endl;
2846  return false;
2847  } catch (std::exception& e) {
2848  std::cerr << "Failed to extract run and timestamp from JSON response: " << e.what() << std::endl;
2849  return false;
2850  }
2851  }
2852  // Clean up done by unique_ptr
2853  } else {
2854  std::cerr << "Failed to initialize libcurl." << std::endl;
2855  return false;
2856  }
2857  // Cleanup libcurl
2858  curl_global_cleanup();
2859 
2860  return true;
2861 }
2862 
2864  // loop over all given filenames
2865  for (std::vector<std::string>::const_iterator itr=m_runfile.begin();
2866  itr!=m_runfile.end();++itr) {
2867  std::cout << "Reading allowed run numbers from file " << *itr << std::endl;
2868  FILE* p_inp=fopen(itr->c_str(),"r");
2869  if (p_inp==nullptr) {
2870  std::cout << "File not found" << std::endl;
2871  return false;
2872  }
2873  char* p_buf=new char[999];
2874  while (!feof(p_inp)) {
2875  char* p_line=fgets(p_buf,999,p_inp);
2876  if (p_line!=nullptr) {
2877  unsigned int run=atoi(p_line);
2878  m_runlist.push_back(run);
2879  }
2880  }
2881  fclose(p_inp);
2882  delete[] p_buf;
2883  }
2884  std::sort(m_runlist.begin(),m_runlist.end());
2885  std::cout << "Read list of " << m_runlist.size() << " runs from " <<
2886  m_runfile.size() << " input runlist files" << std::endl;
2887  for (std::vector<unsigned int>::const_iterator itr=m_runlist.begin();
2888  itr!=m_runlist.end();++itr) std::cout <<
2889  "Update allowed for run " << *itr << std::endl;
2890  return true;
2891 }
2892 
2893 int AtlCoolCopy::getUpdateMode(std::string_view desc,
2894  std::string_view tag) {
2895  // analyse the folder description and tag name for updateMode flags
2896  // return 1 for online mode, 0 otherwise
2897  std::string_view modestr="";
2898  int mode=0;
2899  std::string::size_type iofs1=desc.find("<updateMode>");
2900  std::string::size_type iofs2=desc.find("</updateMode>");
2901  if (iofs1!=std::string::npos && iofs2!=std::string::npos && iofs2>iofs1)
2902  modestr=desc.substr(iofs1+12,iofs2-iofs1-12);
2903  if (modestr=="UPD1" || tag.find("UPD1")!=std::string::npos) mode=1;
2904  if (modestr=="UPD2" || tag.find("UPD2")!=std::string::npos) mode=2;
2905  if (modestr=="UPD3" || tag.find("UPD3")!=std::string::npos) mode=3;
2906  if (modestr=="UPD4" || tag.find("UPD4")!=std::string::npos) mode=4;
2907  return mode;
2908 }
2909 
2910 
2911 bool AtlCoolCopy::checkChannels(const std::string& folder,
2912  const cool::IFolderPtr& sourcefl,const cool::IFolderPtr& destfl,
2913  bool newfolder) {
2914  // Channel manipulation is slow due to lack of bulk API for creating them
2915  // this routine therefore does the minimum work, not checking destination
2916  // if folder is newly created, and not copying description unless requested
2917  // get map of all channels
2918  const std::map<cool::ChannelId,std::string> chanmap=
2919  sourcefl->listChannelsWithNames();
2920  if (m_debug) std::cout << "Checking channels table for folder " << folder
2921  << " with " << chanmap.size() << " channels" << std::endl;
2922  int ncreate=0;
2923  int nmodify=0;
2924  // iterate over all channels
2925  for (std::map<cool::ChannelId,std::string>::const_iterator
2926  itr=chanmap.begin();itr!=chanmap.end();++itr) {
2927  // assume now ALL channels are in channels table (COOL 2.4 and above)
2928  const cool::ChannelId chan=itr->first;
2929  // check if channel should be skipped
2930  if (!m_excludechans.empty()) {
2931  if (find(m_excludechans.begin(),m_excludechans.end(),
2932  chan)!=m_excludechans.end()) continue;
2933  }
2934  if (!m_chansel.inSelection(chan)) continue;
2935 
2936  const std::string& sourcename=itr->second;
2937  // only look up channel description if we are copying it
2938  std::string sourcedesc="";
2939  if (m_chdesc) sourcedesc=sourcefl->channelDescription(chan);
2940  // only check destination if folder alreay existed
2941  if (!newfolder && destfl->existsChannel(chan)) {
2942  const std::string & destname=destfl->channelName(chan);
2943  std::string destdesc="";
2944  if (m_chdesc) destdesc=destfl->channelDescription(chan);
2945  // if sourcename is not set, and destination is, dont worry
2946  if (sourcename!=destname && !sourcename.empty()) {
2947  // channel names differ - error if verifying, set if copying
2948  if (m_verify) {
2949  std::cout << "ERROR: Channel " << chan << " names differ: " <<
2950  sourcename << " " << destname << std::endl;
2951  return false;
2952  }
2953  destfl->setChannelName(chan,sourcename);
2954  std::cout << "Modify channel " << chan << " name from "
2955  << destname << " to " << sourcename << std::endl;
2956  ++nmodify;
2957  }
2958  if (sourcedesc!=destdesc && !sourcedesc.empty()) {
2959  // channel descriptions differ - error if verifying, set if copying
2960  if (m_verify) {
2961  std::cout << "ERROR: Channel " << chan << " descriptions differ: "
2962  << sourcedesc << " " << destdesc << std::endl;
2963  return false;
2964  }
2965  std::cout << "Modify channel " << chan << " description from "
2966  << sourcedesc << " to " << destdesc << std::endl;
2967  destfl->setChannelDescription(chan,sourcedesc);
2968  ++nmodify;
2969  }
2970  } else {
2971  // channel does not exist on destination - if verifying, this is error
2972  if (m_verify) return false;
2973  // otherwise create it
2974  if (m_debug) std::cout << "Create new channel " << chan << " name "
2975  << sourcename << " description" << sourcedesc << std::endl;
2976  destfl->createChannel(chan,sourcename,sourcedesc);
2977  ++ncreate;
2978  }
2979  }
2980  if (ncreate>0) std::cout << "Created " << ncreate << " new channels for "
2981  << folder << std::endl;
2982  if (nmodify>0) std::cout << "Modified " << nmodify << " channel info for "
2983  << folder << std::endl;
2984  return true;
2985 }
2986 
2987 
2988 void AtlCoolCopy::checkRef(const cool::IRecord& payload,
2989  const std::string& folder, const std::string& tag) {
2990  const std::string name=payload[0].name();
2991  if (name=="PoolRef" || name=="fileGUID") {
2992  std::string poolref;
2993  std::string addr=payload[0].data<std::string>();
2994  if (name=="PoolRef") {
2995  std::string::size_type iofs1=addr.find("[DB=");
2996  std::string::size_type iofs2=addr.find(']',iofs1);
2997  if (iofs1!=std::string::npos && iofs2!=std::string::npos && iofs2>iofs1) {
2998  poolref=addr.substr(iofs1+4,iofs2-iofs1-4);
2999  } else {
3000  std::cout << "ERROR: Badly formed POOL object reference " <<
3001  addr << std::endl;
3002  }
3003  } else {
3004  // for fileGUID, POOL GUID is just the string
3005  poolref=addr;
3006  }
3007  std::string foldertag=folder+":"+tag;
3008  // insert into list, first check if same as before
3009  if (m_poollast!=m_poolrefs.end() && m_poollast->first==poolref) {
3010  m_poollast->second.inccount();
3011  m_poollast->second.addfoldertag(foldertag);
3012  } else {
3013  m_poollast=m_poolrefs.find(poolref);
3014  if (m_poollast!=m_poolrefs.end()) {
3015  m_poollast->second.inccount();
3016  m_poollast->second.addfoldertag(foldertag);
3017  } else {
3018  m_poolrefs[poolref]=PoolMapElement(1,foldertag);
3019  m_poollast=m_poolrefs.find(poolref);
3020  }
3021  }
3022  }
3023 }
3024 
3026  std::cout << "Copying additional hierarchical tags of parent folders"
3027  << std::endl;
3028  while (!m_hiparent.empty()) {
3029  // take first element and erase it
3030  std::string folderset=*m_hiparent.begin();
3031  m_hiparent.erase(m_hiparent.begin());
3032  // process any tags defined for this folderset
3033  if (m_sourceDbPtr->existsFolderSet(folderset)) {
3034  cool::IFolderSetPtr sourcefl=m_sourceDbPtr->getFolderSet(folderset);
3035  cool::IFolderSetPtr destfl=m_destDbPtr->getFolderSet(folderset);
3036  std::cout << "Processing folderset " << folderset << std::endl;
3037  for (HiTagMap::const_iterator imap=m_hitagmap.begin();
3038  imap!=m_hitagmap.end();++imap) {
3039  try {
3040  // will throw exception if this tag is not pointing to the folder
3041  std::string sourcetag=sourcefl->findTagRelation(imap->first);
3042  std::cout << "Create hierarchical tag between " << sourcetag <<
3043  " and " << imap->first << " in folder " << imap->second <<
3044  std::endl;
3045  try {
3046  // first check this relation has not already been created
3047  std::string etag=destfl->resolveTag(imap->first);
3048  if (etag==sourcetag) {
3049  std::cout << "This relation has already been created" << std::endl;
3050  } else {
3051  std::cout << "ERROR: Tag in parent already related to " <<
3052  etag << std::endl;
3053  return 34;
3054  }
3055  }
3056  catch (cool::Exception& e ) {
3057  // only do creation if does not already exist - via exception
3058  try {
3059  destfl->createTagRelation(imap->first,sourcetag);
3060  // check if this implicates yet another parent folder to be checked
3061  if (find(m_hiparent.begin(),m_hiparent.end(),imap->second)==
3062  m_hiparent.end()) m_hiparent.push_back(imap->second);
3063  if (m_copytaginfo &&
3064  m_cooltagmap.find(imap->first)==m_cooltagmap.end())
3065  m_cooltagmap.insert(CoolTagMap::value_type(imap->first,
3066  CoolTagInfo(m_sourceDbPtr,imap->second,imap->second,
3067  imap->first,imap->first)));
3068  }
3069  catch (cool::Exception& e) {
3070  std::cout << "Cool exception " << e.what() <<
3071  "thrown in hierarchical tag creation" << std::endl;
3072  return 34;
3073  }
3074  }
3075  }
3076  // exceptions from findTag - do nothing
3077  catch (cool::Exception& e) { }
3078  }
3079  } else {
3080  std::cout << "ERROR Folderset " << folderset << " not found" <<
3081  std::endl;
3082  }
3083  }
3084  return 0;
3085 }
3086 
3088  std::cout << "Write tag description ";
3089  if (m_copytaglock) std::cout << "and lock info ";
3090  std::cout << "for " << m_cooltagmap.size() << " tags" << std::endl;
3091  for (CoolTagMap::const_iterator itr=m_cooltagmap.begin();
3092  itr!=m_cooltagmap.end();++itr) {
3093  itr->second.write(m_destDbPtr,m_copytaglock);
3094  }
3095  return 0;
3096 }
3097 
3099  std::cout << "Total of " << m_poolrefs.size() << " POOL files referenced"
3100  << std::endl;
3101  for (PoolMap::const_iterator ipool=m_poolrefs.begin();
3102  ipool!=m_poolrefs.end();++ipool) {
3103  std::cout << "Ref " << ipool->first << " (" << ipool->second.count()
3104  << ")" << std::endl;
3105  }
3106  return 0;
3107 }
3108 
3109 int AtlCoolCopy::resolvePoolRefs ATLAS_NOT_THREAD_SAFE () {
3110  std::cout << "Total of " << m_poolrefs.size() << " POOL Files referenced"
3111  << std::endl;
3112  pool::IFileCatalog* catalog=setupCatalog(m_poolcat);
3113  if (catalog==nullptr) return 110;
3114  pool::SimpleUtilityBase pool_utility;
3115  if (m_poolopen) {
3116  // prepare POOL session
3117  pool_utility.startSession();
3118  }
3119  // inject additional GUIDs/LFNs if needed
3120  if (!m_addguid.empty()) {
3121  for (std::vector<std::string>::const_iterator itr=m_addguid.begin();
3122  itr!=m_addguid.end();++itr) {
3123  m_poolrefs[*itr]=PoolMapElement(1,"ADDGUID");
3124  std::cout << "Added POOL file GUID: " << *itr << std::endl;
3125  }
3126  }
3127  if (!m_addlfn.empty()) {
3128  for (std::vector<std::string>::const_iterator itr=m_addlfn.begin();
3129  itr!=m_addlfn.end();++itr) {
3130  std::string guid;
3131  catalog->lookupFileByLFN(*itr,guid);
3132  std::cout << "Add POOL file GUID: " << guid << " from LFN " << *itr
3133  << std::endl;
3134  m_poolrefs[guid]=PoolMapElement(1,"ADDLFN");
3135  }
3136  }
3137 
3138  // set up for making new dataset if needed
3139  using LFNGVec = std::vector<std::pair<std::string, std::string> >;
3140  LFNGVec dsfound;
3141  bool dscopy=!m_newdataset.empty();
3142 
3143  // loop through GUIDs and attempt to resolve
3144  int nbad=0;
3145  for (PoolMap::iterator ipool=m_poolrefs.begin();
3146  ipool!=m_poolrefs.end();++ipool) {
3147  pool::FileCatalog::FileID guid=ipool->first;
3149  catalog->getLFNs( guid, lfns );
3150  if( !lfns.empty() ) {
3151  // file found in cataloge - print LFN and usage count
3152  const std::string lfn = lfns[0].first;
3153  ipool->second.setlfn(lfn);
3154  std::cout << "LFN: " << lfn << " (" << ipool->second.count()
3155  << ")" << std::endl;
3156  if (dscopy)
3157  dsfound.push_back(std::pair<std::string,std::string>(lfn,guid));
3158  } else {
3159  // error bit 0 - no LFN
3160  if (!m_listpfn) ipool->second.setErrorBit(0);
3161  }
3162  if (m_listpfn || m_poolopen) {
3163  std::string pfn, tech;
3164  catalog->getFirstPFN( guid, pfn, tech );
3165  if( !pfn.empty() ) {
3166  ipool->second.setpfn(pfn);
3167  std::cout << "PFN: " << pfn << " (" << ipool->second.count()
3168  << ")" << std::endl;
3169  if (m_poolopen) {
3170  // first try the file as a CoolHist file
3171  std::string hguid=getCoolHistGUID(pfn);
3172  if (!hguid.empty()) {
3173  // successful get of CoolHist GUID
3174  if (hguid!=ipool->first) {
3175  std::cout << "ERROR File CoolHist GUID " << hguid <<
3176  " inconsistent with catalogue " << ipool->first << std::endl;
3177  ipool->second.setErrorBit(3);
3178  }
3179  } else {
3180  // try the file as a genuine POOL file
3181  try {
3182  const std::string fid = pool_utility.readFileGUID( pfn );
3183  if( fid != ipool->first ) {
3184  std::cout << "ERROR File GUID " << fid <<
3185  " inconsistent with catalogue " << ipool->first << std::endl;
3186  // file GUID inconsistent with catalogue - error bit 3
3187  ipool->second.setErrorBit(3);
3188  }
3189  }
3190  catch( std::runtime_error& e ) {
3191  std::cout << "Cannot open file for reading!" << std::endl;
3192  std::cout << e.what() << std::endl;
3193  // File cannot be opened: set error bit 2
3194  ipool->second.setErrorBit(2);
3195  }
3196  }
3197  } // end of actions opening POOL file
3198  } else {
3199  // PFN not found - set bit 1
3200  ipool->second.setErrorBit(1);
3201  }
3202  }
3203  // check file error code
3204  if (ipool->second.errcode()>0) ++nbad;
3205  }
3206  catalog->commit();
3207  catalog->disconnect();
3208  delete catalog;
3209 
3210  // produce definition of new dataset if needed
3211  if (dscopy) {
3212  // start up a new catalogue instance with the merge catalogues
3213  // which indicate which files are already available and don't need to
3214  // put in the output dataset definition
3215  catalog=setupCatalog(m_mergecat);
3216  if (catalog==nullptr) return 110;
3217  const std::string dssname="register.sh";
3218  std::cout << "Write DQ2 registerFileInDataset commands to " << dssname
3219  << " for registration in dataset " << m_newdataset << std::endl;
3220  std::ofstream dsstream(dssname.c_str());
3221  for (LFNGVec::const_iterator itr=dsfound.begin();
3222  itr!=dsfound.end();++itr) {
3223  const std::string& lfn=itr->first;
3224  const std::string& guid=itr->second;
3226  catalog->getLFNs( guid, lfns );
3227  if( !lfns.empty() ) {
3228  // file is already registered - check logical names are consistent
3229  const std::string lfn2 = lfns[0].first;
3230  if (lfn2!=lfn) std::cout << "WARNING: LFNs for GUID " << guid <<
3231  " differ in input/merge datasets: " << lfn << " vs "
3232  << lfn2 << std::endl;
3233  } else {
3234  // file is not registered - add to output
3235  dsstream << "dq2-register-files " << m_newdataset << " "
3236  << lfn << " " << guid << std::endl;
3237  }
3238  }
3239  catalog->commit();
3240  catalog->disconnect();
3241  delete catalog;
3242  }
3243 
3244  int retcode=0;
3245  if (nbad==0) {
3246  std::cout << "All POOL references were resolved by catalogues"
3247  << std::endl;
3248  } else {
3249  std::cout << "ERROR Could not resolve " << nbad << " files" << std::endl;
3250  retcode=111;
3251  }
3252  if (nbad>0 || m_poolall) filePoolRefs();
3253  return retcode;
3254 }
3255 
3256 std::string AtlCoolCopy::getCoolHistGUID(const std::string& file) {
3257  // attempt to extract COOL Hist GUID from file
3258  std::string hguid="";
3259  TFile* myfile=TFile::Open(file.c_str(),"READ");
3260  if (myfile!=nullptr) {
3261  TObjString* oguid;
3262  myfile->GetObject("fileGUID",oguid);
3263  if (oguid!=nullptr) {
3264  hguid=oguid->GetString();
3265  std::cout << "CoolHist GUID found to be " << hguid << std::endl;
3266  }
3267  myfile->Close();
3268  }
3269  return hguid;
3270 }
3271 
3273  // list POOL refs and error codes, optionally to file
3274  if (!m_checkoutputfile.empty()) {
3275  std::cout << "Write POOL file checkoutput on " << m_checkoutputfile <<
3276  std::endl;
3277  } else {
3278  m_checkoutputfile="/dev/null";
3279  }
3280  std::ofstream chkostream(m_checkoutputfile.c_str());
3281  std::cout << "ErrCode GUID Count LFN PFN Folders ..." << std::endl;
3282  for (PoolMap::const_iterator ipool=m_poolrefs.begin();
3283  ipool!=m_poolrefs.end();++ipool) {
3284  if (m_poolall || ipool->second.errcode()>0) {
3285  std::ostringstream line;
3286  // write error code, GUID, usage count
3287  line << ipool->second.errcode() << " " << ipool->first << " " <<
3288  ipool->second.count() << " ";
3289  if (!ipool->second.lfn().empty()) {
3290  line << ipool->second.lfn() << " ";
3291  } else {
3292  line << "noLFN ";
3293  }
3294  if (!ipool->second.pfn().empty()) {
3295  line << ipool->second.pfn() << " ";
3296  } else {
3297  line << "noPFN ";
3298  }
3299  for (std::vector<std::string>::const_iterator
3300  itr=ipool->second.foldertag().begin();
3301  itr!=ipool->second.foldertag().end();++itr)
3302  line << *itr << " ";
3303  std::cout << line.str() << std::endl;
3304  chkostream << line.str() << std::endl;
3305  }
3306  }
3307 }
3308 
3310  const std::vector<std::string>& catvec) {
3312  try {
3313  catalog->setWriteCatalog("file:PoolFileCatalog.xml");
3314  for (std::vector<std::string>::const_iterator icat=catvec.begin();
3315  icat!=catvec.end();++icat) {
3316  std::cout << "Add catalogue: " << *icat << std::endl;
3317  // if catalogue contains no ":" specifier, assume plain file
3318  if (icat->find(':')==std::string::npos) {
3319  catalog->addReadCatalog("file:"+(*icat));
3320  } else {
3321  catalog->addReadCatalog(*icat);
3322  }
3323  }
3324  catalog->connect();
3325  catalog->start();
3326  return catalog;
3327  }
3328  catch (std::exception& e) {
3329  std::cout << "Could not setup POOL catalogues, exception:" << e.what()
3330  << std::endl;
3331  return nullptr;
3332  }
3333 }
3334 
3335 void printHelp() {
3336  std::cout << "usage: AtlCoolCopy.exe <sourceCoolDB> <destinationCoolDB> { <options> }" << std::endl;
3337  std::cout << "Options are (see doc/mainpage.h for more):" << std::endl <<
3338  "-a, -alliov : set IOVs on destination to [ValidityKeyMin, ValidityKeyMax]" << std::endl <<" or following settings of -nrls,-nrlu,-nts,-ntu" <<
3339  std::endl <<
3340  "-ag, -addguid <guid> : Add GUID to list accessed for POOL checks" <<
3341  std::endl <<
3342  "-alf, -addlfn <LFN> : Add LFN to list accessed for POOL checks" <<
3343  std::endl <<
3344  "-al, -appendlocked : Allow locked tags to be updated if no overlap" <<
3345  std::endl <<
3346  "-alsv, -appendlockedsv : Allow locked tag update for openended IOVs" <<
3347  std::endl <<
3348  "-ana, -analyse <delta_t>: produce analysis ROOT file (filename = dest DB argument)" << std::endl <<
3349 "-bs, -buffersize <size> : set size of bulkstorage output buf to <size> objs"
3350  << std::endl <<
3351  "-c, -create : create destination DB if not already existing"
3352  << std::endl <<
3353  "-cd, -checkdest : Check destination DB and skip already existing tags"
3354  << std::endl <<
3355  "-ch, -channel : restrict selection to given channel or range specified as c1:c2" << std::endl <<
3356  "-ch1, -channel1 : specify start of a range of channels" << std::endl <<
3357  "-ch2, -channel2 : specify end of a range of channels" << std::endl <<
3358  "-cf, -checkfiles : check POOL files can be opened and have correct GUID"
3359  << std::endl <<
3360  "-co, -checkoutput <file> : write POOL file check output on file"
3361  << std::endl << "-cti, -copytaginfo : Copy tag descriptions"
3362  << std::endl << "-ctl, -copytaglock : Copy tag locked status and descriptions"
3363  << std::endl << "-cr, -checkrefs : check POOL references"
3364  << std::endl << "-d, -debug : produce debug output" << std::endl;
3365  std::cout <<
3366  "-ds, -dataset : output register.sh for creating DQ2 datasets "
3367  << std::endl <<
3368  "-ec, -excludechannel : exclude given channel from copy" << std::endl <<
3369  "-eh, -excludehead : exclude HEAD tag even if no tags found in MV folders"
3370  << std::endl <<
3371  "-ih, -includehead : include HEAD as well as any tags in MV folders" <<
3372  std::endl <<
3373  "-e, -exclude <pattern> : exclude folders" << std::endl <<
3374  "-f, -folder <pattern> : include folders" << std::endl <<
3375  "-fs, -forcesingle : force destination folder to be singleversion"
3376  << std::endl <<
3377  "-fm, -forcemulti : force destination folder to be multiversion"
3378  << std::endl <<
3379  "-frl, -forcerunlumi : force destination folder to be run/LB indexed"
3380  << std::endl <<
3381  "-ftm, -forcetime : force destination folder to be timestamp indexed"
3382  << std::endl <<
3383  "-fp, -forcepayload : Force destn folders to be created with payload tbl" << std::endl <<
3384  "-fnp, -forcenopayload : Force destn folders to be created without payload tbl" << std::endl <<
3385  "-forcerecreate : delete and recreate destination database" << std::endl;
3386  std::cout << "-ht, -headtag : Use HEAD-style tagging"
3387  << std::endl <<
3388  "-go, -getonline : Set minimum run number (-rls setting) to next ONLINE run"
3389  << std::endl <<
3390  "-gb, -getbulk : Set minimum run number (-rls setting) to next bulk reco run"
3391  << std::endl <<
3392  "-gt, -gettime : Extract timestamp information for given run number range"
3393  << std::endl <<
3394  "-h, -help : print help and exit" << std::endl <<
3395  "-hi, -hitag : Copy hierrchical tags inclusively" << std::endl <<
3396  "-ignoremode <pwd> : Ignore UPDx mode protection (experts only)"
3397  << std::endl <<
3398  "-is, -ignorespec : Ignore differences in folder spec if names are all equal" << std::endl <<
3399  "-lo, -lockedonly : Only copy locked/partially-locked top-level tags"
3400  << std::endl <<
3401  "-nc, -nocopy : Do not actually copy, just read source DB" << std::endl <<
3402  "-nch, -nochannel : Do not check or copy channel information" << std::endl
3403 << "-ncr, -noclobroot: Do not copy CLOB data into ROOT files" << std::endl
3404 << "-noc, -nocoracool : Do not copy Coracool structure payloads " << std::endl <<
3405  "-nd, -nodata : Copy only folder structures, not data" << std::endl <<
3406  "-nh, -nohitag : Do not follow hierarchical tag relations" << std::endl <<
3407 "-mc, -mergecat <catfile> : specify POOL file catalogue for new dataset making"
3408  << std::endl;
3409  std::cout << "-of, -outfolder <folder> : rename folder on output"
3410  << std::endl <<
3411  "-onr, -onlinerun : Retrieve run number from online server (not replica)" <<std::endl <<
3412  "-ot, -outtag : " << "Rename tag on output" << std::endl;
3413  std::cout <<
3414  "-pa, -poolall : Output all POOL files (incl good) when checking files"
3415  << std::endl <<
3416 "-pc, -poolcat <catfile> : specify POOL file catalogue for ref checking"
3417  << std::endl <<
3418  "-pf, -parfile <file> : Read additional options/parameters from file" <<
3419  std::endl <<
3420 "-pt, -prunetags : Copy only hierarchical tags descending from specified toptags"
3421  << std::endl <<
3422 "-rdo, -readoracle : force data to be read from Oracle, using dbreplica.config"
3423  << std::endl <<
3424  "-sl, -seal <val>: Set SEAL (hence COOL/POOL) output level to <val>"
3425  << std::endl <<
3426  "-sr, -skiprep : Skip folders having <norep/> folder metadata tag" <<
3427  std::endl <<
3428  "-t, -tag <tag> : Copy multiversion data with tag <tag>" << std::endl <<
3429  "-mt, -magic <tag> : Include magic tags involving the given pattern " << std::endl <<
3430 "-tr, -truncate : Set destination IOVs outside query interval to query interval"
3431  << std::endl <<
3432 "-tl, -taglabel : Specify tag description to enter in destination DB"
3433  << std::endl <<
3434  "-uht, -userheadtag : Also copy user tag data to the HEAD" << std::endl <<
3435  "-v, -verify : Verify data present on destination rather than copying" <<
3436  std::endl <<
3437  "-ro, -root : Produce ROOT output file instead of copying to COOL"
3438  << std::endl <<
3439  "-zn, -zeronull : Zero NULLs in ROOT file instead of skipping them" <<
3440  std::endl <<
3441  "-rls, -runlumisince <run> <LB> : Set minimum IOV interval" << std::endl <<
3442  "-rlu, -runlumiuntil <run> <LB> : Set maximum IOV interval" << std::endl <<
3443  "-rs, -runsince <run> : Set minimum IOV interval" << std::endl <<
3444  "-ru, -rununtil <run> : Set maximum IOV interval" << std::endl <<
3445  "-r, -run <run> : Copy only run <run>" << std::endl <<
3446 "-srls, -skiprunlumisince <run> <LB> : Set minimum IOV for skipping IOV in copy"
3447  << std::endl <<
3448 "-srlu, -skiprunlumiuntil <run> <LB> : Set maximum IOV for skipping IOV in copy"
3449  << std::endl <<
3450  "-tdb, -timedb <dbconn> : Set database connection for time information" <<
3451  "-ts, -timesince <time> : Set minimum IOV interval (UTC SECONDs or UTC YYYY-MM-DD:hh:mm:ss)" <<
3452  std::endl <<
3453  "-tu, -timeuntil <time> : Set maximum IOV interval (UTC SECONDs or UTC YYYY-MM-DD:hh:mm:ss)" <<
3454  std::endl;
3455  std::cout <<
3456  "-nrls, -newrunlumisince <run> <LB> : Set minimum of output IOV interval (use with -alliov)" << std::endl <<
3457  "-nrlu, -newrunlumiuntil <run> <LB> : Set maximum of output IOV interval (use with --aliov)" << std::endl <<
3458  "-nts, -newtimesince <time> : Set minimum of outputIOV interval (UTC SECONDs or UTC YYYY-MM-DD:hh:mm:ss) (use with --alliov)" <<
3459  std::endl <<
3460  "-ntu, -newtimeuntil <time> : Set maximum of output IOV interval (UTC SECONDs or UTC YYYY-MM-DD:hh:mm:ss) (use with --alliov)" <<
3461  std::endl;
3462  std::cout << "See http://twiki.cern.ch/twiki/bin/view/Atlas/AtlCoolCopy for more details" << std::endl;
3463 }
3464 
3465 int main ATLAS_NOT_THREAD_SAFE (int argc, const char* argv[]) {
3466  int retcode=0;
3467  if (argc<3) {
3468  printHelp();
3469  retcode=1;
3470  } else {
3471  AtlCoolCopy mycopy(argv[1],argv[2]);
3472  retcode=mycopy.setOpts(argc-3,&argv[3]);
3473  if (retcode==999) {
3474  printHelp();
3475  return 0;
3476  }
3477  if (retcode==0) retcode=mycopy.doCopy();
3478  }
3479  if (retcode>0) std::cout << "ERROR AtlCoolCopy.exe fails with exit code " <<
3480  retcode << std::endl;
3481  return retcode;
3482 }
SimpleUtilityBase.h
AtlCoolCopy::analyseIOVs
int analyseIOVs(const std::string &folder, const cool::IFolderPtr &sourcefl, const std::string &sourcetag, const cool::ValidityKey since, const cool::ValidityKey until, const bool timestamp)
Definition: AtlCoolCopy.cxx:1847
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AtlCoolCopy::runLBVal
static cool::ValidityKey runLBVal(const char *input1, const char *input2)
Definition: AtlCoolCopy.cxx:2575
AtlCoolCopy::channelID
static cool::ChannelId channelID(const cool::IFolderPtr &folder, const std::string &chanstring)
Definition: AtlCoolCopy.cxx:856
AtlCoolCopy::m_skipout
bool m_skipout
Definition: AtlCoolCopy.cxx:204
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
AtlCoolCopy::rootWrite
void rootWrite(void *sptr, const cool::IField &field) const
Definition: AtlCoolCopy.cxx:1769
AtlCoolCopy::m_magic
std::vector< std::string > m_magic
Definition: AtlCoolCopy.cxx:264
AtlCoolCopy::m_getbulk
bool m_getbulk
Definition: AtlCoolCopy.cxx:212
pool::SimpleUtilityBase::readFileGUID
virtual std::string readFileGUID(const std::string &pfn)
AtlCoolCopy::verifyIOVs
int verifyIOVs(const std::string &folder, const cool::IFolderPtr &sourcefl, const CoraCoolFolderPtr &sourceflc, const cool::IFolderPtr &destfl, const CoraCoolFolderPtr &destflc, const std::string &sourcetag, const cool::ValidityKey since, const cool::ValidityKey until, const bool checkrefs, const bool iscora, const cool::PayloadMode::Mode paymode)
Definition: AtlCoolCopy.cxx:1356
AtlCoolCopy::m_nt_rununtil
UInt_t m_nt_rununtil
Definition: AtlCoolCopy.cxx:288
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAOD::short
short
Definition: Vertex_v1.cxx:165
TH1F::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:326
AtlCoolCopy
Definition: AtlCoolCopy.cxx:81
AtlCoolCopy::m_outtag
std::string m_outtag
Definition: AtlCoolCopy.cxx:239
get_generator_info.result
result
Definition: get_generator_info.py:21
pool::IFileCatalog::Files
Gaudi::IFileCatalog::Files Files
Definition: IFileCatalog.h:26
AtlCoolCopy::m_channel1
std::string m_channel1
Definition: AtlCoolCopy.cxx:233
AtlCoolCopy::ATLAS_NOT_THREAD_SAFE
int doCopy ATLAS_NOT_THREAD_SAFE()
python.rtime.rtime
def rtime(fn, *args, **kw)
Definition: rtime.py:15
CheckTagAssociation.localtag
localtag
Definition: CheckTagAssociation.py:19
AtlCoolCopy::m_verify
bool m_verify
Definition: AtlCoolCopy.cxx:182
AtlCoolCopy::m_nt_lbuntil
UInt_t m_nt_lbuntil
Definition: AtlCoolCopy.cxx:290
AtlCoolCopy::m_srunemax
cool::ValidityKey m_srunemax
Definition: AtlCoolCopy.cxx:231
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CoraCoolDatabase
Definition: CoraCoolDatabase.h:24
AtlCoolCopy::m_coralsvc
coral::ConnectionService m_coralsvc
Definition: AtlCoolCopy.cxx:253
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
json
nlohmann::json json
Definition: HistogramDef.cxx:9
AtlCoolCopy::m_copytaglock
bool m_copytaglock
Definition: AtlCoolCopy.cxx:216
AtlCoolCopy::getTimeFromRun
bool getTimeFromRun()
Definition: AtlCoolCopy.cxx:2594
response
MDT_Response response
Definition: MDT_ResponseTest.cxx:28
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
AtlCoolCopy::m_readoracle
bool m_readoracle
Definition: AtlCoolCopy.cxx:208
AtlCoolCopy::m_destdb
std::string m_destdb
Definition: AtlCoolCopy.cxx:173
AtlCoolCopy::m_repsort
ReplicaSorter * m_repsort
Definition: AtlCoolCopy.cxx:256
AtlCoolCopy::m_getonline
bool m_getonline
Definition: AtlCoolCopy.cxx:210
AtlCoolCopy::getUpdateMode
static int getUpdateMode(std::string_view desc, std::string_view tag)
Definition: AtlCoolCopy.cxx:2893
mergePhysValFiles.newfolder
newfolder
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:83
AtlCoolCopy::m_checkoutputfile
std::string m_checkoutputfile
Definition: AtlCoolCopy.cxx:241
pool::FileCatalog::FileID
std::string FileID
Definition: IFileCatalog.h:20
AtlCoolCopy::setChannelRange
void setChannelRange(const cool::IFolderPtr &sourcefl)
Definition: AtlCoolCopy.cxx:821
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:983
extractSporadic.c1
c1
Definition: extractSporadic.py:134
tree
TChain * tree
Definition: tile_monitor.h:30
IDatabase.h
AtlCoolCopy::m_excludehead
bool m_excludehead
Definition: AtlCoolCopy.cxx:177
IFileCatalog.h
dirname
std::string dirname(std::string name)
Definition: utils.cxx:200
AtlCoolCopy::rootDirs
std::string rootDirs(const std::string &folder, const std::string &toproot)
Definition: AtlCoolCopy.cxx:1682
AtlCoolCopy::m_truncate
bool m_truncate
Definition: AtlCoolCopy.cxx:203
AtlCoolCopy::ATLAS_NOT_THREAD_SAFE
int copyFolder ATLAS_NOT_THREAD_SAFE(const std::string &folder, const std::vector< std::string > &taglist)
AtlCoolCopy::m_timemax
cool::ValidityKey m_timemax
Definition: AtlCoolCopy.cxx:225
bin
Definition: BinsDiffFromStripMedian.h:43
AtlCoolCopy::m_hitag
bool m_hitag
Definition: AtlCoolCopy.cxx:194
AtlCoolCopy::m_chansel
cool::ChannelSelection m_chansel
Definition: AtlCoolCopy.cxx:268
PlotCalibFromCool.nchan
nchan
Definition: PlotCalibFromCool.py:564
AtlCoolCopy::openConnections
bool openConnections(const std::string &sourcedb, const std::string &destdb, bool allowcreate)
Definition: AtlCoolCopy.cxx:340
AtlCoolCopy::m_userupdatehead
bool m_userupdatehead
Definition: AtlCoolCopy.cxx:179
CheckTagAssociation.taglist
taglist
Definition: CheckTagAssociation.py:103
AtlCoolCopy::m_parfile
std::vector< std::string > m_parfile
Definition: AtlCoolCopy.cxx:247
pool::IFileCatalog::disconnect
void disconnect()
Definition: IFileCatalog.h:40
AtlCoolCopy::m_hitagmap
HiTagMap m_hitagmap
Definition: AtlCoolCopy.cxx:274
pool::IFileCatalog::commit
void commit()
Save catalog to file.
Definition: IFileCatalog.h:49
AtlCoolCopy::m_dbSvc
cool::IDatabaseSvc * m_dbSvc
Definition: AtlCoolCopy.cxx:255
exclude
std::set< std::string > exclude
list of directories to be excluded
Definition: hcg.cxx:95
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
AtlCoolCopy::m_newrunemin
cool::ValidityKey m_newrunemin
Definition: AtlCoolCopy.cxx:226
AtlCoolCopy::m_usertags
bool m_usertags
Definition: AtlCoolCopy.cxx:178
AtlCoolCopy::m_srunemin
cool::ValidityKey m_srunemin
Definition: AtlCoolCopy.cxx:230
AtlCoolCopy::m_sourcedb
std::string m_sourcedb
Definition: AtlCoolCopy.cxx:172
CaloSwCorrections.gap
def gap(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:212
AtlCoolCopy::m_forcemulti
bool m_forcemulti
Definition: AtlCoolCopy.cxx:197
ITransaction.h
physics_parameters.url
string url
Definition: physics_parameters.py:27
ATLAS_NOT_THREAD_SAFE
int AtlCoolCopy::copyFolder ATLAS_NOT_THREAD_SAFE(const std::string &folder, const std::vector< std::string > &taglist)
Definition: AtlCoolCopy.cxx:536
AtlCoolCopy::equalRecord
static bool equalRecord(const cool::IRecord &lhs, const cool::IRecord &rhs)
Definition: AtlCoolCopy.cxx:2499
AtlCoolCopy::m_ignoremode
bool m_ignoremode
Definition: AtlCoolCopy.cxx:218
atlasStyleMacro.icol
int icol
Definition: atlasStyleMacro.py:13
AtlCoolCopy::m_newtimemax
cool::ValidityKey m_newtimemax
Definition: AtlCoolCopy.cxx:229
CoraCoolObject.h
cool
Definition: CoolTagInfo.h:12
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
AtlCoolCopy::timeVal
static cool::ValidityKey timeVal(const char *input)
Definition: AtlCoolCopy.cxx:2531
AtlCoolCopy::m_coracool
bool m_coracool
Definition: AtlCoolCopy.cxx:217
AtlCoolCopy::m_applocksv
bool m_applocksv
Definition: AtlCoolCopy.cxx:207
pool::IFileCatalog::lookupFileByLFN
void lookupFileByLFN(const std::string &lfn, std::string &fid) const
Return the status of a LFName.
Definition: IFileCatalog.h:82
python.Dumpers.aname
string aname
Definition: Dumpers.py:5541
AtlCoolCopy::getCoolHistGUID
static std::string getCoolHistGUID(const std::string &file)
Definition: AtlCoolCopy.cxx:3256
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
AtlCoolCopy::m_forcesingle
bool m_forcesingle
Definition: AtlCoolCopy.cxx:196
AtlCoolCopy::tagParents
int tagParents()
Definition: AtlCoolCopy.cxx:3025
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
AtlCoolCopy::m_gettime
bool m_gettime
Definition: AtlCoolCopy.cxx:209
AtlCoolCopy::checkRef
void checkRef(const cool::IRecord &payload, const std::string &folder, const std::string &tag)
Definition: AtlCoolCopy.cxx:2988
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
AtlCoolCopy::m_checkrefs
bool m_checkrefs
Definition: AtlCoolCopy.cxx:186
ReplicaSorter.h
python.TileCalibTools.copyFolder
def copyFolder(dbr, dbw, folder, tagr, tagw, chanNum, pointInTime1, pointInTime2)
Definition: TileCalibTools.py:441
AtlCoolCopy::setupCatalog
static pool::IFileCatalog * setupCatalog(const std::vector< std::string > &catvec)
Definition: AtlCoolCopy.cxx:3309
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AtlCoolCopy::m_poolrefs
PoolMap m_poolrefs
Definition: AtlCoolCopy.cxx:271
defineDB.folders
list folders
Definition: JetTagCalibration/share/defineDB.py:26
skel.input1
tuple input1
Definition: skel.GENtoEVGEN.py:770
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
AtlCoolCopy::m_nt_lbsince
UInt_t m_nt_lbsince
Definition: AtlCoolCopy.cxx:289
AtlCoolCopy::m_newrunemax
cool::ValidityKey m_newrunemax
Definition: AtlCoolCopy.cxx:227
CoraCoolObject::const_iterator
AttrListVec::const_iterator const_iterator
Definition: CoraCoolObject.h:23
AtlCoolCopy::m_nt_since
ULong64_t m_nt_since
Definition: AtlCoolCopy.cxx:285
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
AtlCoolCopy::m_nohitag
bool m_nohitag
Definition: AtlCoolCopy.cxx:195
pool::IFileCatalog
Definition: IFileCatalog.h:23
rerun_display.lfn
lfn
Definition: rerun_display.py:60
AtlCoolCopy::m_open
bool m_open
Definition: AtlCoolCopy.cxx:267
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
AtlCoolCopy::m_poolall
bool m_poolall
Definition: AtlCoolCopy.cxx:189
AtlCoolCopy::m_nt_runsince
UInt_t m_nt_runsince
Definition: AtlCoolCopy.cxx:287
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
AtlCoolCopy::m_skiprep
bool m_skiprep
Definition: AtlCoolCopy.cxx:205
lumiFormat.i
int i
Definition: lumiFormat.py:92
AtlCoolCopy::CoolTagMap
std::map< std::string, CoolTagInfo > CoolTagMap
Definition: AtlCoolCopy.cxx:279
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
python.LArBadChannelDBAlg.xFFFFFFFF
xFFFFFFFF
Definition: LArBadChannelDBAlg.py:73
AtlCoolCopy::m_alliov
bool m_alliov
Definition: AtlCoolCopy.cxx:181
AtlCoolCopy::m_nt_until
ULong64_t m_nt_until
Definition: AtlCoolCopy.cxx:286
maskDeadModules.run1
run1
Definition: maskDeadModules.py:40
AtlCoolCopy::m_channelRange
std::vector< std::string > m_channelRange
Definition: AtlCoolCopy.cxx:232
AtlCoolCopy::m_channel2
std::string m_channel2
Definition: AtlCoolCopy.cxx:234
AtlCoolCopy::m_ignorespec
bool m_ignorespec
Definition: AtlCoolCopy.cxx:219
AtlCoolCopy::m_checkdesttag
bool m_checkdesttag
Definition: AtlCoolCopy.cxx:220
AtlCoolCopy::m_poolcat
std::vector< std::string > m_poolcat
Definition: AtlCoolCopy.cxx:265
pool::IFileCatalog::start
void start()
redirect to init() for Gaudi FC
Definition: IFileCatalog.h:45
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
calibdata.exception
exception
Definition: calibdata.py:496
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
AtlCoolCopy::m_sourceread
bool m_sourceread
Definition: AtlCoolCopy.cxx:202
AtlCoolCopy::m_debug
bool m_debug
Definition: AtlCoolCopy.cxx:180
file
TFile * file
Definition: tile_monitor.h:29
AtlCoolCopy::m_excludechans
std::vector< cool::ChannelId > m_excludechans
Definition: AtlCoolCopy.cxx:248
ISession.h
AtlCoolCopy::adjustIOVs
void adjustIOVs(const cool::ValidityKey &since, const cool::ValidityKey &until, const cool::ValidityKey &qsince, const cool::ValidityKey &quntil, cool::ValidityKey &newsince, cool::ValidityKey &newuntil, const bool timestamp) const
Definition: AtlCoolCopy.cxx:1291
AtlCoolCopy::m_outfolder
std::string m_outfolder
Definition: AtlCoolCopy.cxx:238
Preparation.mode
mode
Definition: Preparation.py:95
AtlCoolCopy::ATLAS_NOT_THREAD_SAFE
int copyIOVs ATLAS_NOT_THREAD_SAFE(const std::string &folder, const std::string &destfolder, const cool::IFolderPtr &sourcefl, const CoraCoolFolderPtr &sourceflc, const cool::IFolderPtr &destfl, const CoraCoolFolderPtr &destflc, const std::string &sourcetag, const std::string &desttag, const cool::ValidityKey since, const cool::ValidityKey until, bool timestamp, bool checkrefs, bool iscora, const cool::PayloadMode::Mode paymode, bool created)
pool::IFileCatalog::setWriteCatalog
void setWriteCatalog(const std::string &connect)
Access to the (first) writable file catalog.
run
Definition: run.py:1
AtlCoolCopy::m_lockedonly
bool m_lockedonly
Definition: AtlCoolCopy.cxx:214
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
PoolMapElement.h
AtlCoolCopy::m_coolapp
cool::Application m_coolapp
Definition: AtlCoolCopy.cxx:254
AtlCoolCopy::m_listpfn
bool m_listpfn
Definition: AtlCoolCopy.cxx:187
AtlCoolCopy::procOptVector
bool procOptVector(const int argc, const char *argv[], std::vector< std::string > &folders)
Definition: AtlCoolCopy.cxx:2121
AtlCoolCopy::m_forcerune
bool m_forcerune
Definition: AtlCoolCopy.cxx:198
AtlCoolCopy::m_sourceDbPtr
cool::IDatabasePtr m_sourceDbPtr
Definition: AtlCoolCopy.cxx:257
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:319
pool::IFileCatalog::connect
void connect()
Definition: IFileCatalog.h:39
CoraCoolFolderPtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
Definition: CoraCoolTypes.h:15
AtlCoolCopy::m_runemax
cool::ValidityKey m_runemax
Definition: AtlCoolCopy.cxx:223
AtlCoolCopy::m_folderlist
std::vector< std::string > m_folderlist
Definition: AtlCoolCopy.cxx:261
AtlCoolCopy::m_poolopen
bool m_poolopen
Definition: AtlCoolCopy.cxx:188
AtlCoolCopy::m_runlist
std::vector< unsigned int > m_runlist
Definition: AtlCoolCopy.cxx:250
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
pool_uuid.guid
guid
Definition: pool_uuid.py:112
grepfile.ic
int ic
Definition: grepfile.py:33
ReadCellNoiseFromCoolCompare.run2
run2
Definition: ReadCellNoiseFromCoolCompare.py:53
AtlCoolCopy::m_onlinerun
bool m_onlinerun
Definition: AtlCoolCopy.cxx:211
CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
Definition: CoraCoolTypes.h:12
CoraCoolFolder.h
AtlCoolCopy::m_sealmsg
int m_sealmsg
Definition: AtlCoolCopy.cxx:236
AtlCoolCopy::m_sourceCoraPtr
CoraCoolDatabasePtr m_sourceCoraPtr
Definition: AtlCoolCopy.cxx:259
AtlCoolCopy::m_applock
bool m_applock
Definition: AtlCoolCopy.cxx:206
AtlCoolCopy::ATLAS_NOT_THREAD_SAFE
int resolvePoolRefs ATLAS_NOT_THREAD_SAFE()
AtlCoolCopy::listPoolRefs
int listPoolRefs()
Definition: AtlCoolCopy.cxx:3098
AtlCoolCopy::PoolMap
std::map< std::string, PoolMapElement > PoolMap
Definition: AtlCoolCopy.cxx:269
AtlCoolCopy::checkChannels
bool checkChannels(const std::string &folder, const cool::IFolderPtr &sourcefl, const cool::IFolderPtr &destfl, bool newfolder)
Definition: AtlCoolCopy.cxx:2911
pmontree.code
code
Definition: pmontree.py:443
AtlCoolCopy::m_taglabel
std::string m_taglabel
Definition: AtlCoolCopy.cxx:243
AtlCoolCopy::m_timemin
cool::ValidityKey m_timemin
Definition: AtlCoolCopy.cxx:224
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
printHelp
void printHelp()
Definition: AtlCoolCopy.cxx:3335
AtlCoolCopy::m_destDbPtr
cool::IDatabasePtr m_destDbPtr
Definition: AtlCoolCopy.cxx:258
AtlCoolCopy::nocopyIOVs
int nocopyIOVs(const std::string &folder, const cool::IFolderPtr &sourcefl, const std::string &sourcetag, const cool::ValidityKey since, const cool::ValidityKey until, bool checkrefs)
Definition: AtlCoolCopy.cxx:1322
AtlCoolCopy::filePoolRefs
void filePoolRefs()
Definition: AtlCoolCopy.cxx:3272
compileRPVLLRates.c2
c2
Definition: compileRPVLLRates.py:361
AtlCoolCopy::m_nt_bufferptr
std::vector< void * > m_nt_bufferptr
Definition: AtlCoolCopy.cxx:294
AtlCoolCopy::getBulkRun
bool getBulkRun()
Definition: AtlCoolCopy.cxx:2771
EventContainers::Mode
Mode
Definition: IdentifiableContainerBase.h:13
pool::SimpleUtilityBase
Common base class for POOL utilities.
Definition: SimpleUtilityBase.h:23
AtlCoolCopy::HiTagMap
std::map< std::string, std::string > HiTagMap
Definition: AtlCoolCopy.cxx:273
AtlCoolCopy::m_runemin
cool::ValidityKey m_runemin
Definition: AtlCoolCopy.cxx:222
AtlCoolCopy::writeTagInfo
int writeTagInfo()
Definition: AtlCoolCopy.cxx:3087
AtlCoolCopy::m_prunetags
bool m_prunetags
Definition: AtlCoolCopy.cxx:213
AtlCoolCopy::p_rootfile
TFile * p_rootfile
Definition: AtlCoolCopy.cxx:282
mc.nskip
nskip
Definition: mc.PhPy8EG_Hto4l_NNLOPS_nnlo_30_ggH125_ZZ4l.py:41
AtlCoolCopy::m_bufsize
int m_bufsize
Definition: AtlCoolCopy.cxx:235
AtlCoolCopy::m_timedb
std::string m_timedb
Definition: AtlCoolCopy.cxx:242
AtlCoolCopy::m_analyse
bool m_analyse
Definition: AtlCoolCopy.cxx:185
AtlCoolCopy::m_poollast
PoolMap::iterator m_poollast
Definition: AtlCoolCopy.cxx:270
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
AtlCoolCopy::m_tags
std::vector< std::string > m_tags
Definition: AtlCoolCopy.cxx:263
AtlCoolCopy::m_nochannel
bool m_nochannel
Definition: AtlCoolCopy.cxx:192
AtlCoolCopy::m_mergecat
std::vector< std::string > m_mergecat
Definition: AtlCoolCopy.cxx:266
pool::IFileCatalog::getFirstPFN
void getFirstPFN(const std::string &fid, std::string &pfn, std::string &tech) const
Get the first PFN + filetype for the given FID.
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:64
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
AtlCoolCopy::m_runinfohost
std::string m_runinfohost
Definition: AtlCoolCopy.cxx:244
CoolTagInfo
Definition: CoolTagInfo.h:16
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
AtlCoolCopy::m_nt_tagid
char m_nt_tagid[256]
Definition: AtlCoolCopy.cxx:292
AtlCoolCopy::m_forcepay
bool m_forcepay
Definition: AtlCoolCopy.cxx:200
AtlCoolCopy::m_nodata
bool m_nodata
Definition: AtlCoolCopy.cxx:191
TileSynchronizeBch.copyall
copyall
Definition: TileSynchronizeBch.py:47
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
AtlCoolCopy::bookOrFindTH1F
static TH1F * bookOrFindTH1F(const std::string &hID, const std::string &htitle, const int chan, const float xlow, const float xhigh)
Definition: AtlCoolCopy.cxx:2068
AtlCoolCopy::m_runfile
std::vector< std::string > m_runfile
Definition: AtlCoolCopy.cxx:249
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
CoraCoolObjectIterPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
Definition: CoraCoolTypes.h:21
TH1F
Definition: rootspy.cxx:320
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
CaloCellTimeCorrFiller.foldertag
string foldertag
Definition: CaloCellTimeCorrFiller.py:21
AtlCoolCopy::addFolder
bool addFolder(const std::string &folder, const bool onlyTags)
Definition: AtlCoolCopy.cxx:461
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
AtlCoolCopy::m_cooltagmap
CoolTagMap m_cooltagmap
Definition: AtlCoolCopy.cxx:280
AtlCoolCopy::m_copytaginfo
bool m_copytaginfo
Definition: AtlCoolCopy.cxx:215
AtlCoolCopy::transConn
static std::string transConn(const std::string &inconn)
Definition: AtlCoolCopy.cxx:450
AtlCoolCopy::m_includehead
bool m_includehead
Definition: AtlCoolCopy.cxx:176
AtlCoolCopy::getRunList
bool getRunList()
Definition: AtlCoolCopy.cxx:2863
CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
Definition: CoraCoolTypes.h:18
AtlCoolCopy::m_newdataset
std::string m_newdataset
Definition: AtlCoolCopy.cxx:240
AtlCoolCopy::m_nt_treename
std::string m_nt_treename
Definition: AtlCoolCopy.cxx:293
AtlCoolCopy::m_root
bool m_root
Definition: AtlCoolCopy.cxx:183
CoraCoolDatabase.h
BchCleanup.outtag
outtag
Definition: BchCleanup.py:109
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
AtlCoolCopy::isOpen
bool isOpen() const
Definition: AtlCoolCopy.cxx:297
AtlCoolCopy::m_recreate
bool m_recreate
Definition: AtlCoolCopy.cxx:175
AtlCoolCopy::rootAllocate
bool rootAllocate(const cool::IFieldSpecification &spec, void *&sptr, char &rootID) const
Definition: AtlCoolCopy.cxx:1716
AtlCoolCopy::m_destCoraPtr
CoraCoolDatabasePtr m_destCoraPtr
Definition: AtlCoolCopy.cxx:260
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
CoolTagInfo.h
CoraCoolObjectIter.h
WriteCallback
size_t WriteCallback(void *contents, size_t size, size_t nmemb, std::string *s)
Definition: AtlCoolCopy.cxx:65
AtlCoolCopy::m_nocopy
bool m_nocopy
Definition: AtlCoolCopy.cxx:190
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
AtlCoolCopy::getLockedTags
bool getLockedTags()
Definition: AtlCoolCopy.cxx:430
AtlCoolCopy::m_nt_channel
UInt_t m_nt_channel
Definition: AtlCoolCopy.cxx:291
AtlCoolCopy::m_zeronull
bool m_zeronull
Definition: AtlCoolCopy.cxx:184
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
AtlCoolCopy::AtlCoolCopy
AtlCoolCopy(const std::string &sourcedb, const std::string &destdb, bool allowcreate=false)
Definition: AtlCoolCopy.cxx:301
AtlCoolCopy::m_noclobroot
bool m_noclobroot
Definition: AtlCoolCopy.cxx:221
AtlCoolCopy::setOpts
int setOpts(int argc, const char *argv[])
Definition: AtlCoolCopy.cxx:2368
AtlCoolCopy::m_addlfn
std::vector< std::string > m_addlfn
Definition: AtlCoolCopy.cxx:246
get_generator_info.error
error
Definition: get_generator_info.py:40
AtlCoolCopy::addExclude
bool addExclude(const std::string &folder)
Definition: AtlCoolCopy.cxx:529
AtlCoolCopy::m_anadelt
long long m_anadelt
Definition: AtlCoolCopy.cxx:237
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:135
error
Definition: IImpactPoint3dEstimator.h:70
AtlCoolCopy::m_hiparent
std::vector< std::string > m_hiparent
Definition: AtlCoolCopy.cxx:276
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
AtlCoolCopy::m_chdesc
bool m_chdesc
Definition: AtlCoolCopy.cxx:193
AtlCoolCopy::timeString
static std::string timeString(const cool::ValidityKey iovtime)
Definition: AtlCoolCopy.cxx:2562
AtlCoolCopy::rootIOVs
int rootIOVs(const std::string &folder, const cool::IFolderPtr &sourcefl, const std::string &sourcetag, const cool::ValidityKey since, const cool::ValidityKey until, const bool timestamp)
Definition: AtlCoolCopy.cxx:1551
pool::IFileCatalog::addReadCatalog
void addReadCatalog(const std::string &connect)
Add new catalog identified by name to the existing ones.
Definition: IFileCatalog.h:116
ReplicaSorter
Definition: Database/CoolConvUtilities/src/ReplicaSorter.h:12
readCCLHist.float
float
Definition: readCCLHist.py:83
AtlCoolCopy::m_folderexcl
std::vector< std::string > m_folderexcl
Definition: AtlCoolCopy.cxx:262
AtlCoolCopy::m_allowcreate
bool m_allowcreate
Definition: AtlCoolCopy.cxx:174
AtlCoolCopy::m_forcetime
bool m_forcetime
Definition: AtlCoolCopy.cxx:199
AtlCoolCopy::getOnlineRun
bool getOnlineRun()
Definition: AtlCoolCopy.cxx:2683
PersistencySvcException.h
AtlCoolCopy::m_forcenopay
bool m_forcenopay
Definition: AtlCoolCopy.cxx:201
AtlCoolCopy::isNumeric
static bool isNumeric(const char *input)
Definition: AtlCoolCopy.cxx:2488
AtlCoolCopy::m_addguid
std::vector< std::string > m_addguid
Definition: AtlCoolCopy.cxx:245
AtlCoolCopy::openCoraCool
bool openCoraCool()
Definition: AtlCoolCopy.cxx:410
AtlCoolCopy::m_newtimemin
cool::ValidityKey m_newtimemin
Definition: AtlCoolCopy.cxx:228
PoolMapElement
Definition: PoolMapElement.h:14
pool::IFileCatalog::getLFNs
void getLFNs(const std::string &fid, Files &files) const
Get all logical names for a given FID. Return pairs <LFN,FID>
Definition: IFileCatalog.h:61