12 #include "CoolKernel/DatabaseId.h"
13 #include "CoolKernel/Exception.h"
14 #include "CoolKernel/IDatabaseSvc.h"
15 #include "CoolKernel/IDatabase.h"
16 #include "CoolApplication/Application.h"
17 #include "CoolKernel/IFolder.h"
18 #include "CoolKernel/FolderSpecification.h"
19 #include "CoolKernel/RecordSpecification.h"
20 #include "CoolKernel/Record.h"
21 #include "CoolKernel/FieldSpecification.h"
22 #include "CoolKernel/IObject.h"
23 #include "CoolKernel/IObjectIterator.h"
24 #include "CoolKernel/IRecordIterator.h"
25 #include "CoolKernel/StorageType.h"
31 #include "RelationalAccess/ConnectionService.h"
67 typedef cool::Float
c_t;
258 typedef std::pair<cool::ValidityKey, cool::ValidityKey>
IovPeriod_t;
261 cool::ValidityKey
s =runstart<<32LL;
263 cool::ValidityKey
e =(runend+1LL)<<32LL;
267 bool inInterval(
const cool::ValidityKey
n,
const cool::ValidityKey from,
const cool::ValidityKey
to){
268 return ((
n>from) and (
n<=
to));
272 if (
until ==0)
return 140000;
273 if (
until==1230768000000000000)
return 139999;
274 if (
until==1262304000000000000)
return 149999;
275 if (
until==1288569600000000000)
return 167999;
276 if (
until==1290686400000000000)
return 169799;
277 if (
until==1293840000000000000)
return 170999;
279 if (
until==1333588404000000000)
return 200804;
280 if (
until==1333612447000000000)
return 200805;
282 if (
until==1356998400000000000)
return 216999;
283 return cool::ValidityKeyMax;
288 if (
since==0)
return 0;
289 if (
since==1230768000000000000)
return 140000;
290 if (
since==1262304000000000000)
return 150000;
291 if (
since==1288569600000000000)
return 168000;
292 if (
since==1290686400000000000)
return 169800;
293 if (
since==1293840000000000000)
return 171000;
295 if (
since==1333588404000000000)
return 200805;
297 if (
since==1333612447000000000)
return 200806;
315 result = (numArgs>1) and (numArgs<4);
324 std::string
result(inconn);
325 if (inconn.find(
'/')==std::string::npos) {
326 result=
"sqlite://X;schema=/tmp/sroe/mycool.db;dbname="+inconn;
334 DbConnection(
const std::string & sourceDb,
const bool isCoraCool=
false);
343 const cool::IDatabaseSvc &
m_dbSvc;
352 return (descriptor.find(
"<coracool") != std::string::npos);
358 m_coolapp(&m_coralsvc),
359 m_dbSvc(m_coolapp.databaseService()),
360 m_sourceDbPtr(
nullptr),
361 m_sourceCoraPtr(
nullptr),
364 const std::string dbConnectionString=
transConn(sourceDb);
365 readOnly= (dbConnectionString.find (
"sqlite")==std::string::npos);
367 m_sourceDbPtr=m_dbSvc.openDatabase(dbConnectionString,readOnly);
369 m_sourceDbPtr,m_coralsvc,readOnly));
372 std::cout <<
"Cool exception caught: " <<
e.what() << std::endl;
375 std::cout<<
"creating "<<dbConnectionString<<std::endl;
376 m_sourceDbPtr=m_dbSvc.createDatabase(dbConnectionString);
378 std::cout <<
"Cool exception caught: " <<
e.what() << std::endl;
382 m_isOpen=(m_sourceDbPtr!=
nullptr);
412 std::string
tag=run1Tag;
421 const std::string
name;
422 const std::string
tag;
423 FolderSpec(
const std::string & thename,
const std::string & thetag):
name(thename),
tag(thetag){};
440 const cool::IFolderPtr &
ptr()
const;
451 :m_connection(theConnection),m_folderSpec(
theFolder),m_folderPtr{},
452 m_sourceflc{},m_isCoraCool(
false){
454 m_folderPtr=m_connection.dbPtr()->getFolder(
theFolder.name);
455 m_isCoraCool=checkWhetherCoraCool();
456 if (m_isCoraCool) m_sourceflc=m_connection.coraCoolPtr()->getFolder(
theFolder.name);
457 }
catch (cool::Exception &
e){
458 std::cout<<
" Could not get folder "<<
theFolder.name<<std::endl;
467 const cool::IFolderPtr &
482 return (cool::FolderVersioning::SINGLE_VERSION ==
m_folderPtr->versioningMode());
495 cool::RecordSpecification
497 if (
m_sourceflc==
nullptr)
return cool::RecordSpecification();
501 cool::RecordSpecification
533 if (ccPtr->size()>0){
556 std::map<IovKey_t, CoraCoolObject::AttrListVec> mapOfVectorsByIov;
563 return mapOfVectorsByIov;
571 cool::IObjectIteratorPtr sourceitr;
578 std::map<IovKey_t, cool::IRecordVector> mapOfVectorsByIov;
580 const cool::IObject& sobj=sourceitr->currentRef();
581 cool::IRecordIterator& spitr=sobj.payloadIterator();
582 const cool::IRecordVectorPtr svptr=spitr.fetchAllAsVector();
583 cool::IRecordVector::const_iterator svitr=svptr->begin();
584 cool::IRecordVector::const_iterator svend=svptr->end();
585 IovKey_t iov(sobj.since(),sobj.until(),sobj.channelId());
586 mapOfVectorsByIov[
iov]=*svptr;
589 return mapOfVectorsByIov;
600 template<
class R2,
class R1>
603 static bool warning(
true);
605 if (not
a[itemName].isNull()){
606 const R1 attribute =
a[itemName].data<R1>();
607 const R2
field =
static_cast<R2
>(attribute);
608 if (attribute !=
static_cast<R1
>(
field)) std::cout<<
"Cast value mismatch, attr.="<<attribute<<
", field="<<
field<<std::endl;
609 r[targetName].setValue<R2>(attribute);
611 r[targetName].setNull();
613 }
catch (coral::AttributeException &
e) {
614 if (warning) std::cout<<itemName<<
" gives exception"<<std::endl;
619 template<
class R2,
class R1>
622 setRecord<R2,R1>(
r,
a,itemName,itemName);
629 std::cout<<
"data size "<<
data.size()<<std::endl;
634 cool::RecordSpecification rSpec = destination.
payloadSpec();
635 cool::IRecordVector cvp;
636 for (
auto const & attrList:thisVectorPayload){
637 cool::Record
r(rSpec);
638 setRecord<Run2::Chip::chip_t, Run1::Chip::chip_t>(
r,attrList,
"chip");
639 setRecord<Run2::Chip::active_t, Run1::Chip::active_t>(
r,attrList,
"active");
640 setRecord<Run2::Chip::address_t, Run1::Chip::address_t>(
r,attrList,
"address");
641 setRecord<Run2::Chip::config_t, Run1::Chip::config_t>(
r,attrList,
"config");
642 setRecord<Run2::Chip::mask_t, Run1::Chip::mask_t>(
r,attrList,
"mask0");
643 setRecord<Run2::Chip::mask_t, Run1::Chip::mask_t>(
r,attrList,
"mask1");
644 setRecord<Run2::Chip::mask_t, Run1::Chip::mask_t>(
r,attrList,
"mask2");
645 setRecord<Run2::Chip::mask_t, Run1::Chip::mask_t>(
r,attrList,
"mask3");
646 setRecord<Run2::Chip::settings_t, Run1::Chip::settings_t>(
r,attrList,
"vthr");
647 setRecord<Run2::Chip::settings_t, Run1::Chip::settings_t>(
r,attrList,
"vcal");
648 setRecord<Run2::Chip::settings_t, Run1::Chip::settings_t>(
r,attrList,
"delay");
649 setRecord<Run2::Chip::settings_t, Run1::Chip::settings_t>(
r,attrList,
"preamp");
650 setRecord<Run2::Chip::settings_t, Run1::Chip::settings_t>(
r,attrList,
"shaper");
651 setRecord<Run2::Chip::rc_t, Run1::Chip::rc_t>(
r,attrList,
"rc_function");
652 setRecord<Run2::Chip::rcArgs_t, Run1::Chip::rcArgs_t>(
r, attrList,
"rc_args");
653 setRecord<Run2::Chip::c_t, Run1::Chip::c_t>(
r, attrList,
"c_factor");
654 setRecord<Run2::Chip::target_t, Run1::Chip::target_t>(
r,attrList,
"target");
655 setRecord<Run2::Chip::trim_t, Run1::Chip::trim_t>(
r,attrList,
"trim");
657 const auto pRec=std::make_shared<cool::Record>(
r);
669 std::cout<<
"data size "<<
data.size()<<std::endl;
674 cool::RecordSpecification rSpec = destination.
payloadSpec();
675 cool::IRecordVector cvp;
676 for (
auto const & attrList:thisVectorPayload){
677 cool::Record
r(rSpec);
678 setRecord<Run2::Geog::MUR_t, Run1::Geog::MUR_t>(
r,attrList,
"MUR");
679 setRecord<Run2::Geog::super_t, Run1::Geog::super_t>(
r,attrList,
"super");
680 setRecord<Run2::Geog::medium_t, Run1::Geog::medium_t>(
r,attrList,
"medium");
681 setRecord<Run2::Geog::position_t, Run1::Geog::position_t>(
r,attrList,
"position");
683 const auto pRec=std::make_shared<cool::Record>(
r);
686 std::cout<<
iov.first.first<<
"-"<<
iov.first.second<<
" : "<<
iov.first.channelId<<std::endl;
694 std::cout<<
"data size "<<
data.size()<<std::endl;
699 cool::RecordSpecification rSpec = destination.
payloadSpec();
700 cool::IRecordVector cvp;
701 for (
auto const & attrList:thisVectorPayload){
702 cool::Record
r(rSpec);
703 setRecord<Run2::MUR::MUR_t, Run1::MUR::MUR_t>(
r,attrList,
"MUR");
704 setRecord<Run2::MUR::module_t, Run1::MUR::module_t>(
r,attrList,
"module");
705 setRecord<Run2::MUR::moduleId_t, Run1::MUR::moduleId_t>(
r,attrList,
"moduleID");
706 setRecord<Run2::MUR::moduleId_t, Run1::MUR::moduleId_t>(
r,attrList,
"rmoduleID");
707 setRecord<Run2::MUR::xxFibre_t, Run1::MUR::xxFibre_t>(
r,attrList,
"rx0Fibre");
708 setRecord<Run2::MUR::xxFibre_t, Run1::MUR::xxFibre_t>(
r,attrList,
"rx1Fibre");
709 setRecord<Run2::MUR::xxFibre_t, Run1::MUR::xxFibre_t>(
r,attrList,
"txFibre");
710 const auto pRec=std::make_shared<cool::Record>(
r);
713 std::cout<<
iov.first.first<<
"-"<<
iov.first.second<<
" : "<<
iov.first.channelId<<std::endl;
722 std::cout<<
"data size "<<
data.size()<<std::endl;
727 cool::RecordSpecification rSpec = destination.
payloadSpec();
728 cool::IRecordVector cvp;
729 for (
auto const & attrList:thisVectorPayload){
730 cool::Record
r(rSpec);
731 setRecord<Run2::Module::id_t, Run1::Module::id_t>(
r,attrList,
"id");
732 setRecord<Run2::Module::group_t, Run1::Module::group_t>(
r,attrList,
"group",
"slaveGroup");
733 setRecord<Run2::Module::active_t, Run1::Module::active_t>(
r,attrList,
"active");
734 setRecord<Run2::Module::select_t, Run1::Module::select_t>(
r,attrList,
"select",
"clockSelect");
737 const auto pRec=std::make_shared<cool::Record>(
r);
750 std::cout<<
"data size "<<
data.size()<<std::endl;
755 cool::RecordSpecification rSpec = destination.
payloadSpec();
756 cool::IRecordVector cvp;
757 for (
auto const & attrList:thisVectorPayload){
758 cool::Record
r(rSpec);
759 setRecord<Run2::Channel::crate_t, Run1::Channel::crate_t>(
r,attrList,
"crate");
760 setRecord<Run2::Channel::rod_t, Run1::Channel::rod_t>(
r,attrList,
"rod");
761 setRecord<Run2::Channel::channel_t, Run1::Channel::channel_t>(
r,attrList,
"channel");
762 setRecord<Run2::Channel::opCurrent_t, Run1::Channel::opCurrent_t>(
r,attrList,
"outputCurrent");
763 setRecord<Run2::Channel::opDelay_t, Run1::Channel::opDelay_t>(
r,attrList,
"outputDelay");
764 setRecord<Run2::Channel::opMarkSpace_t, Run1::Channel::opMarkSpace_t>(
r,attrList,
"outputMarkSpace");
765 setRecord<Run2::Channel::threshold_t, Run1::Channel::threshold_t>(
r,attrList,
"stream0Threshold");
766 setRecord<Run2::Channel::delay_t, Run1::Channel::delay_t>(
r,attrList,
"stream0Delay");
767 setRecord<Run2::Channel::errMask_t, Run1::Channel::errMask_t>(
r,attrList,
"stream0ErrMask");
768 setRecord<Run2::Channel::threshold_t, Run1::Channel::threshold_t>(
r,attrList,
"stream1Threshold");
769 setRecord<Run2::Channel::delay_t, Run1::Channel::delay_t>(
r,attrList,
"stream1Delay");
770 setRecord<Run2::Channel::errMask_t, Run1::Channel::errMask_t>(
r,attrList,
"stream1ErrMask");
771 const auto pRec=std::make_shared<cool::Record>(
r);
783 std::cout<<
"data size "<<
data.size()<<std::endl;
788 cool::RecordSpecification rSpec = destination.
payloadSpec();
789 cool::IRecordVector cvp;
790 for (
auto const & attrList:thisVectorPayload){
791 cool::Record
r(rSpec);
792 setRecord<Run2::ROD::crate_t, Run1::ROD::crate_t>(
r,attrList,
"crate");
793 setRecord<Run2::ROD::slot_t, Run1::ROD::slot_t>(
r,attrList,
"slot");
794 setRecord<Run2::ROD::ROB_t, Run1::ROD::ROB_t>(
r,attrList,
"ROB");
795 setRecord<Run2::ROD::SRC_t, Run1::ROD::SRC_t>(
r,attrList,
"SRCid");
796 setRecord<Run2::ROD::bcid_t, Run1::ROD::bcid_t>(
r,attrList,
"BCIDOffset");
797 setRecord<Run2::ROD::slave_t, Run1::ROD::slave_t>(
r,attrList,
"slave0");
798 setRecord<Run2::ROD::slave_t, Run1::ROD::slave_t>(
r,attrList,
"slave1");
799 setRecord<Run2::ROD::slave_t, Run1::ROD::slave_t>(
r,attrList,
"slave2");
800 setRecord<Run2::ROD::slave_t, Run1::ROD::slave_t>(
r,attrList,
"slave3");
801 const auto pRec=std::make_shared<cool::Record>(
r);
804 std::cout<<
iov.first.first<<
"-"<<
iov.first.second<<
" : "<<
iov.first.channelId<<std::endl;
814 std::cout<<
"data size "<<
data.size()<<std::endl;
819 cool::RecordSpecification rSpec = destination.
payloadSpec();
820 cool::IRecordVector cvp;
821 for (
auto const & attrList:thisVectorPayload){
822 cool::Record
r(rSpec);
823 setRecord<Run2::RODMUR::crate_t, Run1::RODMUR::crate_t>(
r,attrList,
"crate");
824 setRecord<Run2::RODMUR::rod_t, Run1::RODMUR::rod_t>(
r,attrList,
"rod");
825 setRecord<Run2::RODMUR::position_t, Run1::RODMUR::position_t>(
r,attrList,
"position");
826 setRecord<Run2::RODMUR::MUR_t, Run1::RODMUR::MUR_t>(
r,attrList,
"MUR");
827 const auto pRec=std::make_shared<cool::Record>(
r);
830 std::cout<<
iov.first.first<<
"-"<<
iov.first.second<<
" : "<<
iov.first.channelId<<std::endl;
839 const std::string
s(
"|");
840 std::cout<<
"|*Payload Name*|*COOL Type*|"<<std::endl;
841 for (
unsigned int i(0);
i!=
spec.size();++
i){
842 const cool::IFieldSpecification&
f=
spec[
i];
843 std::cout<<
s<<
f.name()<<
s<<
f.storageType().name()<<
s<<std::endl;
854 return vectorEntry->attributeList();
861 for (
const auto &
i:theResult){
863 typename T::mapped_type dataVector=
i.second;
864 std::cout<<
"IOV: "<<
iov.first<<
","<<
iov.second<<std::endl;
865 std::cout<<
"Data: "<<std::endl;
866 const unsigned int numEntries=dataVector.size();
867 const unsigned int numberToShow=
std::min(numEntries,maxShown);
868 for(
unsigned int j(0);j!=numberToShow;++j){
870 thisEntry.toOutputStream(std::cout);
871 std::cout<<std::endl;
905 const std::string
result = itsCoraCool?(
"/SCT/DAQ/Configuration/"):(
"/SCT/DAQ/Config/");
911 std::string::size_type
p1,
p2;
914 const bool valid= ((
p1<
p2) and (
p2!=std::string::npos));
923 bool replacementMade(
false);
927 if (replacementMade) std::cout<<
"timestamp replacement made\n"<<
description<<std::endl;
930 cool::IFolderPtr pSourceFolder=sourceFolder.
ptr();
933 const cool::FolderSpecification coolFolderSpec(dvermode,pSourceFolder->payloadSpecification(),payMode);
934 cool::IFolderPtr destfl=writeDb.
dbPtr()->createFolder(destFolder,coolFolderSpec,
description,
true);
935 std::cout<<
"Folder "<<destFolder<<
" created."<<std::endl;
937 const std::map<cool::ChannelId,std::string> & chanmap=pSourceFolder->listChannelsWithNames();
938 for (
const auto &
chan:chanmap){
940 const std::string & sourcedesc=pSourceFolder->channelDescription(
chan.first);
941 const std::string& sourcename=
chan.second;
942 destfl->createChannel(
chan.first,sourcename,sourcedesc);
944 std::cout<<std::endl;
948 std::vector<std::string> &
949 split(
const std::string &
s,
char delim, std::vector<std::string> &elems) {
950 std::stringstream
ss(
s);
952 while (std::getline(
ss,
item, delim)) {
953 elems.push_back(
item);
957 std::vector<std::string>
958 split(
const std::string &
s,
char delim) {
959 std::vector<std::string> elems;
994 std::array<std::string,2> chipTagNames={
"SctDaqConfigChip-Run2-10July2015",
"SctDaqConfigurationChip-MC-06"};
1019 std::array<std::string,2> geogTagNames={
"SctDaqConfigGeog-Run2-10July2015",
"SctDaqConfigurationGeog-MC-06"};
1044 std::array<std::string,2> murTagNames={
"SctDaqConfigMur-Run2-10July2015",
"SctDaqConfigurationMur-MC-06"};
1070 std::array<std::string,2> moduleTagNames={
"SctDaqConfigModule-Run2-10July2015",
"SctDaqConfigurationModule-MC-06"};
1082 std::array<std::string,2> channelTagNames={
"SctDaqConfigChannel-Run2-10July2015",
"SctDaqConfigurationChannel-MC-06"};
1107 std::array<std::string,2> rodTagNames={
"SctDaqConfigRod-Run2-10July2015",
"SctDaqConfigurationRod-MC-06"};
1132 std::array<std::string,2> rodmurTagNames={
"SctDaqConfigRodmur-Run2-10July2015",
"SctDaqConfigurationRodmur-MC-06"};
1135 std::array<std::string,6> folderNames={
"Chip",
"Geog",
"MUR",
"Module",
"ROD",
"RODMUR"};
1137 const std::string defaultDbName=
"COOLOFL_SCT/OFLP200";
1138 std::string iovString=
argv[1];
1140 std::cout<<
"No arguments? "<<std::endl;
1141 std::cout<<
argc<<std::endl;
1142 iovString=
"1333588404000000000-1333588404000000001";
1143 std::cout<<
"running with default argument "<<iovString<<std::endl;
1156 std::array<std::string,2> folderPaths={
"/SCT/DAQ/Config/",
"/SCT/DAQ/Configuration/"};
1157 const unsigned int nFolders=folderNames.size();
1160 std::cout<<
"problem"<<std::endl;
1163 unsigned int index(0);
1165 bool itsCoraCool =(
folderPath.find(
"Configuration") != std::string::npos);
1166 const std::string chipTagName=chipTagNames[
index];
1167 const std::string geogTagName=geogTagNames[
index];
1168 const std::string murTagName=murTagNames[
index];
1169 const std::string moduleTagName=moduleTagNames[
index];
1170 const std::string channelTagName=channelTagNames[
index];
1171 const std::string rodTagName=rodTagNames[
index];
1172 const std::string rodmurTagName=rodmurTagNames[
index++];
1175 const unsigned int nData(1000000);
1176 for (
unsigned int i(0);
i!=nFolders;++
i){
1177 std::string tagName;
1178 if (folderNames[
i]==
"Chip") tagName=chipTagName;
1179 if (folderNames[
i]==
"Geog") tagName=geogTagName;
1180 if (folderNames[
i]==
"MUR") tagName=murTagName;
1181 if (folderNames[
i]==
"Module") tagName=moduleTagName;
1182 if (folderNames[
i]==
"Channel") tagName=channelTagName;
1183 if (folderNames[
i]==
"ROD") tagName=rodTagName;
1184 if (folderNames[
i]==
"RODMUR") tagName=rodmurTagName;
1210 std::string run1Tag =
folder.folderSpec().tag;
1212 std::cout<<
"Destination tag "<<destTag<<std::endl;
1214 if (folderNames[
i]==
"Chip"){
1216 const FolderSpec destFolder(
"/SCT/DAQ/Config/Chip",tagName);
1220 if (folderNames[
i]==
"Geog"){
1222 const FolderSpec destFolder(
"/SCT/DAQ/Config/Geog",tagName);
1226 if (folderNames[
i]==
"MUR"){
1228 const FolderSpec destFolder(
"/SCT/DAQ/Config/MUR",tagName);
1232 if (folderNames[
i]==
"Module"){
1234 const FolderSpec destFolder(
"/SCT/DAQ/Config/Module",tagName);
1238 if (folderNames[
i]==
"Channel"){
1240 const FolderSpec destFolder(
"/SCT/DAQ/Config/Channel",tagName);
1244 if (folderNames[
i]==
"ROD"){
1246 const FolderSpec destFolder(
"/SCT/DAQ/Config/ROD",tagName);
1250 if (folderNames[
i]==
"RODMUR"){
1252 const FolderSpec destFolder(
"/SCT/DAQ/Config/RODMUR",tagName);