59int main(
int argc,
char ** argv) {
61 boost::program_options::options_description
description(
"Options" );
64 (
"help,h",
"produce help message" )
65 (
"runstart,r", boost::program_options::value<uint32_t>()->default_value(0),
"run number to start IOV" )
66 (
"lbstart,l", boost::program_options::value<uint32_t>()->default_value(0),
"lumi block to start IOV" )
67 (
"runend,R", boost::program_options::value<uint32_t>()->default_value(0),
"run number to end IOV (infty if 0)" )
68 (
"lbend,L", boost::program_options::value<uint32_t>()->default_value(0),
"lumi block to end IOV (infty if 0)" )
69 (
"input,i", boost::program_options::value<std::string>()->default_value(
"calonoise.txt"),
"name of input text file" )
70 (
"output,t", boost::program_options::value<std::string>()->default_value(
""),
"name of output text file" )
71 (
"mu,,", boost::program_options::value<uint32_t>()->default_value(0),
"mu for which to fill noise" )
72 (
"dt,,", boost::program_options::value<float>()->default_value(25.),
"bunch spacing to use" )
73 (
"folder,f", boost::program_options::value<std::string>()->default_value(
"/LAR/NoiseOfl/CellNoise"),
"name of Folder" )
74 (
"tag,a", boost::program_options::value<std::string>()->default_value(
"LARNoiseOflCellNoisenoise-mc16-EposA3-ofc25mu140-25ns"),
"name of folder tag" )
75 (
"crest,C", boost::program_options::value<std::string>()->default_value(
""),
"CREST URL string for storing" )
76 (
"crestfs,c", boost::program_options::value<std::string>()->default_value(
"/tmp/crest"),
"CREST FS string for storing" )
77 (
"globalTag,g", boost::program_options::value<std::string>()->default_value(
""),
"Global tag in CREST" )
78 (
"head,H", boost::program_options::bool_switch()->default_value(
false),
"Use HEAD tag" )
79 (
"loglevel,o", boost::program_options::value<int>()->default_value(3),
"chai logLevel" )
80 (
"readonly,D", boost::program_options::bool_switch()->default_value(
false),
"Only read the DB" );
82 boost::program_options::variables_map arguments;
84 boost::program_options::store( boost::program_options::parse_command_line( argc, argv,
description ), arguments );
85 boost::program_options::notify( arguments );
87 catch ( boost::program_options::error & ex ) {
88 std::cerr << ex.what() << std::endl;
93 if ( arguments.count(
"help") ) {
94 std::cout <<
"LAr noise filling application" << std::endl;
99 chai::setLogLevel(
static_cast<chai::LogLevel
>(arguments[
"loglevel"].as<int>()));
101 std::string globalTag(arguments[
"globalTag"].as<std::string>());
102 std::string folder(arguments[
"folder"].as<std::string>());
103 std::string
ftag(arguments[
"tag"].as<std::string>());
104 bool isRead(arguments[
"readonly"].as<bool>());
105 unsigned int runs(arguments[
"runstart"].as<uint32_t>());
106 unsigned int rune=(arguments[
"runend"].as<uint32_t>()) > 0 ? arguments[
"runend"].as<uint32_t>() : UINT_MAX;
107 unsigned int lbs=(arguments[
"lbstart"].as<uint32_t>());
108 unsigned int lbe=(arguments[
"lbend"].as<uint32_t>()) > 0 ? arguments[
"lbend"].as<uint32_t>() : UINT_MAX;
109 unsigned int mu=(arguments[
"mu"].as<uint32_t>());
110 float dt=(arguments[
"dt"].as<
float>());
111 std::string server(arguments[
"crest"].as<std::string>());
112 std::string fsdir(arguments[
"crestfs"].as<std::string>());
116 std::vector<std::pair<float,float> > noisetable;
117 std::ifstream inpf(arguments[
"input"].as<std::string>());
120 unsigned int chanId, subh, igain;
121 unsigned int prevId=0;
122 float noisea=0, noiseb=0.;
123 while(inpf >> chanId >> subh >> igain >> noisea >> noiseb) {
124 if(igain != 0 || chanId <= prevId) {
125 std::cout<<
"Wrong line in input file, starting with "<<chanId<<std::endl;
128 noisetable.push_back(std::make_pair(noisea, noiseb));
132 std::cout<<
"Bad length of noise values, exiting !!"<<std::endl;
135 std::cout<<
"Read out " <<
NUM_SCELLS <<
" noise values"<<std::endl;
140 coral::Blob blob(5*
sizeof(uint32_t)+2*noisetable.size()*
sizeof(
float));
142 uint32_t* pDestination =
static_cast<uint32_t*
> (blob.startingAddress());
147 std::vector<float> gVec;
150 std::vector<std::vector<float> > defVec;
151 defVec.push_back(gVec);
152 flt->init(defVec,noisetable.size(),1);
155 for(
unsigned h=0;
h<noisetable.size(); ++
h) {
156 flt->setData(
h,0,0,noisetable[
h].first);
157 if (mu > 0 && dt > 0) {
164 flt->setData(
h,0,1,noisetable[
h].second );
169 std::string connectionString = (server.size()==0) ?
"crest_fs:" + fsdir :
"crest:" + server;
171 std::cout <<
"Connecting to: " << connectionString << std::endl << std::endl;
175 chai::Database db(connectionString);
179 if (db.getTag(
ftag)) {
182 }
catch (
const std::exception& e) {
188 std::cout <<
"Creating tag "<<
ftag << std::endl;
190 chai::PayloadSpec spec(
192 {
"CaloCondBlob16M", chai::Blob}
194 chai::ChannelSpec({ {0,
""} })
197 chai::Tag::Metadata chaiMD{
198 .iovType=chai::Tag::IovType::RunNumberLumiBlock,
199 .objectType=
"crest-json-single-iov",
200 .synchronization=chai::Tag::Synchronization::All,
201 .status=chai::Tag::Status::Unlocked,
203 chai::Tag::buildNodeDescription(
204 chai::Tag::IovType::RunNumberLumiBlock,
205 "CondAttrListCollection",
209 auto tag = db.createTag(
216 std::cout <<
"Tag created: " << tag->getName() << std::endl;
217 std::cout <<
"IOV Type: RunNumberLumiBlock" << std::endl;
221 chai::Container container(spec);
225 std::cout <<
"Container created with " << container.numChannels() <<
" channels" << std::endl;
228 std::cout <<
"Writing IOVs for selected run/lumiblock interval..." << std::endl;
233 tag->addPayload(container, since, until);
235 std::cout <<
"All IOVs written successfully!" << std::endl << std::endl;
236 }
catch (
const std::exception& e) {
237 std::cerr << std::endl <<
"Error: " << e.what() << std::endl;
246 std::cout <<
"================================================================================" << std::endl;
247 std::cout <<
"READ: Retrieving Tag and Reading Back Payloads" << std::endl;
248 std::cout <<
"================================================================================" << std::endl;
250 std::string connectionString = (server.size()==0) ?
"crest_fs:" + fsdir :
"crest:" + server;
252 std::cout <<
"Connecting to: " << connectionString << std::endl << std::endl;
254 chai::Database db(connectionString);
257 std::cout <<
"Getting tag by name "<<
ftag<<
" ..." << std::endl;
258 auto retrievedTag = db.getTag(
ftag);
259 std::cout <<
"Tag retrieved: " << retrievedTag->getName() << std::endl;
260 std::cout <<
"Description: " << retrievedTag->getDescription() << std::endl;
261 std::cout <<
"Number of IOVs: " << retrievedTag->getSize() << std::endl;
264 std::cout <<
"Iterating over IOVs and payloads..." << std::endl << std::endl;
268 if(arguments[
"output"].as<std::string>().
size()>0) onpf.open(arguments[
"output"].as<std::string>());
270 for (
const auto& iov : retrievedTag->getIovs(0)) {
271 uint64_t since = iov.getSince();
275 std::cout <<
"IOV: Run " <<
run <<
", Lumiblock " << lumiblock <<
" (encoded: " << since <<
")" << std::endl;
276 std::cout <<
" Payload hash: " << iov.getPayloadHash().substr(0, 16) <<
"..." << std::endl;
279 auto payloadContainer = retrievedTag->getPayload(iov.getPayloadHash());
281 std::cout <<
" Payload has " << payloadContainer.numChannels() <<
" channel(s)" << std::endl;
284 for (uint64_t channelId : payloadContainer.channelIds()) {
287 if(payloadContainer.hasChannel(channelId)) {
288 const auto cblob =
BlobDataToBlob(payloadContainer.get<chai::BlobData>(channelId,
"CaloCondBlob16M"));
289 std::cout <<
" Channel " << channelId <<
" size: " << cblob.size() << std::endl;
291 std::cout <<
"nGains: " << rflt->
getNGains() <<
" nChannels: " << rflt->
getNChans() << std::endl;
293 std::cout<<
h <<
" noisea: " << rflt->
getData(
h,0,0) <<
" noiseb: " << rflt->
getData(
h,0,1) << std::endl;
296 std::cout <<
" Channel " << channelId <<
" does not have data in this IOV" << std::endl;
300 std::cout <<
"Done"<<std::endl;
303 }
catch (
const std::exception& e) {
304 std::cerr << std::endl <<
"Error: " << e.what() << std::endl;