12 constexpr int BSMax[]={11,19,26};
16 const std::string
Error=
"InvalidChannel";
25 s <<
"[" << system <<
"." << subSystem <<
"." << endcap <<
"."
26 << layer <<
"." <<
phi <<
"." <<
eta <<
".0]";
37 std::istringstream s(offlineID);
45 if (s.bad())
return 0;
56 if ( system!=2 && subSystem!=1 )
return Error;
80 if (bist<10) s <<
"-B0";
82 s << bist <<
"-S0" << stav <<
"-";
84 if (
eta<=0 ) s <<
"C7";
87 if (
eta<0 ) s <<
"C6";
90 s <<
"-M" << abs(
eta);
92 if (
eta>0 ) s <<
"A";
93 else if (
eta<0) s<<
"C";
100 if (endcap>0) s <<
"A";
105 s <<
"-S0" << sector <<
"-M";
125 std::string
OnlineID(
const std::string& offlineID) {
154 std::istringstream s(onlineID);
164 if (layer<=0 || layer>
NLayer )
return 0;
176 if ( c!=
'S' )
return 0;
178 int sect{}, insect{};
182 if ( c !=
'M' )
return 0;
184 if ( insect<=0 || insect>
NinSector )
return 0;
201 if ( s.bad() || layer<0 || layer>=
NLayer )
return 0;
203 if ( c!=
'B' )
return 0;
206 s >> bist >> c >> c >> stav;
207 if ( c!=
'S' || bist<=0 || bist>
BSMax[layer] || stav<=0 || stav>2 )
209 phi=2*(bist-1)+stav-1;
227 s >> c >> c >> c >> c >> c;
228 if ( c!=
'M' )
return 0;
246 if (s.bad())
return 0;
251 int system{}, subSystem{}, endcap{}, layer{},
phi{},
eta{};
264 system = ((hashID>>29)& 0x7)+2;
265 subSystem = ((hashID>>27)& 0x3)+1;
266 endcap = ((hashID>>25)& 0x3);
267 endcap = 2*(endcap-1);
268 layer = ((hashID>>23)& 0x3);
269 phi = ((hashID>>17)&0x3f);
270 eta = ((hashID>>13)& 0xf);
277 int system{}, subSystem{}, endcap{}, layer{},
phi{},
eta{};
283 int system{}, subSystem{}, endcap{}, layer{},
phi{},
eta{};
303 endcap = (endcap+2)/2;
306 return (( system& 0x7)<<29)
307 + ((subSystem&0x3)<<27)
308 + (( endcap& 0x3)<<25)
309 + (( layer& 0x3)<<23)
316 std::string newID(
Error);
319 std::replace(
ID.begin(),
ID.end(),
'-',
'_');
321 if (
ID.at(0)==
'L' ) {
323 if ( pos!=std::string::npos ) {
325 if ( ch==
'0' )
ID.erase(pos+1,1);
331 if ( ch==
'0' ) {pos++; ch=
ID.at(pos);}
360 ID.replace(4,pos-3,newID);
366 const std::string &newID(
Error);
367 std::replace(
ID.begin(),
ID.end(),
'_',
'-');
368 if (
ID.at(0)==
'L' )
return ID;
369 std::istringstream in(
DCSID);
371 char c{}, c1{}, c2{};
372 in >> c >> dum >> c >> c >> c1 >> b >> c >> c2 >> s;
373 if ( c1!=
'B' || c2!=
'S' )
return newID;
376 if (sector==0) sector=Nsector;
377 else if (sector<0 || sector>=Nsector)
return Error;
378 int start=
ID.find(
'-',0)+1;
379 int stop =
ID.find(
'-',start);
380 stop=
ID.find(
'-',stop+1);
381 std::ostringstream out;
382 out <<
"S0" << sector;
383 ID.replace(start,stop-start,out.str());
401 std::cerr <<
"INFO: Opening data file " << filename << std::endl;
402 std::ifstream f(filename.c_str());
404 std::cerr <<
"ERROR: Cannot open data file " << filename << std::endl;
407 map.m_hashIndex = std::make_unique<PixelConvert::Map::modulemap>();
408 map.m_SNIndex = std::make_unique<PixelConvert::Map::modulemap>();
409 unsigned int hashID, SN;
413 f >> dummy >> hashID >> dummy >> dummy >> SN
414 >> dummy >> dummy >> dummy >> dummy;
417 std::cerr <<
"ERROR: error reading " << filename
418 <<
" after " <<
map.m_hashIndex->size() <<
" entries"
422 }
else if ( f.eof() )
break;
423 map.m_hashIndex->insert(std::make_pair(hashID,SN));
424 map.m_SNIndex->insert(std::make_pair(SN,hashID));
426 std::cerr <<
"INFO: end of file " << filename
427 <<
" after " <<
map.m_hashIndex->size() <<
" entries"
434 const unsigned int moduleID)
436 if ( moduleID>=510000 && moduleID<=519999 )
437 return (*
map.m_SNIndex)[moduleID];
439 return (*
map.m_hashIndex)[moduleID];
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
std::vector< Identifier > ID
Define macros for attributes used to control the static checker.
unsigned int GetID(const Map &map, const unsigned int moduleID)
int UnpackOfflineID(const std::string &offlineID, int &system, int &subSystem, int &endcap, int &layer, int &phi, int &eta)
std::string OnlineIDfromDCSID(const std::string &DCSID)
std::string DCSID(const std::string &OnlineID)
int HashID(const std::string &ID)
std::string PackOfflineID(int system, int subSystem, int endcap, int layer, int phi, int eta)
int OfflineID(const std::string &onlineID, int &system, int &subSystem, int &endcap, int &layer, int &phi, int &eta)
int ReadMap(const std::string &filename, Map &map)
std::string OnlineID(int system, int subSystem, int endcap, int layer, int phi, int eta)