ATLAS Offline Software
Loading...
Searching...
No Matches
openCoraCool.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
6
7#include <vector>
8#include <string>
9#include <array>
10#include <iostream>
11
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"
26
31#include "RelationalAccess/ConnectionService.h"
32
33struct MyKey{
34 cool::ValidityKey first;
35 cool::ValidityKey second;
36 cool::ChannelId channelId;
37
39 MyKey(const cool::ValidityKey & f,const cool::ValidityKey & s, const cool::ChannelId & c):first(f),second(s),channelId(c){}
40 bool operator<(const MyKey & rhs) const{
41 if (channelId > rhs.channelId) return true;
42 if ((channelId == rhs.channelId) and (first<rhs.first)) return true;
43 if ((channelId == rhs.channelId) and (first==rhs.first) and (second<rhs.second)) return true;
44 return false;
45 }
46};
47
48//typedef std::pair<cool::ValidityKey, cool::ValidityKey> IovKey_t;
50
51typedef std::map<IovKey_t, CoraCoolObject::AttrListVec> CCIovVectorMap_t;
52
56//conversion between types is going to be very manual
57namespace Run1{
58 namespace Chip{
59 typedef cool::Int16 chip_t;
60 typedef cool::Int16 active_t;
61 typedef cool::Int16 address_t;
62 typedef cool::Int16 config_t;
63 typedef cool::Int32 mask_t;
64 typedef cool::Int16 settings_t;
65 typedef cool::Int16 rc_t;
66 typedef cool::String255 rcArgs_t;
67 typedef cool::Float c_t;
68 typedef cool::Float target_t;
69 typedef cool::String255 trim_t;
70 }
71 // NOTE: Order of variables changed Run1/Run2 for Geog
72 namespace Geog{
73 typedef cool::Int32 super_t;
74 typedef cool::Int32 medium_t;
75 typedef cool::Int32 position_t;
76 typedef cool::Int32 MUR_t; //<! last in run 1
77
78 }
79 namespace MUR{
80 typedef cool::Int32 MUR_t;
81 typedef cool::Int32 module_t;
82 typedef cool::Int64 moduleId_t;
83 typedef cool::Int32 xxFibre_t;
84 }
85 namespace Module{
86 typedef cool::Int64 id_t;
87 typedef cool::Int16 group_t;
88 typedef cool::Int16 active_t;
89 typedef cool::Int16 select_t;
90 }
91 namespace PowerMUR{
92 typedef cool::Int32 MUR_t;
93 typedef cool::Int16 module_t;
94 typedef cool::Int16 crate_t;
95 typedef cool::Int16 channel_t;
96 }
97 namespace Channel{
98 typedef cool::Int32 crate_t;
99 typedef cool::Int32 rod_t;
100 typedef cool::Int32 channel_t;
101 typedef cool::Int16 opCurrent_t;
102 typedef cool::Int16 opDelay_t;
103 typedef cool::Int16 opMarkSpace_t;
104 typedef cool::Int16 threshold_t;
105 typedef cool::Int16 delay_t;
106 typedef cool::Int32 errMask_t;
107 }
108 namespace ROD{
109 typedef cool::Int32 crate_t;
110 typedef cool::Int16 slot_t;
111 typedef cool::Int32 ROB_t;
112 typedef cool::Int32 SRC_t;
113 typedef cool::Int16 bcid_t;
114 typedef cool::Int32 slave_t;
115 }
116 namespace RODMUR{
117 typedef cool::Int32 crate_t;
118 typedef cool::Int32 rod_t;
119 typedef cool::Int32 position_t;
120 typedef cool::Int32 MUR_t;
121 }
122 namespace Slave{
123 typedef cool::Int32 id_t;
124 typedef cool::String255 file_t;
125 }
126 namespace TIM {
127 typedef cool::Int32 crate_t;
128 typedef cool::Float freq_t;
129 typedef cool::Int32 trigType_t;
130 typedef cool::Int32 bcidOffset_t;
131 typedef cool::Int32 trigEnable_t;
132 typedef cool::Int16 runMode_t;
133 typedef cool::Int16 delay_t;
134 }
135}
136
137namespace Run2{
138 namespace Chip{
139 typedef cool::UChar chip_t;
140 typedef cool::Bool active_t;
141 typedef cool::UChar address_t;
142 typedef cool::UInt16 config_t;
143 typedef cool::UInt32 mask_t;
144 typedef cool::UChar settings_t;
145 typedef cool::UChar rc_t;
146 typedef cool::String255 rcArgs_t;
147 typedef cool::Float c_t;
148 typedef cool::Float target_t;
149 typedef cool::String255 trim_t;
150 }
151 // NOTE: Order of variables changed Run1/Run2 for Geog
152 namespace Geog{
153 typedef cool::UInt32 MUR_t; //<! first in run 2
154 typedef cool::Int16 super_t;
155 typedef cool::UChar medium_t;
156 typedef cool::Int16 position_t;
157 }
158
159 namespace MUR{
160 typedef cool::UInt32 MUR_t;
161 typedef cool::UChar module_t;
162 typedef cool::Int64 moduleId_t;
163 typedef cool::UChar xxFibre_t;
164 }
165 namespace Module{
166 typedef cool::Int64 id_t;
167 typedef cool::Int16 group_t;
168 typedef cool::Bool active_t;
169 typedef cool::Bool select_t;
170 typedef cool::UInt16 chipStatus_t;
171 }
172 namespace PowerMUR{
173 typedef cool::UInt32 MUR_t;
174 typedef cool::UChar module_t;
175 typedef cool::UChar crate_t;
176 typedef cool::UChar channel_t;
177 }
178 namespace Channel{
179 typedef cool::UChar crate_t;
180 typedef cool::UChar rod_t;
181 typedef cool::UChar channel_t;
182 typedef cool::UChar opCurrent_t;
183 typedef cool::UInt16 opDelay_t;
184 typedef cool::UChar opMarkSpace_t;
185 typedef cool::UChar threshold_t;
186 typedef cool::UChar delay_t;
187 typedef cool::UInt32 errMask_t;
188 }
189 namespace ROD{
190 typedef cool::UChar crate_t;
191 typedef cool::UChar slot_t;
192 typedef cool::Int32 ROB_t;
193 typedef cool::Int32 SRC_t;
194 typedef cool::Int16 bcid_t;
195 typedef cool::Int32 slave_t;
196 }
197 namespace RODMUR{
198 typedef cool::UChar crate_t;
199 typedef cool::UChar rod_t;
200 typedef cool::UChar position_t;
201 typedef cool::UInt32 MUR_t;
202 }
203 namespace Slave{
204 typedef cool::Int32 id_t;
205 typedef cool::String255 file_t;
206 }
207 namespace TIM {
208 typedef cool::UChar crate_t;
209 typedef cool::Float freq_t;
210 typedef cool::UInt32 trigType_t;
211 typedef cool::UInt16 bcidOffset_t;
212 typedef cool::UInt32 trigEnable_t;
213 typedef cool::UChar runMode_t;
214 typedef cool::UInt16 delay_t;
215 }
216}
217//http://acode-browser.usatlas.bnl.gov/lxr/source/atlas/Simulation/RunDependentSim/RunDependentSimComps/python/RunDMCFlags.py
255
256
257
258typedef std::pair<cool::ValidityKey, cool::ValidityKey> IovPeriod_t;
260makeRunInterval(const cool::ValidityKey runstart, const cool::ValidityKey runend,const cool::ChannelId channelId ){
261 cool::ValidityKey s =runstart<<32LL;
262 if (runend==cool::ValidityKeyMax) return IovKey_t(s, cool::ValidityKeyMax,channelId);
263 cool::ValidityKey e =(runend+1LL)<<32LL;
264 return IovKey_t(s, e,channelId);
265}
266
267bool inInterval(const cool::ValidityKey n, const cool::ValidityKey from, const cool::ValidityKey to){
268 return ((n>from) and (n<=to));
269}
270cool::ValidityKey
271convertUntil(const cool::ValidityKey & until){
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;
278
279 if (until==1333588404000000000) return 200804;
280 if (until==1333612447000000000) return 200805;
281
282 if (until==1356998400000000000) return 216999;
283 return cool::ValidityKeyMax;
284}
285
286cool::ValidityKey
287convertSince(const cool::ValidityKey & since){
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;
294
295 if (since==1333588404000000000) return 200805;
296
297 if (since==1333612447000000000) return 200806;
298 return 217000;
299}
300
301
304 const auto since=iov.first;
305 const auto until=iov.second;
306 const auto channelId = iov.channelId;
307
308 return makeRunInterval(convertSince(since),convertUntil(until),channelId);
309}
310
311//function to check the input arguments to main()
312bool
313argumentsOK(const int numArgs, const char **){
314 bool result(true);
315 result = (numArgs>1) and (numArgs<4);
316 return result;
317}
318
319
320// translate simple connection string (no slash) to mycool.db with given
321// instance name, all others are left alone
322std::string
323transConn(const std::string& inconn) {
324 std::string result(inconn);
325 if (inconn.find('/')==std::string::npos) {
326 result= "sqlite://X;schema=/tmp/sroe/mycool.db;dbname="+inconn;
327 }
328 return result;
329}
330
331//RAII context carrying the database connection
332class DbConnection{
333public:
334 DbConnection(const std::string & sourceDb,const bool isCoraCool=false);
336 bool isOpen() const;
337 cool::IDatabasePtr dbPtr() const;
339
340private:
341 coral::ConnectionService m_coralsvc;
342 cool::Application m_coolapp;
343 const cool::IDatabaseSvc & m_dbSvc;
344 cool::IDatabasePtr m_sourceDbPtr;
346 bool m_isOpen;
347};
348
349//is the descriptor that of a CoraCool-style folder?
350bool
351isCoraCoolDescriptor(const std::string & descriptor){
352 return (descriptor.find("<coracool") != std::string::npos);
353}
354
355//make db connection upon construction
356DbConnection::DbConnection(const std::string & sourceDb, const bool isCoraCool):
357 m_coralsvc{},
359 m_dbSvc(m_coolapp.databaseService()),
360 m_sourceDbPtr(nullptr),
361 m_sourceCoraPtr(nullptr),
362 m_isOpen(false){
363 bool readOnly(true);
364 const std::string dbConnectionString=transConn(sourceDb);
365 readOnly= (dbConnectionString.find ("sqlite")==std::string::npos);
366 try {
367 m_sourceDbPtr=m_dbSvc.openDatabase(dbConnectionString,readOnly);
368 if (isCoraCool) m_sourceCoraPtr=CoraCoolDatabasePtr(new CoraCoolDatabase(sourceDb,
369 m_sourceDbPtr,m_coralsvc,readOnly));
370 }
371 catch (std::exception& e) {
372 std::cout << "Cool exception caught: " << e.what() << std::endl;
373 if (not readOnly){
374 try {
375 std::cout<<"creating "<<dbConnectionString<<std::endl;
376 m_sourceDbPtr=m_dbSvc.createDatabase(dbConnectionString);
377 } catch (std::exception& e){
378 std::cout << "Cool exception caught: " << e.what() << std::endl;
379 }
380 }
381 }
382 m_isOpen=(m_sourceDbPtr!=nullptr);
383}
384
385//break db connection on destruction
387 if (isOpen()){
388 m_sourceDbPtr->closeDatabase();
389 }
390}
391
392//return bare db pointer
393cool::IDatabasePtr
394DbConnection::dbPtr() const{
395 return m_sourceDbPtr;
396}
397
398//return coracool style db pointer
403
404bool
406 return m_isOpen;
407}
408
409
410std::string
411convertTagToRun2(const std::string & run1Tag){
412 std::string tag=run1Tag;
413 tag.erase(12,7);
414 return tag;
415}
416
417
418
419//specification to identify a given folder from full name and tag
420struct FolderSpec{
421 const std::string name;
422 const std::string tag;
423 FolderSpec(const std::string & thename, const std::string & thetag):name(thename),tag(thetag){};
425};
426
427
428//Folder interface class
429class Folder{
430public:
431 Folder(const DbConnection & theConnection, const FolderSpec & theFolder);
432 bool isValid() const;
433 std::string description() const;
434 const FolderSpec& folderSpec() const;
435 cool::RecordSpecification foreignKeySpec();
436 cool::RecordSpecification payloadSpec() const;
437 bool isSingleVersion() const;
438 const std::string& tag() const;
439 const CoraCoolFolderPtr & ccPtr() const;
440 const cool::IFolderPtr & ptr() const;
441private:
444 cool::IFolderPtr m_folderPtr;
447 bool checkWhetherCoraCool() const;
448};
449
450Folder::Folder(const DbConnection & theConnection, const FolderSpec & theFolder)
451 :m_connection(theConnection),m_folderSpec(theFolder),m_folderPtr{},
452 m_sourceflc{},m_isCoraCool(false){
453 try{
454 m_folderPtr=m_connection.dbPtr()->getFolder(theFolder.name);
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;
459 }
460}
461
462const FolderSpec&
463Folder::folderSpec() const{
464 return m_folderSpec;
465}
466
467const cool::IFolderPtr &
468Folder::ptr() const{
469 return m_folderPtr;
470}
471
472//assume the coracool folder is valid if the pointer to it is valid
473bool
474Folder::isValid() const{
475 bool result = (m_folderPtr != nullptr);
476 if (m_isCoraCool) result &=(m_sourceflc != nullptr);
477 return result;
478}
479
480bool
482 return (cool::FolderVersioning::SINGLE_VERSION == m_folderPtr->versioningMode());
483}
484
485std::string
486Folder::description() const{
487 return (m_folderPtr->description());
488}
489
490bool
494
495cool::RecordSpecification
497 if (m_sourceflc==nullptr) return cool::RecordSpecification();
498 return m_sourceflc->fkSpecification();
499}
500
501cool::RecordSpecification
502Folder::payloadSpec() const{
503 if (m_isCoraCool){
504 return m_sourceflc->payloadSpecification();
505 }
506 return m_folderPtr->payloadSpecification();
507}
508
509const std::string&
510Folder::tag() const{
511 return m_folderSpec.tag;
512}
513
514const CoraCoolFolderPtr &
516 return m_sourceflc;
517}
518
519//Criterion for selecting a particular set of data vectors in the folder
521 SelectionCriterion(const cool::ChannelSelection & c, const cool::ValidityKey & s, const cool::ValidityKey & u):
522 channels(c), since(s),until(u){
524 }
525 const cool::ChannelSelection channels;
526 const cool::ValidityKey since;
527 const cool::ValidityKey until;
528};
529
530//Read one vector of attribute lists
533 if (ccPtr->size()>0){
534 CoraCoolObject::const_iterator i(ccPtr->begin());
535 CoraCoolObject::const_iterator end(ccPtr->end());
537 return result;
538 }
540 return emptyArray;
541}
542
543
544
545//read a selection of vectors of attribute lists in the given folder
547readCC(const Folder & theFolder, const SelectionCriterion & choice, const unsigned int limit=10){
548 theFolder.ccPtr()->setPrefetchAll(true);
549 CoraCoolObjectIterPtr sourceitr;
550 if (theFolder.isSingleVersion()) {
551 sourceitr=theFolder.ccPtr()->browseObjects(choice.since, choice.until, choice.channels);
552 } else {
553 sourceitr=theFolder.ccPtr()->browseObjects(choice.since, choice.until, choice.channels, theFolder.tag());
554 }
555 unsigned int counter(0);
556 std::map<IovKey_t, CoraCoolObject::AttrListVec> mapOfVectorsByIov;
557 while (sourceitr->hasNext() and (counter<limit)) {
558 CoraCoolObjectPtr obj=sourceitr->next();
559 IovKey_t iov(obj->since(),obj->until(),obj->channelId());
560 mapOfVectorsByIov[iov]=readOneDatum(obj);
561 ++counter;
562 }
563 return mapOfVectorsByIov;
564}
565
566typedef std::map<IovKey_t, cool::IRecordVector> IovVectorMap_t;
567
569read(const Folder & theFolder, const SelectionCriterion & choice, const unsigned int limit=10){
570 theFolder.ptr()->setPrefetchAll(false);
571 cool::IObjectIteratorPtr sourceitr;
572 if (theFolder.isSingleVersion()) {
573 sourceitr=theFolder.ptr()->browseObjects(choice.since, choice.until, choice.channels);
574 } else {
575 sourceitr=theFolder.ptr()->browseObjects(choice.since, choice.until, choice.channels, theFolder.tag());
576 }
577 unsigned int counter(0);
578 std::map<IovKey_t, cool::IRecordVector> mapOfVectorsByIov;
579 while (sourceitr->goToNext() and counter<limit) {
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;
587 ++counter;
588 }
589 return mapOfVectorsByIov;
590}
591
597
598
599
600template<class R2, class R1>
601void
602setRecord(cool::Record & r, const coral::AttributeList & a, const std::string & itemName, const std::string &targetName){
603 static bool warning(true);
604 try{
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);
610 } else {
611 r[targetName].setNull();
612 }
613 } catch (coral::AttributeException & e) {
614 if (warning) std::cout<<itemName<<" gives exception"<<std::endl;
615 warning=true;
616 }
617}
618
619template<class R2, class R1>
620void
621setRecord(cool::Record & r, const coral::AttributeList & a, const std::string & itemName){
622 setRecord<R2,R1>(r,a,itemName,itemName);
623}
624
625
626void
627writeChip(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
628 //assumed monte carlo, translate IOVs
629 std::cout<<"data size "<<data.size()<<std::endl;
630 for (const auto &iov: data){
631 const IovKey_t & runLumi = time2RunLumi(iov.first);
632 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
633 //its going to be a Cool Vector Payload
634 cool::RecordSpecification rSpec = destination.payloadSpec();
635 cool::IRecordVector cvp;
636 for (auto const & attrList:thisVectorPayload){
637 cool::Record r(rSpec);
651 setRecord<Run2::Chip::rc_t, Run1::Chip::rc_t>(r,attrList, "rc_function");
656
657 const auto pRec=std::make_shared<cool::Record>(r);
658 cvp.push_back(pRec);
659 }
660 //std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
661 // std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
662
663 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,(runLumi.channelId-1),tag );
664 }
665}
666void
667writeGeog(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
668 //assumed monte carlo, translate IOVs
669 std::cout<<"data size "<<data.size()<<std::endl;
670 for (const auto &iov: data){
671 const IovKey_t & runLumi = time2RunLumi(iov.first);
672 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
673 //its going to be a Cool Vector Payload
674 cool::RecordSpecification rSpec = destination.payloadSpec();
675 cool::IRecordVector cvp;
676 for (auto const & attrList:thisVectorPayload){
677 cool::Record r(rSpec);
682
683 const auto pRec=std::make_shared<cool::Record>(r);
684 cvp.push_back(pRec);
685 }
686 std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
687 std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
688 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,runLumi.channelId,tag );
689 }
690}
691void
692writeMUR(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
693 //assumed monte carlo, translate IOVs
694 std::cout<<"data size "<<data.size()<<std::endl;
695 for (const auto &iov: data){
696 const IovKey_t & runLumi = time2RunLumi(iov.first);
697 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
698 //its going to be a Cool Vector Payload
699 cool::RecordSpecification rSpec = destination.payloadSpec();
700 cool::IRecordVector cvp;
701 for (auto const & attrList:thisVectorPayload){
702 cool::Record r(rSpec);
710 const auto pRec=std::make_shared<cool::Record>(r);
711 cvp.push_back(pRec);
712 }
713 std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
714 std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
715
716 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,runLumi.channelId,tag );
717 }
718}
719void
720writeModule(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
721 //assumed monte carlo, translate IOVs
722 std::cout<<"data size "<<data.size()<<std::endl;
723 for (const auto &iov: data){
724 const IovKey_t & runLumi = time2RunLumi(iov.first);
725 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
726 //its going to be a Cool Vector Payload
727 cool::RecordSpecification rSpec = destination.payloadSpec();
728 cool::IRecordVector cvp;
729 for (auto const & attrList:thisVectorPayload){
730 cool::Record r(rSpec);
732 setRecord<Run2::Module::group_t, Run1::Module::group_t>(r,attrList,"group","slaveGroup");
734 setRecord<Run2::Module::select_t, Run1::Module::select_t>(r,attrList,"select","clockSelect");
735 //the chipStatus is only in run 2
736 r["chipStatus"].setValue<Run2::Module::chipStatus_t>(static_cast<Run2::Module::chipStatus_t>(0x0FFF));
737 const auto pRec=std::make_shared<cool::Record>(r);
738 cvp.push_back(pRec);
739 }
740 //std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
741 // std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
742
743 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,(runLumi.channelId-1),tag );
744 }
745}
746
747void
748writeChannel(const CCIovVectorMap_t & data, const Folder & destination, const std::string &tag){
749 //assumed monte carlo, translate IOVs
750 std::cout<<"data size "<<data.size()<<std::endl;
751 for (const auto &iov: data){
752 const IovKey_t & runLumi = time2RunLumi(iov.first);
753 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
754 //its going to be a Cool Vector Payload
755 cool::RecordSpecification rSpec = destination.payloadSpec();
756 cool::IRecordVector cvp;
757 for (auto const & attrList:thisVectorPayload){
758 cool::Record r(rSpec);
771 const auto pRec=std::make_shared<cool::Record>(r);
772 cvp.push_back(pRec);
773 }
774 //std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
775 // std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
776
777 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,runLumi.channelId,tag );
778 }
779}
780void
781writeRod(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
782 //assumed monte carlo, translate IOVs
783 std::cout<<"data size "<<data.size()<<std::endl;
784 for (const auto &iov: data){
785 const IovKey_t & runLumi = time2RunLumi(iov.first);
786 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
787 //its going to be a Cool Vector Payload
788 cool::RecordSpecification rSpec = destination.payloadSpec();
789 cool::IRecordVector cvp;
790 for (auto const & attrList:thisVectorPayload){
791 cool::Record r(rSpec);
801 const auto pRec=std::make_shared<cool::Record>(r);
802 cvp.push_back(pRec);
803 }
804 std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
805 std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
806
807 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,runLumi.channelId,tag );
808 }
809}
810
811void
812writeRodmur(const CCIovVectorMap_t & data, const Folder & destination,const std::string &tag){
813 //assumed monte carlo, translate IOVs
814 std::cout<<"data size "<<data.size()<<std::endl;
815 for (const auto &iov: data){
816 const IovKey_t & runLumi = time2RunLumi(iov.first);
817 const CoraCoolObject::AttrListVec & thisVectorPayload = iov.second;
818 //its going to be a Cool Vector Payload
819 cool::RecordSpecification rSpec = destination.payloadSpec();
820 cool::IRecordVector cvp;
821 for (auto const & attrList:thisVectorPayload){
822 cool::Record r(rSpec);
827 const auto pRec=std::make_shared<cool::Record>(r);
828 cvp.push_back(pRec);
829 }
830 std::cout<<iov.first.first<<"-"<<iov.first.second<<" : "<<iov.first.channelId<<std::endl;
831 std::cout<<">"<<runLumi.first<<"-"<<runLumi.second<<" : "<<runLumi.channelId<<std::endl;
832
833 destination.ptr()->storeObject(runLumi.first,runLumi.second,cvp,runLumi.channelId,tag );
834 }
835}
836//print specification for a cool record as TWiki table markup
837void
838printRecordSpec(const cool::RecordSpecification & spec){
839 const std::string s("|");//TWiki table separator
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;
844 }
845}
846
847
848const coral::AttributeList &
849getAttributes(const coral::AttributeList & vectorEntry){
850 return vectorEntry;
851}
852const coral::AttributeList &
853getAttributes(const cool::IRecordPtr & vectorEntry){
854 return vectorEntry->attributeList();
855}
856
857
858template <class T>
859void
860showResult(const T & theResult, const unsigned int maxShown=5){
861 for (const auto & i:theResult){
862 const IovKey_t &iov=i.first;
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){
869 const coral::AttributeList & thisEntry=getAttributes(dataVector[j]);
870 thisEntry.toOutputStream(std::cout);
871 std::cout<<std::endl;
872 }
873 }
874}
875
876
902
903std::string
904defaultFolderPath(const bool itsCoraCool){
905 const std::string result = itsCoraCool?("/SCT/DAQ/Configuration/"):("/SCT/DAQ/Config/");
906 return result;
907}
908
909bool
910 replaceTimestamp(std::string & metadata){
911 std::string::size_type p1,p2;
912 p1=metadata.find("<timeStamp>")+11;
913 p2=metadata.find("</timeStamp>");
914 const bool valid= ((p1<p2) and (p2!=std::string::npos));
915 if (valid) metadata.replace(p1,p2-11,"time");
916 return valid;
917}
918
919cool::IFolderPtr
920createLocalCopyStructure(const Folder & sourceFolder, const DbConnection & writeDb, const bool forceTimestamp=false){
921 std::string description=sourceFolder.description();
922
923 bool replacementMade(false);
924 if (forceTimestamp){
925 replacementMade=replaceTimestamp(description);
926 }
927 if (replacementMade) std::cout<<"timestamp replacement made\n"<<description<<std::endl;
928
929 const std::string destFolder=sourceFolder.folderSpec().name;
930 cool::IFolderPtr pSourceFolder=sourceFolder.ptr();
931 const cool::FolderVersioning::Mode dvermode=cool::FolderVersioning::MULTI_VERSION;
932 const cool::PayloadMode::Mode payMode=pSourceFolder->folderSpecification().payloadMode();
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;
936 //copy channels
937 const std::map<cool::ChannelId,std::string> & chanmap=pSourceFolder->listChannelsWithNames();
938 for (const auto & chan:chanmap){
939 std::cout<<".";
940 const std::string & sourcedesc=pSourceFolder->channelDescription(chan.first);
941 const std::string& sourcename=chan.second;
942 destfl->createChannel(chan.first,sourcename,sourcedesc);
943 }
944 std::cout<<std::endl;
945 return destfl;
946}
947
948std::vector<std::string> &
949split(const std::string &s, char delim, std::vector<std::string> &elems) {
950 std::stringstream ss(s);
951 std::string item;
952 while (std::getline(ss, item, delim)) {
953 elems.push_back(item);
954 }
955 return elems;
956}
957std::vector<std::string>
958split(const std::string &s, char delim) {
959 std::vector<std::string> elems;
960 split(s, delim, elems);
961 return elems;
962}
963
964int main(int argc, const char * argv[]) {
965 int retcode=0;
966 //http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Configuration/Chip/tags
967 //http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Config/Chip/tags
994 std::array<std::string,2> chipTagNames={"SctDaqConfigChip-Run2-10July2015","SctDaqConfigurationChip-MC-06"};
995 //xmllint --format 'http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Configuration/Geog/tags'
1019 std::array<std::string,2> geogTagNames={"SctDaqConfigGeog-Run2-10July2015","SctDaqConfigurationGeog-MC-06"};
1020 //xmllint --format 'http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Configuration/MUR/tags'
1044 std::array<std::string,2> murTagNames={"SctDaqConfigMur-Run2-10July2015","SctDaqConfigurationMur-MC-06"};
1045 //xmllint --format 'http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Configuration/Module/tags'
1070 std::array<std::string,2> moduleTagNames={"SctDaqConfigModule-Run2-10July2015","SctDaqConfigurationModule-MC-06"};
1071 //xmllint --format 'http://coolcherrypy.cern.ch:8080/cooldb/ATLAS_COOLPROD/ATLAS_COOLOFL_SCT/OFLP200/SCT/DAQ/Configuration/PowerMUR/tags'
1072 //std::array<std::string,2> powerMurTagNames={"SctDaqConfigPowermMur-Run2-10July2015","SctDaqConfigurationPowerMur-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"};
1133
1134 //
1135 std::array<std::string,6> folderNames={"Chip","Geog","MUR","Module","ROD","RODMUR"};
1136 std::string dbName("");
1137 const std::string defaultDbName="COOLOFL_SCT/OFLP200";
1138 std::string iovString=argv[1];
1139 if (argc!=2){
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;
1144 }
1145
1146 std::vector<std::string> splitString=split(iovString,'-');
1147 if (splitString.size()!=2) exit(-1);
1148 std::cout<<"From "<<splitString[0]<<" to "<<splitString[1]<<std::endl;
1149 const cool::ValidityKey since = std::stoll(splitString[0]);
1150 cool::ValidityKey until = std::stoll(splitString[1]);
1151 dbName=defaultDbName;
1152
1153 //bool itsCoraCool =(dbName.find("COMP200") != std::string::npos);
1154 //DbConnection connection(dbName, itsCoraCool);
1155 //const std::string folderPath = defaultFolderPath(itsCoraCool);
1156 std::array<std::string,2> folderPaths={"/SCT/DAQ/Config/","/SCT/DAQ/Configuration/"};
1157 const unsigned int nFolders=folderNames.size();
1158 DbConnection writeDb("LOCAL");
1159 if (!writeDb.isOpen()) {
1160 std::cout<<"problem"<<std::endl;
1161 return -1;
1162 }
1163 unsigned int index(0);
1164 for (const auto & folderPath:folderPaths){
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++];
1173
1174 DbConnection connection(dbName, itsCoraCool);
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;
1185
1186 std::string folderName=folderPath+folderNames[i];
1187 const FolderSpec theFolder(folderName,tagName);
1188 Folder folder(connection, theFolder);
1189 //std::cout<<folder.description()<<std::endl;
1190 std::cout<<"---++++"<<folderName<<std::endl;
1191 printRecordSpec(folder.payloadSpec());
1203
1204 SelectionCriterion selection(cool::ChannelSelection::all(),since,until);
1205
1206 if (!itsCoraCool){
1207 createLocalCopyStructure(folder, writeDb);
1208 //showResult(result);
1209 } else {
1210 std::string run1Tag = folder.folderSpec().tag;
1211 const std::string destTag = convertTagToRun2(run1Tag);
1212 std::cout<<"Destination tag "<<destTag<<std::endl;
1213
1214 if (folderNames[i]=="Chip"){
1215 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1216 const FolderSpec destFolder("/SCT/DAQ/Config/Chip",tagName);
1217 Folder target(writeDb,destFolder);
1218 writeChip(result,target,destTag);
1219 }
1220 if (folderNames[i]=="Geog"){
1221 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1222 const FolderSpec destFolder("/SCT/DAQ/Config/Geog",tagName);
1223 Folder target(writeDb,destFolder);
1224 writeGeog(result,target,destTag);
1225 }
1226 if (folderNames[i]=="MUR"){
1227 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1228 const FolderSpec destFolder("/SCT/DAQ/Config/MUR",tagName);
1229 Folder target(writeDb,destFolder);
1230 writeMUR(result,target,destTag);
1231 }
1232 if (folderNames[i]=="Module"){
1233 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1234 const FolderSpec destFolder("/SCT/DAQ/Config/Module",tagName);
1235 Folder target(writeDb,destFolder);
1236 writeModule(result,target,destTag);
1237 }
1238 if (folderNames[i]=="Channel"){
1239 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1240 const FolderSpec destFolder("/SCT/DAQ/Config/Channel",tagName);
1241 Folder target(writeDb,destFolder);
1242 writeChannel(result,target,destTag);
1243 }
1244 if (folderNames[i]=="ROD"){
1245 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1246 const FolderSpec destFolder("/SCT/DAQ/Config/ROD",tagName);
1247 Folder target(writeDb,destFolder);
1248 writeRod(result,target,destTag);
1249 }
1250 if (folderNames[i]=="RODMUR"){
1251 const CCIovVectorMap_t &result = readCC(folder,selection,nData);
1252 const FolderSpec destFolder("/SCT/DAQ/Config/RODMUR",tagName);
1253 Folder target(writeDb,destFolder);
1254 writeRodmur(result,target,destTag);
1255 }
1256 //const IovVectorMap_t &result = read(folder,selection,5);
1257 //showResult(result);
1258 }
1259 }
1260 }
1261
1262
1263
1264 return retcode;
1265}
boost::shared_ptr< CoraCoolObject > CoraCoolObjectPtr
boost::shared_ptr< CoraCoolObjectIter > CoraCoolObjectIterPtr
boost::shared_ptr< CoraCoolDatabase > CoraCoolDatabasePtr
boost::shared_ptr< CoraCoolFolder > CoraCoolFolderPtr
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t a
static Double_t ss
std::vector< std::string > splitString(const std::string &in, const std::string &delim)
AttrListVec::const_iterator const_iterator
std::vector< coral::AttributeList > AttrListVec
CoraCoolDatabasePtr coraCoolPtr() const
DbConnection(const std::string &sourceDb)
const cool::IDatabaseSvc & m_dbSvc
CoraCoolDatabasePtr m_sourceCoraPtr
cool::IDatabasePtr m_sourceDbPtr
cool::Application m_coolapp
coral::ConnectionService m_coralsvc
bool isOpen() const
cool::IDatabasePtr dbPtr() const
Folder(const DbConnection &theConnection, const FolderSpec &theFolder)
const DbConnection & m_connection
bool isValid() const
bool m_isCoraCool
CoraCoolFolderPtr m_sourceflc
const cool::IFolderPtr & ptr() const
const FolderSpec & folderSpec() const
cool::RecordSpecification foreignKeySpec()
const FolderSpec m_folderSpec
bool isSingleVersion() const
cool::RecordSpecification payloadSpec() const
specification of the payload entries
bool checkWhetherCoraCool() const
const CoraCoolFolderPtr & ccPtr() const
cool::IFolderPtr m_folderPtr
const std::string & tag() const
std::string description() const
const std::string selection
int r
Definition globals.cxx:22
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
int main()
Definition hello.cxx:18
cool::Int32 channel_t
cool::Int32 rod_t
cool::Int16 delay_t
cool::Int16 opMarkSpace_t
cool::Int32 errMask_t
cool::Int16 opCurrent_t
cool::Int16 opDelay_t
cool::Int16 threshold_t
cool::Int32 crate_t
cool::Float target_t
cool::Int16 chip_t
cool::String255 rcArgs_t
cool::Float c_t
cool::Int32 mask_t
cool::Int16 rc_t
cool::Int16 address_t
cool::String255 trim_t
cool::Int16 settings_t
cool::Int16 active_t
cool::Int16 config_t
cool::Int32 super_t
cool::Int32 medium_t
cool::Int32 MUR_t
cool::Int32 position_t
cool::Int32 MUR_t
cool::Int32 xxFibre_t
cool::Int64 moduleId_t
cool::Int32 module_t
cool::Int16 group_t
cool::Int64 id_t
cool::Int16 active_t
cool::Int16 select_t
cool::Int32 MUR_t
cool::Int16 module_t
cool::Int16 channel_t
cool::Int16 crate_t
cool::Int32 position_t
cool::Int32 rod_t
cool::Int32 MUR_t
cool::Int32 crate_t
cool::Int32 slave_t
cool::Int32 SRC_t
cool::Int32 ROB_t
cool::Int16 slot_t
cool::Int16 bcid_t
cool::Int32 crate_t
cool::Int32 id_t
cool::String255 file_t
cool::Float freq_t
cool::Int16 delay_t
cool::Int32 crate_t
cool::Int32 trigType_t
cool::Int16 runMode_t
cool::Int32 trigEnable_t
cool::Int32 bcidOffset_t
USAGE: openCoraCool.exe "COOLONL_SCT/COMP200".
cool::UChar crate_t
cool::UInt16 opDelay_t
cool::UChar channel_t
cool::UChar rod_t
cool::UInt32 errMask_t
cool::UChar opMarkSpace_t
cool::UChar opCurrent_t
cool::UChar delay_t
cool::UChar threshold_t
cool::String255 rcArgs_t
cool::Float c_t
cool::UChar settings_t
cool::UChar address_t
cool::Float target_t
cool::String255 trim_t
cool::Bool active_t
cool::UInt16 config_t
cool::UChar chip_t
cool::UChar rc_t
cool::UInt32 mask_t
cool::Int16 position_t
cool::Int16 super_t
cool::UChar medium_t
cool::UInt32 MUR_t
cool::Int64 moduleId_t
cool::UChar xxFibre_t
cool::UChar module_t
cool::UInt32 MUR_t
cool::Bool select_t
cool::Int16 group_t
cool::UInt16 chipStatus_t
cool::Bool active_t
cool::Int64 id_t
cool::UChar crate_t
cool::UChar channel_t
cool::UChar module_t
cool::UInt32 MUR_t
cool::UChar crate_t
cool::UChar position_t
cool::UChar rod_t
cool::UInt32 MUR_t
cool::Int16 bcid_t
cool::Int32 ROB_t
cool::Int32 slave_t
cool::Int32 SRC_t
cool::UChar crate_t
cool::UChar slot_t
cool::String255 file_t
cool::Int32 id_t
cool::UInt16 bcidOffset_t
cool::Float freq_t
cool::UChar runMode_t
cool::UChar crate_t
cool::UInt32 trigType_t
cool::UInt32 trigEnable_t
cool::UInt16 delay_t
Definition index.py:1
const coral::AttributeList & getAttributes(const coral::AttributeList &vectorEntry)
std::string transConn(const std::string &inconn)
void writeModule(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
IovKey_t time2RunLumi(const IovKey_t &iov)
cool::ValidityKey convertSince(const cool::ValidityKey &since)
bool inInterval(const cool::ValidityKey n, const cool::ValidityKey from, const cool::ValidityKey to)
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
cool::ValidityKey convertUntil(const cool::ValidityKey &until)
CoraCoolObject::AttrListVec readOneDatum(const CoraCoolObjectPtr &ccPtr)
std::map< IovKey_t, cool::IRecordVector > IovVectorMap_t
void writeChannel(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
void writeMUR(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
IovKey_t makeRunInterval(const cool::ValidityKey runstart, const cool::ValidityKey runend, const cool::ChannelId channelId)
void writeChip(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
std::string convertTagToRun2(const std::string &run1Tag)
cool::IFolderPtr createLocalCopyStructure(const Folder &sourceFolder, const DbConnection &writeDb, const bool forceTimestamp=false)
bool replaceTimestamp(std::string &metadata)
std::string defaultFolderPath(const bool itsCoraCool)
cool::StorageType::TypeId coral2CoolType(const std::string & coralTypeName){ std::vector<std::string>...
CCIovVectorMap_t readCC(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
std::map< IovKey_t, CoraCoolObject::AttrListVec > CCIovVectorMap_t
void setRecord(cool::Record &r, const coral::AttributeList &a, const std::string &itemName, const std::string &targetName)
IovKey_t runLumiFromTimeStamp(const IovKey_t & timeStamp){ return timeStamp; }.
void showResult(const T &theResult, const unsigned int maxShown=5)
bool isCoraCoolDescriptor(const std::string &descriptor)
void writeGeog(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
std::pair< cool::ValidityKey, cool::ValidityKey > IovPeriod_t
https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/ConditionsRun1RunNumbers 152777:1270866809,...
bool argumentsOK(const int numArgs, const char **)
void printRecordSpec(const cool::RecordSpecification &spec)
MyKey IovKey_t
void writeRod(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
void writeRodmur(const CCIovVectorMap_t &data, const Folder &destination, const std::string &tag)
const std::string tag
const std::string name
FolderSpec(const std::string &thename, const std::string &thetag)
cool::ValidityKey first
MyKey(const cool::ValidityKey &f, const cool::ValidityKey &s, const cool::ChannelId &c)
cool::ValidityKey second
bool operator<(const MyKey &rhs) const
cool::ChannelId channelId
const cool::ChannelSelection channels
const cool::ValidityKey until
SelectionCriterion(const cool::ChannelSelection &c, const cool::ValidityKey &s, const cool::ValidityKey &u)
const cool::ValidityKey since